先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using asap.core;
|
|
using Game;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace UIExtend
|
|
{
|
|
public class AnimatorWithSoundStateMachine : StateMachineBehaviour
|
|
{
|
|
[SerializeField] private List<AssetReferenceT<AudioClip>> UISounds;
|
|
[SerializeField] private List<AssetReferenceT<AudioClip>> UILoopSounds;
|
|
private Dictionary<string,AssetReferenceAudioClip> _sounds;
|
|
|
|
private void SetEffectObjState(Animator animator,bool isActive)
|
|
{
|
|
_sounds ??= new Dictionary<string, AssetReferenceAudioClip>();
|
|
|
|
if (UISounds is { Count: > 0 })
|
|
foreach (var audioClip in UISounds)
|
|
PlaySound(isActive, audioClip,SoundMainType.UI);
|
|
|
|
if (UILoopSounds is { Count: > 0 })
|
|
foreach (var audioClip in UILoopSounds)
|
|
PlaySound(isActive, audioClip,SoundMainType.UILoop);
|
|
}
|
|
|
|
private void PlaySound(bool isActive, AssetReferenceT<AudioClip> soundName,SoundMainType mainType)
|
|
{
|
|
if (isActive)
|
|
{
|
|
if (!_sounds.TryGetValue(soundName.AssetGUID, out var soundEvent))
|
|
{
|
|
soundEvent = new AssetReferenceAudioClip(soundName)
|
|
{
|
|
mainType = mainType,
|
|
};
|
|
_sounds.TryAdd(soundName.AssetGUID,soundEvent);
|
|
}
|
|
GContext.Publish(soundEvent);
|
|
}
|
|
else
|
|
{
|
|
if(_sounds.TryGetValue(soundName.AssetGUID, out var soundEvent))
|
|
GContext.Publish(new FadeOutEvent(soundEvent.Sound,0));
|
|
}
|
|
}
|
|
|
|
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
|
{
|
|
SetEffectObjState(animator,true);
|
|
}
|
|
|
|
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
|
{
|
|
SetEffectObjState(animator,false);
|
|
}
|
|
}
|
|
} |