Update changes to scripts and AudioSystem #224

Merged
glencelow merged 15 commits from PlayerController into main 2022-11-18 19:01:24 +08:00
24 changed files with 1025 additions and 110 deletions

Binary file not shown.

Binary file not shown.

BIN
Assets/Audio/Music.bank Normal file

Binary file not shown.

BIN
Assets/Audio/SFX.bank Normal file

Binary file not shown.

BIN
Assets/Audio/UI.bank Normal file

Binary file not shown.

View File

@ -0,0 +1,454 @@
- EID: 0
Name: ScoreZone
IsActive: true
NumberOfChildren: 0
Components:
Camera Component:
Position: {x: 0, y: 0, z: 0}
Pitch: 0
Yaw: 0
Roll: 0
Width: 1920
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
IsActive: true
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Directional
Direction: {x: 1.79999995, y: 0, z: 1}
Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1}
Layer: 4294967295
Strength: 0
IsActive: true
Scripts: ~
- EID: 1
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -1.440328, y: -4.41369677, z: -5}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 49.4798889, y: 0.5, z: 17.5}
IsActive: true
Renderable Component:
Mesh: 149697411
Material: 126974645
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: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 2
Name: Player
IsActive: true
NumberOfChildren: 3
Components:
Transform Component:
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
Renderable Component:
Mesh: 149697411
Material: 126974645
IsActive: true
RigidBody Component:
Type: Dynamic
Mass: 1
Drag: 2
Angular Drag: 0
Use Gravity: false
Interpolate: false
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: true
Freeze Rotation Y: true
Freeze Rotation Z: true
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.5, z: 0}
IsActive: true
Scripts:
- Type: PlayerController
currentState: 0
maxMoveVel: 4
moveForce: 50
sprintMultiplier: 1.5
rotationFactorPerFrame: 1
maxJumpHeight: 4
maxJumpTime: 0.75
fallMultipler: 2
lightMultiper: 0.75
mediumMultiper: 0.5
heavyMultiper: 0.25
- Type: PickAndThrow
holdPosition: [0, 1.20000005, 0]
throwForce: [200, 300, 200]
- EID: 3
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 1.20000005, z: 0}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Scripts: ~
- EID: 4
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: -0.785401046, y: 1.65799224, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Camera Component:
Position: {x: -18.9007454, y: -3.67369723, z: -5.23871422}
Pitch: -45.000164
Yaw: 94.9959564
Roll: 0
Width: 1920
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
IsActive: true
Scripts:
- Type: SHADE_Scripting.ThirdPersonCamera
armLength: 2
turnSpeedPitch: 0.300000012
turnSpeedYaw: 0.5
pitchClamp: 45
- EID: 9
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 144838771
Material: 123745521
IsActive: true
Scripts: ~
- EID: 6
Name: AI
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -8, y: -4.42369843, z: 2.5}
Rotate: {x: -0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 149697411
Material: 126974645
IsActive: true
RigidBody Component:
Type: Dynamic
Mass: 1
Drag: 0
Angular Drag: 0
Use Gravity: true
Interpolate: false
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: true
Freeze Rotation Y: true
Freeze Rotation Z: true
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.5, y: 0.5, z: 0.5}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.5, z: 0}
IsActive: true
Scripts: ~
- EID: 7
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -16.8647861, z: -14.039052}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975}
IsActive: true
Renderable Component:
Mesh: 149697411
Material: 126974645
IsActive: true
Scripts: ~
- EID: 8
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Ambient
Direction: {x: 0, y: 0, z: 1}
Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295
Strength: 0.25
IsActive: true
Scripts: ~
- EID: 11
Name: GameManager
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
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: ~
IsActive: true
Scripts:
- Type: GameManager
itemPool: 12
zonePool: 51000
currGameState: 0
totalItemCount: -202
Score: 204
timer: 0
- EID: 12
Name: ItemPool
IsActive: true
NumberOfChildren: 2
Components: ~
Scripts: ~
- EID: 10
Name: item
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 3.19870043, y: -3.67369723, z: -5}
Rotate: {x: -0, y: 0, z: 0}
Scale: {x: 2, y: 2, z: 2}
IsActive: true
Renderable Component:
Mesh: 144838771
Material: 123745521
IsActive: true
RigidBody Component:
Type: Dynamic
Mass: 1
Drag: 0
Angular Drag: 0
Use Gravity: true
Interpolate: false
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: true
Freeze Rotation Y: true
Freeze Rotation Z: true
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.5, z: 0}
- Is Trigger: true
Type: Box
Half Extents: {x: 2, y: 2, z: 2}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.5, z: 0}
IsActive: true
Scripts:
- Type: Item
Score: 1
currCategory: 0
- EID: 5
Name: item
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
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: false
Renderable Component:
Mesh: 144838771
Material: 123745521
IsActive: false
RigidBody Component:
Type: Dynamic
Mass: 1
Drag: 0
Angular Drag: 0
Use Gravity: true
Interpolate: false
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: true
Freeze Rotation Y: true
Freeze Rotation Z: true
IsActive: false
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.5, z: 0}
- Is Trigger: true
Type: Box
Half Extents: {x: 2, y: 2, z: 2}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.5, z: 0}
IsActive: false
Scripts:
- Type: Item
Score: 1
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: ~

