| using System; |
| using System; |
| using System.Collections; |
| using System.Collections; |
| using LlamAcademy.Spring; |
| using LlamAcademy.Spring; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class ConditionalObject : MonoBehaviour, Hoverable |
| public class ConditionalObject : MonoBehaviour, Hoverable |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_startScale = this.m_enableObject.transform.localScale; |
| this.m_startScale = this.m_enableObject.transform.localScale; |
| this.m_startHeight = this.m_enableObject.transform.position.y; |
| this.m_startHeight = this.m_enableObject.transform.position.y; |
| this.m_scaleSpring = new SpringVector3 |
| this.m_scaleSpring = new SpringVector3 |
| { |
| { |
| Damping = this.m_springDamping, |
| Damping = this.m_springDamping, |
| Stiffness = this.m_springStiffness, |
| Stiffness = this.m_springStiffness, |
| StartValue = this.m_startScale, |
| StartValue = this.m_startScale, |
| EndValue = this.m_startScale, |
| EndValue = this.m_startScale, |
| InitialVelocity = this.m_startSpringVelocity |
| InitialVelocity = this.m_startSpringVelocity |
| }; |
| }; |
| . | if (this.ShouldBeVisible()) |
| if (this.ShouldBeVisible() && !string.IsNullOrEmpty(this.m_globalKeyCondition)) |
| { |
| { |
| this.m_enableObject.SetActive(true); |
| this.m_enableObject.SetActive(true); |
| if (!string.IsNullOrEmpty(this.m_animatorBool)) |
| if (!string.IsNullOrEmpty(this.m_animatorBool)) |
| { |
| { |
| Animator componentInChildren = this.m_enableObject.GetComponentInChildren<Animator>(); |
| Animator componentInChildren = this.m_enableObject.GetComponentInChildren<Animator>(); |
| if (componentInChildren != null) |
| if (componentInChildren != null) |
| { |
| { |
| componentInChildren.SetBool(this.m_animatorBool, true); |
| componentInChildren.SetBool(this.m_animatorBool, true); |
| } |
| } |
| } |
| } |
| this.m_springActive = false; |
| this.m_springActive = false; |
| this.m_dropTimer = float.PositiveInfinity; |
| this.m_dropTimer = float.PositiveInfinity; |
| . | return; |
| |
| } |
| } |
| . | this.m_enableObject.SetActive(false); |
| else |
| |
| { |
| |
| this.m_enableObject.SetActive(false); |
| |
| } |
| |
| this.m_dropTimeActual = this.m_dropTime + UnityEngine.Random.Range(0f, this.m_dropTimeVariance); |
| } |
| } |
| |
| |
| private void Update() |
| private void Update() |
| { |
| { |
| if (!this.m_enableObject.activeInHierarchy && this.ShouldBeVisible()) |
| if (!this.m_enableObject.activeInHierarchy && this.ShouldBeVisible()) |
| { |
| { |
| this.m_delayTimer += Time.deltaTime; |
| this.m_delayTimer += Time.deltaTime; |
| if (this.m_delayTimer > this.m_appearDelay) |
| if (this.m_delayTimer > this.m_appearDelay) |
| { |
| { |
| if (this.m_dropEnabled) |
| if (this.m_dropEnabled) |
| { |
| { |
| this.m_enableObject.transform.position = this.m_enableObject.transform.position + Vector3.up * this.m_dropHeight; |
| this.m_enableObject.transform.position = this.m_enableObject.transform.position + Vector3.up * this.m_dropHeight; |
| } |
| } |
| else if (this.m_springEnabled) |
| else if (this.m_springEnabled) |
| { |
| { |
| this.ActivateSpring(); |
| this.ActivateSpring(); |
| } |
| } |
| this.m_enableObject.SetActive(true); |
| this.m_enableObject.SetActive(true); |
| this.m_showEffects.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1); |
| this.m_showEffects.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1); |
| if (!string.IsNullOrEmpty(this.m_animatorBool)) |
| if (!string.IsNullOrEmpty(this.m_animatorBool)) |
| { |
| { |
| Animator componentInChildren = this.m_enableObject.GetComponentInChildren<Animator>(); |
| Animator componentInChildren = this.m_enableObject.GetComponentInChildren<Animator>(); |
| if (componentInChildren != null) |
| if (componentInChildren != null) |
| { |
| { |
| componentInChildren.SetBool(this.m_animatorBool, true); |
| componentInChildren.SetBool(this.m_animatorBool, true); |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.LogError(string.Concat(new string[] { "Object '", base.name, "' trying to set animation trigger '", this.m_animatorBool, "' but no animator was found!" })); |
| ZLog.LogError(string.Concat(new string[] { "Object '", base.name, "' trying to set animation trigger '", this.m_animatorBool, "' but no animator was found!" })); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| if (this.m_enableObject.activeInHierarchy) |
| if (this.m_enableObject.activeInHierarchy) |
| { |
| { |
| if (this.m_springEnabled && this.m_springActive) |
| if (this.m_springEnabled && this.m_springActive) |
| { |
| { |
| this.m_enableObject.transform.localScale = this.m_scaleSpring.Evaluate(Time.deltaTime); |
| this.m_enableObject.transform.localScale = this.m_scaleSpring.Evaluate(Time.deltaTime); |
| } |
| } |
| if (this.m_dropEnabled) |
| if (this.m_dropEnabled) |
| { |
| { |
| . | if (this.m_dropTimer <= this.m_dropTime) |
| if (this.m_dropTimer <= this.m_dropTimeActual) |
| { |
| { |
| this.m_dropTimer += Time.deltaTime; |
| this.m_dropTimer += Time.deltaTime; |
| Vector3 position = this.m_enableObject.transform.position; |
| Vector3 position = this.m_enableObject.transform.position; |
| . | float num = (1f - this.m_dropCurve.Evaluate(this.m_dropTimer / this.m_dropTime)) * this.m_dropHeight; |
| float num = (1f - this.m_dropCurve.Evaluate(this.m_dropTimer / this.m_dropTimeActual)) * this.m_dropHeight; |
| position.y = this.m_startHeight + num; |
| position.y = this.m_startHeight + num; |
| this.m_enableObject.transform.position = position; |
| this.m_enableObject.transform.position = position; |
| } |
| } |
| . | if (this.m_dropTimer > this.m_dropTime && !this.m_springActive) |
| if (this.m_dropTimer > this.m_dropTimeActual && !this.m_springActive) |
| { |
| { |
| this.ActivateSpring(); |
| this.ActivateSpring(); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private bool ShouldBeVisible() |
| private bool ShouldBeVisible() |
| { |
| { |
| . | return !string.IsNullOrEmpty(this.m_globalKeyCondition) && ZoneSystem.instance && ZoneSystem.instance.GetGlobalKey(this.m_globalKeyCondition); |
| return string.IsNullOrEmpty(this.m_globalKeyCondition) || (ZoneSystem.instance && ZoneSystem.instance.GetGlobalKey(this.m_globalKeyCondition)); |
| } |
| } |
| |
| |
| private void ActivateSpring() |
| private void ActivateSpring() |
| { |
| { |
| base.StartCoroutine(this.DisableSpring()); |
| base.StartCoroutine(this.DisableSpring()); |
| this.m_springActive = true; |
| this.m_springActive = true; |
| } |
| } |
| |
| |
| private IEnumerator DisableSpring() |
| private IEnumerator DisableSpring() |
| { |
| { |
| yield return new WaitForSeconds(this.m_springDisableTime); |
| yield return new WaitForSeconds(this.m_springDisableTime); |
| this.m_springActive = false; |
| this.m_springActive = false; |
| this.m_enableObject.transform.localScale = this.m_startScale; |
| this.m_enableObject.transform.localScale = this.m_startScale; |
| yield break; |
| yield break; |
| } |
| } |
| |
| |
| public string GetHoverText() |
| public string GetHoverText() |
| { |
| { |
| return Localization.instance.Localize(this.m_hoverName); |
| return Localization.instance.Localize(this.m_hoverName); |
| } |
| } |
| |
| |
| public string GetHoverName() |
| public string GetHoverName() |
| { |
| { |
| return Localization.instance.Localize(this.m_hoverName); |
| return Localization.instance.Localize(this.m_hoverName); |
| } |
| } |
| |
| |
| private float m_delayTimer; |
| private float m_delayTimer; |
| |
| |
| . | private float m_dropTimer; |
| [NonSerialized] |
| |
| public float m_dropTimer; |
| |
| |
| private SpringVector3 m_scaleSpring; |
| private SpringVector3 m_scaleSpring; |
| |
| |
| private bool m_springActive; |
| private bool m_springActive; |
| |
| |
| private Vector3 m_startScale; |
| private Vector3 m_startScale; |
| |
| |
| private float m_startHeight; |
| private float m_startHeight; |
| |
| |
| public GameObject m_enableObject; |
| public GameObject m_enableObject; |
| |
| |
| public string m_hoverName = "Oddity"; |
| public string m_hoverName = "Oddity"; |
| |
| |
| public string m_globalKeyCondition = ""; |
| public string m_globalKeyCondition = ""; |
| |
| |
| public float m_appearDelay; |
| public float m_appearDelay; |
| |
| |
| public string m_animatorBool; |
| public string m_animatorBool; |
| |
| |
| public EffectList m_showEffects = new EffectList(); |
| public EffectList m_showEffects = new EffectList(); |
| |
| |
| [Header("Drop Settings")] |
| [Header("Drop Settings")] |
| public bool m_dropEnabled; |
| public bool m_dropEnabled; |
| |
| |
| public float m_dropHeight = 1f; |
| public float m_dropHeight = 1f; |
| |
| |
| public float m_dropTime = 0.5f; |
| public float m_dropTime = 0.5f; |
| . | |
| |
| |
| public float m_dropTimeVariance; |
| |
| |
| |
| private float m_dropTimeActual; |
| |
| |
| public AnimationCurve m_dropCurve = AnimationCurve.Linear(0f, 1f, 0f, 1f); |
| public AnimationCurve m_dropCurve = AnimationCurve.Linear(0f, 1f, 0f, 1f); |
| |
| |
| [Header("Spring Settings")] |
| [Header("Spring Settings")] |
| public bool m_springEnabled; |
| public bool m_springEnabled; |
| |
| |
| public float m_springDisableTime = 3f; |
| public float m_springDisableTime = 3f; |
| |
| |
| [Min(0f)] |
| [Min(0f)] |
| public float m_springDamping = 8f; |
| public float m_springDamping = 8f; |
| |
| |
| [Min(0f)] |
| [Min(0f)] |
| public float m_springStiffness = 180f; |
| public float m_springStiffness = 180f; |
| |
| |
| public Vector3 m_startSpringVelocity = new Vector3(1.5f, -1f, 1.5f); |
| public Vector3 m_startSpringVelocity = new Vector3(1.5f, -1f, 1.5f); |
| } |
| } |
| |
| |