private void DisconnectTextScene() { if (go == null) { return; } Undo.RegisterSceneUndo("Disconnect TextScene " + go.name); TextSceneObject textSceneComp = go.GetComponent <TextSceneObject>(); if (textSceneComp != null) { DestroyImmediate(textSceneComp); } TextSceneObject[] firstLayer = Helper.GetComponentsInChildren <TextSceneObject>(go, 1); //Enable next layer of TextSceneObjects. foreach (TextSceneObject tso in firstLayer) { tso.hideFlags = 0; tso.transform.hideFlags = 0; } //Enable all disconnected gameobjects until the next TextSceneObject. foreach (Transform child in go.transform) { Component[] toEnable = Helper.GetComponentsInChildrenAboveType <TextSceneObject>(child.gameObject); foreach (Component comp in toEnable) { comp.hideFlags = 0; } } TextSceneHierarchy tsh = EditorWindow.GetWindow(typeof(TextSceneHierarchy)) as TextSceneHierarchy; tsh.OnHierarchyChange(); }
public override void OnInspectorGUI() { TextSceneObject tso = target as TextSceneObject; EditorGUILayout.BeginVertical(); GUILayout.Label("External scene"); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Open scene: "); if (GUILayout.Button(tso.textScene.name)) { if (EditorUtility.DisplayDialog("Open scenefile?", "Do you want to close the current scene and open the scene pointed to by this TextSceneObject?", "Yes", "No")) { TextSceneDeserializer.LoadSafe(EditorHelper.GetProjectFolder() + AssetDatabase.GetAssetPath(tso.textScene)); GUIUtility.ExitGUI(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
public void OnGUI(int level, ref float offset) { float startOffset = offset; GUIStyle style = EntryTypeStyle.Get(type); if (go != null) { Rect lineRect = new Rect(0, offset, 1000, style.lineHeight); Rect labelRect = new Rect(level * 20.0f, offset, 1000, style.lineHeight); Rect expandRect = new Rect(level * 20.0f, offset, 20, style.lineHeight); offset += style.lineHeight; if (selected == this) { style.Draw(lineRect, false, true, true, false); } if (hasChildren) { expanded = GUI.Toggle(expandRect, expanded, GUIContent.none, Styles.foldout); } GUI.Label(labelRect, go.name, style); //FIXME: This is to get the scrollbar to work :S GUILayout.BeginHorizontal(); GUILayout.Space(level * 20.0f); GUILayout.Label("", style); GUILayout.EndHorizontal(); } if (go == null || expanded) { foreach (Entry e in entries) { e.OnGUI(level + 1, ref offset); } } Rect selectRect = new Rect(0, startOffset + style.lineHeight * 0.1f, 200, offset - startOffset - style.lineHeight * 0.1f); //Base entry if (go == null) { selectRect.height = float.MaxValue; } if (selectRect.Contains(Event.current.mousePosition)) { if (go != null) { if (Event.current.type == EventType.MouseDown) { if (Event.current.button == 1) { EditorGUIUtility.PingObject(go); GenericMenu menu = new GenericMenu(); if (type == EntryType.Normal || type == EntryType.PrefabRoot || type == EntryType.TextSceneRoot) { menu.AddItem(EditorHelper.TextContent("Duplicate"), false, new GenericMenu.MenuFunction(this.Duplicate)); menu.AddItem(EditorHelper.TextContent("Delete"), false, new GenericMenu.MenuFunction(this.Delete)); if (type == EntryType.PrefabRoot) { menu.AddSeparator(""); menu.AddItem(EditorHelper.TextContent("Disconnect"), false, new GenericMenu.MenuFunction(this.DisconnectPrefab)); } else if (type == EntryType.TextSceneRoot) { menu.AddSeparator(""); menu.AddItem(EditorHelper.TextContent("Disconnect"), false, new GenericMenu.MenuFunction(this.DisconnectTextScene)); } else if (type == EntryType.Normal) { menu.AddSeparator(""); menu.AddItem(EditorHelper.TextContent("Create Empty"), false, new GenericMenu.MenuFunction(delegate { GameObject empty = new GameObject(); empty.transform.parent = go.transform; empty.transform.localPosition = Vector3.zero; empty.transform.localRotation = Quaternion.identity; })); } } else { menu.AddItem(EditorHelper.TextContent("No options"), false, null); } menu.ShowAsContext(); } else if (Event.current.clickCount == 2) { expanded = !expanded; } Event.current.Use(); } else if (Event.current.type == EventType.MouseUp) { if (Event.current.clickCount == 1) { Selection.activeGameObject = go; TextSceneObject tso = go.GetComponent <TextSceneObject>(); if (tso != null) { EditorGUIUtility.PingObject(tso.textScene); } Object prefabParent = EditorUtility.GetPrefabParent(go); if (prefabParent != null) { EditorGUIUtility.PingObject(prefabParent); } } Event.current.Use(); } else if (Event.current.type == EventType.MouseDrag) { DragAndDrop.PrepareStartDrag(); UnityEngine.Object[] draggedGO = new Object[1]; draggedGO[0] = go; DragAndDrop.objectReferences = draggedGO; DragAndDrop.SetGenericData("entry", this); DragAndDrop.StartDrag("Dragging " + go.name); Event.current.Use(); } } HandleDrag(); } else { //Reset expand timer if the cursor moves out of the entry rect. expandedTimer = EditorApplication.timeSinceStartup + 0.3; } if (selected == this) { if (go != null) { if (Event.current.type == EventType.KeyDown) { if (Event.current.keyCode == KeyCode.Delete) { this.Delete(); } //FIXME: Use control/command, not shift. else if (Event.current.shift && Event.current.keyCode == KeyCode.D) { this.Duplicate(); } } } } }
private static void Serialize(StringBuilder stream, GameObject go, int indent) { //FIXME: Uh-oh. Seems like I missed this the first time - I might have overcomplicated // matters slightly :S Need to investigate this further. /* * SerializedObject serializeObject = new SerializedObject(go); * * SerializedProperty seralizedProperty = serializeObject.GetIterator(); * * do * { * stream.WriteLine(seralizedProperty.name + " = " + seralizedProperty.ToString()); * }while(seralizedProperty.Next(true)); * * Component[] cList = Helper.GetComponentsInChildren<Transform>(go); * * foreach(Component c in cList) * { * stream.WriteLine("Component: " + c.GetType().ToString()); * * serializeObject = new SerializedObject(go); * * seralizedProperty = serializeObject.GetIterator(); * * do * { * stream.WriteLine(seralizedProperty.name + " = " + seralizedProperty.stringValue); * }while(seralizedProperty.Next(true)); * } * * stream.WriteLine(); * * return; */ Object prefab = EditorUtility.GetPrefabParent(go); if (prefab != null) { PrefabType prefabType = EditorUtility.GetPrefabType(go); if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { } else { string path = AssetDatabase.GetAssetPath(prefab); string guid = AssetDatabase.AssetPathToGUID(path); WriteLine(stream, indent, "prefab " + go.name); WriteLine(stream, indent, "assetpath " + path + ", " + guid); WriteLine(stream, indent, Vector3ToString(go.transform.localPosition)); WriteLine(stream, indent, QuatToString(go.transform.localRotation)); WriteLine(stream, indent, Vector3ToString(go.transform.localScale)); if (indent == 0) { WriteLine(stream, indent, ""); } return; } } TextSceneObject tso = go.GetComponent <TextSceneObject>(); if (tso) { string path = AssetDatabase.GetAssetPath(tso.textScene); if (path.Length == 0) { EditorUtility.DisplayDialog("ERROR", "TextSceneObjects must point at assets!", "OK"); warnings++; return; } string fullPath = Helper.GetFullName(go); GameObject[] matchingObjects = Helper.FindGameObjectsFromFullName(fullPath); if (matchingObjects.Length > 1) { EditorUtility.DisplayDialog("WARNING", "There are several objects that has the path '" + fullPath + "' in the scene. It is not a good thing to let TextSceneObjects have the same path as other objects, because links within the TextSceneObjects may horribly break when you least need it.", "OK, I'll fix it"); warnings++; } string guid = AssetDatabase.AssetPathToGUID(path); WriteLine(stream, indent, "textscene " + go.name); WriteLine(stream, indent, "assetpath " + path + ", " + guid); WriteLine(stream, indent, Vector3ToString(go.transform.localPosition)); WriteLine(stream, indent, QuatToString(go.transform.localRotation)); WriteLine(stream, indent, Vector3ToString(go.transform.localScale)); if (indent == 0) { WriteLine(stream, indent, ""); } return; } //Debug.Log("Writing object: " + go.name); WriteLine(stream, indent, "gameobject " + go.name); WriteLine(stream, indent, "tag " + go.tag + " layer " + go.layer); WriteLine(stream, indent, Vector3ToString(go.transform.localPosition)); WriteLine(stream, indent, QuatToString(go.transform.localRotation)); WriteLine(stream, indent, Vector3ToString(go.transform.localScale)); int childCount = go.transform.GetChildCount(); WriteLine(stream, indent, "children " + childCount); //Write out all children , sorted. List <Transform> children = new List <Transform>(); foreach (Transform t in go.transform) { children.Add(t); } children.Sort(CompareTransform); foreach (Transform t in children) { Serialize(stream, t.gameObject, indent + 1); } Component[] components = go.GetComponents <Component>(); List <Component> componentsToWrite = new List <Component>(); foreach (Component comp in components) { if (comp is Transform) { continue; } //HACK. Fix this gracefully. if (comp is ParticleEmitter) { EditorUtility.DisplayDialog("Warning", "The component " + comp.GetType().ToString() + " cannot be saved. You can get around this by making the object " + Helper.GetFullName(go) + " into a prefab and drop that into the scene instead", "OK"); Debug.LogWarning("Skipping abstract component: " + comp.GetType().ToString(), go); warnings++; continue; } componentsToWrite.Add(comp); } WriteLine(stream, indent, "components " + componentsToWrite.Count); foreach (Component comp in componentsToWrite) { Serialize(stream, comp, indent + 1); } if (indent == 0) { WriteLine(stream, indent, ""); } }