Merge branch 'main' into SP3-20-UI-System

This commit is contained in:
maverickdgg 2023-02-03 15:53:26 +08:00
commit bb00889553
47 changed files with 6177 additions and 93 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,10 @@
Name: MD_CarRed
ID: 76808537
Type: 4
Sub Assets:
Name: CarBody
ID: 135736753
Type: 8
Name: CarWindows
ID: 139618182
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,22 @@
Name: MD_Prop_Large_Watermelon
ID: 70609427
Type: 4
Sub Assets:
Name: Watermelon_Unbroken
ID: 134305891
Type: 8
Name: Watermelon_Broken01
ID: 144023586
Type: 8
Name: Watermelon_Broken02
ID: 142132679
Type: 8
Name: Watermelon_Broken03
ID: 138231239
Type: 8
Name: Watermelon_Broken04
ID: 135293480
Type: 8
Name: Watermelon_Broken05
ID: 146157335
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,19 @@
Name: MD_Prop_Small_Egg
ID: 78383364
Type: 4
Sub Assets:
Name: Egg_Unbroken
ID: 147457317
Type: 8
Name: Egg._Broken01
ID: 134900190
Type: 8
Name: Egg._Broken02
ID: 146271645
Type: 8
Name: Egg._Broken03
ID: 135945648
Type: 8
Name: Egg._Broken04
ID: 141722646
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,19 @@
Name: MD_TutorialGarageProps01
ID: 75936469
Type: 4
Sub Assets:
Name: MetalShelf
ID: 141619727
Type: 8
Name: Chair01.001
ID: 139750047
Type: 8
Name: Cube.002
ID: 137072050
Type: 8
Name: Cube.003
ID: 149524108
Type: 8
Name: GarageDoor
ID: 148373587
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,10 @@
Name: MD_TutorialGarageProps02
ID: 79889545
Type: 4
Sub Assets:
Name: CupboardSolidBlock.001
ID: 141180771
Type: 8
Name: CupboardSinkPiece.002
ID: 141816633
Type: 8

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,10 @@
Name: MD_WashingMachine
ID: 67614549
Type: 4
Sub Assets:
Name: WashingMachine
ID: 138744683
Type: 8
Name: WashingMachineDoor
ID: 139502794
Type: 8

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
Name: Level1Scene
ID: 96668835
Type: 5

View File

