From 7d2435131fd8d3c2edf8ced2d0e00ccdf5598d97 Mon Sep 17 00:00:00 2001 From: Glence Date: Thu, 17 Nov 2022 12:54:08 +0800 Subject: [PATCH] added game manager along with scoring zones for item to be thrown in --- Assets/Scenes/PlayerControllerTest.shade | 118 ++++++++++++++++++----- Assets/Scripts/SC_GameManager.cs | 35 +++++-- Assets/Scripts/SC_Item.cs | 6 ++ Assets/Scripts/SC_ScoringZone.cs | 21 ++++ Assets/Scripts/SC_ScoringZone.cs.shmeta | 3 + 5 files changed, 152 insertions(+), 31 deletions(-) create mode 100644 Assets/Scripts/SC_ScoringZone.cs create mode 100644 Assets/Scripts/SC_ScoringZone.cs.shmeta diff --git a/Assets/Scenes/PlayerControllerTest.shade b/Assets/Scenes/PlayerControllerTest.shade index 271e0d80..01039622 100644 --- a/Assets/Scenes/PlayerControllerTest.shade +++ b/Assets/Scenes/PlayerControllerTest.shade @@ -1,5 +1,5 @@ - EID: 0 - Name: Default + Name: ScoreZone IsActive: true NumberOfChildren: 0 Components: @@ -68,7 +68,7 @@ NumberOfChildren: 3 Components: Transform Component: - Translate: {x: -17.1017113, y: -3.67369723, z: -6.04142666} + Translate: {x: -18.9007454, y: -3.67369723, z: -5.23871422} Rotate: {x: -0, y: 0, z: 0} Scale: {x: 2, y: 2, z: 2} IsActive: true @@ -134,13 +134,13 @@ Components: Transform Component: Translate: {x: 0, y: 0, z: 0} - Rotate: {x: -0.78538686, y: 1.26529622, z: 0} + Rotate: {x: -0.785401046, y: 1.65799224, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true Camera Component: - Position: {x: -17.1017113, y: -3.67369723, z: -6.04142666} - Pitch: -44.9993515 - Yaw: 72.4961319 + Position: {x: -18.9007454, y: -3.67369723, z: -5.23871422} + Pitch: -45.000164 + Yaw: 94.9959564 Roll: 0 Width: 1920 Height: 1080 @@ -262,20 +262,16 @@ Freeze Rotation Z: false IsActive: true Collider Component: - Colliders: - - Is Trigger: true - Type: Box - Half Extents: {x: 3.5999999, y: 8, z: 7.19999981} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: -24.3999996, y: -3.0999999, z: -5.0999999} + Colliders: ~ IsActive: true Scripts: - Type: GameManager itemPool: 12 - totalItemCount: 0 - Score: 1 + zonePool: 51000 + currGameState: 0 + totalItemCount: -202 + Score: 204 + timer: 0 - EID: 12 Name: ItemPool IsActive: true @@ -337,14 +333,14 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: -3.09096575, y: -2.43732405, z: -6.98679876} - Rotate: {x: -0, y: 0, z: -0} + Translate: {x: -20.6163979, y: -0.0419634879, z: -5.08873653} + Rotate: {x: -0, y: 0, z: 0} Scale: {x: 2, y: 2, z: 2} - IsActive: true + IsActive: false Renderable Component: Mesh: 144838771 Material: 123745521 - IsActive: true + IsActive: false RigidBody Component: Type: Dynamic Mass: 1 @@ -358,7 +354,7 @@ Freeze Rotation X: true Freeze Rotation Y: true Freeze Rotation Z: true - IsActive: true + IsActive: false Collider Component: Colliders: - Is Trigger: false @@ -375,8 +371,84 @@ Bounciness: 0 Density: 1 Position Offset: {x: 0, y: 0.5, z: 0} - IsActive: true + IsActive: false Scripts: - Type: Item Score: 1 - currCategory: 0 \ No newline at end of file + currCategory: 0 +- EID: 15 + Name: ScoreZonePool + IsActive: true + NumberOfChildren: 2 + Components: ~ + Scripts: ~ +- EID: 13 + Name: ScoreZone + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -24.5947151, y: -3.15127993, z: -3.29243231} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + RigidBody Component: + Type: Static + Mass: 1 + Drag: 0.00999999978 + Angular Drag: 0.00999999978 + Use Gravity: true + Interpolate: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true + Collider Component: + Colliders: + - Is Trigger: true + Type: Box + Half Extents: {x: 1, y: 20, z: 20} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: ~ +- EID: 14 + Name: ScoreZone + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -6.64785767, y: 0, z: -14.217104} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + RigidBody Component: + Type: Static + Mass: 1 + Drag: 0.00999999978 + Angular Drag: 0.00999999978 + Use Gravity: true + Interpolate: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true + Collider Component: + Colliders: + - Is Trigger: true + Type: Box + Half Extents: {x: 20, y: 20, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scripts/SC_GameManager.cs b/Assets/Scripts/SC_GameManager.cs index b4425473..743827ed 100644 --- a/Assets/Scripts/SC_GameManager.cs +++ b/Assets/Scripts/SC_GameManager.cs @@ -4,19 +4,33 @@ using System.Collections.Generic; public class GameManager : Script { - enum GameState + public enum GameState { + MAINMENU, + WIN, + LOSE, + TOTAL } public GameObject itemPool; + public GameObject zonePool; + public GameState currGameState; + + [NonSerialized] public int totalItemCount; + [NonSerialized] public int Score; + [NonSerialized] + public float timer; + private IEnumerable listOfItems; + private IEnumerable listOfZone; protected override void awake() { totalItemCount = 0; Score = 0; + currGameState = GameState.MAINMENU; if (itemPool) { @@ -24,20 +38,25 @@ public class GameManager : Script foreach (Item i in listOfItems) totalItemCount += 1; } + + if (zonePool) + { + listOfZone = itemPool.GetScriptsInChildren(); + foreach (ScoringZone i in listOfZone) + i.gameManger = Owner.GetScript(); + } } protected override void update() - { + { + if (timer > 0) + timer -= Time.DeltaTimeF; + else + currGameState = GameState.LOSE; } protected override void onTriggerEnter(CollisionInfo info) { - if (info.GameObject.GetScript()) - { - totalItemCount -= 1; - Score = info.GameObject.GetScript().Score; - info.GameObject.SetActive(false); - } } } diff --git a/Assets/Scripts/SC_Item.cs b/Assets/Scripts/SC_Item.cs index b14b5a2a..cb2a5d32 100644 --- a/Assets/Scripts/SC_Item.cs +++ b/Assets/Scripts/SC_Item.cs @@ -8,6 +8,7 @@ public class Item : Script MEDIUM, HEAVY } + public int Score = 10; public ItemCategory currCategory; @@ -15,4 +16,9 @@ public class Item : Script protected override void awake() { } + + protected override void onTriggerEnter(CollisionInfo info) + { + } + } \ No newline at end of file diff --git a/Assets/Scripts/SC_ScoringZone.cs b/Assets/Scripts/SC_ScoringZone.cs new file mode 100644 index 00000000..849f3e1c --- /dev/null +++ b/Assets/Scripts/SC_ScoringZone.cs @@ -0,0 +1,21 @@ +using SHADE; +using System; +public class ScoringZone : Script +{ + public GameManager gameManger { get; set; } + + protected override void awake() + { + } + + protected override void onTriggerEnter(CollisionInfo info) + { + if (gameManger && info.GameObject.GetScript()) + { + gameManger.Score += info.GameObject.GetScript().Score; + gameManger.totalItemCount -= 1; + info.GameObject.SetActive(false); + } + } + +} \ No newline at end of file diff --git a/Assets/Scripts/SC_ScoringZone.cs.shmeta b/Assets/Scripts/SC_ScoringZone.cs.shmeta new file mode 100644 index 00000000..51ef171b --- /dev/null +++ b/Assets/Scripts/SC_ScoringZone.cs.shmeta @@ -0,0 +1,3 @@ +Name: SC_ScoringZone +ID: 153171688 +Type: 9