31 lines
722 B
C#
31 lines
722 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Game;
|
|
using asap.core;
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
[RequireComponent(typeof(Button))]
|
|
[AddComponentMenu("UGUI/UI/UIButtonSound")]
|
|
public class UIButtonSound : MonoBehaviour
|
|
{
|
|
public AssetReferenceT<AudioClip> assetReference;
|
|
public float startTimer = 0f;
|
|
void Awake()
|
|
{
|
|
var btn = gameObject.GetComponent<Button>();
|
|
|
|
if (null != btn)
|
|
{
|
|
btn.onClick.AddListener(OnClick);
|
|
}
|
|
}
|
|
|
|
public void OnClick()
|
|
{
|
|
if (assetReference != null && assetReference.RuntimeKeyIsValid())
|
|
{
|
|
GContext.Publish(new AssetReferenceAudioClip(assetReference, time: startTimer));
|
|
}
|
|
}
|
|
}
|