Add / Implement FinishObjective
This commit is contained in:
parent
d93381aae2
commit
55d6feae55
11 changed files with 79 additions and 64 deletions
|
@ -1059,7 +1059,7 @@ RectTransform:
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
m_AnchorMax: {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_SizeDelta: {x: 0, y: 0}
|
||||||
m_Pivot: {x: 1, y: 0.5}
|
m_Pivot: {x: 1, y: 0.5}
|
||||||
--- !u!224 &224218339018349506
|
--- !u!224 &224218339018349506
|
||||||
|
|
|
@ -497,17 +497,6 @@ Prefab:
|
||||||
propertyPath: m_IsActive
|
propertyPath: m_IsActive
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 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_RemovedComponents: []
|
||||||
m_ParentPrefab: {fileID: 100100000, guid: 3d1911457c1e44f53b6b4044334db52f, type: 2}
|
m_ParentPrefab: {fileID: 100100000, guid: 3d1911457c1e44f53b6b4044334db52f, type: 2}
|
||||||
m_IsPrefabParent: 0
|
m_IsPrefabParent: 0
|
||||||
|
@ -851,7 +840,7 @@ Prefab:
|
||||||
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
|
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
|
||||||
type: 2}
|
type: 2}
|
||||||
propertyPath: m_AnchoredPosition.x
|
propertyPath: m_AnchoredPosition.x
|
||||||
value: 66.396866
|
value: 67.14285
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
|
- target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743,
|
||||||
type: 2}
|
type: 2}
|
||||||
|
@ -883,15 +872,6 @@ Prefab:
|
||||||
propertyPath: m_SizeDelta.x
|
propertyPath: m_SizeDelta.x
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 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_RemovedComponents: []
|
||||||
m_ParentPrefab: {fileID: 100100000, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2}
|
m_ParentPrefab: {fileID: 100100000, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2}
|
||||||
m_IsPrefabParent: 0
|
m_IsPrefabParent: 0
|
||||||
|
@ -1094,11 +1074,6 @@ Transform:
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 3
|
m_RootOrder: 3
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
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
|
--- !u!1 &1908750961
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -1224,11 +1199,6 @@ AudioSource:
|
||||||
m_PreInfinity: 2
|
m_PreInfinity: 2
|
||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
m_RotationOrder: 4
|
||||||
--- !u!4 &2032758561 stripped
|
|
||||||
Transform:
|
|
||||||
m_PrefabParentObject: {fileID: 4676354101874032, guid: 3d1911457c1e44f53b6b4044334db52f,
|
|
||||||
type: 2}
|
|
||||||
m_PrefabInternal: {fileID: 865504979}
|
|
||||||
--- !u!1 &2063368131
|
--- !u!1 &2063368131
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -67,9 +67,11 @@ public class Door : MonoBehaviour {
|
||||||
if ( collision.tag == "Player") {
|
if ( collision.tag == "Player") {
|
||||||
// TODO better checks
|
// TODO better checks
|
||||||
Debug.Log("Leaving Trigger");
|
Debug.Log("Leaving Trigger");
|
||||||
if (parent != null) {
|
if(parent == null) {
|
||||||
|
Debug.Log("This door has no parent Room!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
parent.OnPlayerEnter(collision.gameObject.GetComponent<Player>());
|
parent.OnPlayerEnter(collision.gameObject.GetComponent<Player>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ public class GameController : MonoBehaviour {
|
||||||
private Room start;
|
private Room start;
|
||||||
private Room finish;
|
private Room finish;
|
||||||
|
|
||||||
|
public enum EndedCause {
|
||||||
|
WIN, DIED
|
||||||
|
}
|
||||||
|
|
||||||
// Generation Settings
|
// Generation Settings
|
||||||
[Header("Tile Prefabs")]
|
[Header("Tile Prefabs")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
@ -82,7 +86,7 @@ public class GameController : MonoBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum GameState { UNSET, INIT, STARTING, RUNNING, ENDED };
|
public enum GameState { UNSET, INIT, STARTING, RUNNING, ENDED };
|
||||||
|
private EndedCause endCause = EndedCause.DIED;
|
||||||
private GameState state = GameState.UNSET;
|
private GameState state = GameState.UNSET;
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
|
@ -193,8 +197,11 @@ public class GameController : MonoBehaviour {
|
||||||
doorRootf.name = "Doors";
|
doorRootf.name = "Doors";
|
||||||
doorRootf.transform.SetParent(goFinish.transform);
|
doorRootf.transform.SetParent(goFinish.transform);
|
||||||
ltf = ltf.FindAll(x => x.tag == "door");
|
ltf = ltf.FindAll(x => x.tag == "door");
|
||||||
ltf.ForEach(x => x.SetParent(doorRootf.transform));
|
|
||||||
finish = goFinish.AddComponent<Room>();
|
finish = goFinish.AddComponent<Room>();
|
||||||
|
ltf.ForEach(x => {
|
||||||
|
x.SetParent(doorRootf.transform);
|
||||||
|
x.gameObject.GetComponent<Door>().SetParent(finish);
|
||||||
|
});
|
||||||
finish.SetDoorsRootObject(doorRootf);
|
finish.SetDoorsRootObject(doorRootf);
|
||||||
finish.Reload();
|
finish.Reload();
|
||||||
finish.transform.SetParent(mapRoot.transform);
|
finish.transform.SetParent(mapRoot.transform);
|
||||||
|
@ -206,9 +213,13 @@ public class GameController : MonoBehaviour {
|
||||||
GameObject doorRootg = new GameObject();
|
GameObject doorRootg = new GameObject();
|
||||||
doorRootg.name = "Doors";
|
doorRootg.name = "Doors";
|
||||||
doorRootg.transform.SetParent(groom.transform);
|
doorRootg.transform.SetParent(groom.transform);
|
||||||
ltg = ltg.FindAll(x => x.tag == "door");
|
|
||||||
ltg.ForEach(x => x.SetParent(doorRootg.transform));
|
|
||||||
Room grom = groom.AddComponent<Room>();
|
Room grom = groom.AddComponent<Room>();
|
||||||
|
ltg = ltg.FindAll(x => x.tag == "door");
|
||||||
|
ltg.ForEach(x => {
|
||||||
|
x.SetParent(doorRootg.transform);
|
||||||
|
x.gameObject.GetComponent<Door>().SetParent(grom);
|
||||||
|
});
|
||||||
|
|
||||||
grom.SetDoorsRootObject(doorRootg);
|
grom.SetDoorsRootObject(doorRootg);
|
||||||
grom.Reload();
|
grom.Reload();
|
||||||
groom.transform.SetParent(mapRoot.transform);
|
groom.transform.SetParent(mapRoot.transform);
|
||||||
|
@ -232,6 +243,7 @@ public class GameController : MonoBehaviour {
|
||||||
} else {
|
} else {
|
||||||
Debug.Log("No Player spawned!");
|
Debug.Log("No Player spawned!");
|
||||||
}
|
}
|
||||||
|
finish.SetObjective(new FinishObjective(finish));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Running() {
|
private void Running() {
|
||||||
|
@ -242,9 +254,15 @@ public class GameController : MonoBehaviour {
|
||||||
Debug.Log("Game ended");
|
Debug.Log("Game ended");
|
||||||
//Time.timeScale = 0;
|
//Time.timeScale = 0;
|
||||||
if ( ui != null ) {
|
if ( ui != null ) {
|
||||||
Debug.Log("show Gameover UI");
|
Debug.Log("show end UI");
|
||||||
|
if(endCause == EndedCause.DIED) {
|
||||||
cam.GetComponent<AudioControl>().SfxPlay(2);
|
cam.GetComponent<AudioControl>().SfxPlay(2);
|
||||||
ui.GetComponent<UIController>().ShowGameOverUI();
|
ui.GetComponent<UIController>().ShowGameOverUI();
|
||||||
|
} else if(endCause == EndedCause.WIN) {
|
||||||
|
//cam.GetComponent<AudioControl>().SfxPlay(2);
|
||||||
|
ui.GetComponent<UIController>().ShowWinUI();
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Debug.Log("No UI specified");
|
Debug.Log("No UI specified");
|
||||||
}
|
}
|
||||||
|
@ -261,4 +279,9 @@ public class GameController : MonoBehaviour {
|
||||||
public bool GameEnded() {
|
public bool GameEnded() {
|
||||||
return state == GameState.ENDED;
|
return state == GameState.ENDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void EndGame(EndedCause cause) {
|
||||||
|
endCause = cause;
|
||||||
|
ChangeState(GameState.ENDED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
23
Assets/Scripts/Objectives/FinishObjective.cs
Normal file
23
Assets/Scripts/Objectives/FinishObjective.cs
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Objectives/FinishObjective.cs.meta
Normal file
11
Assets/Scripts/Objectives/FinishObjective.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 409e13e4d4aa55c4fa47137e828d465c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -114,15 +114,17 @@ public class Room : MonoBehaviour {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="player"></param>
|
/// <param name="player"></param>
|
||||||
public void OnPlayerEnter(Player player) {
|
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.");
|
Debug.Log("[ROOMS] This room has been cleared already.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( objective != null ) {
|
|
||||||
Debug.Log("[ROOMS] Player activated Objective");
|
Debug.Log("[ROOMS] Player activated Objective");
|
||||||
objective.ActivateGoal(player);
|
objective.ActivateGoal(player);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the Spawnpoints a room has.
|
/// Returns the Spawnpoints a room has.
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class UIController : MonoBehaviour
|
||||||
string headerText = won ? "You won!" : "Game Over";
|
string headerText = won ? "You won!" : "Game Over";
|
||||||
if (restartUIPanel != null) {
|
if (restartUIPanel != null) {
|
||||||
restartUIPanel.SetActive(true);
|
restartUIPanel.SetActive(true);
|
||||||
restartUIPanel.GetComponent<Text>().text = headerText;
|
restartUIPanel.GetComponentInChildren<Text>().text = headerText;
|
||||||
} else {
|
} else {
|
||||||
Debug.Log("No restart panel assigned");
|
Debug.Log("No restart panel assigned");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ TextureImporter:
|
||||||
maxTextureSize: 2048
|
maxTextureSize: 2048
|
||||||
textureSettings:
|
textureSettings:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
filterMode: 0
|
filterMode: 1
|
||||||
aniso: -1
|
aniso: -1
|
||||||
mipBias: -1
|
mipBias: -1
|
||||||
wrapU: 1
|
wrapU: 1
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 9ec323b9157704d00a3409f8ea6e46b2
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: df6e7833427b5497b92308fb6f54e552
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
Add table
Reference in a new issue