2023-03-05 14:42:31 +08:00
|
|
|
using SHADE;
|
2023-02-27 07:32:26 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace SHADE_Scripting.UI
|
|
|
|
{
|
|
|
|
public class ButtonFX:Script
|
|
|
|
{
|
2023-03-10 19:50:34 +08:00
|
|
|
public string onHoverEnterSound = "event:/UI/botton_hover";
|
2023-03-05 10:47:16 +08:00
|
|
|
public string onHoverExitSound = "Empty";
|
2023-03-10 19:00:58 +08:00
|
|
|
public string onClickSound = "event:/UI/button_success";
|
2023-03-10 19:50:34 +08:00
|
|
|
public string onReleaseSound = "event:/UI/button_fail";
|
2023-02-27 07:32:26 +08:00
|
|
|
|
|
|
|
[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;
|
|
|
|
|
|
|
|
|
2023-02-27 15:16:48 +08:00
|
|
|
[NonSerialized]
|
|
|
|
private TweenThread thread;
|
|
|
|
|
|
|
|
[NonSerialized]
|
|
|
|
private bool tweening = false;
|
|
|
|
[NonSerialized]
|
|
|
|
private float currentScale = 1.0f;
|
|
|
|
|
2023-02-27 07:32:26 +08:00
|
|
|
protected override void awake()
|
|
|
|
{
|
2023-03-05 10:47:16 +08:00
|
|
|
if(onHoverEnterSound != "Empty")
|
|
|
|
onHoverEnterACHandler = SHADE.Audio.CreateAudioClip(onHoverEnterSound);
|
|
|
|
|
|
|
|
if(onHoverExitSound != "Empty")
|
|
|
|
onHoverExitACHandler = SHADE.Audio.CreateAudioClip(onHoverExitSound);
|
2023-02-27 15:16:48 +08:00
|
|
|
|
2023-03-05 10:47:16 +08:00
|
|
|
if (onClickSound != "Empty")
|
|
|
|
onClickACHandler = SHADE.Audio.CreateAudioClip(onClickSound);
|
|
|
|
if (onReleaseSound != "Empty")
|
|
|
|
onReleaseACHandler = SHADE.Audio.CreateAudioClip(onReleaseSound);
|
2023-02-27 07:32:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void start()
|
|
|
|
{
|
2023-04-01 16:30:33 +08:00
|
|
|
thread = TweenManager.CreateTweenThread(0.1f, 0.9f, 1.0f, EASING_METHOD.EASE_OUT_BACK);
|
2023-02-27 15:16:48 +08:00
|
|
|
|
|
|
|
|
2023-02-27 07:32:26 +08:00
|
|
|
Transform transform = GetComponent<Transform>();
|
|
|
|
if (transform == null)
|
|
|
|
return;
|
|
|
|
defaultScale = transform.LocalScale;
|
|
|
|
|
|
|
|
|
|
|
|
UIElement ui = GetComponent<UIElement>();
|
|
|
|
if (ui == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
ui.OnClick.RegisterAction(() =>
|
|
|
|
{
|
2023-03-05 10:47:16 +08:00
|
|
|
if (onClickSound != "Empty")
|
2023-02-27 09:55:54 +08:00
|
|
|
onClickACHandler.Play();
|
2023-02-27 15:16:48 +08:00
|
|
|
tweening = true;
|
|
|
|
if(thread != null)
|
|
|
|
thread.Reset(currentScale,clickScale);
|
2023-02-27 07:32:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
ui.OnRelease.RegisterAction(() =>
|
|
|
|
{
|
2023-03-05 10:47:16 +08:00
|
|
|
if (onReleaseSound != "Empty")
|
2023-02-27 09:55:54 +08:00
|
|
|
onReleaseACHandler.Play();
|
2023-03-05 10:47:16 +08:00
|
|
|
|
|
|
|
|
2023-02-27 15:16:48 +08:00
|
|
|
tweening = true;
|
|
|
|
if (thread != null)
|
|
|
|
thread.Reset(currentScale, 1.0f);
|
2023-02-27 07:32:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
ui.OnHoverEnter.RegisterAction(() =>
|
|
|
|
{
|
2023-03-05 10:47:16 +08:00
|
|
|
if (onHoverEnterSound!="Empty")
|
|
|
|
{
|
|
|
|
|
2023-02-27 09:55:54 +08:00
|
|
|
onHoverEnterACHandler.Play();
|
2023-03-05 10:47:16 +08:00
|
|
|
}
|
|
|
|
|
2023-02-27 15:16:48 +08:00
|
|
|
tweening = true;
|
|
|
|
if (thread != null)
|
|
|
|
thread.Reset(currentScale, hoverScale);
|
2023-02-27 07:32:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
ui.OnHoverExit.RegisterAction(() =>
|
|
|
|
{
|
2023-03-05 10:47:16 +08:00
|
|
|
if (onHoverExitSound != "Empty")
|
2023-02-27 09:55:54 +08:00
|
|
|
onHoverExitACHandler.Play();
|
2023-02-27 15:16:48 +08:00
|
|
|
tweening = true;
|
|
|
|
if (thread != null)
|
|
|
|
thread.Reset(currentScale, 1.0f);
|
2023-02-27 07:32:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void update()
|
|
|
|
{
|
2023-02-27 15:16:48 +08:00
|
|
|
Transform transform = GetComponent<Transform>();
|
|
|
|
if (transform == null)
|
|
|
|
return;
|
|
|
|
if (tweening == true && thread != null)
|
|
|
|
{
|
2023-03-05 13:55:51 +08:00
|
|
|
|
2023-02-27 15:16:48 +08:00
|
|
|
transform.LocalScale = defaultScale * thread.GetValue();
|
|
|
|
currentScale = thread.GetValue();
|
|
|
|
if (thread.IsCompleted())
|
|
|
|
tweening = false;
|
|
|
|
}
|
2023-02-27 07:32:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|