SHADE_Y3/Assets/Scripts/Gameplay/Item/SC_Item.cs

160 lines
3.7 KiB
C#

using SHADE;
using SHADE_Scripting.Audio;
using SHADE_Scripting.Gameplay.AIBehaviour.AIRework;
using System;
public class Item : Script
{
public enum ItemCategory
{
LIGHT,
MEDIUM,
HEAVY
}
public enum Food
{
EGG,
APPLE,
MEAT,
WATERMELON,
CHEESE
}
public int Score = 10;
public ItemCategory currCategory;
public Food currFood;
public bool returnBack { get; set; }
private Transform transform;
private RigidBody rb;
private bool caputurePos = false;
private Vector3 firstPostion;
private Vector3 firstRotation;
public bool dontReturn = false;
private bool once = true;
private bool homeownerOnce = true;
public float soundDistance = 10;
private float highlightPos = 0.0f;
private Renderable rend;
public float highlightSpeed = 200.0f;
public float highlightThickness = 600.0f;
public float highlightLowerClamp = 0.25f;
private ParticleEmitter emitter;
protected override void awake()
{
transform = GetComponent<Transform>();
rb = GetComponent<RigidBody>();
rend = GetComponent<Renderable>();
if (!rend)
Debug.Log("NO RENDERABLE");
returnBack = false;
AudioHandler.audioClipHandlers["SFXImpactElastic"] = Audio.CreateAudioClip("event:/Props/impact_elastic");
AudioHandler.audioClipHandlers["SFXImpactHard"] = Audio.CreateAudioClip("event:/Props/impact_hard");
if (currCategory == ItemCategory.LIGHT)
Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXImpactElastic"], GameObject.EntityId);
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXImpactHard"], GameObject.EntityId);
emitter = GetComponent<ParticleEmitter>();
}
protected override void start()
{
GameManager.Instance.totalItemCount += 1;
if (rend)
{
if (currCategory == ItemCategory.LIGHT)
{
highlightThickness /= 10;
}
if (currCategory == ItemCategory.MEDIUM)
{
highlightThickness /= 5;
}
rend.Material.SetProperty<float>("data.thickness", highlightThickness);
}
}
protected override void update()
{
if (rend)
{
Vector3 dis = Camera.GetMainCamera().Position - transform.LocalPosition;
float disSqr = dis.GetSqrMagnitude();
float ratio = System.Math.Clamp(1 - (disSqr / (1 + disSqr)), highlightLowerClamp, 1.0f);
highlightPos += highlightSpeed * Time.DeltaTimeF * ratio;
rend.Material.SetProperty<float>("data.highlightPosition", highlightPos);
}
if (returnBack && !dontReturn)
{
if (rb)
{
rb.LinearVelocity = Vector3.Zero;
rb.AngularVelocity = Vector3.Zero;
rb.ClearForces();
rb.ClearTorque();
}
if (transform)
{
transform.LocalEulerAngles = firstRotation;
transform.LocalPosition = firstPostion;
}
returnBack = false;
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
if (!caputurePos)
{
firstPostion = transform.LocalPosition;
firstRotation = transform.LocalEulerAngles;
caputurePos = true;
}
if (once)
{
if (currCategory == ItemCategory.LIGHT)
AudioHandler.audioClipHandlers["SFXImpactElastic"].Play();
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
AudioHandler.audioClipHandlers["SFXImpactHard"].Play();
if (emitter)
emitter.Emit();
once = false;
}
if (info.GameObject.GetScript<HomeOwnerAI>() && homeownerOnce)
{
homeownerOnce = false;
returnBack = true;
}
}
protected override void onCollisionExit(CollisionInfo info)
{
homeownerOnce = true;
once = true;
}
}