using QFramework; using QFramework.Example; using System; using System.Collections.Generic; using UnityEngine; using XMLTool; public class ActionHelper { public static readonly Dictionary typeDict = new Dictionary() { { "UIRightTop", typeof(UIRightTop) }, { "UIOperationList", typeof(UIOperationList) }, { "UIBtns", typeof(QFramework.Example.UIBtns) }, { "UITools", typeof(QFramework.Example.UITools) }, { "UIHint", typeof(QFramework.Example.UIHint) }, { "UIPointQuestion", typeof(QFramework.Example.UIPointQuestion) }, { "UICameraSwitch", typeof(QFramework.Example.UICameraSwitch) }, { "UIInstruction", typeof(QFramework.Example.UIInstruction) }, { "UIScore", typeof(QFramework.Example.UIScore) }, }; /// /// 递归生成所有的Action /// /// /// /// public static IAction GetActionAndSub(XMLTool.ActionItem action, IAction parentAct = null) { IAction sub = null; if (action != null) { if (parentAct == null) { parentAct = ActionHelper.GetAction(action); } else { sub = ActionHelper.GetAction(action); switch (parentAct) { case QFramework.IParallel act: act.Append(sub); break; case QFramework.ISequence seq: seq.Append(sub); break; } } if (action.SubActions != null && action.SubActions.Count > 0) { if (sub != null) { parentAct = sub; } foreach (var item in action.SubActions) { GetActionAndSub(item, parentAct); } } } return parentAct; } /// /// 只生成一个 /// /// /// public static IAction GetAction(XMLTool.ActionItem action) { switch (action) { case XMLTool.Action act: switch (act.Type) { case "Sequence": return ActionKit.Sequence(); case "Parallel": return ActionKit.Parallel(); case "Any": return AnyAction.Allocate(); case "Log": return LogAction.Allocate(action.Value); case "Delay": return ActionKit.Delay(float.Parse(action.Value), null); case "NextOperation": return NextOperationAction.Allocate(); case "Move": var move = (XMLTool.MoveOrAction)act; return MoveAction.Allocate(act.Value, move.to, move.time); case "Rotate": var rotate = (XMLTool.MoveOrAction)act; return RotateAction.Allocate(act.Value, rotate.to, rotate.time); case "Scale": var scaleAct = (XMLTool.MoveOrAction)act; return ScaleAction.Allocate(act.Value, scaleAct.to, scaleAct.time); case "Btns": return BtnsAction.Allocate(act.Value); case "Anim": { var strAction = (XMLTool.DictionaryAction)act; return QFramework.AnimationAction.Allocate(act.Value, strAction.args); } case "UITools": { var strAction = (XMLTool.DictionaryAction)act; return UIToolsAction.Allocate(strAction.args); } case "PointQuestion": return PointQuestionAction.Allocate(act.Value); case "Point3DQuestion": var point3d = (Point3DQuestion)act; return Point3DQuestionAction.Allocate(point3d.datas); case "TextQuestion": { var strAction = (XMLTool.DictionaryAction)act; return TextQuestionAction.Allocate(strAction.args); } case "Hint": { var strAction = (XMLTool.StringListAction)act; return HintAction.Allocate(strAction.Value, strAction.args[0], strAction.args[1], strAction.args[2]); } case "Var": return SetVarAction.Allocate(act.Name, act.Value); case "Show": { var strAction = (XMLTool.DictionaryAction)act; return ShowAction.Allocate(act.Value, strAction.args); } case "TipWindow": { var strAction = (XMLTool.StringListAction)act; return TipWindowAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); } case "TextTip": { var strAction = (XMLTool.StringListAction)act; return TextTipAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); } case "UIShow": { var strAction = (XMLTool.StringListAction)act; return UIShowAction.Allocate(act.Value, strAction.args[0]); } case "SetScore": return SetScoreAction.Allocate(act.Name, act.Value); case "CameraSwitch": { var dictAction = (XMLTool.DictionaryAction)act; return CameraSwitchAction.Allocate(dictAction.args); } case "CameraLock": { var strAction = (XMLTool.DictionaryAction)act; return CameraLockAction.Allocate(strAction.args); } case "Video": { var strAction = (XMLTool.StringListAction)act; return VideoAction.Allocate(act.Value, strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3]); } case "HighLight": { var strAction = (XMLTool.DictionaryAction)act; return HighLightAction.Allocate(act.Value, strAction.args); } case "LoadRes": { var dictAction = (XMLTool.DictionaryAction)act; return LoadResAction.Allocate(act.Value, dictAction.args); } 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]); } case "Line": { var strAction = (XMLTool.StringListAction)act; return LineAction.Allocate(act.Name, act.Value, strAction.args[0], strAction.args[1], strAction.args[2]); } case "Destroy": { return DestroyAction.Allocate(act.Value); } case "ResultTip": { var strAction = (XMLTool.DictionaryAction)act; return ResultTipAction.Allocate(act.Value, strAction.args); } case "Led": { var strAction = (XMLTool.StringListAction)act; return LedAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); } case "Script": { var strAction = (XMLTool.StringListAction)act; return ScriptAction.Allocate(act.Name, act.Value, strAction.args[0]); } case "Collider": { var strAction = (XMLTool.StringListAction)act; return ColliderAction.Allocate(act.Value, strAction.args[0], strAction.args[1], strAction.args[2]); } case "TimeTip": { var dictAction = (XMLTool.DictionaryAction)act; return TimeTipAction.Allocate(act.Value, dictAction.args); } case "StrEvent": { return StrEventAction.Allocate(act.Name, act.Value); } case "SkinnedBake": { var dictAction = (XMLTool.DictionaryAction)act; return SkinnedBakeAction.Allocate(act.Value, dictAction.args); } case "TimeLine": { var dictAction = (XMLTool.DictionaryAction)act; return TimeLineAction.Allocate(act.Value, dictAction.args); } case "Mat": { var dictAction = (XMLTool.DictionaryAction)act; return MatAction.Allocate(dictAction.args); } default: Debug.LogError($"没有找到此Action的类型{act.Type}"); break; } break; case XMLTool.Condition condition: return GetCondition(condition); } return null; } /// /// 生成条件组 /// /// /// public static ICondition GetCondition(XMLTool.ActionItem condition) { switch (condition.Type) { case "And": case "Or": var group = ConditionGroup.Allocate(condition.Type); foreach (var item in condition.SubActions) { group.AddCondition(GetCondition(item)); } return group; case "UIClick": return UIClickCondition.Allocate(condition.Value); case "ObjClick": var dict = (XMLTool.DictionaryCondition)condition; return ObjClickCondition.Allocate(dict.Value, dict.args); case "Input": return InputCondition.Allocate(condition.Value); case "Var": return VarCondition.Allocate(condition.Name, condition.Value); case "StrEvent": return StrEventCondition.Allocate(condition.Value); } return null; } }