备份CatanBuilding瘦身独立工程
This commit is contained in:
37
Assets/Scripts/Sound/UIToggleSound.cs
Normal file
37
Assets/Scripts/Sound/UIToggleSound.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user