SHADE_Y3/Assets/Scripts/UI/SC_ButtonFX.cs

92 lines
2.6 KiB
C#
Raw Normal View History

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;
protected override void awake()
{
onHoverEnterACHandler = SHADE.Audio.CreateAudioClip(onHoverEnterSound);
onHoverExitACHandler = SHADE.Audio.CreateAudioClip(onHoverExitSound);
onClickACHandler = SHADE.Audio.CreateAudioClip(onClickSound);
onReleaseACHandler = SHADE.Audio.CreateAudioClip(onReleaseSound);
}
protected override void start()
{
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();
transform.LocalScale = defaultScale * clickScale;
});
ui.OnRelease.RegisterAction(() =>
{
2023-02-27 09:55:54 +08:00
if (onReleaseSound != "")
onReleaseACHandler.Play();
transform.LocalScale = defaultScale;
});
ui.OnHoverEnter.RegisterAction(() =>
{
2023-02-27 09:55:54 +08:00
if(onHoverEnterSound != "")
onHoverEnterACHandler.Play();
transform.LocalScale = defaultScale * hoverScale;
});
ui.OnHoverExit.RegisterAction(() =>
{
2023-02-27 09:55:54 +08:00
if (onHoverExitSound != "")
onHoverExitACHandler.Play();
transform.LocalScale = defaultScale;
});
}
protected override void update()
{
}
}
}