@ -8466,7 +8466,7 @@
- EID: 240 - EID: 240
Name: ====ItemPool==== Name: ====ItemPool====
IsActive: true IsActive: true
NumberOfChildren: 9 NumberOfChildren: 11
Components: ~ Components: ~
Scripts: ~ Scripts: ~
- EID: 241 - EID: 241
@ -8514,6 +8514,8 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
density: 1
dontReturn: false
- EID: 157 - EID: 157
Name: Mesh_Meat Name: Mesh_Meat
IsActive: true IsActive: true
@ -8559,6 +8561,8 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
density: 1
dontReturn: false
- EID: 156 - EID: 156
Name: Mesh_Meat Name: Mesh_Meat
IsActive: true IsActive: true
@ -8604,6 +8608,8 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
density: 1
dontReturn: false
- EID: 155 - EID: 155
Name: Mesh_Cheese Name: Mesh_Cheese
IsActive: true IsActive: true
@ -8649,6 +8655,8 @@
Enabled: true Enabled: true
Score: 100 Score: 100
currCategory: 2 currCategory: 2
density: 1
dontReturn: false
- EID: 154 - EID: 154
Name: Mesh_Cheese Name: Mesh_Cheese
IsActive: true IsActive: true
@ -8694,6 +8702,8 @@
Enabled: true Enabled: true
Score: 100 Score: 100
currCategory: 2 currCategory: 2
density: 1
dontReturn: false
- EID: 153 - EID: 153
Name: Mesh_Cheese Name: Mesh_Cheese
IsActive: true IsActive: true
@ -8739,6 +8749,8 @@
Enabled: true Enabled: true
Score: 100 Score: 100
currCategory: 2 currCategory: 2
density: 1
dontReturn: false
- EID: 65778 - EID: 65778
Name: Mesh_Apple Name: Mesh_Apple
IsActive: true IsActive: true
@ -8784,6 +8796,8 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
density: 1
dontReturn: false
- EID: 152 - EID: 152
Name: Mesh_Apple Name: Mesh_Apple
IsActive: true IsActive: true
@ -8829,6 +8843,8 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
density: 1
dontReturn: false
- EID: 151 - EID: 151
Name: Mesh_Apple Name: Mesh_Apple
IsActive: true IsActive: true
@ -8874,6 +8890,509 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
density: 1
dontReturn: false
- EID: 65686
Name: Watermelon
IsActive: true
NumberOfChildren: 5
Components:
Transform Component:
Translate: {x: 2.44600534, y: 0.333341181, z: 6.14019775}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 0.999979734, y: 1, z: 0.999979734}
IsActive: true
Renderable Component:
Mesh: 134305891
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Sphere
Radius: 0.5
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Breakable
Enabled: true
threshHold: 2
ignoreRaccoon: true
- Type: Item
Enabled: true
Score: 100
currCategory: 2
density: 1
dontReturn: false
- EID: 131220
Name: Piece1
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0219824314, y: 2.77459621e-05, z: 0.140744686}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 144023586
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.25, y: 0.25, z: 0.100000001}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0.164060935, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 131219
Name: Piece2
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.0213363171, y: 0.0825135708, z: -0.0573720932}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 142132679
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.300000012, y: 0.200000003, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -0.34906584}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 131221
Name: Piece3
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0268242359, y: -0.140726641, z: -0.0336794853}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 138231239
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.200000003, y: 0.0799999982, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -0.261799395}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 145
Name: Piece4
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.194803953, y: -0.0580093563, z: -0.00789308548}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 135293480
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.200000003, y: 0.0500000007, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -1.04719758}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 196754
Name: Piece5
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0839636326, y: 0.175804704, z: 0.0484313965}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 146157335
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.25, y: 0.0500000007, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0.436332315}
IsActive: true
Scripts:
- Type: Item
Enabled: true
Score: 10
currCategory: 1
density: 5
dontReturn: false
- EID: 144
Name: Egg
IsActive: true
NumberOfChildren: 4
Components:
Transform Component:
Translate: {x: 3.11708331, y: 0.333341181, z: 6.14019775}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 0.999979734, y: 1, z: 0.999979734}
IsActive: true
Renderable Component:
Mesh: 147457317
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Sphere
Radius: 0.075000003
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Breakable
Enabled: true
threshHold: 1
ignoreRaccoon: true
- Type: Item
Enabled: true
Score: 10
currCategory: 0
density: 80
dontReturn: false
- EID: 143
Name: Piece1
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.0224030018, y: 0.0607728958, z: -0.00627422333}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 134900190
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0.164060935, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 142
Name: Piece2
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.00627422333, y: 0.0337567925, z: -0.00243234634}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 146271645
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -0.34906584}
IsActive: true
Scripts: ~
- EID: 141
Name: Piece3
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0166685581, y: -0.0367090404, z: 0.0114421844}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 135945648
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -0.261799395}
IsActive: true
Scripts: ~
- EID: 140
Name: Piece4
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.020128727, y: -0.0155199468, z: -0.0045747757}
Rotate: {x: 0, y: 3.6088712e-09, z: 1.97286229e-16}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 141722646
Material: 131956078
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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: false
Collision Tag: 1
Type: Box
Half Extents: {x: 0.0500000007, y: 0.0500000007, z: 0.0500000007}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: -1.04719758}
IsActive: true
Scripts: ~
- EID: 15 - EID: 15
Name: ====ScoreZonePool==== Name: ====ScoreZonePool====
IsActive: true IsActive: true
@ -8966,8 +9485,6 @@
Scripts: Scripts:
- Type: GameManager - Type: GameManager
Enabled: true Enabled: true
itemPool: 240
zonePool: 15
winScene: 92009475 winScene: 92009475
loseScene: 91685359 loseScene: 91685359
currGameState: 0 currGameState: 0
@ -9087,7 +9604,7 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: 0.700000048, z: 0.200000286} Translate: {x: 0, y: 0.899999976, z: 0.200000286}
Rotate: {x: 0, y: 0, z: -0} Rotate: {x: 0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
@ -9206,7 +9723,7 @@
- Type: Breakable - Type: Breakable
Enabled: true Enabled: true
threshHold: 0.100000001 threshHold: 0.100000001
force: 1 ignoreRaccoon: false
- EID: 196 - EID: 196
Name: Piece1 Name: Piece1
IsActive: true IsActive: true
@ -9415,7 +9932,7 @@
- Type: Breakable - Type: Breakable
Enabled: true Enabled: true
threshHold: 0.100000001 threshHold: 0.100000001
force: 1 ignoreRaccoon: false
- EID: 65703 - EID: 65703
Name: Piece1 Name: Piece1
IsActive: true IsActive: true
@ -9624,7 +10141,7 @@
- Type: Breakable - Type: Breakable
Enabled: true Enabled: true
threshHold: 0.100000001 threshHold: 0.100000001
force: 1 ignoreRaccoon: false
- EID: 65708 - EID: 65708
Name: Piece1 Name: Piece1
IsActive: true IsActive: true

View File

@ -95,6 +95,9 @@ public partial class LeafAttack : BehaviourTreeNode
//Catch player when in range for long enough //Catch player when in range for long enough
//Debug.Log("Success: Caught"); //Debug.Log("Success: Caught");
player.GetScript<PlayerController>().currentState = PlayerController.RaccoonStates.CAUGHT; player.GetScript<PlayerController>().currentState = PlayerController.RaccoonStates.CAUGHT;
if (player.GetScript<PlayerController>().stateMachine && !player.GetScript<PlayerController>().stateMachine.IsState(typeof(PlayerCaughtState)))
player.GetScript<PlayerController>().stateMachine.SetState(typeof(PlayerCaughtState));
status = BehaviourTreeNodeStatus.SUCCESS; status = BehaviourTreeNodeStatus.SUCCESS;
onExit(BehaviourTreeNodeStatus.SUCCESS); onExit(BehaviourTreeNodeStatus.SUCCESS);
return status; return status;

View File

@ -7,12 +7,13 @@ using System.Xml.Linq;
public class Breakable : Script public class Breakable : Script
{ {
public float threshHold = 1.0f; public float threshHold = 1.0f;
public float force = 2.0f; public bool ignoreRaccoon = false;
private RigidBody rb; private RigidBody rb;
private Transform trans; private Transform trans;
private bool isBreak = false; public bool isBreak { get; set; }
private List<GameObject> itemPieces = new List<GameObject>(); private List<GameObject> itemPieces = new List<GameObject>();
private Random ran = new Random(); private Random ran = new Random();
protected override void awake() protected override void awake()
{ {
rb = GetComponent<RigidBody>(); rb = GetComponent<RigidBody>();
@ -28,6 +29,8 @@ public class Breakable : Script
itemPieces.Add(pieces); itemPieces.Add(pieces);
pieces.SetActive(false); pieces.SetActive(false);
} }
isBreak = false;
} }
protected override void update() protected override void update()
@ -38,9 +41,14 @@ public class Breakable : Script
protected override void onCollisionEnter(CollisionInfo info) protected override void onCollisionEnter(CollisionInfo info)
{ {
if (ignoreRaccoon && info.GameObject.GetScript<PlayerController>())
return;
if (rb.LinearVelocity.GetSqrMagnitude() > threshHold) if (rb.LinearVelocity.GetSqrMagnitude() > threshHold)
{ {
isBreak = true; isBreak = true;
if(GameObject.GetScript<Item>())
GameManager.Instance.totalItemCount -= 1;
} }
} }
protected override void onTriggerEnter(CollisionInfo info) protected override void onTriggerEnter(CollisionInfo info)
@ -54,12 +62,14 @@ public class Breakable : Script
{ {
item.SetActive(true); item.SetActive(true);
item.GetComponent<Transform>().GlobalPosition = trans.LocalPosition + item.GetComponent<Transform>().LocalPosition; item.GetComponent<Transform>().GlobalPosition = trans.LocalPosition + item.GetComponent<Transform>().LocalPosition;
if (item.GetScript<Item>())
GameManager.Instance.totalItemCount += 1;
GameObject gO = item; GameObject gO = item;
gO.Parent = GameObject.Null; gO.Parent = GameObject.Null;
} }
isBreak = false; isBreak = false;
Audio.PlaySFXOnce2D("event:/Props/impact_break"); Audio.PlaySFXOnce2D("event:/Props/impact_break");
Owner.SetActive(false); GameObject.SetActive(false);
} }
} }

