Update changes to scripts and AudioSystem #224

Merged
glencelow merged 15 commits from PlayerController into main 2022-11-18 19:01:24 +08:00
5 changed files with 120 additions and 13 deletions
Showing only changes of commit d4d9e0c3b3 - Show all commits

View File

@ -8,6 +8,7 @@ public class Item : Script
MEDIUM,
HEAVY
}
public int Score = 1;
public ItemCategory currCategory;
public Item(GameObject gameObj) : base(gameObj) { }

View File

@ -4,6 +4,7 @@ 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;
private PlayerController pc;
@ -23,7 +24,7 @@ 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()
{
@ -38,21 +39,12 @@ public class PickAndThrow : Script
lastZDir = camerAixs.z;
}
if (item.GetScript<Item>() != null && itemTransform == null && itemRidibody == null)
{
itemTransform = item.GetComponent<Transform>();
if (itemTransform == null)
Debug.Log("Item transform EMPTY");
RetrieveItemComponets();
itemRidibody = item.GetComponent<RigidBody>();
if (itemRidibody == null)
Debug.Log("Item rb EMPTY");
}
if (pc != null && inRange && !pc.holdItem && Input.GetKey(Input.KeyCode.E))
if (pc != null && inRange && !pc.holdItem && Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
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;
@ -71,6 +63,30 @@ public class PickAndThrow : Script
else if(!pc.holdItem && itemRidibody != null)
itemRidibody.IsGravityEnabled = true;
}
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");
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
}

View File

@ -1,5 +1,6 @@
using SHADE;
using System;
using System.Collections.Generic;
using static Item;
public class PlayerController : Script
@ -11,10 +12,20 @@ public class PlayerController : Script
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;
@ -215,6 +226,7 @@ public class PlayerController : Script
{
if (rb != null)
{
rb.AddForce(new Vector3(axisMove.x, 0.0f,axisMove.y) * moveForce);
if (isMoveKeyPress)

View File

@ -0,0 +1,63 @@
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(float dt);
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 other)
{
}
public virtual void onCollisionStay(CollisionInfo other)
{
}
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,15 @@
using SHADE;
using System;
using System.Collections.Generic;
public abstract class StateMachine : Script
{
private Dictionary<Type, BaseState> stateDictionary;
public BaseState currentState = null;
public string currentStateName;
public string currentAnimName;
public StateMachine(GameObject gameObj) : base(gameObj) { }
}