2135 lines
79 KiB
C#

using QFramework;
using QFramework.Example;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using UnityEngine;
using static XMLTool.Body3D;
namespace XMLTool
{
public class AppData
{
public PreLoad preLoad;
public List<Module> Modules
{
get; set;
}
}
public class PreLoad
{
public Action action;
}
public class Module
{
public string type
{
get; set;
}
public string Scene
{
get; set;
}
public string ModuleName
{
get; set;
}
public string Descript
{
get; set;
}
public string OnlyCurScore
{
get; set;
}
public string Icon
{
get; set;
}
public List<Operation> Operations
{
get; set;
}
public List<Device> Devices
{
get; set;
}
public Dictionary<string, FSM> FSM = new Dictionary<string, FSM>();
public Dictionary<string, Action> ActionDict
{
get; set;
}
public Score score;
public Body3D body3d;
public Knowledge knowledge;
}
public class Device
{
public string Name
{
get; set;
}
public string Icon
{
get; set;
}
public string HighColor
{
get; set;
}
public string Path
{
get; set;
}
public string Tip
{
get; set;
}
public string BoxColliderSize
{
get; set;
}
public string BoxColliderCenter
{
get; set;
}
public bool MeshCollider
{
get; set;
}
// 可以限制场景中一共有多少个此道具 -1 代表无限多
public int Count = -1;
public RightMenu rightMenu;
}
public class RightMenu
{
public List<string> items = new List<string>();
}
public class Score
{
public List<ScoreStep> scores;
}
public class ScoreStep
{
public string step;
public string name;
public string sum;
public string bind;
public float value;
public string time;
public string timeFormat = "yyyy-MM-dd HH:mm:ss";
}
public class ActionItem
{
public string Name
{
get; set;
}
public string Type
{
get; set;
}
public string Value
{
get; set;
}
public List<ActionItem> SubActions
{
get; set;
}
}
public class Action : ActionItem
{
}
public class Point3DQuestion : Action
{
public class Data
{
public string name;
public string deviceName;
public Vector3 pos;
public Vector3 rotate;
public Vector3 scale;
public float rotateSpeed;
public int order = 1;
public string clickEvent;
}
public List<Data> datas = new List<Data>();
}
public class InputAction : Action
{
public UIInputData data;
}
public class Show3DAction : Action
{
public UI3DObjShowData data;
}
public class Condition : ActionItem
{
}
public class FSM
{
public string Name
{
get; set;
}
public List<Transision> Transisions
{
get; set;
}
public Dictionary<string, State> StateDict
{
get; set;
}
}
public class State
{
public string Name
{
get; set;
}
public StatePart Enter
{
get; set;
}
public StatePart Exit
{
get; set;
}
}
public class StatePart
{
public Action Action
{
get; set;
}
}
public class Transision
{
public string Name
{
get; set;
}
public string From
{
get; set;
}
public string To
{
get; set;
}
public Condition Action
{
get; set;
}
}
public class Operation
{
public string name;
public string moduleType
{
get; set;
}
public bool freeStep
{
get; set;
}
public List<Step> Steps
{
get; set;
}
}
public class Step
{
public Step Parent
{
get; set;
}
public string Name
{
get; set;
}
public Action Reset
{
get; set;
}
public Action Start
{
get; set;
}
public Action Finished
{
get; set;
}
public bool isFinished = false;
public List<Step> SubSteps
{
get; set;
}
}
public class Body3D
{
public class Body
{
public string Icon
{
get; set;
}
public string Name
{
get; set;
}
public string Path
{
get; set;
}
public string Tip
{
get; set;
}
public string Audio
{
get; set;
}
public string FocusDistance
{
get; set;
}
public bool isShow = false;
public bool isBodyList = false;
public ObjectToggle toggle;
public Dictionary<string, Body> subBody { get; set; } = new Dictionary<string, Body>();
public Body parent;
//public Dictionary<string, Body> bodyList { get; set; } = new Dictionary<string, Body>();
}
public Dictionary<string, Body> parts = new Dictionary<string, Body>();
}
public class ObjectToggle
{
public ColorToggle color;
}
public class ColorToggle
{
public string isOn;
public string isOff;
}
public class Knowledge
{
public class Item
{
public class Component
{
public string type;
public string size;
public string pos;
public Action action;
}
public string title;
public string bgImage;
public string setPos;
public List<Item> subs;
public List<Component> components;
}
public string bgImage;
public List<Item> items;
public List<Item.Component> components;
}
public class XmlParser
{
public static AppData ParseXml(string xmlString)
{
// 加载XML
XDocument doc = XDocument.Parse(xmlString);
// 获取根元素
XElement appDataElement = doc.Root;
// 初始化AppData对象
AppData appData = new AppData
{
Modules = new List<Module>(),
};
// 解析预加载动作
var preLoadElement = appDataElement.Element("PreLoad");
if (preLoadElement != null)
{
appData.preLoad = new PreLoad();
foreach (XElement actionElement in preLoadElement.Elements("Action"))
{
var action = ParseAction(actionElement);
appData.preLoad.action = action;
}
}
// 加载模块数据
LoadModules(appDataElement, appData);
return appData;
}
public static void LoadModules(XElement appDataElement, AppData appData)
{
foreach (XElement moduleElement in appDataElement.Elements("Module"))
{
LoadModule(moduleElement, appData);
}
}
public static void LoadModule(XElement moduleElement, AppData appData)
{
if (moduleElement != null)
{
Module module = new Module()
{
Devices = new List<Device>(),
ActionDict = new Dictionary<string, Action>(),
Operations = new List<Operation>(),
};
appData.Modules.Add(module);
// 解析模块名称
module.type = moduleElement.Element("Type")?.Value;
module.ModuleName = moduleElement.Element("Name")?.Value;
module.Icon = moduleElement.Element("Icon")?.Value;
module.OnlyCurScore = moduleElement.Element("OnlyCurScore")?.Value;
module.Descript = moduleElement.Element("Descript")?.Value.Trim();
module.Scene = moduleElement.Element("Scene")?.Value;
// 解析设备
foreach (XElement deviceElement in moduleElement.Elements("Device"))
{
Device device = new Device
{
Name = deviceElement.Element("Name")?.Value,
Icon = deviceElement.Element("Icon")?.Value,
HighColor = deviceElement.Element("HighLight")?.Attribute("color")?.Value,
Path = deviceElement.Element("Path")?.Value,
Tip = deviceElement.Element("Tip")?.Value,
MeshCollider = deviceElement.Element("MeshCollider") != null,
BoxColliderCenter = deviceElement.Element("BoxCollider")?.Attribute("center")?.Value,
BoxColliderSize = deviceElement.Element("BoxCollider")?.Attribute("size")?.Value,
};
var menuElment = deviceElement.Element("RightMenu");
if (menuElment != null)
{
device.rightMenu = new RightMenu();
var atrr = menuElment.Attribute("values");
if (atrr != null)
{
device.rightMenu.items = atrr.Value.Split(',').ToList();
}
}
module.Devices.Add(device);
}
// 解析动作
foreach (XElement actionElement in moduleElement.Elements("Action"))
{
var action = ParseAction(actionElement);
// 解析动作
module.ActionDict.Add(action.Name, action);
}
// 解析状态机
foreach (XElement fsmElement in moduleElement.Elements("FSM"))
{
FSM fsm = new FSM()
{
Name = fsmElement.Attribute("name")?.Value,
StateDict = new Dictionary<string, State>(),
Transisions = new List<Transision>(),
};
// 解析状态
foreach (var stateNode in fsmElement.Elements("State"))
{
State state = new State()
{
Name = stateNode.Attribute("name")?.Value,
};
fsm.StateDict.Add(state.Name, state);
XElement enterElement = stateNode.Element("Enter");
XElement exitElement = stateNode.Element("Exit");
if (enterElement != null)
{
state.Enter = new StatePart();
state.Enter.Action = ParseAction(enterElement.Element("Action"));
}
if (exitElement != null)
{
state.Exit = new StatePart();
state.Exit.Action = ParseAction(exitElement.Element("Action"));
}
}
// 解析状态转换
foreach (var transNode in fsmElement.Elements("Transision"))
{
Transision trans = new Transision()
{
Name = transNode.Attribute("name")?.Value,
From = transNode.Attribute("from")?.Value,
To = transNode.Attribute("to")?.Value,
};
trans.Action = ParseCondition(transNode.Element("Condition"));
fsm.Transisions.Add(trans);
}
module.FSM.Add(fsm.Name, fsm);
}
// 解析操作列表
foreach (var operationNode in moduleElement.Elements("Operation"))
{
//module.Operations
// 解析操作步骤
var op = new Operation()
{
Steps = new List<Step>(),
};
op.name = operationNode.Attribute("name")?.Value;
op.moduleType = operationNode.Attribute("moduleType")?.Value;
var free = operationNode.Attribute("freeStep");
bool isFree = true;
if (free != null)
{
bool.TryParse(free.Value, out isFree);
}
op.freeStep = isFree;
foreach (XElement stepNode in operationNode.Elements("Step"))
{
op.Steps.Add(ParserStep(stepNode, null));
}
module.Operations.Add(op);
}
// 解析3DBody
var body3d = moduleElement.Element("Body3D");
if (body3d != null)
{
module.body3d = new Body3D();
foreach (var item in body3d.Elements("Body"))
{
var part = ParseBody(item);
module.body3d.parts.Add(part.Name, part);
}
}
// 解析评分
XElement scoreNode = moduleElement.Element("Score");
if (scoreNode != null)
{
module.score = new Score()
{
scores = new List<ScoreStep>()
};
foreach (var item in scoreNode.Elements("Item"))
{
module.score.scores.Add(
new ScoreStep()
{
step = item.Attribute("step")?.Value,
name = item.Attribute("name")?.Value,
sum = item.Attribute("sum")?.Value,
bind = item.Attribute("bind")?.Value,
timeFormat = item.Attribute("timeFormat")?.Value,
});
}
}
// 解析知识点
var knowledge = moduleElement.Element("Knowledge");
if (knowledge != null)
{
module.knowledge = new Knowledge();
module.knowledge.bgImage = knowledge.Attribute("bgImage")?.Value;
foreach (var itemXml in knowledge.Elements("Item"))
{
Knowledge.Item item = ParserKnowledgeItem(itemXml);
if (module.knowledge.items == null)
{
module.knowledge.items = new List<Knowledge.Item>();
}
module.knowledge.items.Add(item);
}
module.knowledge.components = ParserKnowledgeComponet(knowledge);
}
}
}
private static Knowledge.Item ParserKnowledgeItem(XElement itemXml)
{
Knowledge.Item item = new Knowledge.Item();
item.title = itemXml.Attribute("title")?.Value;
item.bgImage = itemXml.Attribute("bgImage")?.Value;
item.setPos = itemXml.Attribute("setPos")?.Value;
item.components = ParserKnowledgeComponet(itemXml);
foreach (var subXml in itemXml.Elements("Item"))
{
if (item.subs == null)
{
item.subs = new List<Knowledge.Item>();
}
// 增加子物体
item.subs.Add(ParserKnowledgeItem(subXml));
}
return item;
}
private static List<Knowledge.Item.Component> ParserKnowledgeComponet(XElement xmlData)
{
List<Knowledge.Item.Component> list = null;
foreach (var componentXml in xmlData.Elements("Component"))
{
if (list == null)
{
list = new List<Knowledge.Item.Component>();
}
Knowledge.Item.Component component = new Knowledge.Item.Component();
component.type = componentXml.Attribute("type")?.Value;
component.pos = componentXml.Attribute("pos")?.Value;
component.size = componentXml.Attribute("size")?.Value;
component.action = ParseAction(componentXml.Element("Action"));
list.Add(component);
}
return list;
}
private static Body3D.Body ParseBody(XElement bodyElement, Body parent = null)
{
Body3D.Body body = new Body3D.Body
{
Icon = bodyElement.Attribute("icon")?.Value,
Name = bodyElement.Attribute("name")?.Value,
Path = bodyElement.Attribute("path")?.Value,
Tip = bodyElement.Attribute("tip")?.Value,
Audio = bodyElement.Attribute("audio")?.Value,
FocusDistance = bodyElement.Attribute("FocusDistance")?.Value
};
var isShow = bodyElement.Attribute("isShow");
if (isShow != null)
{
bool.TryParse(isShow.Value, out body.isShow);
}
var isBodyList = bodyElement.Attribute("isBodyList");
if (isBodyList != null)
{
bool.TryParse(isBodyList.Value, out body.isBodyList);
}
var toggle = bodyElement.Element("ObjectToggle");
if (toggle != null)
{
body.toggle = new ObjectToggle();
var color = toggle.Element("Color");
if (color != null)
{
body.toggle.color = new ColorToggle();
body.toggle.color.isOn = color.Attribute("isOn")?.Value;
body.toggle.color.isOff = color.Attribute("isOff")?.Value;
}
}
foreach (var childElement in bodyElement.Elements("Body"))
{
var subBody = ParseBody(childElement, body);
body.subBody.Add(subBody.Name, subBody);
}
body.parent = parent;
return body;
}
public static Step ParserStep(XElement stepNode, Step parent)
{
Step step = new Step();
step.Name = stepNode.Attribute("name")?.Value;
step.Reset = ParseAction(stepNode.Element("Reset")?.Element("Action"));
step.Start = ParseAction(stepNode.Element("Start")?.Element("Action"));
step.Finished = ParseAction(stepNode.Element("Finished")?.Element("Action"));
step.SubSteps = ParserSteps(stepNode, step);
step.Parent = parent;
return step;
}
public static List<Step> ParserSteps(XElement step, Step parent)
{
List<Step> steps = new List<Step>();
if (step.Elements("Step").Any())
{
foreach (var item in step.Elements("Step"))
{
steps.Add(ParserStep(item, parent));
}
}
return steps;
}
public static Action ParseAction(XElement action)
{
if (action == null)
{
return null;
}
string type = action.Attribute("type").Value;
Action newAction = null;
// 这里是用于扩展Action的字段
switch (type)
{
case "Move":
case "Rotate":
case "Scale":
{
var act = new MoveOrAction();
act.to = Utility.GetVector3FromStrArray(action.Attribute("to").Value);
act.time = float.Parse(action.Attribute("time").Value);
newAction = act;
}
break;
case "Anim":
{
var act = new DictionaryAction();
var animName = action.Attribute("animName");
if (animName != null)
{
act.args.Add("animName", animName.Value);
}
var frame = action.Attribute("frame");
if (frame != null)
{
act.args.Add("frame", frame.Value);
}
var speed = action.Attribute("speed");
if (speed != null)
{
act.args.Add("speed", speed.Value);
}
var deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
newAction = act;
}
break;
case "UITools":
{
var act = new DictionaryAction();
act.args.Add("devices", action.Attribute("devices").Value);
act.args.Add("answers", action.Attribute("answers").Value);
var setActive = action.Attribute("setActive");
if (setActive != null)
{
act.args.Add("setActive", setActive.Value);
}
var rightLabel = action.Attribute("rightLabel");
if (rightLabel != null)
{
act.args.Add("rightLabel", rightLabel.Value);
}
var wrongLabel = action.Attribute("wrongLabel");
if (wrongLabel != null)
{
act.args.Add("wrongLabel", wrongLabel.Value);
}
var rightEvent = action.Attribute("rightEvent");
if (rightEvent != null)
{
act.args.Add("rightEvent", rightEvent.Value);
}
var wrongEvent = action.Attribute("wrongEvent");
if (wrongEvent != null)
{
act.args.Add("wrongEvent", wrongEvent.Value);
}
var rightScore = action.Attribute("rightScore");
if (rightScore != null)
{
act.args.Add("rightScore", rightScore.Value);
}
var wrongScore = action.Attribute("wrongScore");
if (wrongScore != null)
{
act.args.Add("wrongScore", wrongScore.Value);
}
var totalScore = action.Attribute("totalScore");
if (totalScore != null)
{
act.args.Add("totalScore", totalScore.Value);
}
var scoreStepName = action.Attribute("scoreStepName");
if (scoreStepName != null)
{
act.args.Add("scoreStepName", scoreStepName.Value);
}
var autoHide = action.Attribute("autoHide");
if (autoHide != null)
{
act.args.Add("autoHide", autoHide.Value);
}
var random = action.Attribute("random");
if (random != null)
{
act.args.Add("random", random.Value);
}
var scrollSpeed = action.Attribute("scrollSpeed");
if (scrollSpeed != null)
{
act.args.Add("scrollSpeed", scrollSpeed.Value);
}
var position = action.Attribute("position");
if (position != null)
{
act.args.Add("position", position.Value);
}
var wrongCount = action.Attribute("wrongCount");
if (wrongCount != null)
{
act.args.Add("wrongCount", wrongCount.Value);
}
newAction = act;
}
break;
case "UIBackPack":
{
var act = new DictionaryAction();
act.args.Add("devices", action.Attribute("devices").Value);
var random = action.Attribute("random");
if (random != null)
{
act.args.Add("random", random.Value);
}
var scrollSpeed = action.Attribute("scrollSpeed");
if (scrollSpeed != null)
{
act.args.Add("scrollSpeed", scrollSpeed.Value);
}
var position = action.Attribute("position");
if (position != null)
{
act.args.Add("position", position.Value);
}
newAction = act;
}
break;
case "TextQuestion":
{
var act = new DictionaryAction();
XAttribute title = action.Attribute("title");
if (title != null)
{
act.args.Add("title", title.Value);
}
XAttribute options = action.Attribute("options");
if (options != null)
{
act.args.Add("options", options.Value);
}
XAttribute answers = action.Attribute("answers");
if (answers != null)
{
act.args.Add("answers", answers.Value);
}
XAttribute btns = action.Attribute("btns");
if (btns != null)
{
act.args.Add("btns", btns.Value);
}
XAttribute wait = action.Attribute("wait");
if (wait != null)
{
act.args.Add("wait", wait.Value);
}
XAttribute showAnswer = action.Attribute("showAnswer");
if (showAnswer != null)
{
act.args.Add("showAnswer", showAnswer.Value);
}
XAttribute rightScore = action.Attribute("rightScore");
if (rightScore != null)
{
act.args.Add("rightScore", rightScore.Value);
}
XAttribute errorScore = action.Attribute("wrongScore");
if (errorScore != null)
{
act.args.Add("errorScore", errorScore.Value);
}
XAttribute scoreName = action.Attribute("scoreName");
if (scoreName != null)
{
act.args.Add("scoreName", scoreName.Value);
}
XAttribute absolutely = action.Attribute("absolutely");
if (absolutely != null)
{
act.args.Add("absolutely", absolutely.Value);
}
XAttribute format = action.Attribute("format");
if (format != null)
{
act.args.Add("format", format.Value);
}
XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null)
{
act.args.Add("finishedEvent", finishedEvent.Value);
}
XAttribute optionType = action.Attribute("optionType");
if (optionType != null)
{
act.args.Add("optionType", optionType.Value);
}
newAction = act;
}
break;
case "UIShow":
{
var act = new StringListAction();
XAttribute isShow = action.Attribute("isShow");
if (isShow == null)
{
act.args.Add("true");
}
else
{
act.args.Add(isShow.Value);
}
newAction = act;
}
break;
case "Hint":
{
var act = new StringListAction();
XAttribute time = action.Attribute("time");
if (time != null)
{
act.args.Add(time.Value);
}
else
{
act.args.Add("-1");
}
XAttribute icon = action.Attribute("icon");
if (icon != null)
{
act.args.Add(icon.Value);
}
else
{
act.args.Add("true");
}
XAttribute audio = action.Attribute("audio");
if (audio != null)
{
act.args.Add(audio.Value);
}
else
{
act.args.Add("");
}
newAction = act;
}
break;
case "Show":
{
var act = new DictionaryAction();
XAttribute isShow = action.Attribute("isShow");
if (isShow != null)
{
act.args.Add("isShow", isShow.Value);
}
XAttribute isDevice = action.Attribute("isDevice");
if (isDevice != null)
{
act.args.Add("isDevice", isDevice.Value);
}
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
XAttribute isRoot = action.Attribute("isRoot");
if (isRoot != null)
{
act.args.Add("isRoot", isRoot.Value);
}
newAction = act;
}
break;
case "CameraSwitch":
{
var act = new DictionaryAction();
XAttribute nearDevice = action.Attribute("nearDevice");
if (nearDevice != null)
{
act.args.Add("nearDevice", nearDevice.Value);
}
else
{
XAttribute nearPos = action.Attribute("nearPos");
if (nearPos != null)
{
act.args.Add("nearPos", nearPos.Value);
}
XAttribute nearRot = action.Attribute("nearRot");
if (nearRot != null)
{
act.args.Add("nearRot", nearRot.Value);
}
}
XAttribute normalDevice = action.Attribute("normalDevice");
if (normalDevice != null)
{
act.args.Add("normalDevice", normalDevice.Value);
}
else
{
XAttribute normalPos = action.Attribute("normalPos");
if (normalPos != null)
{
act.args.Add("normalPos", normalPos.Value);
}
XAttribute normalRot = action.Attribute("normalRot");
if (normalRot != null)
{
act.args.Add("normalRot", normalRot.Value);
}
}
XAttribute nearTime = action.Attribute("nearTime");
if (nearTime != null)
{
act.args.Add("nearTime", nearTime.Value);
}
else
{
act.args.Add("nearTime", "0");
}
XAttribute normalTime = action.Attribute("normalTime");
if (normalTime != null)
{
act.args.Add("normalTime", normalTime.Value);
}
else
{
act.args.Add("normalTime", "0");
}
XAttribute isOn = action.Attribute("isOn");
if (isOn != null)
{
act.args.Add("isOn", isOn.Value);
}
XAttribute vrPos = action.Attribute("vrPos");
if (vrPos != null)
{
act.args.Add("vrPos", vrPos.Value);
}
XAttribute vrRot = action.Attribute("vrRot");
if (vrRot != null)
{
act.args.Add("vrRot", vrRot.Value);
}
XAttribute vrTime = action.Attribute("vrTime");
if (vrTime != null)
{
act.args.Add("vrTime", vrTime.Value);
}
else
{
act.args.Add("vrTime", "0");
}
newAction = act;
}
break;
case "CameraLock":
{
var act = new DictionaryAction();
XAttribute isMove = action.Attribute("isMove");
if (isMove != null)
{
act.args.Add("isMove", isMove.Value);
}
XAttribute isRotate = action.Attribute("isRotate");
if (isRotate != null)
{
act.args.Add("isRotate", isRotate.Value);
}
newAction = act;
}
break;
case "TipWindow":
case "TextTip":
{
var act = new DictionaryAction();
XAttribute audio = action.Attribute("audio");
if (audio != null)
{
act.args.Add("audio", audio.Value);
}
XAttribute btns = action.Attribute("btns");
if (btns != null)
{
act.args.Add("btns", btns.Value);
}
XAttribute title = action.Attribute("title");
if (title != null)
{
act.args.Add("title", title.Value);
}
XAttribute alpha = action.Attribute("alpha");
if (alpha != null)
{
act.args.Add("alpha", alpha.Value);
}
newAction = act;
}
break;
case "TextWindow":
{
var act = new DictionaryAction();
XAttribute audio = action.Attribute("audio");
if (audio != null)
{
act.args.Add("audio", audio.Value);
}
XAttribute btns = action.Attribute("btns");
if (btns != null)
{
act.args.Add("btns", btns.Value);
}
XAttribute title = action.Attribute("title");
if (title != null)
{
act.args.Add("title", title.Value);
}
var scrollSpeed = action.Attribute("scrollSpeed");
if (scrollSpeed != null)
{
act.args.Add("scrollSpeed", scrollSpeed.Value);
}
var position = action.Attribute("position");
if (position != null)
{
act.args.Add("position", position.Value);
}
newAction = act;
}
break;
case "Video":
{
var act = new StringListAction();
XAttribute size = action.Attribute("size");
if (size != null)
{
act.args.Add(size.Value);
}
else
{
act.args.Add("792,458");
}
XAttribute offset = action.Attribute("offset");
if (offset != null)
{
act.args.Add(offset.Value);
}
else
{
act.args.Add("0,0");
}
XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null)
{
act.args.Add(finishedEvent.Value);
}
else
{
act.args.Add("");
}
XAttribute closeEvent = action.Attribute("closeEvent");
if (closeEvent != null)
{
act.args.Add(closeEvent.Value);
}
else
{
act.args.Add("");
}
newAction = act;
}
break;
case "HighLight":
{
var act = new DictionaryAction();
XAttribute isHigh = action.Attribute("isHigh");
if (isHigh != null)
{
act.args.Add("isHigh", isHigh.Value);
}
XAttribute color = action.Attribute("color");
if (color != null)
{
act.args.Add("color", color.Value);
}
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
newAction = act;
XAttribute isIndependent = action.Attribute("isIndependent");
if (isIndependent != null)
{
act.args.Add("isIndependent", isIndependent.Value);
}
XAttribute visibility = action.Attribute("visibility");
if (visibility != null)
{
act.args.Add("visibility", visibility.Value);
}
newAction = act;
}
break;
case "HighLightFlash":
{
var act = new DictionaryAction();
XAttribute isHigh = action.Attribute("isHigh");
if (isHigh != null)
{
act.args.Add("isHigh", isHigh.Value);
}
XAttribute color = action.Attribute("color");
if (color != null)
{
act.args.Add("color", color.Value);
}
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
newAction = act;
XAttribute isIndependent = action.Attribute("isIndependent");
if (isIndependent != null)
{
act.args.Add("isIndependent", isIndependent.Value);
}
XAttribute time = action.Attribute("time");
if (time != null)
{
act.args.Add("time", time.Value);
}
XAttribute count = action.Attribute("count");
if (count != null)
{
act.args.Add("count", count.Value);
}
XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null)
{
act.args.Add("finishedEvent", finishedEvent.Value);
}
XAttribute visibility = action.Attribute("visibility");
if (visibility != null)
{
act.args.Add("visibility", visibility.Value);
}
newAction = act;
}
break;
case "LoadRes":
{
var act = new DictionaryAction();
XAttribute resType = action.Attribute("resType");
if (resType != null)
{
act.args.Add("resType", resType.Value);
}
XAttribute index = action.Attribute("index");
if (index != null)
{
act.args.Add("index", index.Value);
}
newAction = act;
}
break;
case "Audio":
{
//string path, string audioType, string loop, string finishedEvent, string volume,
var act = new StringListAction();
XAttribute audioType = action.Attribute("audioType");
if (audioType != null)
{
act.args.Add(audioType.Value);
}
else
{
act.args.Add("Sound");
}
XAttribute loop = action.Attribute("loop");
if (loop != null)
{
act.args.Add(loop.Value);
}
else
{
act.args.Add("false");
}
XAttribute waitFinished = action.Attribute("waitFinished");
if (waitFinished != null)
{
act.args.Add(waitFinished.Value);
}
else
{
act.args.Add("");
}
XAttribute volume = action.Attribute("volume");
if (volume != null)
{
act.args.Add(volume.Value);
}
else
{
act.args.Add("");
}
XAttribute isPlay = action.Attribute("isPlay");
if (isPlay != null)
{
act.args.Add(isPlay.Value);
}
else
{
act.args.Add("true");
}
newAction = act;
}
break;
case "Line":
{
var act = new StringListAction();
XAttribute color = action.Attribute("color");
if (color != null)
{
act.args.Add(color.Value);
}
else
{
act.args.Add("");
}
XAttribute width = action.Attribute("width");
if (width != null)
{
act.args.Add(width.Value);
}
else
{
act.args.Add("0.1");
}
XAttribute lineScale = action.Attribute("lineScale");
if (lineScale != null)
{
act.args.Add(lineScale.Value);
}
else
{
act.args.Add("1,1");
}
newAction = act;
}
break;
case "ResultTip":
{
var act = new DictionaryAction();
XAttribute isRight = action.Attribute("isRight");
if (isRight != null)
{
act.args.Add("isRight", isRight.Value);
}
XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null)
{
act.args.Add("finishedEvent", finishedEvent.Value);
}
XAttribute autoHide = action.Attribute("autoHide");
if (autoHide != null)
{
act.args.Add("autoHide", autoHide.Value);
}
newAction = act;
}
break;
case "Led":
{
var act = new StringListAction();
XAttribute number = action.Attribute("number");
if (number != null)
{
act.args.Add(number.Value);
}
else
{
act.args.Add("0");
}
XAttribute color = action.Attribute("color");
if (color != null)
{
act.args.Add(color.Value);
}
else
{
act.args.Add("255,255,255,255");
}
newAction = act;
}
break;
case "Script":
{
var act = new StringListAction();
XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null)
{
act.args.Add(finishedEvent.Value);
}
else
{
act.args.Add("");
}
newAction = act;
}
break;
case "Collider":
{
var act = new StringListAction();
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add(deviceName.Value);
}
else
{
act.args.Add("");
}
XAttribute colliderType = action.Attribute("colliderType");
if (colliderType != null)
{
act.args.Add(colliderType.Value);
}
else
{
act.args.Add("空");
}
XAttribute arg = action.Attribute("args");
if (arg != null)
{
act.args.Add(arg.Value);
}
else
{
act.args.Add("");
}
newAction = act;
}
break;
case "TimeTip":
{
var act = new DictionaryAction();
XAttribute time = action.Attribute("time");
if (time != null)
{
act.args.Add("time", time.Value);
}
else
{
act.args.Add("time", "0");
}
XAttribute values = action.Attribute("values");
if (values != null)
{
act.args.Add("values", values.Value);
}
XAttribute format = action.Attribute("format");
if (format != null)
{
act.args.Add("format", format.Value);
}
XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null)
{
act.args.Add("finishedEvent", finishedEvent.Value);
}
XAttribute needClick = action.Attribute("needClick");
if (needClick != null)
{
act.args.Add("needClick", needClick.Value);
}
XAttribute reverse = action.Attribute("reverse");
if (reverse != null)
{
act.args.Add("reverse", reverse.Value);
}
newAction = act;
}
break;
case "SkinnedBake":
{
var act = new DictionaryAction();
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
newAction = act;
}
break;
case "TimeLine":
{
var act = new DictionaryAction();
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
XAttribute isShow = action.Attribute("isShow");
if (isShow != null)
{
act.args.Add("isShow", isShow.Value);
}
XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null)
{
act.args.Add("finishedEvent", finishedEvent.Value);
}
XAttribute isWait = action.Attribute("isWait");
if (isWait != null)
{
act.args.Add("isWait", isWait.Value);
}
XAttribute frame = action.Attribute("frame");
if (frame != null)
{
act.args.Add("frame", frame.Value);
}
XAttribute endFrame = action.Attribute("endFrame");
if (endFrame != null)
{
act.args.Add("endFrame", endFrame.Value);
}
XAttribute speed = action.Attribute("speed");
if (speed != null)
{
act.args.Add("speed", speed.Value);
}
newAction = act;
}
break;
case "Point3DQuestion":
{
var act = new Point3DQuestion();
var datas = action.Elements("Data");
foreach (var item in datas)
{
Point3DQuestion.Data data = new Point3DQuestion.Data();
data.name = item.Attribute("name")?.Value;
XAttribute atr = item.Attribute("deviceName");
if (atr != null)
{
data.deviceName = item.Attribute("deviceName").Value;
}
else
{
data.pos = Utility.GetVector3FromStrArray(item.Attribute("position")?.Value);
data.rotate = Utility.GetVector3FromStrArray(item.Attribute("rotate")?.Value);
data.scale = Utility.GetVector3FromStrArray(item.Attribute("scale")?.Value);
}
float.TryParse(item.Attribute("rotateSpeed")?.Value, out data.rotateSpeed);
var order = item.Attribute("order");
if (order != null)
{
int.TryParse(order.Value, out data.order);
}
data.clickEvent = item.Attribute("clickEvent")?.Value;
act.datas.Add(data);
}
newAction = act;
}
break;
case "Mat":
{
var act = new DictionaryAction();
XAttribute value = action.Attribute("value");
if (value != null)
{
act.args.Add("value", value.Value);
}
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
XAttribute matName = action.Attribute("matName");
if (matName != null)
{
act.args.Add("matName", matName.Value);
}
XAttribute index = action.Attribute("index");
if (index != null)
{
act.args.Add("index", index.Value);
}
XAttribute mainTexture = action.Attribute("mainTexture");
if (mainTexture != null)
{
act.args.Add("mainTexture", mainTexture.Value);
}
newAction = act;
}
break;
case "Input":
{
var act = new InputAction();
act.data = new UIInputData();
act.data.title = action.Attribute("title")?.Value;
act.data.finishedEvent = action.Attribute("finishedEvent")?.Value;
foreach (var item in action.Elements("Input"))
{
UIInputData.InputData inputData = new UIInputData.InputData();
inputData.answer = item.Attribute("answer")?.Value;
inputData.var = item.Attribute("var")?.Value;
inputData.name = item.Attribute("name")?.Value;
act.data.inputs.Add(inputData);
}
foreach (var item in action.Elements("Btn"))
{
UIInputData.BtnData btnData = new UIInputData.BtnData();
btnData.name = item.Attribute("name")?.Value;
btnData.clickEvent = item.Attribute("clickEvent")?.Value;
XAttribute checkAnswer = item.Attribute("checkAnswer");
if (checkAnswer != null)
{
bool.TryParse(checkAnswer.Value, out btnData.checkAnswer);
}
btnData.wrongLabel = item.Attribute("wrongLabel")?.Value;
btnData.wrongEvent = item.Attribute("wrongEvent")?.Value;
XAttribute wrongCount = item.Attribute("wrongCount");
if (wrongCount != null)
{
int.TryParse(wrongCount.Value, out btnData.wrongCount);
}
XAttribute autoHide = item.Attribute("autoHide");
if (autoHide != null)
{
float.TryParse(autoHide.Value, out btnData.autoHide);
}
btnData.scoreStepName = item.Attribute("scoreStepName")?.Value;
XAttribute rightScore = item.Attribute("rightScore");
if (rightScore != null)
{
float.TryParse(rightScore.Value, out btnData.rightScore);
}
XAttribute wrongScore = item.Attribute("wrongScore");
if (wrongScore != null)
{
float.TryParse(wrongScore.Value, out btnData.wrongScore);
}
act.data.btns.Add(btnData);
}
newAction = act;
}
break;
case "ImageTip":
{
var act = new DictionaryAction();
XAttribute path = action.Attribute("path");
if (path != null)
{
act.args.Add("path", path.Value);
}
XAttribute size = action.Attribute("size");
if (size != null)
{
act.args.Add("size", size.Value);
}
XAttribute isDrag = action.Attribute("isDrag");
if (isDrag != null)
{
act.args.Add("isDrag", isDrag.Value);
}
XAttribute position = action.Attribute("position");
if (position != null)
{
act.args.Add("position", position.Value);
}
newAction = act;
}
break;
case "3DObjShow":
{
var act = new Show3DAction();
act.data = new UI3DObjShowData();
act.data.datas = new List<UI3DObjShowData.ObjData>();
foreach (var item in action.Elements("Object"))
{
UI3DObjShowData.ObjData objData = new UI3DObjShowData.ObjData();
objData.deviceName = item.Attribute("deviceName")?.Value;
XAttribute position = item.Attribute("position");
if (position != null)
{
objData.position = Utility.GetVector3FromStrArray(position.Value);
}
XAttribute rotate = item.Attribute("rotate");
if (rotate != null)
{
objData.rotate = Utility.GetVector3FromStrArray(rotate.Value);
}
XAttribute scale = item.Attribute("scale");
if (scale != null)
{
objData.scale = Utility.GetVector3FromStrArray(scale.Value);
}
XAttribute rotateSpeed = item.Attribute("rotateSpeed");
if (rotateSpeed != null)
{
float.TryParse(rotateSpeed.Value, out objData.rotateSpeed);
}
XAttribute moveSpeed = item.Attribute("moveSpeed");
if (moveSpeed != null)
{
float.TryParse(moveSpeed.Value, out objData.moveSpeed);
}
XAttribute distance = item.Attribute("distance");
if (distance != null)
{
float.TryParse(distance.Value, out objData.distance);
}
XAttribute distanceMin = item.Attribute("distanceMin");
if (distanceMin != null)
{
float.TryParse(distanceMin.Value, out objData.distanceMin);
}
XAttribute distanceMax = item.Attribute("distanceMax");
if (distanceMax != null)
{
float.TryParse(distanceMax.Value, out objData.distanceMax);
}
XAttribute pitchMin = item.Attribute("pitchMin");
if (pitchMin != null)
{
float.TryParse(pitchMin.Value, out objData.pitchMin);
}
XAttribute pitchMax = item.Attribute("pitchMax");
if (pitchMax != null)
{
float.TryParse(pitchMax.Value, out objData.pitchMax);
}
act.data.datas.Add(objData);
}
newAction = act;
}
break;
case "OperationChange":
{
var act = new DictionaryAction();
XAttribute name = action.Attribute("name");
if (name != null)
{
act.args.Add("name", name.Value);
}
newAction = act;
}
break;
case "ShowScore":
{
var act = new DictionaryAction();
XAttribute onlyCurModule = action.Attribute("onlyCurModule");
if (onlyCurModule != null)
{
act.args.Add("onlyCurModule", onlyCurModule.Value);
}
newAction = act;
}
break;
case "ImageSelectMap":
{
var act = new ImageSelectMapAction();
XAttribute scoreName = action.Attribute("scoreName");
if (scoreName != null)
{
act.args.Add("scoreName", scoreName.Value);
}
XAttribute totalScore = action.Attribute("totalScore");
if (totalScore != null)
{
act.args.Add("totalScore", totalScore.Value);
}
XAttribute rightScore = action.Attribute("rightScore");
if (rightScore != null)
{
act.args.Add("rightScore", rightScore.Value);
}
XAttribute wrongScore = action.Attribute("wrongScore");
if (wrongScore != null)
{
act.args.Add("wrongScore", wrongScore.Value);
}
XAttribute rightLabel = action.Attribute("rightLabel");
if (rightLabel != null)
{
act.args.Add("rightLabel", rightLabel.Value);
}
XAttribute wrongLabel = action.Attribute("wrongLabel");
if (wrongLabel != null)
{
act.args.Add("wrongLabel", wrongLabel.Value);
}
XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null)
{
act.args.Add("finishedEvent", finishedEvent.Value);
}
XAttribute rightBg = action.Attribute("rightBg");
if (rightBg != null)
{
act.args.Add("rightBg", rightBg.Value);
}
foreach (var itemData in action.Elements("Item"))
{
act.items.Add(new ImageSelectMapAction.Item()
{
pic = itemData.Attribute("pic")?.Value,
size = itemData.Attribute("rightSize")?.Value,
pos = itemData.Attribute("rightPos")?.Value
});
}
newAction = act;
}
break;
case "UIGuideTip":
{
var act = new DictionaryAction();
XAttribute targetName = action.Attribute("targetName");
if (targetName != null)
{
act.args.Add("targetName", targetName.Value);
}
XAttribute showName = action.Attribute("showName");
if (showName != null)
{
act.args.Add("showName", showName.Value);
}
XAttribute offSet = action.Attribute("offSet");
if (offSet != null)
{
act.args.Add("offSet", offSet.Value);
}
XAttribute tiptext = action.Attribute("tiptext");
if (tiptext != null)
{
act.args.Add("tiptext", tiptext.Value);
}
XAttribute tipaudio = action.Attribute("tipaudio");
if (tipaudio != null)
{
act.args.Add("tipaudio", tipaudio.Value);
}
XAttribute tiptitle = action.Attribute("tiptitle");
if (tiptitle != null)
{
act.args.Add("tiptitle", tiptitle.Value);
}
newAction = act;
}
break;
case "UISliderAnim":
{
var act = new DictionaryAction();
XAttribute title = action.Attribute("title");
if (title != null)
{
act.args.Add("title", title.Value);
}
XAttribute targetObj = action.Attribute("targetObj");
if (targetObj != null)
{
act.args.Add("targetObj", targetObj.Value);
}
newAction = act;
}
break;
case "Greatbtns":
{
var act = new DictionaryAction();
XAttribute name = action.Attribute("name");
if (name != null)
{
act.args.Add("name", name.Value);
}
XAttribute pos = action.Attribute("pos");
if (pos != null)
{
act.args.Add("pos", pos.Value);
}
XAttribute size = action.Attribute("size");
if (size != null)
{
act.args.Add("size", size.Value);
}
newAction = act;
}
break;
case "UISliderAnimReSet": {
}break;
default:
newAction = new Action();
break;
}
newAction.Type = action.Attribute("type")?.Value;
newAction.Name = action.Attribute("name")?.Value;
newAction.Value = action.Attribute("value")?.Value;
newAction.SubActions = ParseActions(action);
return newAction;
}
public static Condition ParseCondition(XElement action)
{
if (action == null)
{
return null;
}
Condition newAction = null;
string type = action.Attribute("type")?.Value;
switch (type)
{
case "ObjClick":
{
var act = new DictionaryCondition();
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
XAttribute isRight = action.Attribute("isRight");
if (isRight != null)
{
act.args.Add("isRight", isRight.Value);
}
newAction = act;
}
break;
case "ObjClickLong":
{
var act = new DictionaryCondition();
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
XAttribute time = action.Attribute("time");
if (time != null)
{
act.args.Add("time", time.Value);
}
newAction = act;
}
break;
case "HasDevice":
{
var act = new DictionaryCondition();
XAttribute deviceName = action.Attribute("deviceName");
if (deviceName != null)
{
act.args.Add("deviceName", deviceName.Value);
}
XAttribute count = action.Attribute("count");
if (count != null)
{
act.args.Add("count", count.Value);
}
newAction = act;
}
break;
case "Distance":
{
var act = new DictionaryCondition();
XAttribute targetPos = action.Attribute("targetPos");
if (targetPos != null)
{
act.args.Add("targetPos", targetPos.Value);
}
XAttribute ignoreY = action.Attribute("ignoreY");
if (ignoreY != null)
{
act.args.Add("ignoreY", ignoreY.Value);
}
newAction = act;
}
break;
default:
newAction = new Condition();
break;
}
newAction.Type = type;
newAction.Name = action.Attribute("name")?.Value;
newAction.Value = action.Attribute("value")?.Value;
newAction.SubActions = ParseActions(action);
return newAction;
}
public static ActionItem ParserActionItem(XElement element)
{
ActionItem actItem = null;
switch (element.Name.LocalName)
{
case "Action":
actItem = ParseAction(element);
break;
case "Condition":
actItem = ParseCondition(element);
break;
}
return actItem;
}
private static List<ActionItem> ParseActions(XElement actionElement)
{
List<ActionItem> actions = new List<ActionItem>();
foreach (XElement action in actionElement.Elements())
{
actions.Add(ParserActionItem(action));
}
return actions;
}
}
}