From 55d6feae556de4149c34ec2b1f18ed5f9957e766 Mon Sep 17 00:00:00 2001 From: Saibotk Date: Mon, 23 Apr 2018 14:59:34 +0200 Subject: [PATCH] Add / Implement FinishObjective --- Assets/Prefabs/UI.prefab | 2 +- Assets/Scenes/CodeDEV.unity | 32 +--------------- Assets/Scripts/Door.cs | 6 ++- Assets/Scripts/GameController.cs | 37 +++++++++++++++---- Assets/Scripts/Objectives/FinishObjective.cs | 23 ++++++++++++ .../Objectives/FinishObjective.cs.meta | 11 ++++++ Assets/Scripts/Room.cs | 12 +++--- Assets/Scripts/UIController.cs | 2 +- .../Entities/Enemies/scorpion.png.meta | 2 +- Assets/graphics/textures/car.meta | 8 ---- Assets/graphics/textures/tmp.meta | 8 ---- 11 files changed, 79 insertions(+), 64 deletions(-) create mode 100644 Assets/Scripts/Objectives/FinishObjective.cs create mode 100644 Assets/Scripts/Objectives/FinishObjective.cs.meta delete mode 100644 Assets/graphics/textures/car.meta delete mode 100644 Assets/graphics/textures/tmp.meta diff --git a/Assets/Prefabs/UI.prefab b/Assets/Prefabs/UI.prefab index a011cfe..8a875ee 100644 --- a/Assets/Prefabs/UI.prefab +++ b/Assets/Prefabs/UI.prefab @@ -1059,7 +1059,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 66.396866, y: 0} + m_AnchoredPosition: {x: 64.16286, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 1, y: 0.5} --- !u!224 &224218339018349506 diff --git a/Assets/Scenes/CodeDEV.unity b/Assets/Scenes/CodeDEV.unity index 78c917d..d1fe0d9 100644 --- a/Assets/Scenes/CodeDEV.unity +++ b/Assets/Scenes/CodeDEV.unity @@ -497,17 +497,6 @@ Prefab: propertyPath: m_IsActive value: 0 objectReference: {fileID: 0} - - target: {fileID: 114835806183609276, guid: 3d1911457c1e44f53b6b4044334db52f, - type: 2} - propertyPath: bulletSpawn - value: - objectReference: {fileID: 2032758561} - - target: {fileID: 114835806183609276, guid: 3d1911457c1e44f53b6b4044334db52f, - type: 2} - propertyPath: bulletPrefab - value: - objectReference: {fileID: 1379543051791382, guid: c6c321ecc6516374781405a54c1fa6a7, - type: 2} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 3d1911457c1e44f53b6b4044334db52f, type: 2} m_IsPrefabParent: 0 @@ -851,7 +840,7 @@ Prefab: - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} propertyPath: m_AnchoredPosition.x - value: 66.396866 + value: 67.14285 objectReference: {fileID: 0} - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} @@ -883,15 +872,6 @@ Prefab: propertyPath: m_SizeDelta.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 1604998495297016, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} - propertyPath: m_Name - value: RestartPanel - objectReference: {fileID: 0} - - target: {fileID: 114917026543374048, guid: 460d856ea4eb14cedb5fecde1fe6d743, - type: 2} - propertyPath: restartUIPanel - value: - objectReference: {fileID: 1755791938} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} m_IsPrefabParent: 0 @@ -1094,11 +1074,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1755791938 stripped -GameObject: - m_PrefabParentObject: {fileID: 1604998495297016, guid: 460d856ea4eb14cedb5fecde1fe6d743, - type: 2} - m_PrefabInternal: {fileID: 1379476068} --- !u!1 &1908750961 GameObject: m_ObjectHideFlags: 0 @@ -1224,11 +1199,6 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 ---- !u!4 &2032758561 stripped -Transform: - m_PrefabParentObject: {fileID: 4676354101874032, guid: 3d1911457c1e44f53b6b4044334db52f, - type: 2} - m_PrefabInternal: {fileID: 865504979} --- !u!1 &2063368131 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Door.cs b/Assets/Scripts/Door.cs index b403079..a47cee7 100644 --- a/Assets/Scripts/Door.cs +++ b/Assets/Scripts/Door.cs @@ -67,9 +67,11 @@ public class Door : MonoBehaviour { if ( collision.tag == "Player") { // TODO better checks Debug.Log("Leaving Trigger"); - if (parent != null) { - parent.OnPlayerEnter(collision.gameObject.GetComponent()); + if(parent == null) { + Debug.Log("This door has no parent Room!"); + return; } + parent.OnPlayerEnter(collision.gameObject.GetComponent()); } } } diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index 6332d2d..83e6bce 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -9,6 +9,10 @@ public class GameController : MonoBehaviour { private Room start; private Room finish; + public enum EndedCause { + WIN, DIED + } + // Generation Settings [Header("Tile Prefabs")] [SerializeField] @@ -82,7 +86,7 @@ public class GameController : MonoBehaviour { } public enum GameState { UNSET, INIT, STARTING, RUNNING, ENDED }; - + private EndedCause endCause = EndedCause.DIED; private GameState state = GameState.UNSET; // Use this for initialization @@ -193,8 +197,11 @@ public class GameController : MonoBehaviour { doorRootf.name = "Doors"; doorRootf.transform.SetParent(goFinish.transform); ltf = ltf.FindAll(x => x.tag == "door"); - ltf.ForEach(x => x.SetParent(doorRootf.transform)); finish = goFinish.AddComponent(); + ltf.ForEach(x => { + x.SetParent(doorRootf.transform); + x.gameObject.GetComponent().SetParent(finish); + }); finish.SetDoorsRootObject(doorRootf); finish.Reload(); finish.transform.SetParent(mapRoot.transform); @@ -206,9 +213,13 @@ public class GameController : MonoBehaviour { GameObject doorRootg = new GameObject(); doorRootg.name = "Doors"; doorRootg.transform.SetParent(groom.transform); - ltg = ltg.FindAll(x => x.tag == "door"); - ltg.ForEach(x => x.SetParent(doorRootg.transform)); Room grom = groom.AddComponent(); + ltg = ltg.FindAll(x => x.tag == "door"); + ltg.ForEach(x => { + x.SetParent(doorRootg.transform); + x.gameObject.GetComponent().SetParent(grom); + }); + grom.SetDoorsRootObject(doorRootg); grom.Reload(); groom.transform.SetParent(mapRoot.transform); @@ -232,6 +243,7 @@ public class GameController : MonoBehaviour { } else { Debug.Log("No Player spawned!"); } + finish.SetObjective(new FinishObjective(finish)); } private void Running() { @@ -242,9 +254,15 @@ public class GameController : MonoBehaviour { Debug.Log("Game ended"); //Time.timeScale = 0; if ( ui != null ) { - Debug.Log("show Gameover UI"); - cam.GetComponent().SfxPlay(2); - ui.GetComponent().ShowGameOverUI(); + Debug.Log("show end UI"); + if(endCause == EndedCause.DIED) { + cam.GetComponent().SfxPlay(2); + ui.GetComponent().ShowGameOverUI(); + } else if(endCause == EndedCause.WIN) { + //cam.GetComponent().SfxPlay(2); + ui.GetComponent().ShowWinUI(); + } + } else { Debug.Log("No UI specified"); } @@ -261,4 +279,9 @@ public class GameController : MonoBehaviour { public bool GameEnded() { return state == GameState.ENDED; } + + public void EndGame(EndedCause cause) { + endCause = cause; + ChangeState(GameState.ENDED); + } } diff --git a/Assets/Scripts/Objectives/FinishObjective.cs b/Assets/Scripts/Objectives/FinishObjective.cs new file mode 100644 index 0000000..4a309b5 --- /dev/null +++ b/Assets/Scripts/Objectives/FinishObjective.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FinishObjective : Objective { + + public FinishObjective(Room caller) : base(caller) { } + + public override void ActivateGoal(Player player) { + // Player reached the end => win + base.ActivateGoal(player); + UpdateGoal(); + } + + public override void UpdateGoal() { + ReachedGoal(); + } + + protected override void ReachedGoal() { + base.ReachedGoal(); + GameController.instance.EndGame(GameController.EndedCause.WIN); + } +} diff --git a/Assets/Scripts/Objectives/FinishObjective.cs.meta b/Assets/Scripts/Objectives/FinishObjective.cs.meta new file mode 100644 index 0000000..23c11d0 --- /dev/null +++ b/Assets/Scripts/Objectives/FinishObjective.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 409e13e4d4aa55c4fa47137e828d465c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Room.cs b/Assets/Scripts/Room.cs index 2e28e84..825cd8c 100644 --- a/Assets/Scripts/Room.cs +++ b/Assets/Scripts/Room.cs @@ -114,14 +114,16 @@ public class Room : MonoBehaviour { /// /// public void OnPlayerEnter(Player player) { - if ( objective != null && objective.GetFinished() ) { + if(objective == null) { + Debug.Log("[ROOMS] This Room has no objective!"); + return; + } + if ( objective.GetFinished() ) { Debug.Log("[ROOMS] This room has been cleared already."); return; } - if ( objective != null ) { - Debug.Log("[ROOMS] Player activated Objective"); - objective.ActivateGoal(player); - } + Debug.Log("[ROOMS] Player activated Objective"); + objective.ActivateGoal(player); } /// diff --git a/Assets/Scripts/UIController.cs b/Assets/Scripts/UIController.cs index 6cc50fa..fc7d031 100644 --- a/Assets/Scripts/UIController.cs +++ b/Assets/Scripts/UIController.cs @@ -60,7 +60,7 @@ public class UIController : MonoBehaviour string headerText = won ? "You won!" : "Game Over"; if (restartUIPanel != null) { restartUIPanel.SetActive(true); - restartUIPanel.GetComponent().text = headerText; + restartUIPanel.GetComponentInChildren().text = headerText; } else { Debug.Log("No restart panel assigned"); } diff --git a/Assets/graphics/textures/Entities/Enemies/scorpion.png.meta b/Assets/graphics/textures/Entities/Enemies/scorpion.png.meta index 25a4127..1800392 100644 --- a/Assets/graphics/textures/Entities/Enemies/scorpion.png.meta +++ b/Assets/graphics/textures/Entities/Enemies/scorpion.png.meta @@ -29,7 +29,7 @@ TextureImporter: maxTextureSize: 2048 textureSettings: serializedVersion: 2 - filterMode: 0 + filterMode: 1 aniso: -1 mipBias: -1 wrapU: 1 diff --git a/Assets/graphics/textures/car.meta b/Assets/graphics/textures/car.meta deleted file mode 100644 index 8504594..0000000 --- a/Assets/graphics/textures/car.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 9ec323b9157704d00a3409f8ea6e46b2 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/graphics/textures/tmp.meta b/Assets/graphics/textures/tmp.meta deleted file mode 100644 index 7ebab68..0000000 --- a/Assets/graphics/textures/tmp.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: df6e7833427b5497b92308fb6f54e552 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: