38 lines
898 B
C#
38 lines
898 B
C#
using asap.core;
|
|
using Game;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.UI;
|
|
|
|
[RequireComponent(typeof(Toggle))]
|
|
[AddComponentMenu("UGUI/UI/UIToggleSound")]
|
|
public class UIToggleSound : MonoBehaviour
|
|
{
|
|
public AssetReferenceT<AudioClip> assetReference;
|
|
public float startTimer = 0f;
|
|
public bool isOn = true;
|
|
void Start()
|
|
{
|
|
var btn = gameObject.GetComponent<Toggle>();
|
|
|
|
if (null != btn)
|
|
{
|
|
btn.onValueChanged.AddListener(OnClick);
|
|
}
|
|
}
|
|
|
|
public void OnClick(bool isOn)
|
|
{
|
|
if (isOn != this.isOn)
|
|
{
|
|
return;
|
|
}
|
|
if (assetReference != null && assetReference.RuntimeKeyIsValid())
|
|
{
|
|
GContext.Publish(new AssetReferenceAudioClip(assetReference, time: startTimer));
|
|
}
|
|
}
|
|
}
|