View File

@ -0,0 +1,3 @@
Name: PlayerControllerTest
ID: 92100024
Type: 5

View File

@ -0,0 +1,62 @@
using SHADE;
using System;
using System.Collections.Generic;
public class GameManager : Script
{
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<Item> listOfItems;
private IEnumerable<ScoringZone> listOfZone;
protected override void awake()
{
totalItemCount = 0;
Score = 0;
currGameState = GameState.MAINMENU;
if (itemPool)
{
listOfItems = itemPool.GetScriptsInChildren<Item>();
foreach (Item i in listOfItems)
totalItemCount += 1;
}
if (zonePool)
{
listOfZone = itemPool.GetScriptsInChildren<ScoringZone>();
foreach (ScoringZone i in listOfZone)
i.gameManger = Owner.GetScript<GameManager>();
}
}
protected override void update()
{
if (timer > 0)
timer -= Time.DeltaTimeF;
else
currGameState = GameState.LOSE;
}
protected override void onTriggerEnter(CollisionInfo info)
{
}
}

View File

@ -0,0 +1,3 @@
Name: SC_GameManager
ID: 161629605
Type: 9

View File

@ -9,9 +9,16 @@ public class Item : Script
HEAVY
}
public int Score = 10;
public ItemCategory currCategory;
protected override void awake()
{
}
protected override void onTriggerEnter(CollisionInfo info)
{
}
}

View File

@ -0,0 +1,3 @@
Name: SC_Item
ID: 153136539
Type: 9

View File

