SHADE_Y3/Assets/Scripts/UI/SC_SliderFX.cs

71 lines
1.3 KiB
C#
Raw Permalink Normal View History

2023-03-31 14:18:09 +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 SliderFX : Script
{
public string onClickSound = "event:/UI/button_success";
public string onReleaseSound = "event:/UI/button_fail";
[NonSerialized]
private AudioClipHandler onClickACHandler;
[NonSerialized]
private AudioClipHandler onReleaseACHandler;
protected override void awake()
{
if (onClickSound != "Empty")
onClickACHandler = SHADE.Audio.CreateAudioClip(onClickSound);
if (onReleaseSound != "Empty")
onReleaseACHandler = SHADE.Audio.CreateAudioClip(onReleaseSound);
}
protected override void start()
{
Transform transform = GetComponent<Transform>();
if (transform == null)
return;
UIElement ui = GetComponent<UIElement>();
if (ui == null)
return;
ui.OnClick.RegisterAction(() =>
{
if (onClickSound != "Empty")
onClickACHandler.Play();
});
ui.OnRelease.RegisterAction(() =>
{
if (onReleaseSound != "Empty")
onReleaseACHandler.Play();
});
}
protected override void update()
{
}
}
}