using SHADE; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SHADE_Scripting.UI { public class ButtonFX:Script { public string onHoverEnterSound = "Empty"; public string onHoverExitSound = "Empty"; public string onClickSound = "event:/UI/button_success"; public string onReleaseSound = "Empty"; [NonSerialized] private AudioClipHandler onHoverEnterACHandler; [NonSerialized] private AudioClipHandler onHoverExitACHandler; [NonSerialized] private AudioClipHandler onClickACHandler; [NonSerialized] private AudioClipHandler onReleaseACHandler; [NonSerialized] private Vector3 defaultScale; public float hoverScale = 1.1f; public float clickScale = 0.9f; [NonSerialized] private TweenThread thread; [NonSerialized] private bool tweening = false; [NonSerialized] private float currentScale = 1.0f; protected override void awake() { if(onHoverEnterSound != "Empty") onHoverEnterACHandler = SHADE.Audio.CreateAudioClip(onHoverEnterSound); if(onHoverExitSound != "Empty") onHoverExitACHandler = SHADE.Audio.CreateAudioClip(onHoverExitSound); if (onClickSound != "Empty") onClickACHandler = SHADE.Audio.CreateAudioClip(onClickSound); if (onReleaseSound != "Empty") onReleaseACHandler = SHADE.Audio.CreateAudioClip(onReleaseSound); } protected override void start() { thread = TweenManager.CreateTweenThread(0.1f, 0.9f, 1.0f, EASING_METHOD.EASE_IN_SINE); Transform transform = GetComponent(); if (transform == null) return; defaultScale = transform.LocalScale; UIElement ui = GetComponent(); if (ui == null) return; ui.OnClick.RegisterAction(() => { if (onClickSound != "Empty") onClickACHandler.Play(); tweening = true; if(thread != null) thread.Reset(currentScale,clickScale); }); ui.OnRelease.RegisterAction(() => { if (onReleaseSound != "Empty") onReleaseACHandler.Play(); tweening = true; if (thread != null) thread.Reset(currentScale, 1.0f); }); ui.OnHoverEnter.RegisterAction(() => { if (onHoverEnterSound!="Empty") { onHoverEnterACHandler.Play(); } tweening = true; if (thread != null) thread.Reset(currentScale, hoverScale); }); ui.OnHoverExit.RegisterAction(() => { if (onHoverExitSound != "Empty") onHoverExitACHandler.Play(); tweening = true; if (thread != null) thread.Reset(currentScale, 1.0f); }); } protected override void update() { Transform transform = GetComponent(); if (transform == null) return; if (tweening == true && thread != null) { transform.LocalScale = defaultScale * thread.GetValue(); currentScale = thread.GetValue(); if (thread.IsCompleted()) tweening = false; } } } }