From 8722a9920c1f6119bf6e769cba270e63097f8e25 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 23 May 2024 10:08:29 +0800 Subject: + astar project --- .../Scenes/OldExamples/Example18_RTS/RTSAudio.cs | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSAudio.cs (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSAudio.cs') diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSAudio.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSAudio.cs new file mode 100644 index 0000000..3b18143 --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSAudio.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Pathfinding.Examples.RTS { + [HelpURL("https://arongranberg.com/astar/documentation/stable/rtsaudio.html")] + public class RTSAudio : VersionedMonoBehaviour { + List sources = new List(); + + class Source { + public AudioSource source; + + public bool available { + get { + return !source.isPlaying; + } + } + + public void Play (AudioClip clip) { + source.PlayOneShot(clip); + } + } + + Source GetSource () { + for (int i = 0; i < sources.Count; i++) { + if (sources[i].available) { + return sources[i]; + } + } + + var go = new GameObject("Source"); + go.transform.SetParent(transform, false); + var source = new Source { + source = go.AddComponent() + }; + + sources.Add(source); + return source; + } + + public void Play (AudioClip clip) { + GetSource().Play(clip); + } + } +} -- cgit v1.1-26-g67d0