1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/Room.cs

102 lines
2 KiB
C#
Raw Normal View History

2018-04-21 12:22:17 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2018-04-21 15:39:48 +02:00
public class Room : MonoBehaviour {
2018-04-21 19:50:50 +02:00
public enum TileType {
2018-04-22 02:23:13 +02:00
GROUND, WALL, DOOR, ROCK
2018-04-21 19:50:50 +02:00
}
2018-04-22 11:27:09 +02:00
private bool activated;
2018-04-21 19:50:50 +02:00
Vector2 position;
2018-04-22 02:23:13 +02:00
Dictionary<Vector2, TileType> tiles;
2018-04-21 16:13:59 +02:00
2018-04-21 15:39:48 +02:00
List<Door> doors;
2018-04-21 16:13:59 +02:00
List<Transform> spawnpoints;
2018-04-21 15:39:48 +02:00
[SerializeField]
GameObject doorsRootObject;
2018-04-21 16:13:59 +02:00
[SerializeField]
GameObject spawnpointRootObject;
2018-04-21 15:39:48 +02:00
[SerializeField]
private Objective objective;
2018-04-21 12:22:17 +02:00
2018-04-22 11:27:09 +02:00
enum ObjectiveType { EntityObjective }
// Params for testing
[SerializeField]
GameObject[] enemys;
2018-04-21 12:22:17 +02:00
// Use this for initialization
void Start () {
2018-04-21 15:39:48 +02:00
doors = new List<Door>();
foreach (Door d in doorsRootObject.GetComponentsInChildren<Door>())
{
doors.Add(d);
}
Debug.Log("Doors in Room: " + doors.Count);
2018-04-21 16:13:59 +02:00
spawnpoints = new List<Transform>();
foreach (Transform t in spawnpointRootObject.GetComponentsInChildren<Transform>())
{
if( t.gameObject != spawnpointRootObject)
{
spawnpoints.Add(t);
}
2018-04-21 16:13:59 +02:00
}
Debug.Log("Spawnpoints in Room: " + spawnpoints.Count);
2018-04-22 11:27:09 +02:00
if (enemys.Length != 0)
objective = new EntityObjective(this, new List<GameObject> (enemys));
//Unlock();
2018-04-21 16:13:59 +02:00
}
2018-04-21 12:22:17 +02:00
public void SetObjective(Objective o)
{
objective = o;
}
2018-04-21 15:39:48 +02:00
2018-04-21 16:13:59 +02:00
public void Lock()
2018-04-21 15:39:48 +02:00
{
foreach (Door d in doors)
{
d.Lock();
}
}
2018-04-21 16:13:59 +02:00
public void Unlock()
2018-04-21 15:39:48 +02:00
{
foreach (Door d in doors)
{
d.Unlock();
}
}
public Objective GetObjective()
{
return objective;
}
public void OnPlayerEnter()
{
2018-04-22 11:27:09 +02:00
if (activated)
return;
if(objective != null)
objective.Activate();
2018-04-22 11:27:09 +02:00
activated = true;
}
2018-04-21 16:13:59 +02:00
public List<Transform> GetSpawnpoints()
{
return spawnpoints;
}
2018-04-22 11:27:09 +02:00
public bool GetActivated()
{
return activated;
}
2018-04-21 12:22:17 +02:00
}