public static void ShowWindow(GameObject obj) { identifier = obj.GetComponent <Iidentifier>(); components = new List <Component>(); componentSaves = new List <ComponentSave>(); foreach (Component c in obj.GetComponents <Component>()) { if (c.GetType() != typeof(SaveableIdentifier)) { components.Add(c); } } GetWindow <SaveSpecificEditor>(true, "Save specific", true); if (identifier.componentSaves == null) { for (int i = 0; i < components.Count; i++) { if (components[i].GetType() != typeof(SaveableIdentifier)) { List <bool> refVarList = new List <bool>(); for (int v = 0; v < ScriptReflector.GetVariableNames(components[i]).Count; v++) { refVarList.Add(false); } componentSaves.Add(new ComponentSave(components[i].GetType().Name, false, refVarList)); } } } else { componentSaves = identifier.componentSaves; } }
private void OnGUI() { scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUIStyle.none); closeAllButton = GUILayout.Button("Close all"); if (closeAllButton) { CloseAllFoldouts(); } for (int i = 0; i < componentSaves.Count; i++) { if (components[i].GetType() != typeof(SaveableIdentifier)) { //TODO: save the variables List <System.Tuple <string, string, string> > variables = ScriptReflector.GetVariableNames(components[i]); ComponentSave tempList = componentSaves[i]; tempList.boolItem = EditorGUILayout.BeginFoldoutHeaderGroup(componentSaves[i].boolItem, components[i].GetType().Name); componentSaves[i] = tempList; if (componentSaves[i].boolItem == true) { GUILayout.Space(10); EditorGUI.indentLevel += 5; for (int v = 0; v < variables.Count; v++) { GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(variables[v].Item1); GUILayout.Space(-250); componentSaves[i].boolList[v] = EditorGUILayout.Toggle(componentSaves[i].boolList[v]); GUILayout.EndHorizontal(); } EditorGUI.indentLevel -= 5; GUILayout.Space(20); } EditorGUILayout.EndFoldoutHeaderGroup(); } } GUILayout.FlexibleSpace(); saveButton = GUILayout.Button("Save"); if (saveButton) { SaveToIdentifier(); Close(); } GUILayout.EndScrollView(); }
private static void LoadObject(int id) { if (GetIdNode(id) == null) { return; } GameObject obj = null; for (int i = 0; i < allIdentifiersInScene.Length; i++) { if (allIdentifiersInScene[i].id == id) { obj = allIdentifiersInScene[i].gameObject; } } if (obj == null) { obj = new GameObject(); } XmlNode idNode = GetIdNode(id); //Adds the component with correct values foreach (XmlNode cNode in idNode.ChildNodes) { string cName = cNode.Attributes[0].Value; System.Type cType = System.Type.GetType(cName); Component currentComponent = (obj.GetComponent(cType)) ? obj.GetComponent(cType) : obj.AddComponent(cType); foreach (XmlNode vNode in cNode.ChildNodes) { ScriptReflector.SetComponentVarTo( currentComponent, vNode.Name, ConvertString.ThisType(vNode.InnerText, System.Type.GetType(vNode.Attributes[0].Value))); } } }
private static void MakeVariableNodes(Component component, XmlNode componentNode, ComponentSave componentSave) { List <System.Tuple <string, string, string> > componentFields = ScriptReflector.GetVariableNames(component); for (int i = 0; i < componentFields.Count; i++) { XmlElement fieldNode = GetChildNodeFromName(componentNode, componentFields[i].Item1); if (componentSave.boolList[i]) { if (fieldNode == null) { fieldNode = xmlDocument.CreateElement(componentFields[i].Item1); } fieldNode.SetAttribute("type", componentFields[i].Item2); fieldNode.InnerText = componentFields[i].Item3; componentNode.AppendChild(fieldNode); } else if (fieldNode != null) { componentNode.RemoveChild(fieldNode); } } }