From 8101e4df55fd1a3cd49e1c1e93f063a9bf9eca69 Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Mon, 13 Aug 2018 23:40:56 +0200 Subject: [PATCH 1/3] Solving bugs. --- Assets/Script/InventoryManager.cs | 25 +++++++++++++++++++++++-- Assets/Script/Mission.cs | 26 +++++++++++++++++++------- ProjectSettings/ProjectSettings.asset | 8 ++++---- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/Assets/Script/InventoryManager.cs b/Assets/Script/InventoryManager.cs index 3c354f0..7776866 100644 --- a/Assets/Script/InventoryManager.cs +++ b/Assets/Script/InventoryManager.cs @@ -63,9 +63,17 @@ public class InventoryManager : MonoBehaviour if (Input.GetKeyDown(KeyCode.R)) { ClearBoard(); - //GetComponent().GenerateMission(); GetComponent().WinUI.SetActive(false); GetComponent().UpdateMissionText(); + turnCount.text = "Turn: 01"; + } + if (Input.GetKeyDown(KeyCode.N)) + { + ClearBoard(); + GetComponent().GenerateMission(); + GetComponent().WinUI.SetActive(false); + GetComponent().UpdateMissionText(); + turnCount.text = "Turn: 01"; } } @@ -135,6 +143,18 @@ public class InventoryManager : MonoBehaviour } } + public void PlaceRandomTrees(int number) + { + for (int i = 0; i < number; i++) + { + int index = Random.Range(0, plots.Length); + if(plots[index].treePlaced == TreeType.Nothing) + index = Random.Range(0, plots.Length); + + PlaceTree(items[Random.Range(0, items.Length)], index); + } + } + private void DeleteTreeAt(int index) { Vector2Int plotPos = GetPlotPositionByIndex(index); @@ -371,7 +391,8 @@ public class InventoryManager : MonoBehaviour { for (int i = 0; i < slots.Length; i++) { - slots[i].GetComponentInChildren().text = items[i].count.ToString().Length < 10 ? ("0" + items[i].count.ToString()) : items[i].count.ToString(); + if(slots[i].GetComponentInChildren() != null) + slots[i].GetComponentInChildren().text = items[i].count.ToString().Length < 10 ? ("0" + items[i].count.ToString()) : items[i].count.ToString(); if(items[i].count == 0) slots[i].transform.GetChild(1).GetComponent().sprite = items[i].iconGris; else diff --git a/Assets/Script/Mission.cs b/Assets/Script/Mission.cs index 172575d..b840561 100644 --- a/Assets/Script/Mission.cs +++ b/Assets/Script/Mission.cs @@ -4,11 +4,20 @@ using UnityEngine; public class Mission : MonoBehaviour { - TreeItem[] items; - public float difficulte; + + public int easy; + public int hard; + + [Space] public int minDrop; - public int itemDrop; + public int maxDrop; + + [Space] + public int fewTree; + public int manyTree; + public Dictionary Objectifs = new Dictionary(); + TreeItem[] items; public GameObject WinUI; public GameObject LooseUI; private void Start() @@ -19,7 +28,7 @@ public class Mission : MonoBehaviour { Debug.Log("eroor"); } - if (difficulte> items.Length) + if (hard > items.Length) { Debug.LogError("difficulté trop grande"); } @@ -33,7 +42,8 @@ public class Mission : MonoBehaviour { public void GenerateMission() { Objectifs = new Dictionary(); - for (int i = 0; i < difficulte; i++) + int loop = Random.Range(easy, hard); + for (int i = 0; i < loop; i++) { AddTree(); } @@ -43,7 +53,9 @@ public class Mission : MonoBehaviour { mission = mission + "Place: " + i.Value + " " + i.Key.ToString() +"\n"; } + GetComponent().PlaceRandomTrees(Random.Range(fewTree, manyTree)); GiveTrees(); + GetComponent().UpdateMissionText(); } private void GiveTrees() @@ -54,7 +66,7 @@ public class Mission : MonoBehaviour { if (manager.items[i].type == TreeType.Nothing) continue; - manager.items[i].count = Random.Range(minDrop, itemDrop); + manager.items[i].count = Random.Range(minDrop, maxDrop); if (Objectifs.ContainsKey(manager.items[i].type)) { @@ -85,7 +97,7 @@ public class Mission : MonoBehaviour { { int i = Random.Range(0, trees.Length); TreeType type = trees[i].type; - int number = Random.Range(items[i].maxInstanceForWin / 2, items[i].maxInstanceForWin); + int number = Random.Range(items[i].maxInstanceForWin / 2 + 1, items[i].maxInstanceForWin); Objectifs.Add(type, number); } } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 0e98d03..7aea36f 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -113,11 +113,11 @@ PlayerSettings: vulkanEnableSetSRGBWrite: 0 vulkanUseSWCommandBuffers: 0 m_SupportedAspectRatios: - 4:3: 1 - 5:4: 1 - 16:10: 1 + 4:3: 0 + 5:4: 0 + 16:10: 0 16:9: 1 - Others: 1 + Others: 0 bundleVersion: 0.1 preloadedAssets: [] metroInputSource: 0 From 1128d85674d9ffe7047ba67cd4fa0d2c6ddf0a5d Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Tue, 14 Aug 2018 00:01:49 +0200 Subject: [PATCH 2/3] gze --- Assets/Scenes/SampleScene.unity | 9 ++++++--- Assets/Script/InventoryManager.cs | 14 +++++++++++--- ProjectSettings/GraphicsSettings.asset | 2 ++ ProjectSettings/UnityConnectSettings.asset | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 21ff52a..bc8e331 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.37311992, g: 0.38074034, b: 0.35872713, a: 1} + m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -14478,9 +14478,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b4b4a071451fb1c47af7fedbbf6a4179, type: 3} m_Name: m_EditorClassIdentifier: - difficulte: 5 + easy: 4 + hard: 8 minDrop: 1 - itemDrop: 5 + maxDrop: 10 + fewTree: 0 + manyTree: 4 WinUI: {fileID: 1264435080} LooseUI: {fileID: 1470635746} --- !u!1 &1774186325 stripped diff --git a/Assets/Script/InventoryManager.cs b/Assets/Script/InventoryManager.cs index 7776866..d29bec1 100644 --- a/Assets/Script/InventoryManager.cs +++ b/Assets/Script/InventoryManager.cs @@ -145,13 +145,21 @@ public class InventoryManager : MonoBehaviour public void PlaceRandomTrees(int number) { + TreeItem[] trees = items.Where(x => x.type != TreeType.Nothing).ToArray(); for (int i = 0; i < number; i++) { + TreeItem tree = trees[Random.Range(0, trees.Length)]; int index = Random.Range(0, plots.Length); - if(plots[index].treePlaced == TreeType.Nothing) - index = Random.Range(0, plots.Length); - PlaceTree(items[Random.Range(0, items.Length)], index); + while(!CanPlantAt(index, tree)) + { + print(index); + index++; + if (index > plots.Length) + continue; + } + + PlaceTree(tree, index); } } diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 74d7b53..9e432d1 100644 --- a/ProjectSettings/GraphicsSettings.asset +++ b/ProjectSettings/GraphicsSettings.asset @@ -35,6 +35,8 @@ GraphicsSettings: - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} diff --git a/ProjectSettings/UnityConnectSettings.asset b/ProjectSettings/UnityConnectSettings.asset index f327fe1..863581f 100644 --- a/ProjectSettings/UnityConnectSettings.asset +++ b/ProjectSettings/UnityConnectSettings.asset @@ -3,7 +3,7 @@ --- !u!310 &1 UnityConnectSettings: m_ObjectHideFlags: 0 - m_Enabled: 0 + m_Enabled: 1 m_TestMode: 0 m_TestEventUrl: m_TestConfigUrl: From e771a6f9a18bef63e91f47ecb470fdbe23380e89 Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Tue, 14 Aug 2018 00:08:47 +0200 Subject: [PATCH 3/3] Adding random tree at the begining --- Assets/Script/InventoryManager.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Assets/Script/InventoryManager.cs b/Assets/Script/InventoryManager.cs index d29bec1..685745e 100644 --- a/Assets/Script/InventoryManager.cs +++ b/Assets/Script/InventoryManager.cs @@ -153,13 +153,15 @@ public class InventoryManager : MonoBehaviour while(!CanPlantAt(index, tree)) { - print(index); index++; - if (index > plots.Length) - continue; + if (index == plots.Length) + break; } - PlaceTree(tree, index); + if (index != plots.Length) + PlaceTree(tree, index); + else + i--; } }