1
0
Fork 0

Refactor Room | Objective | Entity | Door Interaction | Code format | clean up

This commit is contained in:
Unknown 2018-04-22 15:59:14 +02:00
parent 7512fef314
commit 5739f3dfb5
19 changed files with 1422 additions and 461 deletions

View file

@ -175,21 +175,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1528048736566048
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4871197587417858}
m_Layer: 0
m_Name: Spawn (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1560863483719772
GameObject:
m_ObjectHideFlags: 0
@ -278,7 +263,6 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4460105983878628}
- {fileID: 4871197587417858}
m_Father: {fileID: 4524829645232432}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -316,7 +300,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1448116197164334}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -9, y: -4.8, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4405955685927858}
@ -365,19 +349,6 @@ Transform:
m_Father: {fileID: 4896748037289080}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4871197587417858
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1528048736566048}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 7.7, y: -0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4405955685927858}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4896145802546722
Transform:
m_ObjectHideFlags: 1
@ -688,7 +659,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
doorsRootObject: {fileID: 1394898907781064}
spawnpointRootObject: {fileID: 1560863483719772}
enemys: []
--- !u!212 &212157662384668488
SpriteRenderer:
m_ObjectHideFlags: 1

File diff suppressed because it is too large Load diff

View file

@ -4,31 +4,28 @@ using UnityEngine;
public class CameraControl : MonoBehaviour {
[SerializeField]
private GameObject followThis;
[SerializeField]
private GameObject followThis;
private Vector3 offset;
private Vector3 offset;
void Start()
{
if (followThis == null)
void Start() {
if ( followThis == null )
return;
offset = transform.position - followThis.transform.position;
}
}
void LateUpdate()
{
if (followThis == null)
void LateUpdate() {
if ( followThis == null )
return;
var target = followThis.transform.position + offset;
var targetVec = target - transform.position;
targetVec.Scale (new Vector3 (0.05f, 0.05f, 0));
var target = followThis.transform.position + offset;
var targetVec = target - transform.position;
targetVec.Scale(new Vector3(0.05f, 0.05f, 0));
transform.position = transform.position + targetVec;
}
transform.position = transform.position + targetVec;
}
public void SetFollow(GameObject g)
{
public void SetFollow(GameObject g) {
followThis = g;
offset = transform.position - followThis.transform.position;
}

View file

@ -1,6 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
public class Door : MonoBehaviour {
private bool locked = false;
@ -9,15 +7,16 @@ public class Door : MonoBehaviour {
GameObject graphics;
[SerializeField]
Room parent;
Room parent;
BoxCollider2D boundingBox;
BoxCollider2D triggerBox;
// Use this for initialization
void Start () {
// Use this for initialization
void Start() {
BoxCollider2D[] colliders = GetComponents<BoxCollider2D>();
foreach (BoxCollider2D collider in colliders) {
if (collider.isTrigger) {
foreach ( BoxCollider2D collider in colliders ) {
if ( collider.isTrigger ) {
triggerBox = collider;
Debug.Log("Found Door trigger");
} else {
@ -26,35 +25,45 @@ public class Door : MonoBehaviour {
}
}
Unlock();
}
public void Lock()
{
}
/// <summary>
/// Locks the door.
/// </summary>
public void Lock() {
locked = true;
boundingBox.enabled = true;
triggerBox.enabled = false;
graphics.GetComponent<SpriteRenderer>().enabled = true;
}
public void Unlock()
{
/// <summary>
/// Unlocks the door.
/// </summary>
public void Unlock() {
locked = false;
boundingBox.enabled = false;
triggerBox.enabled = true;
graphics.GetComponent<SpriteRenderer>().enabled = false;
}
public bool IsLocked()
{
/// <summary>
/// Returns if the door is locked.
/// </summary>
/// <returns></returns>
public bool IsLocked() {
return locked;
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.tag == "Player")
{
Debug.Log("Leavin Trigger");
parent.OnPlayerEnter();
/// <summary>
/// Check if a player moved inside of a room and notify the room.
/// </summary>
/// <param name="collision"></param>
private void OnTriggerExit2D(Collider2D collision) {
if ( collision.tag == "Player" ) {
// TODO better checks
Debug.Log("Leaving Trigger");
parent.OnPlayerEnter(collision.gameObject.GetComponent<Player>());
}
}
}

View file

@ -4,41 +4,38 @@ using UnityEngine;
public class EnemyAI : MonoBehaviour {
[SerializeField]
private GameObject victim;
[SerializeField]
private GameObject agressor;
[SerializeField]
private float speed = 1;
[SerializeField]
private float rotaionSpeedWIP = 1;
[SerializeField]
private GameObject victim;
[SerializeField]
private GameObject agressor;
[SerializeField]
private float speed = 1;
[SerializeField]
private float rotaionSpeedWIP = 1;
/*
/*
* Die destructive dumme deutsche Dungeon Diktator Drifter DLC Debakel Distribution Dokumentations - Druck Datei
* */
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if(victim == null)
{
victim = GameController.instance.GetPlayer().gameObject; // TODO testing purpose only!
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
if ( victim == null ) {
//victim = GameController.instance.GetPlayer().gameObject; // TODO testing purpose only!
return;
}
// movement
agressor.transform.Translate (Vector3.Scale ((victim.transform.position - agressor.transform.position).normalized, new Vector2 (speed, speed)));
// movement
agressor.transform.Translate(Vector3.Scale(( victim.transform.position - agressor.transform.position ).normalized, new Vector2(speed, speed)));
// rotation
agressor.transform.Rotate(agressor.transform.forward, Vector3.Angle(victim.transform.position - agressor.transform.position, agressor.transform.rotation * new Vector3(1, 1, 1)));
}
// rotation
agressor.transform.Rotate(agressor.transform.forward, Vector3.Angle(victim.transform.position - agressor.transform.position, agressor.transform.rotation * new Vector3(1, 1, 1)));
}
public void SetVictim(GameObject g)
{
public void SetVictim(GameObject g) {
victim = g;
}
}

View file

@ -1,8 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collectable : Entity{
public Collectable (EntityObjective referringObjective) : base(referringObjective) {}
public class Collectable : Entity {
public Collectable() : base() { }
}

View file

@ -2,19 +2,14 @@
using System.Collections.Generic;
using UnityEngine;
public abstract class Entity : MonoBehaviour{
EntityObjective referringObjective;
public abstract class Entity : MonoBehaviour {
protected EntityObjective objective;
// Constructor
public Entity(EntityObjective referringObjective)
{
this.referringObjective = referringObjective;
}
// kills the entity
public virtual void Kill()
{
if(referringObjective != null)
referringObjective.Remove (this.gameObject);
}
/// <summary>
/// Sets the Objective this Entity is associated with.
/// </summary>
/// <param name="obj">Objective</param>
public void SetObjective(EntityObjective obj) {
objective = obj;
}
}

View file

@ -1,54 +1,77 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Mob : Entity {
readonly int maxHP;
int currentHP;
bool isDead;
public abstract class Mob : Entity {
readonly int maxHP;
int currentHP;
bool isDead;
int damage;
// Constructor
public Mob(EntityObjective referringObjective, int maxHP) : base(referringObjective)
{
this.maxHP = maxHP;
currentHP = maxHP;
/// <summary>
/// Creates a new Mob instance with the given HP.
/// </summary>
/// <param name="maxHP"></param>
public Mob(int maxHP) {
this.maxHP = maxHP;
currentHP = maxHP;
isDead = false;
}
isDead = false;
}
/// <summary>
/// Inflicts damage to this mob.
/// </summary>
/// <param name="damage"></param>
public void InflictDamage(int damage) {
currentHP -= damage;
if ( !isDead && currentHP <= 0 ) {
isDead = true;
Death();
}
}
// inflicts damage to this mob
public void InflictDamage(int damage)
{
currentHP -= damage;
if (!isDead && currentHP <= 0)
{
base.Kill ();
isDead = true;
}
}
/// <summary>
/// This is called when a mob dies.
/// </summary>
protected virtual void Death() {
if ( objective != null )
objective.RemoveEntity(this);
Destroy(gameObject);
}
// Heals the mob
public void Heal(int healAmount)
{
if (!isDead)
currentHP = (currentHP + healAmount > currentHP) ? maxHP : currentHP + healAmount;
}
/// <summary>
/// Heals the mob.
/// </summary>
/// <param name="healAmount"></param>
public void Heal(int healAmount) {
if ( !isDead )
currentHP = ( currentHP + healAmount > currentHP ) ? maxHP : currentHP + healAmount;
}
public void SetDamage(int dmg)
{
/// <summary>
/// Sets the damage value of a mobs attack.
/// </summary>
/// <param name="dmg"></param>
public void SetDamage(int dmg) {
damage = dmg;
}
public int GetDamage()
{
/// <summary>
/// Gets the damage value og a mobs attack.
/// </summary>
/// <returns></returns>
public int GetDamage() {
return damage;
}
/// <summary>
/// Gets the current HP.
/// </summary>
/// <returns></returns>
public int getHealth() {
return currentHP;
}
/// <summary>
/// Gets the maximum HP.
/// </summary>
/// <returns></returns>
public int getMaxHealth() {
return maxHP;
}

View file

@ -4,38 +4,30 @@ using UnityEngine;
public class Player : Mob {
public Player() : base(null, 100 )
{
}
public Player() : base(100) { }
private void OnCollisionEnter2D(Collision2D collision)
{
/// <summary>
/// Collision checking. Player is going to die on any collision with a wall.
/// </summary>
/// <param name="collision"></param>
private void OnCollisionEnter2D(Collision2D collision) {
Debug.Log("Collision");
if (collision.collider.tag == "wall") {
Kill();
} else if (collision.collider.tag == "enemy")
{
if ( collision.collider.tag == "wall" ) {
Death();
} else if ( collision.collider.tag == "enemy" ) {
Mob m = collision.collider.GetComponent(typeof(Mob)) as Mob;
if(m != null)
{
if ( m != null ) {
InflictDamage(m.GetDamage()); // TODO think about Mob attac mechanic
}
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "door") {
//Debug.Log("Open door");
}
}
}
public override void Kill()
{
base.Kill();
/// <summary>
/// This is called when a Player died.
/// </summary>
protected override void Death() {
Destroy(this.gameObject);
GameController.instance.ChangeState(GameController.GameState.ENDED);
}
}
}

View file

@ -20,8 +20,7 @@ public class GameController : MonoBehaviour {
private bool engineInitDone;
private Player player;
public static GameController instance;
public GameController()
{
public GameController() {
instance = this;
}
@ -29,15 +28,14 @@ public class GameController : MonoBehaviour {
private GameState state = GameState.UNSET;
// Use this for initialization
void Start () {
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update () {
if (!engineInitDone)
{
}
// Update is called once per frame
void Update() {
if ( !engineInitDone ) {
engineInitDone = true;
Debug.Log("First Frame");
ChangeState(GameState.INIT);
@ -45,15 +43,14 @@ public class GameController : MonoBehaviour {
}
public void ChangeState(GameState nextState) {
if(nextState != state) {
if ( nextState != state ) {
state = nextState;
StateLogic(nextState);
}
}
void StateLogic(GameState nstate) {
switch (nstate)
{
switch ( nstate ) {
case GameState.INIT:
Init();
ChangeState(GameState.STARTING);
@ -75,34 +72,26 @@ public class GameController : MonoBehaviour {
}
private void Init()
{
List<GameObject> tmp = new List<GameObject>
{
playerPrefab
};
start.SetObjective(new EntityObjective(start, tmp));
start.OnPlayerEnter();
player = ((EntityObjective) start.GetObjective()).GetEntities()[0].GetComponent<Player>();
private void Init() {
StartObjective goal = new StartObjective(start, playerPrefab);
start.SetObjective(goal);
start.OnPlayerEnter(player);
player = goal.GetPlayer();
cam.GetComponent<CameraControl>().SetFollow(player.gameObject);
((EntityObjective)start.GetObjective()).Remove(player.gameObject);
}
private void Starting()
{
private void Starting() {
}
private void Running()
{
private void Running() {
}
private void Ended()
{
private void Ended() {
Debug.Log("Game ended");
//Time.timeScale = 0;
if (ui != null) {
if ( ui != null ) {
Debug.Log("show gameover UI");
ui.GetComponent<UIController>().ShowGameOverUI();
} else {
@ -110,8 +99,4 @@ public class GameController : MonoBehaviour {
}
}
public Player GetPlayer() {
return player;
}
}

View file

@ -1,23 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HP : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void SetHP(){
}
public void RotateHpBar(){
}
}

View file

@ -8,23 +8,16 @@ public class HealthbarController : MonoBehaviour {
float maxRotation;
private Player player;
// Use this for initialization
void Start () {
UpdatePlayer();
}
// Update is called once per frame
void Update () {
// Update is called once per frame
void Update() {
// if player alive and spawned
if (player != null) {
if ( player != null ) {
UpdatePointer(player.getHealth());
} else {
} else if (currentRotation != 0) {
//if player dead or not spawned
UpdatePointer(0);
UpdatePlayer();
}
}
}
private void UpdatePointer(float playerLife) {
float offset = playerLife - currentRotation;
@ -32,11 +25,7 @@ public class HealthbarController : MonoBehaviour {
currentRotation += offset;
}
private void UpdatePlayer() {
player = GameController.instance.GetPlayer();
if (player != null) {
maxRotation = player.getMaxHealth();
currentRotation = player.getHealth();
}
public void SetPlayer(Player ply) {
player = ply;
}
}

View file

@ -2,45 +2,57 @@
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Objective, where the goal is to "remove" all Entitys, how is defined by the Entity itself.
/// </summary>
public class EntityObjective : Objective {
List<GameObject> prefabList;
List<GameObject> entityList;
List<Transform> spawnPointList;
List<GameObject> prefabList;
List<GameObject> entityList;
// Constructor
public EntityObjective(Room objectiveCaller, List<GameObject> prefabList) : base(objectiveCaller)
{
/// <summary>
/// Creates a new instance of an EntityObjective.
/// </summary>
/// <param name="caller"></param>
/// <param name="prefabList"></param>
public EntityObjective(Room caller, List<GameObject> prefabList) : base(caller) {
this.entityList = new List<GameObject>();
this.prefabList = prefabList;
spawnPointList = objectiveCaller.GetSpawnpoints ();
}
this.prefabList = prefabList;
}
// Activates the objective to start progresstracking
public override void Activate()
{
Random newRand = new Random ();
Debug.Log("Activate");
foreach (GameObject i in prefabList)
{
Debug.Log("Instantiating Prefab");
GameObject tempObject = GameObject.Instantiate (i);
tempObject.transform.position = spawnPointList [Random.Range (0, spawnPointList.Count)].position;
/// <summary>
/// Handle activation code for a goal.
/// </summary>
/// <param name="ply">Player</param>
public override void ActivateGoal(Player ply) {
base.ActivateGoal(ply);
foreach ( GameObject i in prefabList ) {
Debug.Log("[ROOMS] Spawning Entity...");
GameObject tempObject = GameObject.Instantiate(i);
List<Transform> spawnPointList = room.GetSpawnpoints();
tempObject.transform.position = spawnPointList[Random.Range(0, spawnPointList.Count)].position;
entityList.Add(tempObject);
}
}
objectiveCaller.Lock();
}
room.Lock();
}
// Removes the entity from the list and completes the objective, if the list is empty
public void Remove(GameObject inputEntity)
{
entityList.Remove (inputEntity);
if (entityList.Count == 0)
objectiveCaller.Unlock ();
}
/// <summary>
/// Removes an Entity from the list. And checks if the goal was reached.
/// </summary>
/// <param name="e">Entity</param>
public void RemoveEntity(Entity e) {
if ( e == null )
return;
entityList.Remove(e.gameObject);
UpdateGoal();
}
public List<GameObject> GetEntities()
{
return entityList;
/// <summary>
/// Tracks / Updates the progess of a goal.
/// </summary>
public override void UpdateGoal() {
// Goal:
if ( entityList.Count == 0 )
ReachedGoal();
}
}

View file

@ -1,16 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Objective {
protected Room room;
protected Player player;
bool activated;
bool finished;
public abstract class Objective {
protected Room objectiveCaller;
/// <summary>
/// Constructs a new Objective instance.
/// </summary>
/// <param name="caller"></param>
public Objective(Room caller) {
this.room = caller;
}
/// <summary>
/// Handle activation code for a goal.
/// </summary>
/// <param name="ply">Player</param>
public virtual void ActivateGoal(Player ply) {
if ( activated )
return;
activated = true;
player = ply;
}
/// <summary>
/// Tracks / Updates the progess of a goal.
/// </summary>
public abstract void UpdateGoal();
/// <summary>
/// Code executed if the goal is reached eg. opening doors.
/// </summary>
protected virtual void ReachedGoal() {
finished = true;
room.Unlock();
}
/// <summary>
/// Returns wether the goal was reached or not.
/// </summary>
/// <returns></returns>
public bool GetFinished() {
return finished;
}
// Constructor
public Objective(Room objectiveCaller)
{
this.objectiveCaller = objectiveCaller;
}
// Activates the objective to start progresstracking
public virtual void Activate(){}
}

View file

@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StartObjective : Objective {
GameObject playerPrefab;
/// <summary>
/// Creates a new StartObjective instance.
/// </summary>
/// <param name="room"></param>
/// <param name="playerPrefab"></param>
public StartObjective(Room room, GameObject playerPrefab) : base(room) {
this.playerPrefab = playerPrefab;
}
// TODO not as good as possible. Should Objectives ActivateGoal method require a player obj?
/// <summary>
/// Handle activation code for a goal.
/// </summary>
/// <param name="ply">Player is ignored </param>
public override void ActivateGoal(Player player=null) {
if ( room.GetSpawnpoints().Count > 0 ) {
GameObject ply = GameObject.Instantiate(playerPrefab);
ply.transform.position = room.GetSpawnpoints()[0].position;
player = ply.GetComponent<Player>();
base.ActivateGoal(player);
}
}
/// <summary>
/// Returns the created Player object. Call this after <see cref="ActivateGoal(Player)"/> !
/// </summary>
/// <returns>Player</returns>
public Player GetPlayer() {
return player;
}
/// <summary>
/// Code executed if the goal is reached eg. opening doors.
/// </summary>
public override void UpdateGoal() {
ReachedGoal();
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 605b34431fb4e20408494377178f8ecb
guid: cc1002426c801284f84b577c992409bc
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -1,65 +1,63 @@
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
private bool firstKeyPressed;
private bool firstKeyPressed;
[SerializeField]
public float acceleration = 3;
[SerializeField]
public float friction = 0.1f;
[SerializeField]
public float turnSpeed = 2;
[SerializeField]
public float drift = 1f;
[SerializeField]
public float brake = 2f;
[SerializeField]
public float acceleration = 3;
[SerializeField]
public float friction = 0.1f;
[SerializeField]
public float turnSpeed = 2;
[SerializeField]
public float drift = 1f;
[SerializeField]
public float brake = 2f;
Rigidbody2D rigidbody2D;
Rigidbody2D rb;
// Use this for initialization
void Start() {
rigidbody2D = GetComponent<Rigidbody2D>();
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
if(!firstKeyPressed && Input.anyKey)
{
void Update() {
if ( !firstKeyPressed && Input.anyKey ) {
firstKeyPressed = true;
}
}
}
void FixedUpdate() {
if (!firstKeyPressed)
if ( !firstKeyPressed )
return;
Vector3 speedVec = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y, 0);
float speed = speedVec.magnitude;
Vector3 speedVec = new Vector3(rb.velocity.x, rb.velocity.y, 0);
float speed = speedVec.magnitude;
{ // Forward
rigidbody2D.AddForce(transform.up * acceleration);
{ // Forward
rb.AddForce(transform.up * acceleration);
}
{// Drag
Vector3 drag = speedVec.normalized * speed * speed * friction * -1;
if (Input.GetKey(KeyCode.S))
drag *= brake;
rigidbody2D.AddForce(drag);
Vector3 drag = speedVec.normalized * speed * speed * friction * -1;
if ( Input.GetKey(KeyCode.S) )
drag *= brake;
rb.AddForce(drag);
Debug.DrawLine(transform.position, transform.position + drag, Color.cyan, 0.01f, false);
}
{ // Drift
Vector3 forwardNorm = (transform.localRotation * Vector3.up).normalized * speedVec.magnitude;
Vector3 br = forwardNorm - speedVec;
br *= drift;
rigidbody2D.AddForce(br);
//Debug.Log(br);
Debug.DrawLine(transform.position, transform.position + br, Color.red, 0.01f, false);
Vector3 forwardNorm = ( transform.localRotation * Vector3.up ).normalized * speedVec.magnitude;
Vector3 br = forwardNorm - speedVec;
br *= drift;
rb.AddForce(br);
//Debug.Log(br);
Debug.DrawLine(transform.position, transform.position + br, Color.red, 0.01f, false);
}
if (Input.GetKey(KeyCode.A))
rigidbody2D.MoveRotation(rigidbody2D.rotation + turnSpeed);
if ( Input.GetKey(KeyCode.A) )
rb.MoveRotation(rb.rotation + turnSpeed);
//transform.Rotate(Vector3.forward * turnSpeed);
if (Input.GetKey(KeyCode.D))
rigidbody2D.MoveRotation(rigidbody2D.rotation - turnSpeed);
//transform.Rotate(Vector3.forward * -turnSpeed);
if ( Input.GetKey(KeyCode.D) )
rb.MoveRotation(rb.rotation - turnSpeed);
//transform.Rotate(Vector3.forward * -turnSpeed);
// Debug lines
Debug.DrawLine(transform.position, transform.position + speedVec, Color.magenta, 0.01f, false);
Debug.DrawLine(transform.position, transform.position + transform.localRotation * Vector3.up, Color.yellow, 0.01f, false);

View file

@ -4,8 +4,6 @@ using UnityEngine;
public class Room : MonoBehaviour {
private bool activated;
List<Door> doors;
List<Transform> spawnpoints;
@ -15,81 +13,73 @@ public class Room : MonoBehaviour {
[SerializeField]
GameObject spawnpointRootObject;
[SerializeField]
private Objective objective;
private Objective objective;
enum ObjectiveType { EntityObjective }
// Params for testing
[SerializeField]
GameObject[] enemys;
// Use this for initialization
void Start () {
// Use this for initialization
void Start() {
doors = new List<Door>();
foreach (Door d in doorsRootObject.GetComponentsInChildren<Door>())
{
foreach ( Door d in doorsRootObject.GetComponentsInChildren<Door>() ) {
doors.Add(d);
}
Debug.Log("Doors in Room: " + doors.Count);
Debug.Log("[ROOMS] Doors: " + doors.Count);
spawnpoints = new List<Transform>();
foreach (Transform t in spawnpointRootObject.GetComponentsInChildren<Transform>())
{
if( t.gameObject != spawnpointRootObject)
{
foreach ( Transform t in spawnpointRootObject.GetComponentsInChildren<Transform>() ) {
if ( t.gameObject != spawnpointRootObject ) {
spawnpoints.Add(t);
}
}
Debug.Log("Spawnpoints in Room: " + spawnpoints.Count);
if (enemys.Length != 0)
objective = new EntityObjective(this, new List<GameObject> (enemys));
//Unlock();
}
public void SetObjective(Objective o)
{
objective = o;
Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count);
}
public void Lock()
{
foreach (Door d in doors)
{
/// <summary>
/// Locks all doors associated with this room.
/// </summary>
public void Lock() {
foreach ( Door d in doors ) {
d.Lock();
}
Debug.Log("[ROOMS] Locked all doors...");
}
public void Unlock()
{
foreach (Door d in doors)
{
/// <summary>
/// Unlocks all doors associated with this room.
/// </summary>
public void Unlock() {
foreach ( Door d in doors ) {
d.Unlock();
}
Debug.Log("[ROOMS] Unlocked all doors...");
}
/// <summary>
/// Sets the rooms Objective.
/// </summary>
/// <param name="obj">Objective</param>
public void SetObjective(Objective obj) {
objective = obj;
}
/// <summary>
/// Informs the objective / activates it and ensures that a cleared room is not going to be activated again.
/// </summary>
/// <param name="player"></param>
public void OnPlayerEnter(Player player) {
if ( objective != null && objective.GetFinished() ) {
Debug.Log("[ROOMS] This room has been cleared already.");
return;
}
if ( objective != null ) {
Debug.Log("[ROOMS] Player activated Objective");
objective.ActivateGoal(player);
}
}
public Objective GetObjective()
{
return objective;
}
public void OnPlayerEnter()
{
if (activated)
return;
if(objective != null)
objective.Activate();
activated = true;
}
public List<Transform> GetSpawnpoints()
{
/// <summary>
/// Returns the Spawnpoints a room has.
/// </summary>
/// <returns></returns>
public List<Transform> GetSpawnpoints() {
return spawnpoints;
}
public bool GetActivated()
{
return activated;
}
}

View file

@ -3,49 +3,42 @@ using System.Collections.Generic;
using UnityEngine;
public class UIController : MonoBehaviour {
private GameObject score;
private GameObject pauseMenu;
[SerializeField]
private GameObject gameOverPanel;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public static UIController instance;
public void ShowPauseMenu()
{
[SerializeField]
private HealthbarController healthcontroller;
public void ShowPauseMenu() {
pauseMenu.SetActive(true);
}
public void ClosePauseMenu()
{
public void ClosePauseMenu() {
pauseMenu.SetActive(false);
}
public void LoadSceneByIndex(int index)
{
public void LoadSceneByIndex(int index) {
Debug.Log("Loaded scene " + index);
UnityEngine.SceneManagement.SceneManager.LoadScene(index);
}
public void QuitGame()
{
public void QuitGame() {
Debug.Log("Quit game");
Application.Quit();
}
public void ShowGameOverUI() {
if (gameOverPanel != null) {
if ( gameOverPanel != null ) {
Canvas gameOverCanvas = gameOverPanel.GetComponent<Canvas>();
Debug.Log("Loading Canvas");
if (gameOverCanvas != null) {
if ( gameOverCanvas != null ) {
Debug.Log("Loaded Canvas");
gameOverCanvas.enabled = true;
gameOverCanvas.enabled = true;
} else {
Debug.Log("Gameover panel has no Canvas");
}
@ -53,5 +46,9 @@ public class UIController : MonoBehaviour {
Debug.Log("No game over panel assigned");
}
}
public void InitHealthController(Player ply) {
healthcontroller.SetPlayer(ply);
}
}