private static void InitComponets(BinaryNode domNode, GameObject go) { Component[] components = go.GetComponents(typeof(Component)); for (int i = 0; i < domNode.GetChildNum(); i++) { BinaryNode child = domNode.GetChild(i); if (child.GetName() == "Cop") { string nodeAttr = GetNodeAttr(child, "Type"); Component component = null; for (int j = 0; j < components.Length; j++) { if (!isNull(components[j]) && GetPureType(components[j].GetType().ToString()).Equals(nodeAttr)) { component = components[j]; break; } } if (component == null) { component = go.AddComponent(GetType(nodeAttr)); } } } }
public void ObjectDeserialize(ref object o, BinaryNode node) { BinaryNode child = node.GetChild(0); if (child == null) { Debug.LogError("Deserialize FieldObj.FOLevelGrid Failed, child binary node is null"); return; } byte[] value = child.GetValue(); MemoryStream memoryStream = new MemoryStream(value); BinaryReader binaryReader = new BinaryReader(memoryStream); FieldObj.FOLevelGrid fOLevelGrid = default(FieldObj.FOLevelGrid); fOLevelGrid.GridInfo = default(FieldObj.FOGridInfo); fOLevelGrid.GridInfo.CellNumX = UnityBasetypeSerializer.BytesToInt(binaryReader.ReadBytes(4)); fOLevelGrid.GridInfo.CellNumY = UnityBasetypeSerializer.BytesToInt(binaryReader.ReadBytes(4)); fOLevelGrid.GridInfo.CellSizeX = UnityBasetypeSerializer.BytesToInt(binaryReader.ReadBytes(4)); fOLevelGrid.GridInfo.CellSizeY = UnityBasetypeSerializer.BytesToInt(binaryReader.ReadBytes(4)); fOLevelGrid.GridInfo.GridPos = default(VInt2); fOLevelGrid.GridInfo.GridPos.x = UnityBasetypeSerializer.BytesToInt(binaryReader.ReadBytes(4)); fOLevelGrid.GridInfo.GridPos.y = UnityBasetypeSerializer.BytesToInt(binaryReader.ReadBytes(4)); int num = UnityBasetypeSerializer.BytesToInt(binaryReader.ReadBytes(4)); fOLevelGrid.GridCells = new FieldObj.FOGridCell[num]; for (int i = 0; i < num; i++) { fOLevelGrid.GridCells[i] = default(FieldObj.FOGridCell); fOLevelGrid.GridCells[i].CellX = binaryReader.ReadByte(); fOLevelGrid.GridCells[i].CellY = binaryReader.ReadByte(); fOLevelGrid.GridCells[i].m_viewBlockId = binaryReader.ReadByte(); } o = fOLevelGrid; }
private static void InitComponets(BinaryNode domNode, GameObject go) { Component[] components = go.GetComponents(typeof(Component)); for (int i = 0; i < domNode.GetChildNum(); i++) { BinaryNode child = domNode.GetChild(i); if (!(child.GetName() != "Cop")) { string nodeAttr = GameSerializer.GetNodeAttr(child, "Type"); Component x = null; for (int j = 0; j < components.Length; j++) { if (!GameSerializer.isNull(components[j])) { string pureType = GameSerializer.GetPureType(components[j].GetType().ToString()); if (pureType.Equals(nodeAttr)) { x = components[j]; break; } } } if (x == null) { x = go.AddComponent(GameSerializer.GetType(nodeAttr)); } } } }
private static void LoadRecursionTwice(GameObject parentGo, BinaryNode domNode, GameObject go) { if (domNode == domNode.OwnerDocument.Root) { GameSerializer.LoadComponets(domNode, go); int num = -1; for (int i = 0; i < domNode.GetChildNum(); i++) { BinaryNode child = domNode.GetChild(i); if (child.GetName() == "CHD") { num++; GameObject gameObject = go.transform.GetChild(num).gameObject; if (!(gameObject == null)) { GameSerializer.LoadRecursionTwice(null, child, gameObject); } } } } else { BinaryNode parentNode = domNode.ParentNode; for (int j = 0; j < parentNode.GetChildNum(); j++) { BinaryNode child2 = parentNode.GetChild(j); if (!(child2.GetName() != "CHD")) { string attribute = GameSerializer.GetAttribute(child2, "ON"); if (!(attribute != go.name)) { GameSerializer.LoadComponets(child2, go); if (child2.GetChildNum() > 0 && go.transform.childCount > 0) { BinaryNode child3 = child2.GetChild(0); for (int k = 0; k < go.transform.childCount; k++) { GameObject gameObject2 = go.transform.GetChild(k).gameObject; GameSerializer.LoadRecursionTwice(null, child3, gameObject2); } } domNode = child2; } } } } string nodeAttr = GameSerializer.GetNodeAttr(domNode, "DIS"); if (nodeAttr != null) { go.SetActive(false); } else { go.SetActive(true); } }
public void ObjectDeserialize(ref object o, BinaryNode node) { IList list = (IList)o; int childNum = node.GetChildNum(); for (int i = 0; i < childNum; i++) { list.Add(GameSerializer.GetObject(node.GetChild(i))); } }
private static void LoadComponets(BinaryNode domNode, GameObject go) { for (int i = 0; i < domNode.GetChildNum(); i++) { BinaryNode child = domNode.GetChild(i); if (!(child.GetName() != "Cop")) { string nodeAttr = GameSerializer.GetNodeAttr(child, "Type"); Component component = go.GetComponent(nodeAttr); if (!(component == null)) { string nodeAttr2 = GameSerializer.GetNodeAttr(child, "DIS"); if (nodeAttr2 != null && component is Behaviour) { Behaviour behaviour = (Behaviour)component; behaviour.enabled = false; } ICustomizedComponentSerializer componentSerlizer = GameSerializer.GetComponentSerlizer(component.GetType()); if (componentSerlizer != null) { componentSerlizer.ComponentDeserialize(component, child); } else { MemberInfo[] members = component.GetType().GetMembers(); for (int j = 0; j < members.Length; j++) { if (GameSerializer.IsMINeedExport(members[j])) { BinaryNode binaryNode = child.SelectSingleNode(members[j].get_Name()); if (binaryNode != null) { object @object = GameSerializer.GetObject(binaryNode); try { if (@object != null) { GameSerializer.SetMIValue(members[j], component, @object); } } catch (Exception var_11_F4) { } } } } } } } } }
private static void LoadRecursionTwice(GameObject parentGo, BinaryNode domNode, GameObject go) { if (domNode == domNode.OwnerDocument.Root) { LoadComponets(domNode, go); int index = -1; for (int i = 0; i < domNode.GetChildNum(); i++) { BinaryNode child = domNode.GetChild(i); if (child.GetName() == "CHD") { index++; GameObject gameObject = go.transform.GetChild(index).gameObject; if (gameObject != null) { LoadRecursionTwice(null, child, gameObject); } } } } else { BinaryNode parentNode = domNode.ParentNode; for (int j = 0; j < parentNode.GetChildNum(); j++) { BinaryNode node = parentNode.GetChild(j); if ((node.GetName() == "CHD") && (GetAttribute(node, "ON") == go.name)) { LoadComponets(node, go); if ((node.GetChildNum() > 0) && (go.transform.childCount > 0)) { BinaryNode node4 = node.GetChild(0); for (int k = 0; k < go.transform.childCount; k++) { GameObject obj3 = go.transform.GetChild(k).gameObject; LoadRecursionTwice(null, node4, obj3); } } domNode = node; } } } if (GetNodeAttr(domNode, "DIS") != null) { go.SetActive(false); } else { go.SetActive(true); } }
private static void LoadComponets(BinaryNode domNode, GameObject go) { for (int i = 0; i < domNode.GetChildNum(); i++) { BinaryNode child = domNode.GetChild(i); if (child.GetName() == "Cop") { string nodeAttr = GetNodeAttr(child, "Type"); Component cmp = go.GetComponent(nodeAttr); if (cmp != null) { if ((GetNodeAttr(child, "DIS") != null) && (cmp is Behaviour)) { Behaviour behaviour = (Behaviour)cmp; behaviour.enabled = false; } ICustomizedComponentSerializer componentSerlizer = GetComponentSerlizer(cmp.GetType()); if (componentSerlizer != null) { componentSerlizer.ComponentDeserialize(cmp, child); } else { MemberInfo[] members = cmp.GetType().GetMembers(); for (int j = 0; j < members.Length; j++) { if (IsMINeedExport(members[j])) { BinaryNode currNode = child.SelectSingleNode(members[j].Name); if (currNode != null) { object obj2 = GetObject(currNode); try { if (obj2 != null) { SetMIValue(members[j], cmp, obj2); } } catch (Exception) { } } } } } } } } }
public void ComponentDeserialize(Component o, BinaryNode node) { Animation animation = o as Animation; for (int i = 0; i < node.GetChildNum(); i++) { BinaryNode child = node.GetChild(i); if (!(child.GetName() != "AniName")) { string nodeAttr = GameSerializer.GetNodeAttr(child, "Value"); AnimationClip animationClip = (AnimationClip)GameSerializer.GetResource(nodeAttr, typeof(AnimationClip)); if (null == animationClip) { Debug.LogError("Cannot find Animation: " + nodeAttr); return; } if (nodeAttr != null && nodeAttr.get_Length() != 0) { animation.AddClip(animationClip, animationClip.name); } } } }
public static object GetObject(BinaryNode currNode) { string nodeAttr = GameSerializer.GetNodeAttr(currNode, "NULL"); object obj = null; if (nodeAttr != null) { return(obj); } string nodeAttr2 = GameSerializer.GetNodeAttr(currNode, "Type"); string nodeAttr3 = GameSerializer.GetNodeAttr(currNode, "V"); string nodeAttr4 = GameSerializer.GetNodeAttr(currNode, "JT"); if ("Arr".Equals(nodeAttr4)) { if (nodeAttr2 != null) { string typeStr = nodeAttr2.Replace("[]", string.Empty); Type type = GameSerializer.GetType(typeStr); if (type == null) { Debug.LogError("Array type " + nodeAttr2 + " create failed!"); return(null); } Array array = Array.CreateInstance(type, currNode.GetChildNum()); for (int i = 0; i < array.get_Length(); i++) { array.SetValue(GameSerializer.GetObject(currNode.GetChild(i)), i); } obj = array; } } else if ("Cus".Equals(nodeAttr4)) { if (nodeAttr2 != null) { Type type2 = GameSerializer.GetType(nodeAttr2); ICustomizedObjectSerializer objectSerlizer = GameSerializer.GetObjectSerlizer(type2); if (objectSerlizer != null && objectSerlizer is ICustomInstantiate) { obj = ((ICustomInstantiate)objectSerlizer).Instantiate(currNode); } else { obj = GameSerializer.CreateInstance(type2); } if (obj == null) { return(null); } if (objectSerlizer != null) { objectSerlizer.ObjectDeserialize(ref obj, currNode); } } } else if ("Enum".Equals(nodeAttr4)) { if (nodeAttr2 != null) { Type type3 = GameSerializer.GetType(nodeAttr2); obj = Enum.ToObject(type3, int.Parse(nodeAttr3)); } } else if ("Pri".Equals(nodeAttr4)) { if (nodeAttr2 != null) { obj = Convert.ChangeType(nodeAttr3, GameSerializer.GetType(nodeAttr2)); } } else if ("Ref".Equals(nodeAttr4)) { Object gameObjectFromPath = GameSerializer.GetGameObjectFromPath(nodeAttr3, nodeAttr2); if (gameObjectFromPath != null) { if (gameObjectFromPath is GameObject) { if (nodeAttr2 != null) { string pureType = GameSerializer.GetPureType(nodeAttr2); if (!"GameObject".Equals(pureType)) { obj = (gameObjectFromPath as GameObject).GetComponent(pureType); if (obj == null) { Debug.LogError("No " + pureType + " component found in " + nodeAttr3); } } else { obj = gameObjectFromPath; } } } else { obj = gameObjectFromPath; } } else { obj = null; Debug.LogError("Load gameobject " + nodeAttr3 + " failed!"); } } else if ("Com".Equals(nodeAttr4)) { obj = GameSerializer.CreateInstance(nodeAttr2); if (obj == null) { return(null); } MemberInfo[] members = obj.GetType().GetMembers(); for (int j = 0; j < members.Length; j++) { if (GameSerializer.IsMINeedExport(members[j])) { BinaryNode binaryNode = currNode.SelectSingleNode(members[j].get_Name()); if (binaryNode != null) { try { object @object = GameSerializer.GetObject(binaryNode); if (binaryNode != null && @object != null) { GameSerializer.SetMIValue(members[j], obj, @object); } } catch (Exception ex) { Debug.LogError(string.Concat(new object[] { "Set field value failed! Field ", members[j].get_Name(), " in ", obj.GetType(), "e:", ex })); } } } } } return(obj); }
private static GameObject LoadRecursionOnce(GameObject parentGo, BinaryNode domNode) { GameObject gameObject = null; string nodeAttr = GameSerializer.GetNodeAttr(domNode, "ON"); if (parentGo != null) { for (int i = 0; i < parentGo.transform.childCount; i++) { if (parentGo.transform.GetChild(i).name.Equals(nodeAttr)) { gameObject = parentGo.transform.GetChild(i).gameObject; break; } } } if (gameObject == null) { string nodeAttr2 = GameSerializer.GetNodeAttr(domNode, "PFB"); if (nodeAttr2 != null && nodeAttr2.get_Length() != 0) { object resource = GameSerializer.GetResource(nodeAttr2, typeof(GameObject)); if (resource == null || !(resource is GameObject)) { Debug.LogError(nodeAttr2 + " 不存在或者类型错误,请重新导出该场景"); gameObject = new GameObject(); } else { GameObject gameObject2 = resource as GameObject; bool activeSelf = gameObject2.activeSelf; gameObject2.SetActive(false); gameObject = (GameObject)Object.Instantiate(gameObject2); gameObject2.SetActive(activeSelf); } } else { gameObject = new GameObject(); } } Vector3 localScale = gameObject.transform.localScale; gameObject.name = GameSerializer.GetNodeAttr(domNode, "ON"); if (parentGo != null) { gameObject.transform.parent = parentGo.transform; } gameObject.transform.localScale = localScale; GameSerializer.DeserializeObject(domNode, gameObject); gameObject.SetActive(false); GameSerializer.InitComponets(domNode, gameObject); for (int j = 0; j < domNode.GetChildNum(); j++) { BinaryNode child = domNode.GetChild(j); if (child.GetName() == "CHD") { GameSerializer.LoadRecursionOnce(gameObject, child); } } return(gameObject); }
public void ObjectDeserialize(ref object o, BinaryNode node) { BinaryNode child = node.GetChild(0); o = child.GetValue(); }
private static GameObject LoadRecursionOnce(GameObject parentGo, BinaryNode domNode) { GameObject go = null; string nodeAttr = GetNodeAttr(domNode, "ON"); if (parentGo != null) { for (int j = 0; j < parentGo.transform.childCount; j++) { if (parentGo.transform.GetChild(j).name.Equals(nodeAttr)) { go = parentGo.transform.GetChild(j).gameObject; break; } } } if (go == null) { string pathName = GetNodeAttr(domNode, "PFB"); if ((pathName != null) && (pathName.Length != 0)) { object resource = GetResource(pathName, typeof(GameObject)); if ((resource == null) || !(resource is GameObject)) { Debug.LogError(pathName + " 不存在或者类型错误,请重新导出该场景"); go = new GameObject(); } else { GameObject original = resource as GameObject; bool activeSelf = original.activeSelf; original.SetActive(false); go = (GameObject)UnityEngine.Object.Instantiate(original); original.SetActive(activeSelf); } } else { go = new GameObject(); } } Vector3 localScale = go.transform.localScale; go.name = GetNodeAttr(domNode, "ON"); if (parentGo != null) { go.transform.parent = parentGo.transform; } go.transform.localScale = localScale; DeserializeObject(domNode, go); go.SetActive(false); InitComponets(domNode, go); for (int i = 0; i < domNode.GetChildNum(); i++) { BinaryNode child = domNode.GetChild(i); if (child.GetName() == "CHD") { LoadRecursionOnce(go, child); } } return(go); }
public static object GetObject(BinaryNode currNode) { string nodeAttr = GetNodeAttr(currNode, "NULL"); object o = null; if (nodeAttr == null) { string typeStr = GetNodeAttr(currNode, "Type"); string s = GetNodeAttr(currNode, "V"); string str4 = GetNodeAttr(currNode, "JT"); if ("Arr".Equals(str4)) { if (typeStr == null) { return(o); } System.Type elementType = GetType(typeStr.Replace("[]", string.Empty)); if (elementType == null) { Debug.LogError("Array type " + typeStr + " create failed!"); return(null); } Array array = Array.CreateInstance(elementType, currNode.GetChildNum()); for (int i = 0; i < array.Length; i++) { array.SetValue(GetObject(currNode.GetChild(i)), i); } return(array); } if ("Cus".Equals(str4)) { if (typeStr != null) { System.Type type = GetType(typeStr); ICustomizedObjectSerializer objectSerlizer = GetObjectSerlizer(type); if ((objectSerlizer != null) && (objectSerlizer is ICustomInstantiate)) { o = ((ICustomInstantiate)objectSerlizer).Instantiate(currNode); } else { o = CreateInstance(type); } if (o == null) { return(null); } if (objectSerlizer != null) { objectSerlizer.ObjectDeserialize(ref o, currNode); } } return(o); } if ("Enum".Equals(str4)) { if (typeStr != null) { o = Enum.ToObject(GetType(typeStr), int.Parse(s)); } return(o); } if ("Pri".Equals(str4)) { if (typeStr != null) { o = Convert.ChangeType(s, GetType(typeStr)); } return(o); } if ("Ref".Equals(str4)) { UnityEngine.Object gameObjectFromPath = GetGameObjectFromPath(s, typeStr); if (gameObjectFromPath != null) { if (gameObjectFromPath is GameObject) { if (typeStr == null) { return(o); } string pureType = GetPureType(typeStr); if (!"GameObject".Equals(pureType)) { o = (gameObjectFromPath as GameObject).GetComponent(pureType); if (o == null) { Debug.LogError("No " + pureType + " component found in " + s); } return(o); } } return(gameObjectFromPath); } o = null; Debug.LogError("Load gameobject " + s + " failed!"); return(o); } if ("Com".Equals(str4)) { o = CreateInstance(typeStr); if (o == null) { return(null); } MemberInfo[] members = o.GetType().GetMembers(); for (int j = 0; j < members.Length; j++) { if (IsMINeedExport(members[j])) { BinaryNode node = currNode.SelectSingleNode(members[j].Name); if (node != null) { try { object obj4 = GetObject(node); if ((node != null) && (obj4 != null)) { SetMIValue(members[j], o, obj4); } } catch (Exception exception) { Debug.LogError(string.Concat(new object[] { "Set field value failed! Field ", members[j].Name, " in ", o.GetType(), "e:", exception })); } } } } } } return(o); }
public void ObjectDeserialize(ref object o, BinaryNode node) { o = node.GetChild(0).GetValue(); }