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)); } } } }
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); }