From cdfb7e8abb54a64038f632e6e159269d20c2e992 Mon Sep 17 00:00:00 2001 From: amm266 Date: Thu, 11 Mar 2021 19:01:46 +0330 Subject: [PATCH] Debug attack --- Assets/Scenes/MapScene.unity | 3 +- Assets/Scripts/LogScripts/GameLogReader.cs | 8 +-- Assets/Scripts/Map/GameManager.cs | 35 ++++++++--- Assets/Scripts/PrefabScripts/AntScript.cs | 4 +- Assets/Scripts/PrefabScripts/BaseScript.cs | 73 +++++++++++++++++++++- 5 files changed, 107 insertions(+), 16 deletions(-) diff --git a/Assets/Scenes/MapScene.unity b/Assets/Scenes/MapScene.unity index 8f7a42f..360102f 100644 --- a/Assets/Scenes/MapScene.unity +++ b/Assets/Scenes/MapScene.unity @@ -676,7 +676,7 @@ Camera: m_Enabled: 1 serializedVersion: 2 m_ClearFlags: 1 - m_BackGroundColor: {r: 0.8679245, g: 0.79126555, b: 0.118725546, a: 0} + m_BackGroundColor: {r: 0.5943396, g: 0.5443024, b: 0.43454075, a: 0} m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 @@ -781,6 +781,7 @@ MonoBehaviour: y0: 0 width: 2 haight: 2 + playAnime: 0 --- !u!4 &1778195491 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/LogScripts/GameLogReader.cs b/Assets/Scripts/LogScripts/GameLogReader.cs index 8b4cc75..73309d1 100644 --- a/Assets/Scripts/LogScripts/GameLogReader.cs +++ b/Assets/Scripts/LogScripts/GameLogReader.cs @@ -91,7 +91,7 @@ private void MakeLog(string jsonStr) this.GameLog = new GameLog(map, turns); } - private void Awake() + private void Start() { try { @@ -102,8 +102,8 @@ private void Awake() else // desktop app { string jsonStr = File.ReadAllText("./test1.json"); - MakeLog(jsonStr); //TODO: must be called from UI, this is for test. ALSO don't need to inherit MonoBehaviour - GameObject.FindWithTag("GameManager").GetComponent().StartGameManager(GameLog); + MakeLog(jsonStr); + GameManager.Instance.StartGameManager(GameLog); } } catch (Exception x) @@ -115,6 +115,6 @@ private void Awake() public void WebGLSetJson(string json) { MakeLog(json); - GameObject.FindWithTag("GameManager").GetComponent().StartGameManager(GameLog); + GameManager.Instance.StartGameManager(GameLog); } } \ No newline at end of file diff --git a/Assets/Scripts/Map/GameManager.cs b/Assets/Scripts/Map/GameManager.cs index a9e5d8e..4589abe 100644 --- a/Assets/Scripts/Map/GameManager.cs +++ b/Assets/Scripts/Map/GameManager.cs @@ -23,8 +23,15 @@ public class GameManager : MonoBehaviour private Hashtable AntsTable = new Hashtable(); public int MaxTurns { get; private set; } private float baseTime; - public bool playAnime; + [HideInInspector] + private bool playAnime; + public static GameManager Instance { get; private set; } + + private void Awake() + { + Instance = this; + } public void StartGameManager(GameLog gameLog) { @@ -58,7 +65,7 @@ private void ApplyTurnUnAnim(Turn turn) { ChatManager.Instance.SetLeftChatMessages(turn.ChatBox0.Split(',')); ChatManager.Instance.SetRightChatMessages(turn.ChatBox1.Split(',')); - Debug.Log("unAnim move "+currTurn); + Debug.Log("unAnim move " + currTurn); foreach (GameObject temp in Temps) { Destroy(temp); @@ -115,18 +122,15 @@ private IEnumerator ApplyTurnAnim(Turn turn) { //new ants NewAnts.Add(ant.Id, ant); + // antObject = Instantiate(antPrefab); // antObject.GetComponent().Set(ant.Row, ant.Col, ant.Team, ant.Type, ant.Health, ant.Resource); } } - foreach (DictionaryEntry antDE in cloneAntTable) + if (playAnime) { - //dead ants - AntScript antScript = (AntScript) (antDE.Value); - StartCoroutine(antScript.die(baseTime / 2)); - } - + Debug.Log("start phase1"); foreach (DictionaryEntry antDE in NewAnts) { //new ants @@ -138,6 +142,21 @@ private IEnumerator ApplyTurnAnim(Turn turn) AntsTable.Add(antObject.Id, ant); } + foreach (Attack attack in turn.Attacks) + { + GameObject attacker = (GameObject) AntsTable[attack.AttackerId]; + attacker.GetComponent().Attack(attack.DstRow, attack.DstCol, baseTime / 2); + } + + foreach (DictionaryEntry antDE in cloneAntTable) + { + //dead ants + GameObject antScript = (GameObject) (antDE.Value); + AntsTable.Remove(antDE.Key); + StartCoroutine(antScript.GetComponent().die(baseTime / 4, baseTime / 4)); + } + + Debug.Log("end phase1"); yield return new WaitForSeconds(baseTime / 2); if (playAnime) diff --git a/Assets/Scripts/PrefabScripts/AntScript.cs b/Assets/Scripts/PrefabScripts/AntScript.cs index debba39..4d258d9 100644 --- a/Assets/Scripts/PrefabScripts/AntScript.cs +++ b/Assets/Scripts/PrefabScripts/AntScript.cs @@ -80,7 +80,7 @@ public IEnumerator Go(int x, int y, int health, int recource, float time) SetResource(recource); SetHealth(health); yield return new WaitForSeconds(baseTime / 2); - temp = gameManager.ConvertPosition(x, y); + temp = GameManager.Instance.ConvertPosition(x, y); mainAnimator.Play("Walk"); readTemp = true; reachTime = time+Time.time; @@ -117,7 +117,7 @@ public IEnumerator die(float time) private void SetPosition(int x, int y) { - transform.position = gameManager.ConvertPosition(x, y); + transform.position = GameManager.Instance.ConvertPosition(x, y); Debug.Log(transform.position); } diff --git a/Assets/Scripts/PrefabScripts/BaseScript.cs b/Assets/Scripts/PrefabScripts/BaseScript.cs index f0bcc1f..6dd99da 100644 --- a/Assets/Scripts/PrefabScripts/BaseScript.cs +++ b/Assets/Scripts/PrefabScripts/BaseScript.cs @@ -32,4 +32,75 @@ void Start() void Update() { } -} \ No newline at end of file +} +// +// +// +// +// +// +// Unity WebGL Player | AIC21-Graphic +// +// +// +// +//
+// +//
+// +//
+//
+//
+//
+// +//
+// +// +// \ No newline at end of file