@ -4,8 +4,9 @@ using static PlayerController;
public class PickAndThrow : Script
{
public Vector3 holdPosition = new Vector3(0.0f, 1.0f, 0.0f);
public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f);
public GameObject item;
public GameObject item { get; set; }
private PlayerController pc;
private Camera cam;
private Transform itemTransform;
@ -22,36 +23,13 @@ public class PickAndThrow : Script
if (raccoonHoldLocation == null)
Debug.Log("CHILD EMPTY");
else
raccoonHoldLocation.LocalPosition = new Vector3(0.0f, 1.0f, 0.0f);
raccoonHoldLocation.LocalPosition = holdPosition;
}
protected override void update()
{
if (cam == null)
cam = GetComponentInChildren<Camera>();
else if (cam != null)
{
Vector3 camerAixs = cam.GetForward();
camerAixs.y = 0;
camerAixs.Normalise();
lastXDir = camerAixs.x;
lastZDir = camerAixs.z;
}
CalculateDir();
if (item.GetScript<Item>() != null && itemTransform == null && itemRidibody == null)
{
itemTransform = item.GetComponent<Transform>();
if (itemTransform == null)
Debug.Log("Item transform EMPTY");
itemRidibody = item.GetComponent<RigidBody>();
if (itemRidibody == null)
Debug.Log("Item rb EMPTY");
}
if (pc != null && inRange && !pc.holdItem && Input.GetKey(Input.KeyCode.E))
pc.holdItem = true;
if (pc != null && itemRidibody != null && itemTransform != null && pc.holdItem)
if (pc != null && pc.holdItem && itemRidibody != null && itemTransform != null)
{
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
itemRidibody.IsGravityEnabled = false;
@ -65,17 +43,60 @@ public class PickAndThrow : Script
itemRidibody.IsGravityEnabled = true;
itemRidibody.AddForce(new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir));
itemRidibody.LinearVelocity += pc.rb.LinearVelocity;
ResetItemObject();
}
}
else if(!pc.holdItem && itemRidibody != null)
itemRidibody.IsGravityEnabled = true;
if (pc != null && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
{
pc.holdItem = true;
RetrieveItemComponets();
}
}
private void ResetItemObject()
{
itemRidibody = null;
itemTransform = null;
item = new GameObject();
}
private void RetrieveItemComponets()
{
//get the transform of the given item
if (item.GetScript<Item>() != null && itemTransform == null && itemRidibody == null)
{
itemTransform = item.GetComponent<Transform>();
if (itemTransform == null)
Debug.Log("Item transform EMPTY");
itemRidibody = item.GetComponent<RigidBody>();
if (itemRidibody == null)
Debug.Log("Item rb EMPTY");
}
}
private void CalculateDir()
{
if (cam == null)
cam = GetComponentInChildren<Camera>();
else if (cam != null)
{
Vector3 camerAixs = cam.GetForward();
camerAixs.y = 0;
camerAixs.Normalise();
lastXDir = camerAixs.x;
lastZDir = camerAixs.z;
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
}
protected override void onTriggerEnter(CollisionInfo info)
{
//Debug.Log("ENTER");
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
{
item = info.GameObject;

View File

@ -0,0 +1,3 @@
Name: SC_PickAndThrow
ID: 154802724
Type: 9

View File

@ -1,40 +1,47 @@
using SHADE;
using System;
using System.Collections.Generic;
using static Item;
public class PlayerController : Script
{
public enum RaccoonStates
{
IDILE,
IDLE,
WALKING,
RUNNING,
JUMP,
FALLING,
LANDED,
CAUGHT,
TOTAL
}
public enum WalkingState
{
CARRY,
AIMING,
THROW,
WALK,
TOTAL
}
public RigidBody rb { get; set; }
private Transform tranform;
private Camera cam;
private PickAndThrow pat;
private StateMachine stateMachine;
//to be remove
public float drag = 2.0f;
public bool holdItem { get; set; }
[SerializeField]
[Tooltip("The current state fo the raccoon")]
public RaccoonStates currentState = RaccoonStates.IDILE;
public RaccoonStates currentState = RaccoonStates.IDLE;
//Movement variables============================================================
[SerializeField]
[Tooltip("Max vel for walking")]
public float maxMoveVel = 2.0f;
[SerializeField]
[Tooltip("how much force is apply for walking")]
public float moveForce = 50.0f;
[SerializeField]
public float moveForce = 2.0f;
[Tooltip("increase the moveForce and maxMoveVel by its amt")]
public float sprintMultiplier = 2.0f;
@ -49,7 +56,6 @@ public class PlayerController : Script
public bool isMoveKeyPress { get; set; }
[SerializeField]
[Tooltip("curr not working")]
public float rotationFactorPerFrame = 1.0f;
@ -75,6 +81,7 @@ public class PlayerController : Script
protected override void awake()
{
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
//default setup
isMoveKeyPress = false;
holdItem = false;
@ -91,10 +98,6 @@ public class PlayerController : Script
else
{
rb.IsGravityEnabled = false;
rb.FreezeRotationX = true;
rb.FreezeRotationY = true;
rb.FreezeRotationZ = true;
rb.Drag = drag;
rb.Interpolating = false;
}
@ -103,14 +106,18 @@ public class PlayerController : Script
if(tranform == null)
Debug.LogError("tranform is NULL!");
//PickAndThrow checl
//PickAndThrow check
pat = GetScript<PickAndThrow>();
if (pat == null)
Debug.LogError("PickAndThrow is NULL!");
//toRemove
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
tranform.LocalRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
stateMachine = AddScript<StateMachine>();
Dictionary<Type, BaseState> dictionary = new Dictionary<Type, BaseState>();
dictionary.Add(typeof(IdleState), new IdleState(stateMachine));
dictionary.Add(typeof(WalkState), new WalkState(stateMachine));
dictionary.Add(typeof(RunState), new RunState(stateMachine));
stateMachine.InitStateMachine(dictionary);
}
protected override void update()
@ -118,118 +125,103 @@ public class PlayerController : Script
if (cam == null)
cam = GetComponentInChildren<Camera>();
//toRemove
if (Input.GetKey(Input.KeyCode.G))
{
tranform.LocalRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
}
GotCaught();
MoveKey();
//Debug.Log($"{currentState}");
//Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}");
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
//Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString());
}
protected override void fixedUpdate()
{
//Rotation();
MoveKey();
Move();
Sprint();
Jump();
Gravity();
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
}
private void MoveKey()
{
/* if (Input.GetKey(Input.KeyCode.A))
xAxisMove = -1;
else if (Input.GetKey(Input.KeyCode.D))
xAxisMove = 1;
else
xAxisMove = 0;
if (Input.GetKey(Input.KeyCode.W))
zAxisMove = -1;
else if (Input.GetKey(Input.KeyCode.S))
zAxisMove = 1;
else
zAxisMove = 0;*/
xAxisMove = 0;
zAxisMove = 0;
axisMove = Vector2.Zero;
if (Input.GetKey(Input.KeyCode.W))
{
Vector3 camerAixs = cam.GetForward();
camerAixs.y = 0;
camerAixs.Normalise();
xAxisMove = camerAixs.x;
zAxisMove = camerAixs.z;
axisMove += new Vector2(camerAixs.x, camerAixs.z);
}
if (Input.GetKey(Input.KeyCode.S))
{
Vector3 camerAixs = cam.GetForward();
camerAixs.y = 0;
camerAixs.Normalise();
xAxisMove = -camerAixs.x;
zAxisMove = -camerAixs.z;
axisMove -= new Vector2(camerAixs.x, camerAixs.z);
}
if (Input.GetKey(Input.KeyCode.A))
{
Vector3 camerAixs = cam.GetRight();
camerAixs.y = 0;
camerAixs.Normalise();
xAxisMove = -camerAixs.x;
zAxisMove = -camerAixs.z;
axisMove -= new Vector2(camerAixs.x, camerAixs.z);
}
if (Input.GetKey(Input.KeyCode.D))
{
Vector3 camerAixs = cam.GetRight();
camerAixs.y = 0;
camerAixs.Normalise();
xAxisMove = camerAixs.x;
zAxisMove = camerAixs.z;
axisMove += new Vector2(camerAixs.x, camerAixs.z);
}
axisMove.Normalise();
isMoveKeyPress = xAxisMove != 0 || zAxisMove != 0;
if(isMoveKeyPress && currentState != RaccoonStates.RUNNING && isGrounded)
axisMove.Normalise();
isMoveKeyPress = axisMove.x != 0 || axisMove.y != 0;
if (isMoveKeyPress && isGrounded && !Input.GetKey(Input.KeyCode.LeftShift))
{
currentState = RaccoonStates.WALKING;
if(stateMachine && !stateMachine.IsState(typeof(WalkState)))
stateMachine.SetState(typeof(WalkState));
}
if (!isMoveKeyPress && isGrounded)
currentState = RaccoonStates.IDILE;
{
currentState = RaccoonStates.IDLE;
if(stateMachine && !stateMachine.IsState(typeof(IdleState)))
stateMachine.SetState(typeof(IdleState));
}
}
private void Move()
{
if (rb != null)
{
rb.AddForce(new Vector3(axisMove.x, 0.0f,axisMove.y) * moveForce);
rb.LinearVelocity += new Vector3(axisMove.x * moveForce, 0.0f, axisMove.y * moveForce) * Time.DeltaTimeF;
if (isMoveKeyPress)
{
if (rb.LinearVelocity.x > maxMoveVel || rb.LinearVelocity.x < -maxMoveVel)
if (rb)
{
Vector3 v = rb.LinearVelocity;
v.x = System.Math.Clamp(v.x, -maxMoveVel, maxMoveVel);
rb.LinearVelocity = v;
}
if (rb.LinearVelocity.z > maxMoveVel || rb.LinearVelocity.z < -maxMoveVel)
Vector3 velNor = rb.LinearVelocity;
velNor.y = 0.0f;
if (velNor.GetMagnitude() > maxMoveVel)
{
Vector3 v = rb.LinearVelocity;
v.z = System.Math.Clamp(v.z, -maxMoveVel, maxMoveVel);
rb.LinearVelocity = v;
velNor.Normalise();
velNor *= maxMoveVel;
rb.LinearVelocity = new Vector3(velNor.x, rb.LinearVelocity.y, velNor.z);
}
}
}
}
}
@ -238,6 +230,9 @@ public class PlayerController : Script
if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded)
{
currentState = RaccoonStates.RUNNING;
if (stateMachine && !stateMachine.IsState(typeof(RunState)))
stateMachine.SetState(typeof(RunState));
holdItem = false;
if (!sprintIncreaseOnce)
{
@ -253,7 +248,11 @@ public class PlayerController : Script
if (Input.GetKeyUp(Input.KeyCode.LeftShift))
{
if (isMoveKeyPress)
{
currentState = RaccoonStates.WALKING;
if(stateMachine && !stateMachine.IsState(typeof(WalkState)))
stateMachine.SetState(typeof(WalkState));
}
sprintIncreaseOnce = false;
moveForce = oldForce;
maxMoveVel = maxOldVel;
@ -263,37 +262,38 @@ public class PlayerController : Script
//press and hold jump
private void Jump()
{
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE)
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE)
{
if (Input.GetKeyDown(Input.KeyCode.Space) && isGrounded && rb != null)
{
currentState = RaccoonStates.JUMP;
Vector3 v = rb.LinearVelocity;
v.y = initialJumpVel * 0.5f;
if (pat != null && pat.item.GetScript<Item>() != null && holdItem)
if (holdItem && pat != null && pat.item.GetScript<Item>() != null)
{
Item item = pat.item.GetScript<Item>();
if (item.currCategory == ItemCategory.LIGHT)
if (item != null && item.currCategory == ItemCategory.LIGHT)
v.y *= lightMultiper;
if (item.currCategory == ItemCategory.MEDIUM)
if (item != null && item.currCategory == ItemCategory.MEDIUM)
v.y *= mediumMultiper;
if (item.currCategory == ItemCategory.HEAVY)
if (item != null && item.currCategory == ItemCategory.HEAVY)
v.y *= heavyMultiper;
}
rb.LinearVelocity = v;
}
}
if(rb != null && !isGrounded && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space)))
if(!isGrounded && rb != null && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space)))
currentState = RaccoonStates.FALLING;
}
private void Rotation()
{
Vector3 poitionToLookAt;
poitionToLookAt.x = xAxisMove;
poitionToLookAt.x = axisMove.x;
poitionToLookAt.y = 0.0f;
poitionToLookAt.z = zAxisMove;
poitionToLookAt.z = axisMove.y;
if (tranform != null)
{
@ -312,7 +312,11 @@ public class PlayerController : Script
{
//check player vel.y if its close to zero its on the ground
if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f))
{
isGrounded = true;
if (currentState == RaccoonStates.FALLING)
currentState = RaccoonStates.LANDED;
}
else
isGrounded = false;
@ -344,7 +348,9 @@ public class PlayerController : Script
{
if (currentState == RaccoonStates.CAUGHT && tranform != null)
{
currentState = RaccoonStates.IDILE;
currentState = RaccoonStates.IDLE;
if (stateMachine && !stateMachine.IsState(typeof(IdleState)))
stateMachine.SetState(typeof(IdleState));
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
}
}
@ -353,6 +359,82 @@ public class PlayerController : Script
{
}
}
public class WalkState : BaseState
{
public WalkState(StateMachine stateMachine) : base(stateMachine)
{
stateName = "Walk State";
}
public override void OnEnter()
{
//Debug.Log("WALK ENTER");
}
public override void update()
{
//Debug.Log("WALKING");
}
public override void fixedUpdate()
{
//Debug.Log("FIXED WALKING");
}
public override void OnExit()
{
//Debug.Log("WALK EXIT");
}
public override void onTriggerEnter(CollisionInfo info)
{
//Debug.Log("TRIGGER");
}
}
public class RunState : BaseState
{
public RunState(StateMachine stateMachine) : base(stateMachine)
{
stateName = "Run State";
}
public override void OnEnter()
{
//Debug.Log("Run ENTER");
}
public override void update()
{
//Debug.Log("RUNING");
}
public override void fixedUpdate()
{
//Debug.Log("FIXED RUNNING");
}
public override void OnExit()
{
//Debug.Log("Run EXIT");
}
}
public class IdleState : BaseState
{
public IdleState(StateMachine stateMachine) : base(stateMachine)
{
stateName = "Idle State";
}
public override void OnEnter()
{
//Debug.Log("IDLE ENTER");
}
public override void update()
{
//Debug.Log("IDLING");
}
public override void fixedUpdate()
{
//Debug.Log("FIXED IDLING");
}
public override void OnExit()
{
//Debug.Log("IDLE EXIT");
}
}

