private static void ParseVarValue(AIVar var, object val) { switch (var.type) { case "System.Boolean": var.val = val; break; case "System.String": var.val = val.ToString().Replace("\n", "").Replace("\t", "").Replace("\r", ""); break; case "System.Single": var.val = float.Parse(val.ToString()); break; case "System.Int32": var.val = int.Parse(val.ToString()); break; case "Vector3": case "Vector2": case "Vector4": var.val = ParseVector(val.ToString()); break; default: var.val = val; break; } }
private static AIRuntimeTaskData ParseTask(Dictionary <string, object> task) { AIRuntimeTaskData t = new AIRuntimeTaskData(); foreach (var item in task) { if (item.Key == Type) { t.type = task[Type].ToString(); t.mode = Type2Mode(t.type); } else if (item.Key == Children) { List <object> list = task[Children] as List <object>; for (int i = 0, max = list.Count; i < max; i++) { Dictionary <string, object> child = list[i] as Dictionary <string, object>; if (t.children == null) { t.children = new List <AIRuntimeTaskData>(); } AIRuntimeTaskData tt = ParseTask(child); t.children.Add(tt); } } else if (item.Value is Dictionary <string, object> ) { AIVar v = ParseSharedVar(item.Key, item.Value as Dictionary <string, object>); if (t.vars == null) { t.vars = new List <AIVar>(); } t.vars.Add(v); } else { AIVar v = ParseCustomVar(item.Key, item.Value); if (v != null) { if (t.vars == null) { t.vars = new List <AIVar>(); } t.vars.Add(v); } } } return(t); }
private static AIVar ParseCustomVar(string key, object val) { string[] arr = { "Single", "Int32", "Boolean", "String", "Vector3", "Vector2", "Vector4", "GameObject", "Transform" }; for (int i = 0, max = arr.Length; i < max; i++) { if (key.StartsWith(arr[i])) { AIVar v = new AIVar(); v.type = i <= 4 ? "System." + arr[i] : arr[i]; v.name = key; ParseVarValue(v, val); return(v); } } return(null); }