2023-02-27 07:32:26 +08:00
|
|
|
|
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 = "event:/Music/player_undetected";
|
|
|
|
|
public string onHoverExitSound = "event:/Music/player_undetected";
|
|
|
|
|
public string onClickSound = "event:/Music/player_undetected";
|
|
|
|
|
public string onReleaseSound = "event:/Music/player_undetected";
|
|
|
|
|
|
|
|
|
|
[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()
|
|
|
|
|
{
|
|
|
|
|
onHoverEnterACHandler = SHADE.Audio.CreateAudioClip(onHoverEnterSound);
|
|
|
|
|
onHoverExitACHandler = SHADE.Audio.CreateAudioClip(onHoverExitSound);
|
|
|
|
|
onClickACHandler = SHADE.Audio.CreateAudioClip(onClickSound);
|
|
|
|
|
onReleaseACHandler = SHADE.Audio.CreateAudioClip(onReleaseSound);
|
2023-02-27 15:16:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-27 07:32:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void start()
|
|
|
|
|
{
|
2023-02-27 15:16:48 +08:00
|
|
|
|
thread = TweenManager.CreateTweenThread(0.1f, 0.9f, 1.0f, EASING_METHOD.EASE_IN_SINE);
|
|
|
|
|
|
|
|
|
|
|
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-02-27 09:55:54 +08:00
|
|
|
|
if (onClickSound != "")
|
|
|
|
|
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-02-27 09:55:54 +08:00
|
|
|
|
if (onReleaseSound != "")
|
|
|
|
|
onReleaseACHandler.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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ui.OnHoverEnter.RegisterAction(() =>
|
|
|
|
|
{
|
2023-02-27 15:16:48 +08:00
|
|
|
|
if (onHoverEnterSound != "")
|
2023-02-27 09:55:54 +08:00
|
|
|
|
onHoverEnterACHandler.Play();
|
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-02-27 09:55:54 +08:00
|
|
|
|
if (onHoverExitSound != "")
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Tweening value " + thread.GetValue());
|
|
|
|
|
transform.LocalScale = defaultScale * thread.GetValue();
|
|
|
|
|
currentScale = thread.GetValue();
|
|
|
|
|
if (thread.IsCompleted())
|
|
|
|
|
tweening = false;
|
|
|
|
|
}
|
2023-02-27 07:32:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|