View File

@ -12,33 +12,65 @@ public class Item : Script
public int Score = 10; public int Score = 10;
public ItemCategory currCategory; public ItemCategory currCategory;
private RigidBody rb; public bool returnBack { get; set; }
private bool once = false; private Transform transform;
private bool playSound = false;
private bool caputurePos = false;
private Vector3 firstPostion;
private Collider collider;
public float density = 1.0f;
public bool dontReturn = false;
protected override void awake() protected override void awake()
{ {
rb = GetComponent<RigidBody>(); transform = GetComponent<Transform>();
collider = GetComponent<Collider>();
if(collider)
collider.GetCollisionShape(0).Density = density;
returnBack = false;
}
protected override void start()
{
GameManager.Instance.totalItemCount += 1;
} }
protected override void update() protected override void update()
{ {
if (returnBack && !dontReturn)
{
transform.LocalPosition = firstPostion;
returnBack = false;
}
} }
protected override void onCollisionEnter(CollisionInfo info) protected override void onCollisionEnter(CollisionInfo info)
{ {
if (once) if (!caputurePos)
{
firstPostion = transform.LocalPosition;
caputurePos = true;
}
if (playSound)
{ {
if(currCategory == ItemCategory.LIGHT) if(currCategory == ItemCategory.LIGHT)
Audio.PlaySFXOnce2D("event:/Props/impact_elastic"); Audio.PlaySFXOnce2D("event:/Props/impact_elastic");
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY) else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
Audio.PlaySFXOnce2D("event:/Props/impact_hard"); Audio.PlaySFXOnce2D("event:/Props/impact_hard");
once = false; playSound = false;
}
if (info.GameObject.GetScript<Homeowner1>())
{
returnBack = true;
} }
} }
protected override void onCollisionExit(CollisionInfo info) protected override void onCollisionExit(CollisionInfo info)
{ {
once = true; playSound = true;
} }
} }

View File

@ -223,7 +223,6 @@ public class PickAndThrow : Script
return false; return false;
} }
return false; return false;
} }

View File

@ -31,7 +31,7 @@ public class PlayerController : Script
public Camera cam { get; set; } public Camera cam { get; set; }
public CameraArm camArm { get; set; } public CameraArm camArm { get; set; }
private PickAndThrow pat; private PickAndThrow pat;
private StateMachine stateMachine; public StateMachine stateMachine;
public bool holdItem { get; set; } public bool holdItem { get; set; }
public bool isAiming { get; set; } public bool isAiming { get; set; }
@ -370,6 +370,13 @@ public class PlayerController : Script
if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
stateMachine.SetState(typeof(PlayerIdleState)); stateMachine.SetState(typeof(PlayerIdleState));
tranform.LocalPosition = respawnPoint.GetComponent<Transform>().LocalPosition; tranform.LocalPosition = respawnPoint.GetComponent<Transform>().LocalPosition;
if (pat && pat.item.GetScript<Item>())
{
holdItem = false;
isAiming = false;
pat.item.GetScript<Item>().returnBack = true;
}
} }
} }

View File

