From 9474f2bbaaa94c5ec751d82880eea9f224909533 Mon Sep 17 00:00:00 2001 From: Raffael Di Pietro <maxou4170@gmail.com> Date: Tue, 30 Mar 2021 14:02:18 +0200 Subject: [PATCH] Mise en marche de l'ajout des shop, presque fonctionnel --- .../Prefabs/Parcelles/Raffael_boutique.prefab | 64 +++++++------------ Assets/Prefabs/Shop.prefab | 1 - Assets/Scenes/sceneRaffael.unity | 63 +++++++++++++++++- Assets/Scripts/Game/GenerateMap.cs | 54 ++++++++++++++-- Assets/Shopping.cs | 10 +-- ProjectSettings/TagManager.asset | 3 +- 6 files changed, 139 insertions(+), 56 deletions(-) diff --git a/Assets/Prefabs/Parcelles/Raffael_boutique.prefab b/Assets/Prefabs/Parcelles/Raffael_boutique.prefab index 2cc4086..779a279 100644 --- a/Assets/Prefabs/Parcelles/Raffael_boutique.prefab +++ b/Assets/Prefabs/Parcelles/Raffael_boutique.prefab @@ -3517,26 +3517,6 @@ Tilemap: m_TileObjectToInstantiateIndex: 65535 dummyAlignment: 0 m_AllTileFlags: 1073741825 - - first: {x: -1, y: 5, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 19 - m_TileSpriteIndex: 22 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - - first: {x: 0, y: 5, z: 0} - second: - serializedVersion: 2 - m_TileIndex: 20 - m_TileSpriteIndex: 21 - m_TileMatrixIndex: 0 - m_TileColorIndex: 0 - m_TileObjectToInstantiateIndex: 65535 - dummyAlignment: 0 - m_AllTileFlags: 1073741825 - first: {x: -2, y: 6, z: 0} second: serializedVersion: 2 @@ -3550,8 +3530,8 @@ Tilemap: - first: {x: -1, y: 6, z: 0} second: serializedVersion: 2 - m_TileIndex: 9 - m_TileSpriteIndex: 19 + m_TileIndex: 20 + m_TileSpriteIndex: 21 m_TileMatrixIndex: 0 m_TileColorIndex: 0 m_TileObjectToInstantiateIndex: 65535 @@ -3560,8 +3540,8 @@ Tilemap: - first: {x: 0, y: 6, z: 0} second: serializedVersion: 2 - m_TileIndex: 8 - m_TileSpriteIndex: 10 + m_TileIndex: 19 + m_TileSpriteIndex: 19 m_TileMatrixIndex: 0 m_TileColorIndex: 0 m_TileObjectToInstantiateIndex: 65535 @@ -3570,8 +3550,8 @@ Tilemap: - first: {x: 1, y: 6, z: 0} second: serializedVersion: 2 - m_TileIndex: 7 - m_TileSpriteIndex: 9 + m_TileIndex: 9 + m_TileSpriteIndex: 22 m_TileMatrixIndex: 0 m_TileColorIndex: 0 m_TileObjectToInstantiateIndex: 65535 @@ -3743,12 +3723,12 @@ Tilemap: m_Data: {fileID: 11400000, guid: faa829771b4c804488bb4841a128d575, type: 2} - m_RefCount: 1 m_Data: {fileID: 11400000, guid: b5f40bc147a7a044b95761e5022f2dc6, type: 2} + - m_RefCount: 0 + m_Data: {fileID: 0} + - m_RefCount: 0 + m_Data: {fileID: 0} - m_RefCount: 1 - m_Data: {fileID: 11400000, guid: 27e9d4653db1d15449c13a214f02059a, type: 2} - - m_RefCount: 1 - m_Data: {fileID: 11400000, guid: f546dd66cbd85da408219f5c92cfffeb, type: 2} - - m_RefCount: 1 - m_Data: {fileID: 11400000, guid: afa2be86b53242241a6b097e99243162, type: 2} + m_Data: {fileID: 11400000, guid: 0fb20351e5917f247b5861437c1b96ab, type: 2} - m_RefCount: 1 m_Data: {fileID: 11400000, guid: e599b133bfa380d48af0ab12bef4e845, type: 2} - m_RefCount: 1 @@ -3768,9 +3748,9 @@ Tilemap: - m_RefCount: 1 m_Data: {fileID: 11400000, guid: 75286aacbdac0864bbb90a78e34010fa, type: 2} - m_RefCount: 1 - m_Data: {fileID: 11400000, guid: d95a91c4370b0ce43a56ce68bc8fa4a3, type: 2} + m_Data: {fileID: 11400000, guid: 853d86edcea9f094c872f6b3b122b9e9, type: 2} - m_RefCount: 1 - m_Data: {fileID: 11400000, guid: 5ea893e194181fc44b484025c0223143, type: 2} + m_Data: {fileID: 11400000, guid: 9af6c180455b6ca4bb05d3a413627f91, type: 2} - m_RefCount: 1 m_Data: {fileID: 11400000, guid: 625d087f949b36e43a4ae1e4d472cae1, type: 2} - m_RefCount: 1 @@ -3796,10 +3776,10 @@ Tilemap: m_Data: {fileID: 354054504467944110, guid: 5af5b1d45e9216046abb1e81842d9751, type: 3} - m_RefCount: 1 m_Data: {fileID: 5753218368160464045, guid: 5af5b1d45e9216046abb1e81842d9751, type: 3} - - m_RefCount: 1 - m_Data: {fileID: 7495883842154460746, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} - - m_RefCount: 1 - m_Data: {fileID: 2024445995149103190, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} + - m_RefCount: 0 + m_Data: {fileID: 0} + - m_RefCount: 0 + m_Data: {fileID: 0} - m_RefCount: 1 m_Data: {fileID: 4512834315536321620, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} - m_RefCount: 1 @@ -3817,17 +3797,17 @@ Tilemap: - m_RefCount: 1 m_Data: {fileID: -8482321996619687844, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} - m_RefCount: 1 - m_Data: {fileID: 9182632162553372943, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} + m_Data: {fileID: 8073456348942405108, guid: 5af5b1d45e9216046abb1e81842d9751, type: 3} - m_RefCount: 1 m_Data: {fileID: -402968265167798129, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} - m_RefCount: 1 - m_Data: {fileID: 9014208036599442058, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} + m_Data: {fileID: 8626092508109733083, guid: 5af5b1d45e9216046abb1e81842d9751, type: 3} - m_RefCount: 1 - m_Data: {fileID: -6561020996012602876, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} + m_Data: {fileID: 7495883842154460746, guid: 5af5b1d45e9216046abb1e81842d9751, type: 3} - m_RefCount: 1 m_Data: {fileID: -4880669222957850763, guid: bc9976c4741c33f4ba9c2692bab5979b, type: 3} m_TileMatrixArray: - - m_RefCount: 22 + - m_RefCount: 20 m_Data: e00: 1 e01: 0 @@ -3846,7 +3826,7 @@ Tilemap: e32: 0 e33: 1 m_TileColorArray: - - m_RefCount: 22 + - m_RefCount: 20 m_Data: {r: 1, g: 1, b: 1, a: 1} m_TileObjectToInstantiateArray: [] m_AnimationFrameRate: 1 diff --git a/Assets/Prefabs/Shop.prefab b/Assets/Prefabs/Shop.prefab index 4385bb0..adce329 100644 --- a/Assets/Prefabs/Shop.prefab +++ b/Assets/Prefabs/Shop.prefab @@ -160,6 +160,5 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b0d67e78638d146bd8a6878c5027f9c5, type: 3} m_Name: m_EditorClassIdentifier: - inventory: {fileID: 0} sellItem: {fileID: 0} itemForSale: [] diff --git a/Assets/Scenes/sceneRaffael.unity b/Assets/Scenes/sceneRaffael.unity index 3effd3c..b62682e 100644 --- a/Assets/Scenes/sceneRaffael.unity +++ b/Assets/Scenes/sceneRaffael.unity @@ -7156,6 +7156,36 @@ Tilemap: e31: 0 e32: 0 e33: 1 +--- !u!1 &1466266818 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1466266819} + m_Layer: 0 + m_Name: Chaussures_border + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1466266819 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1466266818} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1562290020} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1556478809 GameObject: m_ObjectHideFlags: 0 @@ -7200,6 +7230,37 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1562290019 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1562290020} + m_Layer: 0 + m_Name: Borders + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1562290020 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1562290019} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 13.907721, y: 53.40872, z: 24.306696} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 1466266819} + m_Father: {fileID: 0} + m_RootOrder: 7 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1636778422 GameObject: m_ObjectHideFlags: 0 @@ -41855,7 +41916,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2041949052} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -14.23, y: 38.66, z: -10} + m_LocalPosition: {x: -11.13, y: 39.12, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} diff --git a/Assets/Scripts/Game/GenerateMap.cs b/Assets/Scripts/Game/GenerateMap.cs index 019dcc6..cb3de94 100644 --- a/Assets/Scripts/Game/GenerateMap.cs +++ b/Assets/Scripts/Game/GenerateMap.cs @@ -4,14 +4,23 @@ using UnityEngine; public class GenerateMap : MonoBehaviour { + public Item chaussures; + public Item baton; + public Item rechaud; + public Item tente; + + public GameObject GO_chaussures; + public GameObject GO_baton; + public GameObject GO_rechaud; + public GameObject GO_tente; public List<GameObject> pVillage = new List<GameObject>(); public List<GameObject> pBoutique = new List<GameObject>(); public List<GameObject> pUsine = new List<GameObject>(); public int nb_of_plot = 8; - public Object[,] plot=new Object[3,3]; - public int where; + + //Les coordonées x dans l'ordre private int[] xs=new int[]{-17,0,17}; //colonne @@ -36,28 +45,61 @@ public class GenerateMap : MonoBehaviour { for(int y = 0; y<ys.Length; y++) { - plot[x,y] = Instantiate(pVillage[Random.Range(0, pVillage.Count)], new Vector3(xs[x], ys[y], 0), Quaternion.identity); + if(!(x==2 && y==2)) + plot[x,y] = Instantiate(pVillage[Random.Range(0, pVillage.Count)], new Vector3(xs[x], ys[y], 0), Quaternion.identity); } } } - public void generateBoutique(int column, int line) + public void generateBoutique(int column, int line, string objetVente) { Destroy(plot[column, line]); - plot[column, line] = Instantiate(pBoutique[Random.Range(0, pBoutique.Count)], new Vector3(xs[column], ys[line], 0), Quaternion.identity); + + Item itemToSell = null; + GameObject goToSell = null; + switch (objetVente) + { + case "chaussure": + itemToSell = chaussures; + goToSell = GO_chaussures; + break; + case "baton": + itemToSell = baton; + goToSell = GO_baton; + break; + case "réchaud": + itemToSell = rechaud; + goToSell = GO_rechaud; + break; + case "tente": + itemToSell = tente; + goToSell = GO_tente; + break; + } + if (itemToSell && goToSell) + { + GameObject shop = Instantiate(pBoutique[Random.Range(0, pBoutique.Count)], new Vector3(xs[column], ys[line], 0), Quaternion.identity); + + shop.transform.Find("Shop").gameObject.GetComponent<Shopping>().sellItem = itemToSell; + shop.transform.Find("Shop").gameObject.GetComponent<Shopping>().itemForSale.Add(goToSell); + plot[column, line] = shop; + } + else + Debug.LogError("Mauvais paramètre pour objetVente"); } public void generateUsine(int column, int line) { Destroy(plot[column, line]); plot[column, line] = Instantiate(pUsine[Random.Range(0, pUsine.Count)], new Vector3(xs[column], ys[line], 0), Quaternion.identity); + } public void generateBoutiqueTest() { // COLONNE, LIGNE - generateBoutique(0, 0); + generateBoutique(0, 0, "chaussure"); generateUsine(1, 0); } diff --git a/Assets/Shopping.cs b/Assets/Shopping.cs index 02688f5..a978ea9 100644 --- a/Assets/Shopping.cs +++ b/Assets/Shopping.cs @@ -5,9 +5,9 @@ using UnityEngine; public class Shopping : MonoBehaviour { private bool playerInRange; - public Inventory inventory; - public Item sellItem; - public GameObject[] itemForSale; + public Item sellItem = null; + //public GameObject[] itemForSale = new GameObject[2]; + public List<GameObject> itemForSale = new List<GameObject>(); // Start is called before the first frame update void Start() @@ -18,10 +18,10 @@ public class Shopping : MonoBehaviour // Update is called once per frame void Update() { - if (Input.GetKeyDown(KeyCode.E) && playerInRange) + if (Input.GetKeyDown(KeyCode.E) && playerInRange && sellItem && itemForSale.Count>0) { Dialog.instance.setSituation("Marchand"); - inventory.addItem(sellItem); + Inventory.instance.addItem(sellItem); Destroy(itemForSale[0]); Debug.Log(sellItem.name.ToString() + " a bien ete ajouté a l'inventaire"); } diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index e3d9edb..daa2006 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -3,7 +3,8 @@ --- !u!78 &1 TagManager: serializedVersion: 2 - tags: [] + tags: + - Shop layers: - Default - TransparentFX -- GitLab