/// <summary> /// Traverses the serialization. /// </summary> /// <param name="jsObjID">The js object identifier.</param> /// <param name="st">The parent struct.</param> public void TraverseSerialize(int jsObjID, SerializeStruct st) { while (true) { string s = NextString(); if (s == null) return; int x = s.IndexOf('/'); int y = s.IndexOf('/', x + 1); string s0 = s.Substring(0, x); string s1 = s.Substring(x + 1, y - x - 1); switch (s0) { case "ArrayBegin": { SerializeStruct.SType sType = SerializeStruct.SType.Array; var ss = new SerializeStruct(sType, s1, st); st.AddChild(ss); TraverseSerialize(jsObjID, ss); } break; // StructBegin and ListBegin also contains type case "StructBegin": case "ListBegin": { SerializeStruct.SType sType = SerializeStruct.SType.Array; if (s0 == "StructBegin") sType = SerializeStruct.SType.Struct; else if (s0 == "ListBegin") sType = SerializeStruct.SType.List; string s2 = s.Substring(y + 1, s.Length - y - 1); var ss = new SerializeStruct(sType, s1, st); ss.typeName = s2; st.AddChild(ss); TraverseSerialize(jsObjID, ss); } break; case "ArrayEnd": case "StructEnd": case "ListEnd": { // ! return here return; } //break; default: { UnitType eUnitType = (UnitType)int.Parse(s0); if (eUnitType == UnitType.ST_UnityEngineObject) { string s2 = s.Substring(y + 1, s.Length - y - 1); var valName = s1; var objIndex = int.Parse(s2); JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, this.arrObject[objIndex]); var child = new SerializeStruct(SerializeStruct.SType.Unit, valName, st); child.id = JSApi.getSaveID(); st.AddChild(child); } else if (eUnitType == UnitType.ST_JavaScriptMonoBehaviour) { var valName = s1; string s2 = s.Substring(y + 1, s.Length - y - 1); var arr = s2.Split('/'); var objIndex = int.Parse(arr[0]); var scriptName = arr[1]; var child = new SerializeStruct(SerializeStruct.SType.Unit, valName, st); int refJSObjID = this.GetGameObjectMonoBehaviourJSObj((GameObject)this.arrObject[objIndex], scriptName); if (refJSObjID == 0) { child.id = 0; } else { JSApi.setObject((int)JSApi.SetType.SaveAndTempTrace, refJSObjID); child.id = JSApi.getSaveID(); } st.AddChild(child); } else { string s2 = s.Substring(y + 1, s.Length - y - 1); var valName = s1; int id = toID(eUnitType, s2); var child = new SerializeStruct(SerializeStruct.SType.Unit, valName, st); //child.val = JSMgr.vCall.valTemp; child.id = id; st.AddChild(child); } } break; } } }
/// <summary> /// Traverses the serialization. /// </summary> /// <param name="jsObjID">The js object identifier.</param> /// <param name="st">The parent struct.</param> public void TraverseSerialize(int jsObjID, SerializeStruct st) { while (true) { string s = NextString(); if (s == null) { return; } int x = s.IndexOf('/'); int y = s.IndexOf('/', x + 1); string s0 = s.Substring(0, x); string s1 = s.Substring(x + 1, y - x - 1); switch (s0) { case "ArrayBegin": { SerializeStruct.SType sType = SerializeStruct.SType.Array; var ss = new SerializeStruct(sType, s1, st); st.AddChild(ss); TraverseSerialize(jsObjID, ss); } break; // StructBegin and ListBegin also contains type case "StructBegin": case "ListBegin": { SerializeStruct.SType sType = SerializeStruct.SType.Array; if (s0 == "StructBegin") { sType = SerializeStruct.SType.Struct; } else if (s0 == "ListBegin") { sType = SerializeStruct.SType.List; } string s2 = s.Substring(y + 1, s.Length - y - 1); var ss = new SerializeStruct(sType, s1, st); ss.typeName = s2; st.AddChild(ss); TraverseSerialize(jsObjID, ss); } break; case "ArrayEnd": case "StructEnd": case "ListEnd": { // ! return here return; } //break; default: { UnitType eUnitType = (UnitType)int.Parse(s0); if (eUnitType == UnitType.ST_UnityEngineObject) { string s2 = s.Substring(y + 1, s.Length - y - 1); var valName = s1; var objIndex = int.Parse(s2); JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, this.arrObject[objIndex]); var child = new SerializeStruct(SerializeStruct.SType.Unit, valName, st); child.id = JSApi.getSaveID(); st.AddChild(child); } else if (eUnitType == UnitType.ST_JavaScriptMonoBehaviour) { var valName = s1; string s2 = s.Substring(y + 1, s.Length - y - 1); var arr = s2.Split('/'); var objIndex = int.Parse(arr[0]); var scriptName = arr[1]; var child = new SerializeStruct(SerializeStruct.SType.Unit, valName, st); JSComponent component; int refJSObjID = this.GetGameObjectMonoBehaviourJSObj((GameObject)this.arrObject[objIndex], scriptName, out component); if (refJSObjID == 0) { child.id = 0; } else { if (waitSerialize == null) { waitSerialize = new List <JSComponent>(); } waitSerialize.Add(component); JSApi.setObject((int)JSApi.SetType.SaveAndTempTrace, refJSObjID); child.id = JSApi.getSaveID(); } st.AddChild(child); } else { string s2 = s.Substring(y + 1, s.Length - y - 1); var valName = s1; int id = toID(eUnitType, s2); var child = new SerializeStruct(SerializeStruct.SType.Unit, valName, st); //child.val = JSMgr.vCall.valTemp; child.id = id; st.AddChild(child); } } break; } } }
public void ParseSerializeData(int jsObjID, SerializeStruct st) { while (true) { string s = NextString(); if (s == null) { return; } int i = s.IndexOf('/'); string varName = s.Substring(0, i); string varValue = s.Substring(i + 1); char ct = varName[0]; if (ct == 'o') { // varName / objIndex var objIndex = int.Parse(varValue); JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, this.arrObject[objIndex]); var child = new SerializeStruct(varName); child.id = JSApi.getSaveID(); st.AddChild(child); } else if (ct == 'k') { // varName / objIndex / scriptName var arr = varValue.Split('/'); var objIndex = int.Parse(arr[0]); var scriptName = arr[1]; var child = new SerializeStruct(varName); JSComponent component; int refJSObjID = this.GetGameObjectMonoBehaviourJSObj((GameObject)this.arrObject[objIndex], scriptName, out component); if (refJSObjID == 0) { child.id = 0; } else { if (waitSerialize == null) { waitSerialize = new List <JSComponent>(); } waitSerialize.Add(component); JSApi.setObject((int)JSApi.SetType.SaveAndTempTrace, refJSObjID); child.id = JSApi.getSaveID(); } st.AddChild(child); } else // 'f', 'i', 's' { // varName / varValue int id = toID(ct, varValue); var child = new SerializeStruct(varName); //child.val = JSMgr.vCall.valTemp; child.id = id; st.AddChild(child); } } }