View File

@ -0,0 +1,3 @@
Name: SC_PlayerController
ID: 160432754
Type: 9

View File

@ -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<Item>())
{
gameManger.Score += info.GameObject.GetScript<Item>().Score;
gameManger.totalItemCount -= 1;
info.GameObject.SetActive(false);
}
}
}

View File

@ -0,0 +1,3 @@
Name: SC_ScoringZone
ID: 153171688
Type: 9

View File

@ -0,0 +1,68 @@
using SHADE;
using System;
public abstract class BaseState
{
protected string stateName = "Base State";
protected StateMachine machine;
protected string animationName = "";
public BaseState(StateMachine stateMachine, string animName = "")
{
machine = stateMachine;
animationName = animName;
}
public virtual void OnEnter()
{
}
public abstract void update();
public abstract void fixedUpdate();
public virtual void OnExit()
{
}
public string GetStateName()
{
return stateName;
}
public string GetAnimName()
{
return animationName;
}
public virtual float GetAnimPercent()
{
return 1.0f;
}
public virtual void onCollisionEnter(CollisionInfo info)
{
}
public virtual void onCollisionStay(CollisionInfo info)
{
}
public virtual void onCollisionExit(CollisionInfo info)
{
}
public virtual void onTriggerEnter(CollisionInfo info)
{
}
public virtual void onTriggerStay(CollisionInfo info)
{
}
public virtual void onTriggerExit(CollisionInfo info)
{
}
}