@ -11,9 +11,6 @@ public class GameManager : Script
LOSE LOSE
} }
public GameObject itemPool;
public GameObject zonePool;
public uint winScene = 92009475; public uint winScene = 92009475;
public uint loseScene = 91685359; public uint loseScene = 91685359;
@ -26,49 +23,29 @@ public class GameManager : Script
[NonSerialized] [NonSerialized]
public float timer; public float timer;
private IEnumerable<Item> listOfItems;
private IEnumerable<ScoringZone> listOfZone;
public GameObject scoreText; public GameObject scoreText;
public GameObject timeText; public GameObject timeText;
private bool once = true; public static GameManager Instance { get; private set; }
protected override void awake() protected override void awake()
{ {
if (Instance != null && Instance != this)
RemoveScript<GameManager>();
else
Instance = this;
Audio.PlayBGMOnce2D("event:/Music/player_undetected"); Audio.PlayBGMOnce2D("event:/Music/player_undetected");
Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen"); Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen");
totalItemCount = 0; totalItemCount = 0;
Score = 0; Score = 0;
currGameState = GameState.START; currGameState = GameState.START;
} }
protected override void update() protected override void update()
{ {
Cheats(); Cheats();
if (once)
{
if (itemPool)
{
listOfItems = itemPool.GetScriptsInChildren<Item>();
if (listOfItems != null)
foreach (Item i in listOfItems)
totalItemCount += 1;
}
if (zonePool)
{
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
if (listOfZone != null)
foreach (ScoringZone sz in listOfZone)
sz.gameManger = Owner.GetScript<GameManager>();
}
once = false;
}
if (currGameState == GameState.START) if (currGameState == GameState.START)
{ {
timer -= Time.DeltaTimeF; timer -= Time.DeltaTimeF;
@ -77,7 +54,7 @@ public class GameManager : Script
if(timeText) if(timeText)
timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0.00")}"; timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0.00")}";
if ((timer > 0 && totalItemCount <= 0) || Input.GetKeyDown(Input.KeyCode.F1)) if ((timer > 0 && totalItemCount < 0) || Input.GetKeyDown(Input.KeyCode.F1))
{ {
currGameState = GameState.WIN; currGameState = GameState.WIN;
Audio.StopAllSounds(); Audio.StopAllSounds();
@ -94,6 +71,12 @@ public class GameManager : Script
} }
} }
protected override void onDestroy()
{
if (Instance == this)
Instance = null;
}
private void Cheats() private void Cheats()
{ {
if (Input.GetKeyDown(Input.KeyCode.Escape)) if (Input.GetKeyDown(Input.KeyCode.Escape))

View File

@ -2,7 +2,6 @@
using System; using System;
public class ScoringZone : Script public class ScoringZone : Script
{ {
public GameManager gameManger { get; set; }
protected override void awake() protected override void awake()
{ {
@ -10,11 +9,11 @@ public class ScoringZone : Script
protected override void onTriggerEnter(CollisionInfo info) protected override void onTriggerEnter(CollisionInfo info)
{ {
if (gameManger && info.GameObject.GetScript<Item>()) if (GameManager.Instance && info.GameObject.GetScript<Item>())
{ {
Audio.PlaySFXOnce2D("event:/Music/stingers/item_scored"); Audio.PlaySFXOnce2D("event:/Music/stingers/item_scored");
gameManger.Score += info.GameObject.GetScript<Item>().Score; GameManager.Instance.Score += info.GameObject.GetScript<Item>().Score;
gameManger.totalItemCount -= 1; GameManager.Instance.totalItemCount -= 1;
info.GameObject.SetActive(false); info.GameObject.SetActive(false);
} }
} }

View File

@ -4,6 +4,7 @@
//|| SHADE Includes || //|| SHADE Includes ||
//#==============================================================# //#==============================================================#
#include "Editor/EditorWindow/SHEditorWindow.h" #include "Editor/EditorWindow/SHEditorWindow.h"
#include "Editor/SHEditor.h"
namespace SHADE namespace SHADE
{ {

View File

@ -31,6 +31,9 @@ of DigiPen Institute of Technology is prohibited.
#include "Assets/SHAssetMacros.h" #include "Assets/SHAssetMacros.h"
#include "Tools/Utilities/SHExecUtilities.h" #include "Tools/Utilities/SHExecUtilities.h"
#include "SHVSUtilities.h" #include "SHVSUtilities.h"
#include "UI/Events/SHButtonClickEvent.h"
#include "UI/SHUIComponent.h"
#include "Editor/EditorWindow/MenuBar/SHEditorMenuBar.h"
namespace SHADE namespace SHADE
{ {
@ -121,6 +124,11 @@ namespace SHADE
csScriptsRemoveAllImmediately(entity, callOnDestroy); csScriptsRemoveAllImmediately(entity, callOnDestroy);
} }
void SHScriptEngine::RemoveAllScriptsFromAllImmediately(bool callOnDestroy)
{
csScriptRemoveAllForAllNow(callOnDestroy);
}
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Script Serialisation Functions */ /* Script Serialisation Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -346,6 +354,21 @@ namespace SHADE
return eventData->handle; return eventData->handle;
} }
SHEventHandle SHScriptEngine::onUIElementRemoved(SHEventPtr eventPtr)
{
auto eventData = reinterpret_cast<const SHEventSpec<SHComponentRemovedEvent>*>(eventPtr.get());
if (eventData->data->removedComponentType == ComponentFamily::GetID<SHUIComponent>())
csUIElementOnRemoved(eventData->data->eid);
return eventData->handle;
}
SHEventHandle SHScriptEngine::onUIElementClicked(SHEventPtr eventPtr)
{
auto eventData = reinterpret_cast<const SHEventSpec<SHButtonClickEvent>*>(eventPtr.get());
csUIElementOnClicked(eventData->data->EID);
return eventData->handle;
}
SHEventHandle SHScriptEngine::onSceneNodeChildrenAdded(SHEventPtr eventPtr) SHEventHandle SHScriptEngine::onSceneNodeChildrenAdded(SHEventPtr eventPtr)
{ {
auto eventData = reinterpret_cast<const SHEventSpec<SHSceneGraphAddChildEvent>*>(eventPtr.get()); auto eventData = reinterpret_cast<const SHEventSpec<SHSceneGraphAddChildEvent>*>(eventPtr.get());
@ -360,6 +383,13 @@ namespace SHADE
return eventData->handle; return eventData->handle;
} }
SHEventHandle SHScriptEngine::onSceneDestroyed(SHEventPtr eventPtr)
{
auto eventData = reinterpret_cast<const SHEventSpec<SHEditorStateChangeEvent>*>(eventPtr.get());
csScriptRemoveAllForAllNow(true);
return eventData->handle;
}
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -460,6 +490,12 @@ namespace SHADE
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
"RemoveAllScriptsImmediately" "RemoveAllScriptsImmediately"
); );
csScriptRemoveAllForAllNow = dotNet.GetFunctionPtr<CsScriptBoolFuncPtr>
(
DEFAULT_CSHARP_LIB_NAME,
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
"RemoveAllScriptsFromAllImmediately"
);
csScriptsSerialiseYaml = dotNet.GetFunctionPtr<CsScriptSerialiseYamlFuncPtr> csScriptsSerialiseYaml = dotNet.GetFunctionPtr<CsScriptSerialiseYamlFuncPtr>
( (
DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_LIB_NAME,
@ -490,6 +526,18 @@ namespace SHADE
DEFAULT_CSHARP_NAMESPACE + ".ChildListCache", DEFAULT_CSHARP_NAMESPACE + ".ChildListCache",
"OnChildrenChanged" "OnChildrenChanged"
); );
csUIElementOnRemoved = dotNet.GetFunctionPtr<CsEventRelayFuncPtr>
(
DEFAULT_CSHARP_LIB_NAME,
DEFAULT_CSHARP_NAMESPACE + ".UIElement",
"OnComponentRemoved"
);
csUIElementOnClicked = dotNet.GetFunctionPtr<CsEventRelayFuncPtr>
(
DEFAULT_CSHARP_LIB_NAME,
DEFAULT_CSHARP_NAMESPACE + ".UIElement",
"OnClicked"
);
csEditorRenderScripts = dotNet.GetFunctionPtr<CsScriptEditorFuncPtr> csEditorRenderScripts = dotNet.GetFunctionPtr<CsScriptEditorFuncPtr>
( (
DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_LIB_NAME,
@ -520,6 +568,14 @@ namespace SHADE
}; };
SHEventManager::SubscribeTo(SH_ENTITY_DESTROYED_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(destroyedEventReceiver)); SHEventManager::SubscribeTo(SH_ENTITY_DESTROYED_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(destroyedEventReceiver));
/* Editor */
// Register for editor state change event
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> destroyedSceneEventReceiver
{
std::make_shared<SHEventReceiverSpec<SHScriptEngine>>(this, &SHScriptEngine::onSceneDestroyed)
};
SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(destroyedSceneEventReceiver));
/* Colliders */ /* Colliders */
// Register for collider added event // Register for collider added event
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> addedColliderEventReceiver std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> addedColliderEventReceiver
@ -540,6 +596,18 @@ namespace SHADE
}; };
SHEventManager::SubscribeTo(SH_COMPONENT_REMOVED_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(removedColliderComponentEventReceiver)); SHEventManager::SubscribeTo(SH_COMPONENT_REMOVED_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(removedColliderComponentEventReceiver));
/* UI Element */
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> removedUIElementEventReceiver
{
std::make_shared<SHEventReceiverSpec<SHScriptEngine>>(this, &SHScriptEngine::onUIElementRemoved)
};
SHEventManager::SubscribeTo(SH_COMPONENT_REMOVED_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(removedUIElementEventReceiver));
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> clickedUIElementEventReceiver
{
std::make_shared<SHEventReceiverSpec<SHScriptEngine>>(this, &SHScriptEngine::onUIElementClicked)
};
SHEventManager::SubscribeTo(SH_BUTTON_CLICK_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(clickedUIElementEventReceiver));
/* SceneGraph */ /* SceneGraph */
// Register for SceneNode child added event // Register for SceneNode child added event
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> addChildEventReceiver std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> addChildEventReceiver

View File

@ -148,6 +148,13 @@ namespace SHADE
/// play mode. /// play mode.
/// </param> /// </param>
void RemoveAllScriptsImmediately(EntityID entity, bool callOnDestroy); void RemoveAllScriptsImmediately(EntityID entity, bool callOnDestroy);
/// <summary>
/// Removes all Scripts attached to all entities immediately. The
/// </summary>
/// <param name="callOnDestroy">
/// Whether or not to call OnDestroy on the scripts.
/// </param>
void RemoveAllScriptsFromAllImmediately(bool callOnDestroy);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Script Serialisation Functions */ /* Script Serialisation Functions */
@ -235,6 +242,7 @@ namespace SHADE
using CsScriptManipFuncPtr = bool(*)(EntityID, const char*); using CsScriptManipFuncPtr = bool(*)(EntityID, const char*);
using CsScriptBasicFuncPtr = void(*)(EntityID); using CsScriptBasicFuncPtr = void(*)(EntityID);
using CsScriptOptionalFuncPtr = void(*)(EntityID, bool); using CsScriptOptionalFuncPtr = void(*)(EntityID, bool);
using CsScriptBoolFuncPtr = void(*)(bool);
using CsScriptSerialiseYamlFuncPtr = bool(*)(EntityID, void*); using CsScriptSerialiseYamlFuncPtr = bool(*)(EntityID, void*);
using CsScriptDeserialiseYamlFuncPtr = bool(*)(EntityID, const void*); using CsScriptDeserialiseYamlFuncPtr = bool(*)(EntityID, const void*);
using CsScriptEditorFuncPtr = void(*)(EntityID); using CsScriptEditorFuncPtr = void(*)(EntityID);
@ -271,12 +279,15 @@ namespace SHADE
CsScriptManipFuncPtr csScriptsAdd = nullptr; CsScriptManipFuncPtr csScriptsAdd = nullptr;
CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr; CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr;
CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately = nullptr; CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately = nullptr;
CsScriptBoolFuncPtr csScriptRemoveAllForAllNow = nullptr;
CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml = nullptr; CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml = nullptr;
CsScriptDeserialiseYamlFuncPtr csScriptsDeserialiseYaml = nullptr; CsScriptDeserialiseYamlFuncPtr csScriptsDeserialiseYaml = nullptr;
// - Events // - Events
CsEventRelayFuncPtr csColliderOnListChanged = nullptr; CsEventRelayFuncPtr csColliderOnListChanged = nullptr;
CsEventRelayFuncPtr csColliderOnRemoved = nullptr; CsEventRelayFuncPtr csColliderOnRemoved = nullptr;
CsEventRelayFuncPtr csSceneNodeChildrenChanged = nullptr; CsEventRelayFuncPtr csSceneNodeChildrenChanged = nullptr;
CsEventRelayFuncPtr csUIElementOnRemoved = nullptr;
CsEventRelayFuncPtr csUIElementOnClicked = nullptr;
// - Editor // - Editor
CsScriptEditorFuncPtr csEditorRenderScripts = nullptr; CsScriptEditorFuncPtr csEditorRenderScripts = nullptr;
CsFuncPtr csEditorUndo = nullptr; CsFuncPtr csEditorUndo = nullptr;
@ -289,8 +300,11 @@ namespace SHADE
SHEventHandle onColliderAdded(SHEventPtr eventPtr); SHEventHandle onColliderAdded(SHEventPtr eventPtr);
SHEventHandle onColliderRemoved(SHEventPtr eventPtr); SHEventHandle onColliderRemoved(SHEventPtr eventPtr);
SHEventHandle onColliderComponentRemoved(SHEventPtr eventPtr); SHEventHandle onColliderComponentRemoved(SHEventPtr eventPtr);
SHEventHandle onUIElementRemoved(SHEventPtr eventPtr);
SHEventHandle onUIElementClicked(SHEventPtr eventPtr);
SHEventHandle onSceneNodeChildrenAdded(SHEventPtr eventPtr); SHEventHandle onSceneNodeChildrenAdded(SHEventPtr eventPtr);
SHEventHandle onSceneNodeChildrenRemoved(SHEventPtr eventPtr); SHEventHandle onSceneNodeChildrenRemoved(SHEventPtr eventPtr);
SHEventHandle onSceneDestroyed(SHEventPtr eventPtr);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */

View File

@ -41,6 +41,8 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
Asset::operator bool(Asset asset) Asset::operator bool(Asset asset)
{ {
static_assert(INVALID_ASSET_ID == 0,
"This must be 0 due to the way structs are default initialized to ensure Assets are invalid if default constructed.");
return asset.NativeAssetID != INVALID_ASSET_ID; return asset.NativeAssetID != INVALID_ASSET_ID;
} }
} }

View File

@ -22,7 +22,8 @@ of DigiPen Institute of Technology is prohibited.
namespace SHADE namespace SHADE
{ {
/// <summary> /// <summary>
/// Struct that contains native asset information. /// Struct that contains native asset information. Default constructed assets have
/// an internval value of 0 which is the invalid ID.
/// </summary> /// </summary>
public value struct Asset public value struct Asset
{ {

View File

@ -30,34 +30,36 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Properties */ /* Properties */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHADE::MeshAsset^ Renderable::Mesh::get() MeshAsset Renderable::Mesh::get()
{ {
return gcnew SHADE::MeshAsset(GetNativeComponent()->GetMesh()); auto mesh = GetNativeComponent()->GetMesh();
return mesh ? MeshAsset(mesh) : MeshAsset();
} }
void Renderable::Mesh::set(SHADE::MeshAsset^ value) void Renderable::Mesh::set(MeshAsset value)
{ {
if (value == nullptr) if (value)
{ {
GetNativeComponent()->SetMesh(Handle<SHMesh>()); GetNativeComponent()->SetMesh(Handle<SHMesh>());
} }
else else
{ {
GetNativeComponent()->SetMesh(value->NativeObject); GetNativeComponent()->SetMesh(value.NativeObject);
} }
} }
SHADE::Material^ Renderable::Material::get() SHADE::Material Renderable::Material::get()
{ {
return gcnew SHADE::Material(GetNativeComponent()->GetMaterial()); auto mat = GetNativeComponent()->GetMaterial();
return mat ? SHADE::Material(mat) : SHADE::Material();
} }
void Renderable::Material::set(SHADE::Material^ value) void Renderable::Material::set(SHADE::Material value)
{ {
if (value == nullptr) if (value)
{ {
GetNativeComponent()->SetMaterial(Handle<SHMaterialInstance>()); GetNativeComponent()->SetMaterial(Handle<SHMaterialInstance>());
} }
else else
{ {
GetNativeComponent()->SetMaterial(Handle<SHMaterialInstance>(Convert::ToNative(value->NativeObjectHandle))); GetNativeComponent()->SetMaterial(Handle<SHMaterialInstance>(Convert::ToNative(value.NativeObjectHandle)));
} }
} }
System::Byte Renderable::LightLayer::get() System::Byte Renderable::LightLayer::get()

View File

@ -49,18 +49,18 @@ namespace SHADE
/// <summary> /// <summary>
/// Mesh used to render this Renderable. /// Mesh used to render this Renderable.
/// </summary> /// </summary>
property SHADE::MeshAsset^ Mesh property MeshAsset Mesh
{ {
SHADE::MeshAsset^ get(); MeshAsset get();
void set(SHADE::MeshAsset^ value); void set(MeshAsset value);
} }
/// <summary> /// <summary>
/// Material used to render this Renderable. /// Material used to render this Renderable.
/// </summary> /// </summary>
property SHADE::Material^ Material property SHADE::Material Material
{ {
SHADE::Material^ get(); SHADE::Material get();
void set(SHADE::Material^ value); void set(SHADE::Material value);
} }
/// <summary> /// <summary>
/// Material used to render this Renderable. /// Material used to render this Renderable.

View File

@ -39,19 +39,20 @@ namespace SHADE
{ {
GetNativeComponent()->SetText(Convert::ToNative(value)); GetNativeComponent()->SetText(Convert::ToNative(value));
} }
SHADE::FontAsset^ TextRenderable::Font::get() FontAsset TextRenderable::Font::get()
{ {
return gcnew SHADE::FontAsset(GetNativeComponent()->GetFont()); auto font = GetNativeComponent()->GetFont();
return font ? FontAsset(font) : FontAsset();
} }
void TextRenderable::Font::set(SHADE::FontAsset^ value) void TextRenderable::Font::set(FontAsset value)
{ {
if (value == nullptr) if (value)
{ {
GetNativeComponent()->SetFont(Handle<SHFont>()); GetNativeComponent()->SetFont(Handle<SHFont>());
} }
else else
{ {
GetNativeComponent()->SetFont(value->NativeObject); GetNativeComponent()->SetFont(value.NativeObject);
} }
} }
} }

View File

@ -55,10 +55,10 @@ namespace SHADE
/// <summary> /// <summary>
/// Font to use to render using this TextRenderable. /// Font to use to render using this TextRenderable.
/// </summary> /// </summary>
property SHADE::FontAsset^ Font property FontAsset Font
{ {
SHADE::FontAsset^ get(); FontAsset get();
void set(SHADE::FontAsset^ value); void set(FontAsset value);
} }
}; };
} }

View File

@ -0,0 +1,75 @@
/************************************************************************************//*!
\file UIElement.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Jan 30, 2023
\brief Contains the definition of the functions of the managed UIElement class.
Note: This file is written in C++17/CLI.
Copyright (C) 2023 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "UIElement.hxx"
#include "Assets/NativeAsset.hxx"
#include "Utility/Convert.hxx"
#include "Utility/Debug.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
UIElement::UIElement(Entity entity)
: Component(entity)
{}
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
CallbackEvent^ UIElement::OnClick::get()
{
// Create map if it wasn't before
if (onClickEventMap == nullptr)
{
onClickEventMap = gcnew System::Collections::Generic::Dictionary<Entity, CallbackEvent ^>();
}
// Create event if it wasn't before
if (!onClickEventMap->ContainsKey(owner.EntityId))
{
onClickEventMap->Add(owner.EntityId, gcnew CallbackEvent());
}
// Return the event
return onClickEventMap[owner.EntityId];
}
/*---------------------------------------------------------------------------------*/
/* Event Handling Functions */
/*-----------------------------------------------------------------------------a----*/
void UIElement::OnComponentRemoved(EntityID entity)
{
SAFE_NATIVE_CALL_BEGIN
// Remove the event if it contained an event
if (onClickEventMap != nullptr && onClickEventMap->ContainsKey(entity))
{
onClickEventMap->Remove(entity);
}
SAFE_NATIVE_CALL_END("UIElement.OnComponentRemoved")
}
void UIElement::OnClicked(EntityID entity)
{
SAFE_NATIVE_CALL_BEGIN
// Remove the event if it contained an event
if (onClickEventMap != nullptr && onClickEventMap->ContainsKey(entity))
{
onClickEventMap[entity]->Invoke();
}
SAFE_NATIVE_CALL_END("UIElement.OnClicked")
}
}

View File

@ -0,0 +1,75 @@
/************************************************************************************//*!
\file UIElement.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Jan 30, 2023
\brief Contains the definition of the managed UIElement class with the
declaration of functions for working with it.
Note: This file is written in C++17/CLI.
Copyright (C) 2023 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// Project Includes
#include "Components/Component.hxx"
#include "Math/Vector3.hxx"
#include "Math/Quaternion.hxx"
// External Dependencies
#include "UI/SHUIComponent.h"
namespace SHADE
{
/// <summary>
/// CLR version of the SHADE Engine's SHUIComponent.
/// </summary>
public ref class UIElement : public Component<SHUIComponent>
{
internal:
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructs a UIElement Component that represents a native SHUIComponent
/// tied to the specified Entity.
/// </summary>
/// <param name="entity">Entity that this Component will be tied to.</param>
UIElement(Entity entity);
public:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Event that is raised when this UIElement is clicked.
/// </summary>
property CallbackEvent^ OnClick
{
CallbackEvent^ get();
}
private:
/*-----------------------------------------------------------------------------*/
/* Event Handling Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// To be called from native code when this component is removed.
/// </summary>
/// <param name="entity">The entity which has it's component removed.</param>
static void OnComponentRemoved(EntityID entity);
/// <summary>
/// To be called from native code when this component is clicked.
/// </summary>
/// <param name="entity">The entity which was clicked.</param>
static void OnClicked(EntityID entity);
/*-----------------------------------------------------------------------------*/
/* Static Data Members */
/*-----------------------------------------------------------------------------*/
static System::Collections::Generic::Dictionary<Entity, CallbackEvent^>^ onClickEventMap;
};
}

