From 5a01e45f0cc048265c38c60d2693c9f3e4bf532f Mon Sep 17 00:00:00 2001 From: Saibotk Date: Sun, 22 Apr 2018 19:43:29 +0200 Subject: [PATCH] Added comments to unfinished code | Tile tags changed | WIP Spawnpoint --- Assets/Prefabs/Tiles/door.prefab | 41 +++++- Assets/Prefabs/Tiles/ground.prefab | 26 ---- Assets/Prefabs/Tiles/wallCornerIn.prefab | 2 +- Assets/Prefabs/Tiles/wallCornerOut.prefab | 2 +- Assets/Prefabs/Tiles/wallSide.prefab | 2 +- Assets/Scripts/Door.cs | 27 ++-- Assets/Scripts/Entities/Player.cs | 1 + Assets/Scripts/GameController.cs | 78 +++++++++-- Assets/Scripts/Generation/DungeonGenerator.cs | 42 +++--- Assets/Scripts/Generation/GenRoom.cs | 6 +- Assets/Scripts/NotificationManager.cs | 124 +++++++++--------- Assets/Scripts/Objectives/StartObjective.cs | 2 - Assets/Scripts/Room.cs | 9 +- 13 files changed, 217 insertions(+), 145 deletions(-) diff --git a/Assets/Prefabs/Tiles/door.prefab b/Assets/Prefabs/Tiles/door.prefab index ebe38c6..7a5ed7e 100644 --- a/Assets/Prefabs/Tiles/door.prefab +++ b/Assets/Prefabs/Tiles/door.prefab @@ -21,9 +21,11 @@ GameObject: - component: {fileID: 4704489882212962} - component: {fileID: 212166467098511970} - component: {fileID: 61866627210428188} + - component: {fileID: 114053119853995034} + - component: {fileID: 61243635969098510} m_Layer: 0 m_Name: door - m_TagString: Untagged + m_TagString: door m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -41,6 +43,31 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!61 &61243635969098510 +BoxCollider2D: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1065161683117842} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1, y: 1} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 --- !u!61 &61866627210428188 BoxCollider2D: m_ObjectHideFlags: 1 @@ -66,6 +93,18 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 1, y: 1} m_EdgeRadius: 0 +--- !u!114 &114053119853995034 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1065161683117842} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8b8cc30ac6e59724bba6536a17fbf027, type: 3} + m_Name: + m_EditorClassIdentifier: + parent: {fileID: 0} --- !u!212 &212166467098511970 SpriteRenderer: m_ObjectHideFlags: 1 diff --git a/Assets/Prefabs/Tiles/ground.prefab b/Assets/Prefabs/Tiles/ground.prefab index 93514d6..21274bf 100644 --- a/Assets/Prefabs/Tiles/ground.prefab +++ b/Assets/Prefabs/Tiles/ground.prefab @@ -20,7 +20,6 @@ GameObject: m_Component: - component: {fileID: 4167595944037000} - component: {fileID: 212910617741009226} - - component: {fileID: 61790205413884498} m_Layer: 0 m_Name: ground m_TagString: Untagged @@ -41,31 +40,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!61 &61790205413884498 -BoxCollider2D: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1487413182883822} - m_Enabled: 1 - m_Density: 1 - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_UsedByEffector: 0 - m_UsedByComposite: 0 - m_Offset: {x: 0, y: 0} - m_SpriteTilingProperty: - border: {x: 0, y: 0, z: 0, w: 0} - pivot: {x: 0.5, y: 0.5} - oldSize: {x: 1, y: 1} - newSize: {x: 1, y: 1} - adaptiveTilingThreshold: 0.5 - drawMode: 0 - adaptiveTiling: 0 - m_AutoTiling: 0 - serializedVersion: 2 - m_Size: {x: 1, y: 1} - m_EdgeRadius: 0 --- !u!212 &212910617741009226 SpriteRenderer: m_ObjectHideFlags: 1 diff --git a/Assets/Prefabs/Tiles/wallCornerIn.prefab b/Assets/Prefabs/Tiles/wallCornerIn.prefab index f1cb53d..d9b1ed0 100644 --- a/Assets/Prefabs/Tiles/wallCornerIn.prefab +++ b/Assets/Prefabs/Tiles/wallCornerIn.prefab @@ -23,7 +23,7 @@ GameObject: - component: {fileID: 61976448807984186} m_Layer: 0 m_Name: wallCornerIn - m_TagString: Untagged + m_TagString: wall m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Prefabs/Tiles/wallCornerOut.prefab b/Assets/Prefabs/Tiles/wallCornerOut.prefab index 7ebc18c..e4fb918 100644 --- a/Assets/Prefabs/Tiles/wallCornerOut.prefab +++ b/Assets/Prefabs/Tiles/wallCornerOut.prefab @@ -23,7 +23,7 @@ GameObject: - component: {fileID: 61112856149238616} m_Layer: 0 m_Name: wallCornerOut - m_TagString: Untagged + m_TagString: wall m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Prefabs/Tiles/wallSide.prefab b/Assets/Prefabs/Tiles/wallSide.prefab index 4c8db15..35b43ef 100644 --- a/Assets/Prefabs/Tiles/wallSide.prefab +++ b/Assets/Prefabs/Tiles/wallSide.prefab @@ -23,7 +23,7 @@ GameObject: - component: {fileID: 61106583680129832} m_Layer: 0 m_Name: wallSide - m_TagString: Untagged + m_TagString: wall m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Scripts/Door.cs b/Assets/Scripts/Door.cs index 458af3d..9205fc9 100644 --- a/Assets/Scripts/Door.cs +++ b/Assets/Scripts/Door.cs @@ -1,11 +1,8 @@ using UnityEngine; - +[RequireComponent(typeof(SpriteRenderer))] public class Door : MonoBehaviour { private bool locked = false; - [SerializeField] - GameObject graphics; - [SerializeField] Room parent; @@ -18,15 +15,23 @@ public class Door : MonoBehaviour { foreach ( BoxCollider2D collider in colliders ) { if ( collider.isTrigger ) { triggerBox = collider; - Debug.Log("Found Door trigger"); + //Debug.Log("Found Door trigger"); } else { boundingBox = collider; - Debug.Log("Found Door collider"); + //Debug.Log("Found Door collider"); } } Unlock(); } + /// + /// Sets the parent Room Object reference. + /// + /// + public void SetParent(Room room) { + this.parent = room; + } + /// /// Locks the door. /// @@ -34,7 +39,7 @@ public class Door : MonoBehaviour { locked = true; boundingBox.enabled = true; triggerBox.enabled = false; - graphics.GetComponent().enabled = true; + GetComponent().enabled = true; } /// @@ -44,7 +49,7 @@ public class Door : MonoBehaviour { locked = false; boundingBox.enabled = false; triggerBox.enabled = true; - graphics.GetComponent().enabled = false; + GetComponent().enabled = false; } /// @@ -60,10 +65,12 @@ public class Door : MonoBehaviour { /// /// private void OnTriggerExit2D(Collider2D collision) { - if ( collision.tag == "Player" ) { + if ( collision.tag == "Player") { // TODO better checks Debug.Log("Leaving Trigger"); - parent.OnPlayerEnter(collision.gameObject.GetComponent()); + if (parent != null) { + parent.OnPlayerEnter(collision.gameObject.GetComponent()); + } } } } diff --git a/Assets/Scripts/Entities/Player.cs b/Assets/Scripts/Entities/Player.cs index 36d190d..f551ed0 100644 --- a/Assets/Scripts/Entities/Player.cs +++ b/Assets/Scripts/Entities/Player.cs @@ -27,6 +27,7 @@ public class Player : Mob { /// This is called when a Player died. /// protected override void Death() { + Debug.Log("Player died..."); Destroy(this.gameObject); GameController.instance.ChangeState(GameController.GameState.ENDED); } diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index e733e5c..6577de9 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -4,10 +4,8 @@ using UnityEngine; public class GameController : MonoBehaviour { - [SerializeField] - GameObject playerPrefab; - [SerializeField] + private Room start; private Room finish; @@ -58,14 +56,24 @@ public class GameController : MonoBehaviour { private Dictionary genPrefabs; + [Space(10)] + [Header("References")] + + [SerializeField] + private GameObject playerPrefab; + [SerializeField] private GameObject ui; [SerializeField] private GameObject cam; + [SerializeField] + private GameObject mapRoot; + private bool engineInitDone; private Player player; + public static GameController instance; public GameController() { instance = this; @@ -146,23 +154,67 @@ public class GameController : MonoBehaviour { DungeonGenerator dg = new DungeonGenerator(); GenerationProcessor gp = new GenerationProcessor(genPrefabs); dg.Generate(); + + // Start room GameObject goStart = gp.ProcessRoom(dg.start.tiles); + goStart.name = "Start"; + List lt = new List(goStart.GetComponentsInChildren()); + GameObject doorRoot = new GameObject(); + doorRoot.name = "Doors"; + doorRoot.transform.SetParent(goStart.transform); start = goStart.AddComponent(); - //start.SetDoorsRootObject(new List(goStart.GetComponentsInChildren()).Find(x => x.tag == "DoorRoot").gameObject); + lt = lt.FindAll(x => x.tag == "door"); + lt.ForEach(x => { + x.SetParent(doorRoot.transform); + x.gameObject.GetComponent().SetParent(start); + }); + start.SetDoorsRootObject(doorRoot); + + // WIP + GameObject spawnpointRoot = new GameObject(); + spawnpointRoot.name = "Spawnpoints"; + spawnpointRoot.transform.SetParent(goStart.transform); + spawnpointRoot.transform.position = new Vector3(dg.start.roomPosition.x, dg.start.roomPosition.y, 0); + GameObject spawn = new GameObject(); + spawn.transform.SetParent(spawnpointRoot.transform); + spawn.transform.position = new Vector3(3, 3, 0); + start.SetSpawnPointsRootObject(spawnpointRoot); + start.Reload(); start.transform.SetParent(mapRoot.transform); + + // Finish room GameObject goFinish = gp.ProcessRoom(dg.end.tiles); + goFinish.name = "Finish"; + List ltf = new List(goFinish.GetComponentsInChildren()); + GameObject doorRootf = new GameObject(); + 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(); - //finish.SetDoorsRootObject(new List(goFinish.GetComponentsInChildren()).Find(x => x.tag == "DoorRoot").gameObject); + finish.SetDoorsRootObject(doorRootf); finish.Reload(); finish.transform.SetParent(mapRoot.transform); + + // Other Rooms foreach (GenRoom gr in dg.rooms) { GameObject groom = gp.ProcessRoom(gr.tiles); - groom.AddComponent(); + List ltg = new List(groom.GetComponentsInChildren()); + 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(); + grom.SetDoorsRootObject(doorRootg); + grom.Reload(); groom.transform.SetParent(mapRoot.transform); } + // Hallways GameObject goHallways = gp.ProcessRoom(dg.path.tiles); + goHallways.name = "Hallways"; goHallways.AddComponent(); goHallways.transform.SetParent(mapRoot.transform); } @@ -172,11 +224,11 @@ public class GameController : MonoBehaviour { start.SetObjective(goal); start.OnPlayerEnter(player); player = goal.GetPlayer(); - cam.GetComponent().SetFollow(player.gameObject); - } - - private void Starting() { - + if ( player != null ) { + cam.GetComponent().SetFollow(player.gameObject); + } else { + Debug.Log("No Player spawned!"); + } } private void Running() { @@ -187,10 +239,10 @@ public class GameController : MonoBehaviour { Debug.Log("Game ended"); //Time.timeScale = 0; if ( ui != null ) { - Debug.Log("show gameover UI"); + Debug.Log("show Gameover UI"); ui.GetComponent().ShowGameOverUI(); } else { - Debug.Log("No ui specified"); + Debug.Log("No UI specified"); } } diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 8dd1d8c..73dc8da 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -17,7 +17,7 @@ public class DungeonGenerator { // All rooms except the three above public HashSet rooms; - private const float percentageRocks = 0.03; + private const float percentageRocks = 0.03f; private const int maxRockCluster = 5; public void Generate() { @@ -355,30 +355,30 @@ public class DungeonGenerator { public static void generateInterior(GenRoom r) { - int width = r.bounds.width; - int height = r.bounds.height; + //int width = r.bounds.width; + //int height = r.bounds.height; - Vector2Int root = new Vector2Int (1, 1); - Random rand = new Random (System.DateTime.Now); + //Vector2Int root = new Vector2Int (1, 1); + //Random rand = new Random (System.DateTime.Now); - for(int x = 0; i != width; ++x) - { - for(int y = 0; y != width; ++y) - { - Room.TileType tempTile; - r.tiles.TryGetValue (root + new Vector2Int (x, y), tempTile); + //for(int x = 0; i != width; ++x) + //{ + // for(int y = 0; y != width; ++y) + // { + // Room.TileType tempTile; + // r.tiles.TryGetValue (root + new Vector2Int (x, y), tempTile); - if(rand.NextDouble() <= percentageRocks && tempTile.Equals(Room.TileType.GROUND) - { - int clusterSize = rand.Next (1, maxRockCluster + 1); - r.tiles.Add (root + new Vector2Int (x, y), Room.TileType.ROCK); + // if(rand.NextDouble() <= percentageRocks && tempTile.Equals(Room.TileType.GROUND) + // { + // int clusterSize = rand.Next (1, maxRockCluster + 1); + // r.tiles.Add (root + new Vector2Int (x, y), Room.TileType.ROCK); - for(int i = 0; i != clusterSize; ++i) - { - Vector2Int newRock = root + new Vector2Int(x + rand.Next(0, 2), y + rand.Next(0, 2)); - r.tiles.TryGetValue (newRock, tempTile); - if(!tempTile.Equals(Room.TileType.GROUND)) - break; + // for(int i = 0; i != clusterSize; ++i) + // { + // Vector2Int newRock = root + new Vector2Int(x + rand.Next(0, 2), y + rand.Next(0, 2)); + // r.tiles.TryGetValue (newRock, tempTile); + // if(!tempTile.Equals(Room.TileType.GROUND)) + // break; diff --git a/Assets/Scripts/Generation/GenRoom.cs b/Assets/Scripts/Generation/GenRoom.cs index c4a4d7f..3cab794 100644 --- a/Assets/Scripts/Generation/GenRoom.cs +++ b/Assets/Scripts/Generation/GenRoom.cs @@ -36,7 +36,7 @@ public class GenRoom { return ret; } - public void generateInteror() - { - b + public void generateInteror() { + + } } \ No newline at end of file diff --git a/Assets/Scripts/NotificationManager.cs b/Assets/Scripts/NotificationManager.cs index cc5e574..c770c2c 100644 --- a/Assets/Scripts/NotificationManager.cs +++ b/Assets/Scripts/NotificationManager.cs @@ -1,66 +1,66 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -public class NotificationManager : MonoBehaviour { - - - List messages; - bool showingMessage; - float delay; - Text text; - - class Notification { - string text; - float duration; - - public Notification(string text, float duration) { - this.text = text; - this.duration = duration; - } - - public string getText() { - return text; - } - - public float getDuration() { - return duration; - } - } - - // Use this for initialization - void Start () { - delay = 0; - showingMessage = false; - messages = new List(); - text = GetComponent(); - } +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; - void Update() { - if (showingMessage) { - if (Time.time > delay) { - if (messages.Count == 1) { - GetComponentInParent().enabled = false; - messages.Remove(messages[0]); - showingMessage = false; - } else { - text.text = messages[0].getText(); - delay = Time.time + messages[0].getDuration(); - } - } +public class NotificationManager : MonoBehaviour { + + + List messages; + bool showingMessage; + float delay; + Text text; + + class Notification { + string text; + float duration; + + public Notification(string text, float duration) { + this.text = text; + this.duration = duration; } - } - public void showMessage(string text, float duration) { - if (showingMessage) { - messages.Add(new Notification(text, duration)); - } else { - showingMessage = true; + public string getText() { + return text; + } - GetComponent().text = text; - delay = Time.time + duration; - GetComponentInParent().enabled = true; - } - } -} + public float getDuration() { + return duration; + } + } + + // Use this for initialization + void Start() { + delay = 0; + showingMessage = false; + messages = new List(); + text = GetComponent(); + } + + void Update() { + if ( showingMessage ) { + if ( Time.time > delay ) { + if ( messages.Count == 1 ) { + GetComponentInParent().enabled = false; + messages.Remove(messages[0]); + showingMessage = false; + } else { + text.text = messages[0].getText(); + delay = Time.time + messages[0].getDuration(); + } + } + } + } + + public void showMessage(string text, float duration) { + if ( showingMessage ) { + messages.Add(new Notification(text, duration)); + } else { + showingMessage = true; + + GetComponent().text = text; + delay = Time.time + duration; + GetComponentInParent().enabled = true; + } + } +} diff --git a/Assets/Scripts/Objectives/StartObjective.cs b/Assets/Scripts/Objectives/StartObjective.cs index a799bd9..e7678b1 100644 --- a/Assets/Scripts/Objectives/StartObjective.cs +++ b/Assets/Scripts/Objectives/StartObjective.cs @@ -20,7 +20,6 @@ public class StartObjective : Objective { /// /// Player is ignored public override void ActivateGoal(Player player) { - Debug.Log(room == null); if ( room.GetSpawnpoints().Count > 0 ) { GameObject ply = GameObject.Instantiate(playerPrefab); ply.transform.position = room.GetSpawnpoints()[0].position; @@ -34,7 +33,6 @@ public class StartObjective : Objective { /// /// Player public Player GetPlayer() { - Debug.Log(player == null); return player; } diff --git a/Assets/Scripts/Room.cs b/Assets/Scripts/Room.cs index bc2302e..0e30625 100644 --- a/Assets/Scripts/Room.cs +++ b/Assets/Scripts/Room.cs @@ -26,7 +26,7 @@ public class Room : MonoBehaviour { foreach ( Door d in doorsRootObject.GetComponentsInChildren() ) { doors.Add(d); } - Debug.Log("[ROOMS] Doors: " + doors.Count); + //Debug.Log("[ROOMS] Doors: " + doors.Count); } spawnpoints = new List(); @@ -36,8 +36,9 @@ public class Room : MonoBehaviour { spawnpoints.Add(t); } } - Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count); + //Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count); } + //Unlock(); } /// @@ -49,7 +50,7 @@ public class Room : MonoBehaviour { foreach ( Door d in doorsRootObject.GetComponentsInChildren() ) { doors.Add(d); } - Debug.Log("[ROOMS] Doors: " + doors.Count); + //Debug.Log("[ROOMS] Doors: " + doors.Count); } spawnpoints = new List(); @@ -59,7 +60,7 @@ public class Room : MonoBehaviour { spawnpoints.Add(t); } } - Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count); + //Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count); } }