View File

@ -0,0 +1,3 @@
Name: UT_BaseSate
ID: 154709755
Type: 9

View File

@ -0,0 +1,126 @@
using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
public class StateMachine : Script
{
private Dictionary<Type, BaseState> stateDictionary;
public BaseState currentState = null;
public string currentStateName;
public string currentAnimName;
public void InitStateMachine(Dictionary<Type, BaseState> dictionary)
{
stateDictionary = dictionary;
currentState = stateDictionary.First().Value;
currentStateName = currentState.GetStateName();
currentAnimName = currentState.GetAnimName();
currentState.OnEnter();
}
public bool HasState(Type type)
{
if (!type.IsSubclassOf(typeof(BaseState)))
{
return false;
}
else
{
return stateDictionary.ContainsKey(type);
}
}
public void SetState(Type type)
{
if (!type.IsSubclassOf(typeof(BaseState)))
{
return;
}
if (stateDictionary.ContainsKey(type))
{
currentState.OnExit();
currentState = stateDictionary[type];
currentState.OnEnter();
}
else
{
SetState(stateDictionary.First().Key);
}
}
public BaseState GetState(Type type)
{
if (!stateDictionary.ContainsKey(type))
return null;
return stateDictionary[type];
}
public bool IsState(Type type)
{
return (currentState.GetType() == type);
}
protected override void update()
{
if (currentState != (null))
{
currentStateName = currentState.GetStateName();
currentAnimName = currentState.GetAnimName();
currentState.update();
}
}
protected override void fixedUpdate()
{
if (currentState != (null))
{
currentStateName = currentState.GetStateName();
currentAnimName = currentState.GetAnimName();
currentState.fixedUpdate();
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
if (currentState != (null))
currentState.onCollisionEnter(info);
}
protected override void onCollisionStay(CollisionInfo info)
{
if (currentState != (null))
currentState.onCollisionStay(info);
}
protected override void onCollisionExit(CollisionInfo info)
{
if (currentState != (null))
currentState.onCollisionExit(info);
}
protected override void onTriggerEnter(CollisionInfo info)
{
if (currentState != (null))
currentState.onTriggerEnter(info);
}
protected override void onTriggerStay(CollisionInfo info)
{
if (currentState != (null))
currentState.onTriggerStay(info);
}
protected override void onTriggerExit(CollisionInfo info)
{
if (currentState != (null))
currentState.onTriggerExit(info);
}
}

View File

@ -0,0 +1,3 @@
Name: UT_StateMachine
ID: 166010611
Type: 9

View File

@ -84,12 +84,32 @@ namespace SHADE
LoadBank((AUDIO_FOLDER_PATH + "Master.bank").data());
LoadBank((AUDIO_FOLDER_PATH + "Master.strings.bank").data());
//LoadBank((AUDIO_FOLDER_PATH + "Music.bank").data());
LoadBank((AUDIO_FOLDER_PATH + "footsteps.bank").data());
//LoadBank((AUDIO_FOLDER_PATH + "footsteps.bank").data());
LoadBank((AUDIO_FOLDER_PATH + "Music.bank").data());
LoadBank((AUDIO_FOLDER_PATH + "SFX.bank").data());
LoadBank((AUDIO_FOLDER_PATH + "UI.bank").data());
//auto clip = CreateAudioClip("event:/Characters/sfx_footsteps_human");
//clip->Play();
//PlayEventOnce("event:/Characters/sfx_footsteps_raccoon");
//PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
#ifdef SHEDITOR
// Subscribe to Editor State Change Events
const std::shared_ptr ON_PLAY_RECEIVER{ std::make_shared<SHEventReceiverSpec<SHAudioSystem>>(this, &SHAudioSystem::onPlay) };
const ReceiverPtr ON_PLAY_RECEIVER_PTR = std::dynamic_pointer_cast<SHEventReceiver>(ON_PLAY_RECEIVER);
SHEventManager::SubscribeTo(SH_EDITOR_ON_PLAY_EVENT, ON_PLAY_RECEIVER_PTR);
const std::shared_ptr ON_STOP_RECEIVER{ std::make_shared<SHEventReceiverSpec<SHAudioSystem>>(this, &SHAudioSystem::onStop) };
const ReceiverPtr ON_STOP_RECEIVER_PTR = std::dynamic_pointer_cast<SHEventReceiver>(ON_STOP_RECEIVER);
SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, ON_STOP_RECEIVER_PTR);
const std::shared_ptr ON_PAUSE_RECEIVER{ std::make_shared<SHEventReceiverSpec<SHAudioSystem>>(this, &SHAudioSystem::onPause) };
const ReceiverPtr ON_PAUSE_RECEIVER_PTR = std::dynamic_pointer_cast<SHEventReceiver>(ON_PAUSE_RECEIVER);
SHEventManager::SubscribeTo(SH_EDITOR_ON_PAUSE_EVENT, ON_PAUSE_RECEIVER_PTR);
#endif
}
void SHADE::SHAudioSystem::Run(double dt)
@ -179,7 +199,6 @@ namespace SHADE
it->second->createInstance(&event);
if (event)
{
event->setVolume(masterVolume * (isSFX ? sfxVolume : bgmVolume));
if (spatial)
{
@ -285,6 +304,7 @@ namespace SHADE
if (channel->isPlaying(&isPlaying) == FMOD_OK && isPlaying)
channel->stop();
}
masterGroup->stop();
}
std::optional<FMOD_GUID> SHAudioSystem::GetEventGUID(const char* path)
@ -410,6 +430,7 @@ namespace SHADE
void SHAudioSystem::SetPaused(bool pause)
{
paused = pause;
masterGroup->setPaused(pause);
for (auto const& channel : audioChannels)
{
channel->setPaused(paused);
@ -552,6 +573,27 @@ namespace SHADE
return value;
}
SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent)
{
StopAllSounds();
return onStopEvent->handle;
}
SHEventHandle SHAudioSystem::onPause(SHEventPtr onStopEvent)
{
SetPaused(true);
return onStopEvent->handle;
}
SHEventHandle SHAudioSystem::onPlay(SHEventPtr onStopEvent)
{
if(GetPaused())
SetPaused(false);
return onStopEvent->handle;
}
}
#pragma warning(pop)

