From ed2f790dd31cab9ad72ebcfe041b494483b47314 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Fri, 27 Dec 2024 14:08:27 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=AB=98=E4=BA=AE?= =?UTF-8?q?=E6=94=AF=E6=8C=81deviceName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/ActionHelper.cs | 4 ++-- Assets/Scripts/Actions/HighLightAction.cs | 28 +++++++++++++++++++---- Assets/Scripts/Xml/XmlParser.cs | 15 +++++------- Doc/Xml配置文档.xml | 10 ++++---- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index 029a5ec5..cebc9620 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -159,8 +159,8 @@ public class ActionHelper } case "HighLight": { - var strAction = (XMLTool.StringListAction)act; - return HighLightAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); + var strAction = (XMLTool.DictionaryAction)act; + return HighLightAction.Allocate(act.Value, strAction.args); } case "LoadRes": { diff --git a/Assets/Scripts/Actions/HighLightAction.cs b/Assets/Scripts/Actions/HighLightAction.cs index 3ffdb92d..ce7e9687 100644 --- a/Assets/Scripts/Actions/HighLightAction.cs +++ b/Assets/Scripts/Actions/HighLightAction.cs @@ -1,5 +1,6 @@ using HighlightPlus; using System; +using System.Collections.Generic; using UnityEditor; using UnityEngine; @@ -22,18 +23,26 @@ namespace QFramework string path; Color color = Color.green; bool isHigh = true; - public static HighLightAction Allocate(string path, string isHigh, string color, System.Action OnFinished = null) + string deviceName = string.Empty; + public static HighLightAction Allocate(string path, Dictionary datas, System.Action OnFinished = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.Deinited = false; retNode.Reset(); retNode.path = path; - if (string.IsNullOrEmpty(color) == false) + + if (datas.ContainsKey("color")) { - retNode.color = Utility.ToColor(color); + + retNode.color = Utility.ToColor(datas["color"]); + } - bool.TryParse(isHigh, out retNode.isHigh); + if (datas.ContainsKey("isHigh")) + { + bool.TryParse(datas["isHigh"], out retNode.isHigh); + } + retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : string.Empty; retNode.OnFinished = OnFinished; return retNode; } @@ -44,7 +53,16 @@ namespace QFramework public void OnStart() { - GameObject obj = Utility.FindObj(path); + GameObject obj = null; + if (string.IsNullOrEmpty(deviceName) == false) + { + obj = DeviceController.Instance.GetDeviceObj(deviceName); + } + else + { + obj = Utility.FindObj(path); + } + if (obj != null) { if (isHigh) diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index 5e112adf..9d04ce66 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -763,24 +763,21 @@ namespace XMLTool break; case "HighLight": { - var act = new StringListAction(); + var act = new DictionaryAction(); XAttribute isHigh = action.Attribute("isHigh"); if (isHigh != null) { - act.args.Add(isHigh.Value); - } - else - { - act.args.Add("true"); + act.args.Add("isHigh", isHigh.Value); } XAttribute color = action.Attribute("color"); if (color != null) { - act.args.Add(color.Value); + act.args.Add("color", color.Value); } - else + XAttribute deviceName = action.Attribute("deviceName"); + if (deviceName != null) { - act.args.Add(""); + act.args.Add("deviceName", deviceName.Value); } newAction = act; } diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index 03669536..48307bd2 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -57,8 +57,8 @@ - - + + - - + + @@ -112,7 +112,7 @@ needClick如果为true 动画结束后不会自动小时 需要点击空白处 reverse 是时钟倒计时动画是否倒序播放 format="{0:F1}" F1代表保留1位小数 F2代表2位 F0代表不保留小数 - --> + --> From aff0e81e674da2f3ec06d01e9920d35249bf9806 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Fri, 27 Dec 2024 17:25:30 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E5=88=86=E5=B8=A7=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/AnimationAction.cs | 2 +- .../Editor/FbxAnimListPostprocessor.cs | 84 +++++++++++++++++++ .../Editor/FbxAnimListPostprocessor.cs.meta | 11 +++ Assets/Scripts/Launch.cs | 7 +- Assets/Scripts/TimeScaleController.cs | 18 ++++ Assets/Scripts/TimeScaleController.cs.meta | 11 +++ 6 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 Assets/Scripts/Editor/FbxAnimListPostprocessor.cs create mode 100644 Assets/Scripts/Editor/FbxAnimListPostprocessor.cs.meta create mode 100644 Assets/Scripts/TimeScaleController.cs create mode 100644 Assets/Scripts/TimeScaleController.cs.meta diff --git a/Assets/Scripts/Actions/AnimationAction.cs b/Assets/Scripts/Actions/AnimationAction.cs index c211d434..d99185ca 100644 --- a/Assets/Scripts/Actions/AnimationAction.cs +++ b/Assets/Scripts/Actions/AnimationAction.cs @@ -48,7 +48,7 @@ namespace QFramework anim.Play(animName); if (reset) { - ActionKit.DelayFrame(1, () => anim.Stop()); + ActionKit.DelayFrame(1, () => anim.Stop()).StartGlobal(); } } else diff --git a/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs b/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs new file mode 100644 index 00000000..0f451c54 --- /dev/null +++ b/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs @@ -0,0 +1,84 @@ + +using UnityEngine; +using UnityEditor; +using System.Collections; +using System.IO; +using System.Text.RegularExpressions; +using System; +using System.IO; + + +public class FbxAnimListPostprocessor : MonoBehaviour +{ + [MenuItem("Assets/SplitAnimNew")] + public static void SplitAnim() + { + UnityEngine.Object obj = Selection.activeObject; + if( null != obj ) + { + string assetPath = AssetDatabase.GetAssetPath(obj); + try + { + string fileAnim; + fileAnim = assetPath; + string ClipText = Path.ChangeExtension(fileAnim, ".txt"); + StreamReader file = new StreamReader(ClipText); + string sAnimList = file.ReadToEnd(); + file.Close(); + // + if (EditorUtility.DisplayDialog("FBX Animation Import from file", + fileAnim, "Import", "Cancel")) + { + System.Collections.ArrayList List = new ArrayList(); + ParseAnimFile(sAnimList, ref List); + + ModelImporter modelImporter = ModelImporter.GetAtPath(assetPath) as ModelImporter; + modelImporter.animationType = ModelImporterAnimationType.Legacy; + //modelImporter.clipAnimations. = true; + modelImporter.clipAnimations = (ModelImporterClipAnimation[]) + List.ToArray(typeof(ModelImporterClipAnimation)); + AssetDatabase.ImportAsset(assetPath); + + EditorUtility.DisplayDialog("导入成功", + "Number of imported clips: " + + modelImporter.clipAnimations.GetLength(0).ToString(), "OK"); + } + } + catch { } + // (Exception e) { EditorUtility.DisplayDialog("Imported animations", e.Message, "OK"); } + } + } + + static void ParseAnimFile(string sAnimList, ref System.Collections.ArrayList List) + { + Regex regexString = new Regex(" *(?[0-9]+) *- *(?[0-9]+) *(?(loop|noloop| )) *(?[^\r^\n]*[^\r^\n^ ])", + RegexOptions.Compiled | RegexOptions.ExplicitCapture); + + Match match = regexString.Match(sAnimList, 0); + while (match.Success) + { + ModelImporterClipAnimation clip = new ModelImporterClipAnimation(); + + if (match.Groups["firstFrame"].Success) + { + clip.firstFrame = System.Convert.ToInt32(match.Groups["firstFrame"].Value, 10); + } + if (match.Groups["lastFrame"].Success) + { + clip.lastFrame = System.Convert.ToInt32(match.Groups["lastFrame"].Value, 10); + } + if (match.Groups["loop"].Success) + { + clip.loop = match.Groups["loop"].Value == "loop"; + } + if (match.Groups["name"].Success) + { + clip.name = match.Groups["name"].Value; + } + + List.Add(clip); + + match = regexString.Match(sAnimList, match.Index + match.Length); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs.meta b/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs.meta new file mode 100644 index 00000000..968a154f --- /dev/null +++ b/Assets/Scripts/Editor/FbxAnimListPostprocessor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: deca3cf63294eda47b1155de672f9698 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Launch.cs b/Assets/Scripts/Launch.cs index 2a13b1b4..ed089f65 100644 --- a/Assets/Scripts/Launch.cs +++ b/Assets/Scripts/Launch.cs @@ -56,9 +56,8 @@ public class Launch : MonoBehaviour } - IEnumerator PreLoad() - { - yield return null; - } + + + } diff --git a/Assets/Scripts/TimeScaleController.cs b/Assets/Scripts/TimeScaleController.cs new file mode 100644 index 00000000..1e4272b6 --- /dev/null +++ b/Assets/Scripts/TimeScaleController.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TimeScaleController : MonoBehaviour +{ + + [Range(0, 10)] + public float animSpeed = 1.0f; + + +#if UNITY_EDITOR + private void Update() + { + Time.timeScale = animSpeed; + } +#endif +} diff --git a/Assets/Scripts/TimeScaleController.cs.meta b/Assets/Scripts/TimeScaleController.cs.meta new file mode 100644 index 00000000..d2e999e7 --- /dev/null +++ b/Assets/Scripts/TimeScaleController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b2c08eae7cce6c9479adebcaad5706c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From d6f069c4084251406a39837444defebe02b849a8 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Fri, 27 Dec 2024 19:54:54 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=B7=B3=E6=AD=A5=E9=AA=A4=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=20=E5=85=88=E7=AD=89=E5=89=8D=E9=9D=A2=E7=9A=84finish?= =?UTF-8?q?ed=E6=89=A7=E8=A1=8C=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Controller/OperationController.cs | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/Assets/Scripts/Controller/OperationController.cs b/Assets/Scripts/Controller/OperationController.cs index 0992e08b..991c6527 100644 --- a/Assets/Scripts/Controller/OperationController.cs +++ b/Assets/Scripts/Controller/OperationController.cs @@ -124,18 +124,22 @@ public class OperationController : MonoSingleton { if (this.index < targetIndex) { + var seq = ActionKit.Sequence(); for (int i = this.index + 1; i < targetIndex; i++) { // ɶ ֱִ IAction finishAction = ActionHelper.GetActionAndSub(steps[i].Finished); - if (finishAction != null) - { - finishAction.Start(this); - } TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = i, status = StepStatus.Finished }); - + if (finishAction!=null) + { + seq.Append(finishAction); + } } - curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start); + seq.Start(this,() => + { + curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start); + RunCurAction(curAction, targetIndex); + }); } else if (this.index > targetIndex) { @@ -151,28 +155,35 @@ public class OperationController : MonoSingleton } curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start); + RunCurAction(curAction, targetIndex); } else { curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start); + RunCurAction(curAction, targetIndex); } - if (curAction != null) + + } + } + + public void RunCurAction(IAction curAction,int targetIndex) + { + if (curAction != null) + { + this.index = targetIndex; + isStepRun = true; + TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = targetIndex, status = StepStatus.Start }); + curAction.Start(this, () => { - this.index = targetIndex; - isStepRun = true; - TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = targetIndex, status = StepStatus.Start }); - curAction.Start(this, () => - { - isStepRun = false; - TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = targetIndex, status = StepStatus.Finished }); - }); - } - else - { - this.index = targetIndex; + isStepRun = false; TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = targetIndex, status = StepStatus.Finished }); - Execute(this.index + 1); - } + }); + } + else + { + this.index = targetIndex; + TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = targetIndex, status = StepStatus.Finished }); + Execute(this.index + 1); } } } From 24f97fedbb0abcd23267ac827a2b5ee7571f8322 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Fri, 27 Dec 2024 20:28:53 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=A4=84=E7=90=86resetAction=E9=98=9F?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Controller/OperationController.cs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/Controller/OperationController.cs b/Assets/Scripts/Controller/OperationController.cs index 991c6527..dfad5464 100644 --- a/Assets/Scripts/Controller/OperationController.cs +++ b/Assets/Scripts/Controller/OperationController.cs @@ -125,17 +125,20 @@ public class OperationController : MonoSingleton if (this.index < targetIndex) { var seq = ActionKit.Sequence(); - for (int i = this.index + 1; i < targetIndex; i++) + if (this.index >= 0) { - // ɶ ֱִ - IAction finishAction = ActionHelper.GetActionAndSub(steps[i].Finished); - TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = i, status = StepStatus.Finished }); - if (finishAction!=null) + for (int i = this.index; i < targetIndex; i++) { - seq.Append(finishAction); + // ɶ ֱִ + IAction finishAction = ActionHelper.GetActionAndSub(steps[i].Finished); + TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = i, status = StepStatus.Finished }); + if (finishAction != null) + { + seq.Append(finishAction); + } } } - seq.Start(this,() => + seq.Start(this, () => { curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start); RunCurAction(curAction, targetIndex); @@ -143,19 +146,22 @@ public class OperationController : MonoSingleton } else if (this.index > targetIndex) { + var seq = ActionKit.Sequence(); for (int i = this.index; i > targetIndex; i--) { // ö ֱ IAction resetAction = ActionHelper.GetActionAndSub(steps[i].Reset); if (resetAction != null) { - resetAction.Start(this); + seq.Append(resetAction); } TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = i, status = StepStatus.NoStart }); - } - curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start); - RunCurAction(curAction, targetIndex); + seq.Start(this, () => + { + curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start); + RunCurAction(curAction, targetIndex); + }); } else { @@ -166,7 +172,7 @@ public class OperationController : MonoSingleton } } - public void RunCurAction(IAction curAction,int targetIndex) + public void RunCurAction(IAction curAction, int targetIndex) { if (curAction != null) { From 98169cd3d4861e5c4b9fe147fadc143085a81b4c Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Mon, 30 Dec 2024 10:29:48 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=89=A9=E5=B1=95=E5=8A=A8=E7=94=BBAction?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0=20frame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/ActionHelper.cs | 4 +-- Assets/Scripts/Actions/AnimationAction.cs | 33 ++++++++++++++++++----- Assets/Scripts/Xml/XmlParser.cs | 19 ++++++------- Doc/Xml配置文档.xml | 4 +-- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index cebc9620..9ba39189 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -100,8 +100,8 @@ public class ActionHelper return BtnsAction.Allocate(act.Value); case "Anim": { - var strAction = (XMLTool.StringListAction)act; - return QFramework.AnimationAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); + var strAction = (XMLTool.DictionaryAction)act; + return QFramework.AnimationAction.Allocate(act.Value, strAction.args); } case "UITools": { diff --git a/Assets/Scripts/Actions/AnimationAction.cs b/Assets/Scripts/Actions/AnimationAction.cs index d99185ca..b7d4420d 100644 --- a/Assets/Scripts/Actions/AnimationAction.cs +++ b/Assets/Scripts/Actions/AnimationAction.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using UnityEngine; +using UnityEngine.Rendering.Universal; namespace QFramework { @@ -20,17 +22,19 @@ namespace QFramework string path; string animName; - bool reset = false; Animation anim; - public static AnimationAction Allocate(string path, string animName, string reset, System.Action OnFinished = null) + string frame; + string speed; + public static AnimationAction Allocate(string path, Dictionary datas, System.Action OnFinished = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.Deinited = false; retNode.Reset(); retNode.path = path; - retNode.animName = animName; - bool.TryParse(reset, out retNode.reset); + retNode.animName = datas.ContainsKey("animName") ? datas["animName"] : ""; + retNode.frame = datas.ContainsKey("frame") ? datas["frame"] : ""; + retNode.speed = datas.ContainsKey("speed") ? datas["speed"] : ""; retNode.OnFinished = OnFinished; return retNode; } @@ -45,10 +49,25 @@ namespace QFramework if (obj != null) { anim = obj.GetComponent(); - anim.Play(animName); - if (reset) + + if (string.IsNullOrEmpty(frame) == false && frame != "-1") { - ActionKit.DelayFrame(1, () => anim.Stop()).StartGlobal(); + int curFrame = 0; + int.TryParse(frame, out curFrame); + anim[animName].time = curFrame / anim.clip.frameRate; + anim[animName].speed = 0; + anim.Play(animName); + this.Finish(); + } + else + { + float curSpeed = 1; + if (string.IsNullOrEmpty(speed)==false) + { + float.TryParse(speed, out curSpeed); + } + anim[animName].speed = curSpeed; + anim.Play(animName); } } else diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index 9d04ce66..3fcc3afd 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -358,24 +358,21 @@ namespace XMLTool break; case "Anim": { - var act = new StringListAction(); + var act = new DictionaryAction(); var animName = action.Attribute("animName"); if (animName != null) { - act.args.Add(animName.Value); + act.args.Add("animName",animName.Value); } - else + var frame = action.Attribute("frame"); + if (frame != null) { - act.args.Add(""); + act.args.Add("frame", frame.Value); } - var reset = action.Attribute("reset"); - if (reset != null) + var speed = action.Attribute("speed"); + if (speed != null) { - act.args.Add(reset.Value); - } - else - { - act.args.Add("false"); + act.args.Add("speed", speed.Value); } newAction = act; diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index 48307bd2..ae669757 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -17,8 +17,8 @@ - - + + From 86e495f5ddd5ea80a0adb5d0d3eacf05533dd31d Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Mon, 30 Dec 2024 10:40:39 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Doc/Xml配置文档.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index ae669757..bd79d5cf 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -17,8 +17,8 @@ - - + +