using QFramework; using QFramework.Example; using System; using System.Collections.Generic; using UnityEngine; 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) }, { "UICameraSwitch", typeof(QFramework.Example.UICameraSwitch) }, }; /// /// 递归生成所有的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.StringListAction)act; return QFramework.AnimationAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); } case "UITools": { var strAction = (XMLTool.StringListAction)act; return UIToolsAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4], strAction.args[5], strAction.args[6], strAction.args[7], strAction.args[8], strAction.args[9]); } case "PointQuestion": return PointQuestionAction.Allocate(act.Value); case "TextQuestion": { var strAction = (XMLTool.StringListAction)act; return TextQuestionAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4], strAction.args[5]); } 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.StringListAction)act; return ShowAction.Allocate(act.Value, strAction.args[0]); } 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 strAction = (XMLTool.StringListAction)act; return CameraSwitchAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4], strAction.args[5], strAction.args[6]); } case "CameraLock": { var strAction = (XMLTool.StringListAction)act; return CameraLockAction.Allocate(strAction.args[0], strAction.args[1]); } 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.StringListAction)act; return HighLightAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); } case "LoadRes": { 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]); } 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.StringListAction)act; return ResultTipAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); } 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]); } 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": return ObjClickCondition.Allocate(condition.Value); 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; } }