View File

@ -29,6 +29,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Tools/Logger/SHLog.h" #include "Tools/Logger/SHLog.h"
#include "Graphics\MiddleEnd\Interface\SHRenderable.h" #include "Graphics\MiddleEnd\Interface\SHRenderable.h"
#include "Graphics\MiddleEnd\TextRendering\SHTextRenderableComponent.h" #include "Graphics\MiddleEnd\TextRendering\SHTextRenderableComponent.h"
#include "UI\SHUIComponent.h"
// Project Headers // Project Headers
#include "Utility/Convert.hxx" #include "Utility/Convert.hxx"
#include "Utility/Debug.hxx" #include "Utility/Debug.hxx"
@ -40,6 +41,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Components/Light.hxx" #include "Components/Light.hxx"
#include "Components\Renderable.hxx" #include "Components\Renderable.hxx"
#include "Components\TextRenderable.hxx" #include "Components\TextRenderable.hxx"
#include "Components\UIElement.hxx"
namespace SHADE namespace SHADE
{ {
@ -324,6 +326,7 @@ namespace SHADE
componentMap.Add(createComponentSet<SHCameraArmComponent, CameraArm>()); componentMap.Add(createComponentSet<SHCameraArmComponent, CameraArm>());
componentMap.Add(createComponentSet<SHLightComponent, Light>()); componentMap.Add(createComponentSet<SHLightComponent, Light>());
componentMap.Add(createComponentSet<SHTextRenderableComponent, TextRenderable>()); componentMap.Add(createComponentSet<SHTextRenderableComponent, TextRenderable>());
componentMap.Add(createComponentSet<SHUIComponent, UIElement>());
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -259,6 +259,13 @@ namespace SHADE
ScriptStore::RemoveScript<T>(entity); ScriptStore::RemoveScript<T>(entity);
} }
void GameObject::RemoveScript(Script^ script)
{
if (!valid)
throw gcnew System::NullReferenceException();
ScriptStore::RemoveScript(entity, script);
}
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Scene Graph Functions */ /* Scene Graph Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -259,6 +259,12 @@ namespace SHADE
/// <typeparam name="T">Type of Scripts to remove.</typeparam> /// <typeparam name="T">Type of Scripts to remove.</typeparam>
generic<typename T> where T : ref class, Script generic<typename T> where T : ref class, Script
void RemoveScript(); void RemoveScript();
/// <summary>
/// Removes a specific script from this script's parent.
/// </summary>
/// <param name="script">The script to remove.</param>
/// <returns>True if successfully removed. False otherwise.</returns>
void RemoveScript(Script^ script);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Scene Graph Functions */ /* Scene Graph Functions */

