2022-11-04 17:31:53 +08:00
|
|
|
|
using SHADE;
|
2023-02-03 19:37:18 +08:00
|
|
|
|
using SHADE_Scripting.Audio;
|
2022-11-04 17:31:53 +08:00
|
|
|
|
using System;
|
|
|
|
|
public class Item : Script
|
|
|
|
|
{
|
|
|
|
|
public enum ItemCategory
|
|
|
|
|
{
|
|
|
|
|
LIGHT,
|
|
|
|
|
MEDIUM,
|
|
|
|
|
HEAVY
|
|
|
|
|
}
|
2022-11-17 12:54:08 +08:00
|
|
|
|
|
2023-03-25 02:38:56 +08:00
|
|
|
|
public enum Food
|
|
|
|
|
{
|
|
|
|
|
EGG,
|
|
|
|
|
APPLE,
|
|
|
|
|
MEAT,
|
|
|
|
|
WATERMELON,
|
|
|
|
|
CHEESE
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 00:23:38 +08:00
|
|
|
|
public int Score = 10;
|
2022-11-04 17:31:53 +08:00
|
|
|
|
|
|
|
|
|
public ItemCategory currCategory;
|
2023-03-25 02:38:56 +08:00
|
|
|
|
public Food currFood;
|
2023-01-16 21:31:38 +08:00
|
|
|
|
public bool returnBack { get; set; }
|
|
|
|
|
private Transform transform;
|
2023-02-04 14:11:16 +08:00
|
|
|
|
private RigidBody rb;
|
2023-01-16 21:31:38 +08:00
|
|
|
|
private bool playSound = false;
|
|
|
|
|
private bool caputurePos = false;
|
2023-01-31 18:13:34 +08:00
|
|
|
|
private Vector3 firstPostion;
|
2023-03-24 20:30:01 +08:00
|
|
|
|
private Vector3 firstRotation;
|
2023-01-31 18:13:34 +08:00
|
|
|
|
private Collider collider;
|
|
|
|
|
public float density = 1.0f;
|
|
|
|
|
public bool dontReturn = false;
|
2023-02-21 19:31:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool checkSound = false;
|
2023-03-23 16:49:41 +08:00
|
|
|
|
private bool homeownerOnce = true;
|
2023-02-21 19:31:50 +08:00
|
|
|
|
public float soundDistance = 10;
|
2022-11-04 17:31:53 +08:00
|
|
|
|
|
2023-02-25 21:56:49 +08:00
|
|
|
|
private float highlightPos = 0.0f;
|
|
|
|
|
private Renderable rend;
|
|
|
|
|
public float highlightSpeed = 200.0f;
|
|
|
|
|
public float highlightThickness = 600.0f;
|
|
|
|
|
public float highlightLowerClamp = 0.25f;
|
|
|
|
|
|
2023-03-21 15:27:42 +08:00
|
|
|
|
private ParticleEmitter emitter;
|
|
|
|
|
|
2023-02-04 15:17:58 +08:00
|
|
|
|
|
2022-11-04 17:31:53 +08:00
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
2023-01-16 21:31:38 +08:00
|
|
|
|
transform = GetComponent<Transform>();
|
2023-02-04 14:11:16 +08:00
|
|
|
|
rb = GetComponent<RigidBody>();
|
2023-01-31 18:13:34 +08:00
|
|
|
|
collider = GetComponent<Collider>();
|
|
|
|
|
if(collider)
|
|
|
|
|
collider.GetCollisionShape(0).Density = density;
|
|
|
|
|
|
2023-02-25 21:56:49 +08:00
|
|
|
|
rend = GetComponent<Renderable>();
|
|
|
|
|
if (!rend)
|
|
|
|
|
Debug.Log("NO RENDERABLE");
|
|
|
|
|
|
2023-01-16 21:31:38 +08:00
|
|
|
|
returnBack = false;
|
2023-02-03 19:37:18 +08:00
|
|
|
|
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXImpactElastic"] = Audio.CreateAudioClip("event:/Props/impact_elastic");
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXImpactHard"] = Audio.CreateAudioClip("event:/Props/impact_hard");
|
2023-03-21 15:27:42 +08:00
|
|
|
|
|
|
|
|
|
emitter = GetComponent<ParticleEmitter>();
|
2022-11-25 16:23:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:13:34 +08:00
|
|
|
|
protected override void start()
|
|
|
|
|
{
|
|
|
|
|
GameManager.Instance.totalItemCount += 1;
|
2023-02-28 18:35:43 +08:00
|
|
|
|
|
|
|
|
|
if (rend)
|
|
|
|
|
{
|
|
|
|
|
if (currCategory == ItemCategory.LIGHT)
|
|
|
|
|
{
|
|
|
|
|
highlightThickness /= 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currCategory == ItemCategory.MEDIUM)
|
|
|
|
|
{
|
|
|
|
|
highlightThickness /= 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rend.Material.SetProperty<float>("data.thickness", highlightThickness);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:13:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 16:23:26 +08:00
|
|
|
|
protected override void update()
|
|
|
|
|
{
|
2023-02-25 21:56:49 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:13:34 +08:00
|
|
|
|
if (returnBack && !dontReturn)
|
2023-01-16 21:31:38 +08:00
|
|
|
|
{
|
2023-02-04 14:11:16 +08:00
|
|
|
|
if (rb)
|
2023-03-09 18:47:06 +08:00
|
|
|
|
{
|
2023-02-04 14:11:16 +08:00
|
|
|
|
rb.LinearVelocity = Vector3.Zero;
|
2023-03-09 18:47:06 +08:00
|
|
|
|
rb.AngularVelocity = Vector3.Zero;
|
|
|
|
|
rb.ClearForces();
|
|
|
|
|
rb.ClearTorque();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 16:49:41 +08:00
|
|
|
|
if (transform)
|
|
|
|
|
{
|
2023-03-24 20:30:01 +08:00
|
|
|
|
transform.LocalEulerAngles = firstRotation;
|
2023-03-09 18:47:06 +08:00
|
|
|
|
transform.LocalPosition = firstPostion;
|
2023-03-23 16:49:41 +08:00
|
|
|
|
}
|
2023-02-04 14:11:16 +08:00
|
|
|
|
|
2023-01-16 21:31:38 +08:00
|
|
|
|
returnBack = false;
|
|
|
|
|
}
|
2023-02-21 19:31:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (checkSound)
|
|
|
|
|
{
|
|
|
|
|
/* //need to wait for collisionEnter Fix
|
|
|
|
|
Vector3 itemPos = transform.LocalPosition;
|
|
|
|
|
Vector3 len = Homeowner1.aiInstance.GetComponent<Transform>().LocalPosition - itemPos;
|
|
|
|
|
Debug.Log($"distance: {len.GetSqrMagnitude()}");
|
|
|
|
|
if (len.GetSqrMagnitude() <= soundDistance)
|
|
|
|
|
{
|
|
|
|
|
//set ai to alert
|
|
|
|
|
}
|
|
|
|
|
checkSound = false;*/
|
|
|
|
|
}
|
2022-11-04 17:31:53 +08:00
|
|
|
|
}
|
2022-11-17 12:54:08 +08:00
|
|
|
|
|
2022-11-21 21:01:44 +08:00
|
|
|
|
protected override void onCollisionEnter(CollisionInfo info)
|
2022-11-17 12:54:08 +08:00
|
|
|
|
{
|
2023-02-21 19:31:50 +08:00
|
|
|
|
|
2023-01-16 21:31:38 +08:00
|
|
|
|
if (!caputurePos)
|
|
|
|
|
{
|
|
|
|
|
firstPostion = transform.LocalPosition;
|
2023-03-24 20:30:01 +08:00
|
|
|
|
firstRotation = transform.LocalEulerAngles;
|
2023-01-16 21:31:38 +08:00
|
|
|
|
caputurePos = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playSound)
|
2023-02-03 19:37:18 +08:00
|
|
|
|
{
|
2023-03-04 00:19:35 +08:00
|
|
|
|
Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXImpactElastic"], GameObject.EntityId);
|
|
|
|
|
Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXImpactHard"], GameObject.EntityId);
|
2023-02-03 19:37:18 +08:00
|
|
|
|
if (currCategory == ItemCategory.LIGHT)
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXImpactElastic"].Play();
|
2022-11-21 21:01:44 +08:00
|
|
|
|
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
|
2023-02-03 19:37:18 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["SFXImpactHard"].Play();
|
2023-01-16 21:31:38 +08:00
|
|
|
|
playSound = false;
|
2023-03-04 00:19:35 +08:00
|
|
|
|
Audio.DetachAudioClipFromObject(AudioHandler.audioClipHandlers["SFXImpactElastic"]);
|
|
|
|
|
Audio.DetachAudioClipFromObject(AudioHandler.audioClipHandlers["SFXImpactHard"]);
|
2023-03-21 15:27:42 +08:00
|
|
|
|
|
2023-03-25 02:38:56 +08:00
|
|
|
|
Debug.Log("ENTER");
|
2023-03-21 15:27:42 +08:00
|
|
|
|
if(emitter)
|
|
|
|
|
emitter.Emit();
|
|
|
|
|
|
2022-11-21 21:01:44 +08:00
|
|
|
|
}
|
2023-01-25 18:20:26 +08:00
|
|
|
|
|
2023-03-23 16:49:41 +08:00
|
|
|
|
if (info.GameObject.GetScript<Homeowner1>() && homeownerOnce)
|
2023-01-25 18:20:26 +08:00
|
|
|
|
{
|
2023-03-23 16:49:41 +08:00
|
|
|
|
homeownerOnce = false;
|
2023-01-25 18:20:26 +08:00
|
|
|
|
returnBack = true;
|
|
|
|
|
}
|
2022-11-21 21:01:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void onCollisionExit(CollisionInfo info)
|
|
|
|
|
{
|
2023-01-16 21:31:38 +08:00
|
|
|
|
playSound = true;
|
2023-02-21 19:31:50 +08:00
|
|
|
|
checkSound = true;
|
2023-03-23 16:49:41 +08:00
|
|
|
|
homeownerOnce = true;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-04 17:31:53 +08:00
|
|
|
|
}
|