diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index cd8a99f4..0db34215 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -166,6 +166,11 @@ public class ActionHelper var strAction = (XMLTool.StringListAction)act; return LoadResAction.Allocate(act.Value, strAction.args[0]); } + case "Audio": + { + var strAction = (XMLTool.StringListAction)act; + return AudioAction.Allocate(act.Value, strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4]); + } default: Debug.LogError($"ûҵAction{act.Type}"); break; diff --git a/Assets/Scripts/Actions/AudioAction.cs b/Assets/Scripts/Actions/AudioAction.cs new file mode 100644 index 00000000..7002a150 --- /dev/null +++ b/Assets/Scripts/Actions/AudioAction.cs @@ -0,0 +1,167 @@ +using System; +using UnityEngine; + +namespace QFramework +{ + internal class AudioAction : IAction + { + + + public System.Action OnFinished { get; set; } + + + private AudioAction() + { + } + + private static readonly SimpleObjectPool mPool = + new SimpleObjectPool(() => new AudioAction(), null, 10); + + public string path; + public string audioType; + bool loop = false; + public bool waitFinished = true; + bool isPlay = true; + float volume; + ResLoader loader; + public static AudioAction Allocate(string path, string audioType, string loop, string waitFinished, string volume, string isPlay, System.Action OnFinished = null) + { + var retNode = mPool.Allocate(); + retNode.ActionID = ActionKit.ID_GENERATOR++; + retNode.Deinited = false; + retNode.Reset(); + retNode.path = path; + retNode.audioType = audioType; + bool.TryParse(loop, out retNode.loop); + bool.TryParse(waitFinished, out retNode.waitFinished); + retNode.OnFinished = OnFinished; + bool.TryParse(isPlay, out retNode.isPlay); + if (string.IsNullOrEmpty(volume)) + { + retNode.volume = AudioKit.Settings.MusicVolume.Value; + } + else + { + float.TryParse(volume, out retNode.volume); + } + return retNode; + } + + + public ulong ActionID { get; set; } + public ActionStatus Status { get; set; } + + public void OnStart() + { + if (isPlay) + { + loader = ResLoader.Allocate(); + string audioPath = Global.audioPath + path; + loader.Add2Load(audioPath.ToLocalAudioResName(), (success, res) => + { + if (success) + { + AudioClip clip = res.Asset.As(); + + switch (audioType) + { + case "Music": + if (waitFinished == false) + { + this.Finish(); + AudioKit.PlayMusic(clip, loop: loop); + } + else + { + AudioKit.PlayMusic(clip, loop: loop, onEndCallback: OnPlayFinished); + } + break; + case "Voice": + if (waitFinished == false) + { + this.Finish(); + AudioKit.PlayVoice(clip, loop: loop); + } + else + { + AudioKit.PlayVoice(clip, loop: loop, onEndedCallback: OnPlayFinished); + } + break; + case "Sound": + if (waitFinished == false) + { + this.Finish(); + AudioKit.PlaySound(clip, loop: loop); + } + else + { + AudioKit.PlaySound(clip, loop: loop, callBack: OnSoundPlayFinished); + } + break; + } + + } + }); + loader.LoadAsync(); + + } + else + { + switch (audioType) + { + case "Music": + AudioKit.StopMusic(); + break; + case "Voice": + AudioKit.StopVoice(); + break; + case "Sound": + AudioKit.StopAllSound(); + break; + } + } + + } + + public void OnPlayFinished() + { + Debug.LogError("OnPlayFinished"); + this.Finish(); + } + public void OnSoundPlayFinished(AudioPlayer player) + { + OnPlayFinished(); + } + + public void OnExecute(float dt) + { + } + + public void OnFinish() + { + } + + public void Reset() + { + Status = ActionStatus.NotStart; + Paused = false; + } + + public bool Paused { get; set; } + + public void Deinit() + { + if (!Deinited) + { + OnFinished = null; + Deinited = true; + //loader.Recycle2Cache(); + mPool.Recycle(this); + } + } + + public bool Deinited { get; set; } + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/Actions/AudioAction.cs.meta b/Assets/Scripts/Actions/AudioAction.cs.meta new file mode 100644 index 00000000..d5330ce5 --- /dev/null +++ b/Assets/Scripts/Actions/AudioAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 701ece2f3b3a0ab448541d3fbfc67087 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index c92586d0..a2a85692 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -699,6 +699,58 @@ namespace XMLTool newAction = act; } break; + case "Audio": + { + //string path, string audioType, string loop, string finishedEvent, string volume, + var act = new StringListAction(); + XAttribute audioType = action.Attribute("audioType"); + if (audioType != null) + { + act.args.Add(audioType.Value); + } + else + { + act.args.Add("Sound"); + } + XAttribute loop = action.Attribute("loop"); + if (loop != null) + { + act.args.Add(loop.Value); + } + else + { + act.args.Add("false"); + } + XAttribute waitFinished = action.Attribute("waitFinished"); + if (waitFinished != null) + { + act.args.Add(waitFinished.Value); + } + else + { + act.args.Add(""); + } + XAttribute volume = action.Attribute("volume"); + if (volume != null) + { + act.args.Add(volume.Value); + } + else + { + act.args.Add(""); + } + XAttribute isPlay = action.Attribute("isPlay"); + if (isPlay != null) + { + act.args.Add(isPlay.Value); + } + else + { + act.args.Add("true"); + } + newAction = act; + } + break; default: newAction = new Action(); break; diff --git a/Data/App.xml b/Data/App.xml index 42dca9d6..2c00a7cb 100644 --- a/Data/App.xml +++ b/Data/App.xml @@ -541,6 +541,7 @@ + @@ -638,7 +639,11 @@ + + + + diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index 897e0bb0..0021a891 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -55,7 +55,14 @@ - + + diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index c5866091..2e88fb08 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -120,7 +120,7 @@ QualitySettings: globalTextureMipmapLimit: 0 textureMipmapLimitSettings: [] anisotropicTextures: 1 - antiAliasing: 8 + antiAliasing: 2 softParticles: 0 softVegetation: 1 realtimeReflectionProbes: 1