View File

@ -126,6 +126,11 @@ namespace SHADE
ScriptStore::RemoveScript<T>(owner.GetEntity()); ScriptStore::RemoveScript<T>(owner.GetEntity());
} }
void Script::RemoveScript(Script^ script)
{
ScriptStore::RemoveScript(owner.GetEntity(), script);
}
Script::operator bool(Script^ s) Script::operator bool(Script^ s)
{ {
return s != nullptr; return s != nullptr;

View File

@ -198,6 +198,12 @@ namespace SHADE
/// </typeparam> /// </typeparam>
generic<typename T> where T : ref class, Script generic<typename T> where T : ref class, Script
void RemoveScript(); void RemoveScript();
/// <summary>
/// Removes a specific script from this script's parent.
/// </summary>
/// <param name="script">The script to remove.</param>
/// <returns>True if successfully removed. False otherwise.</returns>
void RemoveScript(Script^ script);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Operator Overloads */ /* Operator Overloads */

View File

@ -400,21 +400,21 @@ namespace SHADE
return; return;
// Clear all // Clear all
System::Collections::Generic::List<Script^>^ scriptList = scripts[entity]; removeAllScriptsImmediately(entity, callOnDestroy && Application::IsPlaying || Application::IsPaused);
for each (Script ^ script in scriptList) SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
{
// Call OnDestroy only if indicated and also if the game has run
if (callOnDestroy && Application::IsPlaying || Application::IsPaused)
{
script->OnDestroy();
} }
script->OnDetached();
// Remove scripts from awakening if they were not woken up to begin with void ScriptStore::RemoveAllScriptsFromAllImmediately(bool callOnDestroy)
awakeList.Remove(script); {
startList.Remove(script); SAFE_NATIVE_CALL_BEGIN
// Clear all
for each (System::Collections::Generic::KeyValuePair<Entity, ScriptList^>^ pair in scripts)
{
removeAllScriptsImmediately(pair->Key, callOnDestroy);
} }
scriptList->Clear(); awakeList.Clear();
startList.Clear();
disposalQueue.Clear();
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
} }
@ -798,6 +798,25 @@ namespace SHADE
script->OnDetached(); script->OnDetached();
} }
void ScriptStore::removeAllScriptsImmediately(Entity entity, bool callOnDestroy)
{
System::Collections::Generic::List<Script^>^ scriptList = scripts[entity];
for each (Script ^ script in scriptList)
{
// Call OnDestroy only if indicated and also if the game has run
if (callOnDestroy)
{
script->OnDestroy();
}
script->OnDetached();
// Remove scripts from awakening if they were not woken up to begin with
awakeList.Remove(script);
startList.Remove(script);
}
scriptList->Clear();
}
namespace namespace
{ {
/* Select Many */ /* Select Many */

View File

@ -203,7 +203,7 @@ namespace SHADE
generic<typename T> where T : ref class, Script generic<typename T> where T : ref class, Script
static void RemoveScript(Entity entity); static void RemoveScript(Entity entity);
/// <summary> /// <summary>
/// Removes a specific script from the /// Removes a specific script from the specified entity.
/// </summary> /// </summary>
/// <param name="entity">The entity to remove the script from.</param> /// <param name="entity">The entity to remove the script from.</param>
/// <param name="script">The script to remove.</param> /// <param name="script">The script to remove.</param>
@ -228,6 +228,13 @@ namespace SHADE
/// play mode. /// play mode.
/// </param> /// </param>
static void RemoveAllScriptsImmediately(Entity entity, bool callOnDestroy); static void RemoveAllScriptsImmediately(Entity entity, bool callOnDestroy);
/// <summary>
/// Removes all Scripts attached to all entities immediately. The
/// </summary>
/// <param name="callOnDestroy">
/// Whether or not to call OnDestroy on the scripts.
/// </param>
static void RemoveAllScriptsFromAllImmediately(bool callOnDestroy);
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -343,6 +350,7 @@ namespace SHADE
/* Helper Functions */ /* Helper Functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
static void removeScript(Script^ script); static void removeScript(Script^ script);
static void removeAllScriptsImmediately(Entity script, bool callOnDestroy);
static void refreshScriptTypeList(); static void refreshScriptTypeList();
static void getGenericMethods(); static void getGenericMethods();
static System::Type^ getScriptType(System::String^ scriptName); static System::Type^ getScriptType(System::String^ scriptName);