322 lines
14 KiB
C#
322 lines
14 KiB
C#
using QFramework;
|
||
using QFramework.Example;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using XMLTool;
|
||
|
||
|
||
public class ActionHelper
|
||
{
|
||
|
||
|
||
public static readonly Dictionary<string, Type> typeDict = new Dictionary<string, Type>()
|
||
{
|
||
{ "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) },
|
||
{ "UIImageTip", typeof(QFramework.Example.UIImageTip) },
|
||
{ "UI3DObjShow", typeof(QFramework.Example.UI3DObjShow) },
|
||
{ "UIBody3D", typeof(QFramework.Example.UIBody3D) },
|
||
{ "UI3DObjSelect", typeof(QFramework.Example.UI3DObjSelect) },
|
||
|
||
};
|
||
|
||
|
||
/// <summary>
|
||
/// µÝ¹éÉú³ÉËùÓеÄAction
|
||
/// </summary>
|
||
/// <param name="action"></param>
|
||
/// <param name="parentAct"></param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
/// <summary>
|
||
/// Ö»Éú³ÉÒ»¸ö
|
||
/// </summary>
|
||
/// <param name="action"></param>
|
||
/// <returns></returns>
|
||
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 "HighLightFlash":
|
||
{
|
||
var strAction = (XMLTool.DictionaryAction)act;
|
||
return HighLightFlashAction.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);
|
||
}
|
||
case "Input":
|
||
{
|
||
var dictAction = (XMLTool.InputAction)act;
|
||
return QFramework.InputAction.Allocate(dictAction.data);
|
||
}
|
||
case "ImageTip":
|
||
{
|
||
var dictAction = (XMLTool.DictionaryAction)act;
|
||
return QFramework.ImageTipAction.Allocate(dictAction.args);
|
||
}
|
||
case "3DObjShow":
|
||
{
|
||
var dictAction = (XMLTool.Show3DAction)act;
|
||
return QFramework.Show3DAction.Allocate(dictAction.data);
|
||
}
|
||
case "OperationChange":
|
||
{
|
||
var dictAction = (XMLTool.DictionaryAction)act;
|
||
return QFramework.OperationChangeAction.Allocate(dictAction.args);
|
||
}
|
||
default:
|
||
Debug.LogError($"ûÓÐÕÒµ½´ËActionµÄÀàÐÍ{act.Type}");
|
||
break;
|
||
}
|
||
break;
|
||
case XMLTool.Condition condition:
|
||
return GetCondition(condition);
|
||
}
|
||
|
||
return null;
|
||
}
|
||
/// <summary>
|
||
/// Éú³ÉÌõ¼þ×é
|
||
/// </summary>
|
||
/// <param name="condition"></param>
|
||
/// <returns></returns>
|
||
public static ICondition GetCondition(XMLTool.ActionItem condition)
|
||
{
|
||
if (condition != null)
|
||
{
|
||
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 "ObjClickLong":
|
||
{
|
||
var dict = (XMLTool.DictionaryCondition)condition;
|
||
return ObjClickLongCondition.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;
|
||
}
|
||
|
||
}
|