SHADE_Y3/Assets/Scripts/UI/SC_ButtonFX.cs

92 lines
2.6 KiB
C#

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(() =>
{
if (onClickSound != "")
onClickACHandler.Play();
transform.LocalScale = defaultScale * clickScale;
});
ui.OnRelease.RegisterAction(() =>
{
if (onReleaseSound != "")
onReleaseACHandler.Play();
transform.LocalScale = defaultScale;
});
ui.OnHoverEnter.RegisterAction(() =>
{
if(onHoverEnterSound != "")
onHoverEnterACHandler.Play();
transform.LocalScale = defaultScale * hoverScale;
});
ui.OnHoverExit.RegisterAction(() =>
{
if (onHoverExitSound != "")
onHoverExitACHandler.Play();
transform.LocalScale = defaultScale;
});
}
protected override void update()
{
}
}
}