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/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) { 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 @@ - - + +