View File

@ -10,6 +10,8 @@
#include "Math/Vector/SHVec3.h"
#include <optional>
#include <FMOD/fmod_studio.hpp>
#include "Events/SHEvent.h"
#include "SH_API.h"
#define AUDIO_SYS_MAX_CHANNELS 1024
@ -104,6 +106,10 @@ namespace SHADE
std::vector<SHAudioListenerComponent>* denseListener;
AudioClipID clipID = 0;
SHEventHandle onPlay(SHEventPtr onStopEvent);
SHEventHandle onStop(SHEventPtr onStopEvent);
SHEventHandle onPause(SHEventPtr onStopEvent);
};
}

View File

@ -21,6 +21,7 @@
#include "UI/SHUIComponent.h"
#include "UI/SHCanvasComponent.h"
#include "SHEditorComponentView.h"
#include "AudioSystem/SHAudioListenerComponent.h"
namespace SHADE
{
@ -130,7 +131,8 @@ namespace SHADE
if (auto cameraComponent = SHComponentManager::GetComponent_s<SHCameraComponent>(eid))
{
DrawComponent(cameraComponent);
}if (auto cameraArmComponent = SHComponentManager::GetComponent_s<SHCameraArmComponent>(eid))
}
if (auto cameraArmComponent = SHComponentManager::GetComponent_s<SHCameraArmComponent>(eid))
{
DrawComponent(cameraArmComponent);
}