using System.Collections; using System.Collections.Generic; using UnityEngine; public class Room : MonoBehaviour { public enum TileType { GROUND, WALL, DOOR, ROCK } Vector2Int center; Vector2Int position; List doors; List spawnpoints; [SerializeField] GameObject doorsRootObject; [SerializeField] GameObject spawnpointRootObject; private Objective objective; // Use this for initialization void Awake() { doors = new List(); if ( doorsRootObject != null ) { foreach ( Door d in doorsRootObject.GetComponentsInChildren() ) { doors.Add(d); } //Debug.Log("[ROOMS] Doors: " + doors.Count); } spawnpoints = new List(); if ( spawnpointRootObject != null ) { foreach ( Transform t in spawnpointRootObject.GetComponentsInChildren() ) { if ( t.gameObject != spawnpointRootObject ) { spawnpoints.Add(t); } } //Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count); } Unlock(); } /// /// Center point in Generation phase. /// /// public void SetCenter(Vector2Int v) { center = v; } public void SetPosition(Vector2Int v) { position = v; } public Vector2Int GetPosition() { return position; } /// /// Returns the Center as global from the generation. TODO change this /// Is available after Generation and after Start Phase. /// /// public Vector2Int GetCenter() { return center; } /// /// Reloads the spawnpoints and doors. /// public void Reload() { doors = new List(); if ( doorsRootObject != null ) { foreach ( Door d in doorsRootObject.GetComponentsInChildren() ) { doors.Add(d); } //Debug.Log("[ROOMS] Doors: " + doors.Count); } spawnpoints = new List(); if ( spawnpointRootObject != null ) { foreach ( Transform t in spawnpointRootObject.GetComponentsInChildren() ) { if ( t.gameObject != spawnpointRootObject ) { spawnpoints.Add(t); } } //Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count); } Unlock(); // Ok to do so? } /// /// Sets the doors root object. /// /// public void SetDoorsRootObject(GameObject go) { doorsRootObject = go; } /// /// Sets the spawnpoints root object. /// /// public void SetSpawnPointsRootObject(GameObject go) { spawnpointRootObject = go; } /// /// Locks all doors associated with this room. /// public void Lock() { foreach ( Door d in doors ) { d.Lock(); } GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.door); Debug.Log("[ROOMS] Locked all doors..."); } /// /// Unlocks all doors associated with this room. /// public void Unlock() { foreach ( Door d in doors ) { d.Unlock(); } GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.door); Debug.Log("[ROOMS] Unlocked all doors..."); } /// /// Sets the rooms Objective. /// /// Objective public void SetObjective(Objective obj) { objective = obj; } /// /// Informs the objective / activates it and ensures that a cleared room is not going to be activated again. /// /// public void OnPlayerEnter(Player player) { 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; } Debug.Log("[ROOMS] Player activated Objective"); objective.ActivateGoal(player); } /// /// Returns the Spawnpoints a room has. /// /// public List GetSpawnpoints() { return spawnpoints; } }