using SHADE; using SHADE_Scripting.Audio; using System; public class Item : Script { public enum ItemCategory { LIGHT, MEDIUM, HEAVY } public int Score = 10; public ItemCategory currCategory; public bool returnBack { get; set; } private Transform transform; private RigidBody rb; private bool playSound = false; private bool caputurePos = false; private Vector3 firstPostion; private Collider collider; public float density = 1.0f; public bool dontReturn = false; private bool checkSound = false; 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; protected override void awake() { transform = GetComponent(); rb = GetComponent(); collider = GetComponent(); if(collider) collider.GetCollisionShape(0).Density = density; rend = GetComponent(); 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"); } 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("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("data.highlightPosition", highlightPos); } if (returnBack && !dontReturn) { if (rb) { rb.LinearVelocity = Vector3.Zero; rb.AngularVelocity = Vector3.Zero; rb.ClearForces(); rb.ClearTorque(); } if(transform) transform.LocalPosition = firstPostion; returnBack = false; } if (checkSound) { /* //need to wait for collisionEnter Fix Vector3 itemPos = transform.LocalPosition; Vector3 len = Homeowner1.aiInstance.GetComponent().LocalPosition - itemPos; Debug.Log($"distance: {len.GetSqrMagnitude()}"); if (len.GetSqrMagnitude() <= soundDistance) { //set ai to alert } checkSound = false;*/ } } protected override void onCollisionEnter(CollisionInfo info) { if (!caputurePos) { firstPostion = transform.LocalPosition; caputurePos = true; } if (playSound) { Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXImpactElastic"], GameObject.EntityId); Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXImpactHard"], GameObject.EntityId); if (currCategory == ItemCategory.LIGHT) AudioHandler.audioClipHandlers["SFXImpactElastic"].Play(); else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY) AudioHandler.audioClipHandlers["SFXImpactHard"].Play(); playSound = false; Audio.DetachAudioClipFromObject(AudioHandler.audioClipHandlers["SFXImpactElastic"]); Audio.DetachAudioClipFromObject(AudioHandler.audioClipHandlers["SFXImpactHard"]); } if (info.GameObject.GetScript() && !returnBack) { returnBack = true; } } protected override void onCollisionExit(CollisionInfo info) { playSound = true; checkSound = true; } }