mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
83 lines
2.3 KiB
C#
83 lines
2.3 KiB
C#
using System;
|
|
using GAS.General;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace GAS.Runtime
|
|
{
|
|
public class CuePlaySound : GameplayCueDurational
|
|
{
|
|
[BoxGroup]
|
|
[LabelText(GASTextDefine.CUE_SOUND_EFFECT)]
|
|
public AudioClip soundEffect;
|
|
|
|
[BoxGroup]
|
|
[LabelText(GASTextDefine.CUE_ATTACH_TO_OWNER)]
|
|
public bool isAttachToOwner = true;
|
|
|
|
public override GameplayCueDurationalSpec CreateSpec(GameplayCueParameters parameters)
|
|
{
|
|
return new CuePlaySoundSpec(this, parameters);
|
|
}
|
|
}
|
|
|
|
public class CuePlaySoundSpec : GameplayCueDurationalSpec<CuePlaySound>
|
|
{
|
|
private AudioSource _audioSource;
|
|
|
|
public CuePlaySoundSpec(CuePlaySound cue, GameplayCueParameters parameters) : base(cue,
|
|
parameters)
|
|
{
|
|
if (cue.isAttachToOwner)
|
|
{
|
|
_audioSource = Owner.GetView()?.gameObject.GetComponent<AudioSource>();
|
|
if (_audioSource == null)
|
|
{
|
|
_audioSource = Owner.GetView()?.gameObject.AddComponent<AudioSource>();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var soundRoot = new GameObject("SoundRoot");
|
|
|
|
if (Owner.GetView() is not null)
|
|
{
|
|
soundRoot.transform.position = Owner.GetView().transform.position;
|
|
}
|
|
|
|
_audioSource = soundRoot.AddComponent<AudioSource>();
|
|
}
|
|
}
|
|
|
|
public override void OnAdd(int frame,int startFrame,int endFrame)
|
|
{
|
|
_audioSource.clip = cue.soundEffect;
|
|
_audioSource.Play();
|
|
}
|
|
|
|
public override void OnRemove(int frame,int startFrame,int endFrame)
|
|
{
|
|
if (!cue.isAttachToOwner)
|
|
{
|
|
Object.Destroy(_audioSource.gameObject);
|
|
}else
|
|
{
|
|
_audioSource.Stop();
|
|
_audioSource.clip = null;
|
|
}
|
|
}
|
|
|
|
public override void OnGameplayEffectActivate()
|
|
{
|
|
}
|
|
|
|
public override void OnGameplayEffectDeactivate()
|
|
{
|
|
}
|
|
|
|
public override void OnTick(int frame,int startFrame,int endFrame)
|
|
{
|
|
}
|
|
}
|
|
} |