void UpdateHierarchyData() { if (m_HierarchyProperty == null) { m_HierarchyProperty = new HierarchyProperty(HierarchyType.GameObjects); m_HierarchyProperty.Next(null); } else { m_HierarchyProperty.Reset(); m_HierarchyProperty.Next(null); } bool hasChanged = false; var hasNext = true; m_HierarchyData = CollectHierarchyData(ref hasNext, ref hasChanged, m_HierarchyData, m_HierarchyProperty); if (hasChanged) { foreach (var list in m_HierarchyLists) { list.hierarchyData = GetHierarchyData(); } } }
public static T findCloseComponent <T>(GameObject child) where T : Component { Transform parent = child.transform.parent; while (parent != null) { T foundComponent = parent.GetComponent <T>(); if (foundComponent != null) { return(foundComponent); } parent = parent.transform.parent; } var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; while (prop.Next(expanded)) { T[] components = ((GameObject)prop.pptrValue).GetComponentsInChildren <T>(); if (components.Length > 0) { return(components[0]); } } return(null); }
public static IEnumerable <GameObject> SceneRoots(string scenePath) { var scene = EditorSceneManager.GetSceneByPath(scenePath); if (Scene_GetRootGameObjects_Method != null && scene.IsValid()) { var roots = (GameObject[])Scene_GetRootGameObjects_Method.Invoke(scene, null); foreach (var root in roots) { yield return(root); } } else { // Fallback; only works in Unity versions without multi-scene support var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; while (prop.Next(expanded)) { yield return(prop.pptrValue as GameObject); } } }
void UpdateHierarchyData() { m_ObjectTypes.Clear(); if (m_HierarchyProperty == null) { m_HierarchyProperty = new HierarchyProperty(HierarchyType.GameObjects); m_HierarchyProperty.Next(null); } else { m_HierarchyProperty.Reset(); m_HierarchyProperty.Next(null); } var hasChanged = false; var hasNext = true; m_HierarchyData = CollectHierarchyData(ref hasNext, ref hasChanged, m_HierarchyData, m_HierarchyProperty, m_ObjectTypes); if (hasChanged) { foreach (var list in m_HierarchyLists) { list.hierarchyData = GetHierarchyData(); } // Send new data to existing filterUIs foreach (var filterUI in m_FilterUIs) { filterUI.filterList = GetFilterList(); } } }
private void UpdateAssetList() { loadedAssets = new List<HierarchyEntry>(); loadedAssetsFlat.Clear(); hierarchyProperty = new HierarchyProperty(HierarchyType.Assets); hierarchyProperty.SetSearchFilter(GetFilter(), (int)SearchableEditorWindow.SearchMode.All); while (hierarchyProperty.Next(null)) { AddAssetInfo(hierarchyProperty); } FilterAssets(ref loadedAssets); loadedAssets.ForEach(SortChildren); loadedAssetsFlat.Clear(); BuildFlatAssets(loadedAssets); UpdateFilter(); if (selectionCallback != null) { SelectedAssetEntry = loadedAssetsFlat.FirstOrDefault(); } }
static IEnumerable<GameObject> SceneRoots() { var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; while (prop.Next(expanded)) { yield return prop.pptrValue as GameObject; } }
public static void LoadAllAssetsOfType(string type) { HierarchyProperty hierarchyProperty = new HierarchyProperty(1); hierarchyProperty.SetSearchFilter(type, 2); while (hierarchyProperty.Next(null)) { AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(hierarchyProperty.get_instanceID())); } }
/// <summary> /// Scenes the root transforms. /// </summary> /// <returns>The root transforms.</returns> static IEnumerable <Transform> SceneRootTransforms() { var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; while (prop.Next(expanded)) { var go = prop.pptrValue as GameObject; yield return(go.transform); } }
public static IEnumerable <GameObject> ActiveSceneRootGameObjects() { #if UNITY_5_3 return(UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects()); #else var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; while (prop.Next(expanded)) { yield return(prop.pptrValue as GameObject); } #endif }
private static IEnumerable <GameObject> GetRootSceneObjects() { #if UNITY_5_3_OR_NEWER return(SceneManager.GetActiveScene().GetRootGameObjects()); #else var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; while (prop.Next(expanded)) { yield return(prop.pptrValue as GameObject); } #endif }
public static List <string> FindAllTextAssets() { var hierarchyProperty = new HierarchyProperty(HierarchyType.Assets); hierarchyProperty.SetSearchFilter("t:TextAsset", 0); hierarchyProperty.Reset(); List <string> list = new List <string>(); while (hierarchyProperty.Next(null)) { list.Add(hierarchyProperty.guid); } return(list); }
static int GetRootIndex(Transform child) { var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; int index = 0; while (prop.Next(expanded)) { GameObject go = (GameObject)prop.pptrValue; if (child == go.transform) { return(index); } index++; } throw new Exception("It should not be happen."); }
private static GameObject GetRootObject(string name) { HierarchyProperty prop = new HierarchyProperty(HierarchyType.GameObjects); int[] expanded = new int[0]; while (prop.Next(expanded)) { GameObject rootObject = prop.pptrValue as GameObject; if (rootObject != null && rootObject.name == name) { return(rootObject); } } return(null); }
/// <summary> /// Update the scene blackboard's instance ids. /// </summary> static void UpdateSceneInstanceIDs() { // The HierarchyProperty is an undocumented class very uesfull to get all GameObjects in the scene or assets in the project var hierarchyProperty = new HierarchyProperty(HierarchyType.GameObjects); // Search for Blackboards hierarchyProperty.SetSearchFilter("internalblackboard", (int)SearchableEditorWindow.SearchModeHierarchyWindow.Type); // Reset the list of game Object instance ids s_SceneInstanceIDs.Clear(); // Go through all objects while (hierarchyProperty.Next(null)) { // Populate the GameObject instanceID list s_SceneInstanceIDs.Add(hierarchyProperty.instanceID); } }
/// <summary> /// Finds Font Awesome on disk and loads it. /// </summary> private void LoadFont(string search, ref Font result) { // Look in assets folder HierarchyProperty fontSearch = new HierarchyProperty(HierarchyType.Assets); // Set our filter fontSearch.SetSearchFilter(search, 0); // Loop over all results while (fontSearch.Next(null)) { if (fontSearch.pptrValue != null && fontSearch.pptrValue is Font) { // Cast our font and load it. result = (Font)fontSearch.pptrValue; } } }
private void SearchAllAssets(string filter) { var assembly = typeof(EditorWindow).Assembly; var searchFilter = assembly.CreateInstance("UnityEditor.SearchFilter"); ParseSearchString(filter, searchFilter); var property = new HierarchyProperty(HierarchyType.Assets); SetSearchFilter(property, searchFilter); property.Reset(); searchBuf.Clear(); while (property.Next(null)) { searchBuf.Add(new SearchBuf { name = property.name, instanceID = property.instanceID }); } }
private static List <GameObject> GetSceneRoots() { var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; var roots = new List <GameObject>(); while (prop.Next(expanded)) { var go = prop.pptrValue as GameObject; if (go == null) { continue; } roots.Add(go); } return(roots); }
void DoObjectSearch(string filter) { var props = new HierarchyProperty(HierarchyType.GameObjects); props.SetSearchFilter(filter, 0); props.Reset(); while (props.Next(null)) { if (res.Count >= kMaxLists) { return; } res.Add(new ID() { name = props.name, gui = new GUIContent(props.name, AssetPreview.GetMiniThumbnail(props.pptrValue)), obj = props.instanceID }); } }
void DoSceneSearch(string filter) { var props = new HierarchyProperty(HierarchyType.Assets); props.SetSearchFilter(filter + " t:Scene", 0); props.Reset(); while (props.Next(null)) { if (res.Count >= kMaxLists) { return; } res.Add(new ID() { name = AssetDatabase.GUIDToAssetPath(props.guid), gui = new GUIContent(props.name, AssetPreview.GetMiniThumbnail(props.pptrValue)), obj = props.instanceID }); } }
public static GameObject[] GetSceneRoots() { #if UNITY_5_4_OR_NEWER || UNITY_5_3_5 return(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().GetRootGameObjects()); #else List <GameObject> result = new List <GameObject>(); var prop = new HierarchyProperty(HierarchyType.GameObjects); var expanded = new int[0]; while (prop.Next(expanded)) { var go = prop.pptrValue as GameObject; if (go) { result.Add(go); } } return(result.ToArray()); #endif }
// Traverses the asset folder, finding all ScriptableObject assets private static IEnumerable <ObjectId> GetScriptableObjects() { var hp = new HierarchyProperty(HierarchyType.Assets); var expanded = new List <int>(); var eArr = expanded.ToArray(); while (hp.Next(eArr)) { if (hp.hasChildren) { expanded.Add(hp.instanceID); eArr = expanded.ToArray(); } else if (hp.pptrValue == null || hp.pptrValue is ScriptableObject) { yield return new ObjectId { id = hp.instanceID, type = ScriptType.ScriptableObject } } ; } }
void UpdateHierarchyData() { m_ObjectTypes.Clear(); if (m_HierarchyProperty == null) { m_HierarchyProperty = new HierarchyProperty(HierarchyType.GameObjects); } else { m_HierarchyProperty.Reset(); } var hasChanged = false; var lastDepth = 0; m_DataStack.Clear(); m_SiblingIndexStack.Clear(); m_DataStack.Push(null); m_SiblingIndexStack.Push(0); while (m_HierarchyProperty.Next(null)) { var instanceID = m_HierarchyProperty.instanceID; var go = EditorUtility.InstanceIDToObject(instanceID) as GameObject; var currentDepth = m_HierarchyProperty.depth; if (m_IgnoreList.Contains(go)) { var depth = currentDepth; // skip children of EVR to prevent the display of EVR contents while (m_HierarchyProperty.Next(null) && m_HierarchyProperty.depth > depth) { } currentDepth = m_HierarchyProperty.depth; instanceID = m_HierarchyProperty.instanceID; // If EVR is the last object, early out if (instanceID == 0) { break; } continue; } if (currentDepth <= lastDepth) { if (m_DataStack.Count > 1) // Pop off last sibling { if (CleanUpHierarchyData(m_DataStack.Pop(), m_SiblingIndexStack.Pop())) { hasChanged = true; } } var count = lastDepth - currentDepth; while (count-- > 0) { if (CleanUpHierarchyData(m_DataStack.Pop(), m_SiblingIndexStack.Pop())) { hasChanged = true; } } } var parent = m_DataStack.Peek(); var siblingIndex = m_SiblingIndexStack.Pop(); if (parent != null && parent.children == null) { parent.children = new List <HierarchyData>(); } var children = parent == null ? m_HierarchyData : parent.children; HierarchyData currentHierarchyData; if (siblingIndex >= children.Count) { currentHierarchyData = new HierarchyData(m_HierarchyProperty); var types = new HashSet <string>(); InstanceIDToComponentTypes(instanceID, types, m_ObjectTypes); currentHierarchyData.types = types; children.Add(currentHierarchyData); hasChanged = true; } else if (children[siblingIndex].index != instanceID) { currentHierarchyData = new HierarchyData(m_HierarchyProperty); var types = new HashSet <string>(); InstanceIDToComponentTypes(instanceID, types, m_ObjectTypes); currentHierarchyData.types = types; children[siblingIndex] = currentHierarchyData; hasChanged = true; } else { currentHierarchyData = children[siblingIndex]; InstanceIDToComponentTypes(instanceID, currentHierarchyData.types, m_ObjectTypes); } m_DataStack.Push(currentHierarchyData); m_SiblingIndexStack.Push(siblingIndex + 1); m_SiblingIndexStack.Push(0); lastDepth = currentDepth; } while (m_SiblingIndexStack.Count > 0 && m_DataStack.Count > 0) { if (CleanUpHierarchyData(m_DataStack.Pop(), m_SiblingIndexStack.Pop())) { hasChanged = true; } } if (hasChanged) { foreach (var list in m_HierarchyLists) { list.hierarchyData = GetHierarchyData(); } // Send new data to existing filterUIs foreach (var filterUI in m_FilterUIs) { filterUI.filterList = GetFilterList(); } } }
HierarchyData CollectHierarchyData(ref bool hasNext, ref bool hasChanged, HierarchyData hd, HierarchyProperty hp, HashSet <string> objectTypes) { var depth = hp.depth; var name = hp.name; var instanceID = hp.instanceID; var types = InstanceIDToComponentTypes(instanceID, objectTypes); List <HierarchyData> children = null; if (hp.hasChildren) { if (hd != null && hd.children == null) { hasChanged = true; } children = hd == null || hd.children == null ? new List <HierarchyData>() : hd.children; hasNext = hp.Next(null); var i = 0; while (hasNext && hp.depth > depth) { var go = EditorUtility.InstanceIDToObject(hp.instanceID); if (go == gameObject) { // skip children of EVR to prevent the display of EVR contents while (hp.Next(null) && hp.depth > depth + 1) { } // If EVR is the last object, don't add anything to the list if (hp.instanceID == 0) { break; } name = hp.name; instanceID = hp.instanceID; types = InstanceIDToComponentTypes(instanceID, objectTypes); } if (i >= children.Count) { children.Add(CollectHierarchyData(ref hasNext, ref hasChanged, null, hp, objectTypes)); hasChanged = true; } else if (children[i].index != hp.instanceID) { children[i] = CollectHierarchyData(ref hasNext, ref hasChanged, null, hp, objectTypes); hasChanged = true; } else { children[i] = CollectHierarchyData(ref hasNext, ref hasChanged, children[i], hp, objectTypes); } if (hasNext) { hasNext = hp.Next(null); } i++; } if (i != children.Count) { children.RemoveRange(i, children.Count - i); hasChanged = true; } if (children.Count == 0) { children = null; } if (hasNext) { hp.Previous(null); } } else if (hd != null && hd.children != null) { hasChanged = true; } if (hd != null) { hd.children = children; hd.name = name; hd.instanceID = instanceID; hd.types = types; } return(hd ?? new HierarchyData(name, instanceID, types, children)); }
public ScriptForgeStyles() { LoadFont(FONT_AWESOME_SEARCH_FILTER, ref m_FontAwesomeFont); LoadFont(TITLE_FONT_NAME, ref m_TitleFont); LoadFont(NORMAL_FONT_NAME, ref m_NormalFont); // Spacer spacer = new GUIStyle(GUI.skin.box); spacer.fixedHeight = 5f; spacer.fixedWidth = 0f; spacer.stretchWidth = true; // Title Bar Icon titleBarIcon = new GUIStyle(GUI.skin.label); titleBarIcon.fontSize = 35; titleBarIcon.fixedWidth = 50f; titleBarIcon.fontStyle = FontStyle.Normal; titleBarIcon.alignment = TextAnchor.MiddleCenter; titleBarIcon.wordWrap = false; titleBarIcon.clipping = TextClipping.Overflow; titleBarIcon.imagePosition = ImagePosition.TextOnly; titleBarIcon.font = fontAwesomeFont; titleBarIcon.normal.textColor = Color.white; // Title title = new GUIStyle(GUI.skin.label); title.fontSize = 30; title.fixedWidth = 50f; title.fixedHeight = 50f; title.fontStyle = FontStyle.Normal; title.alignment = TextAnchor.LowerLeft; title.wordWrap = false; title.contentOffset = new Vector2(-10f, 10f); title.clipping = TextClipping.Overflow; title.imagePosition = ImagePosition.TextOnly; title.font = rustFont; title.normal.textColor = Color.white; // Sub Title subTitle = new GUIStyle(GUI.skin.label); subTitle.fontSize = 15; subTitle.fixedWidth = 50f; subTitle.fontStyle = FontStyle.Normal; subTitle.alignment = TextAnchor.MiddleCenter; subTitle.wordWrap = false; subTitle.contentOffset = new Vector2(80, 40f); subTitle.clipping = TextClipping.Overflow; subTitle.imagePosition = ImagePosition.TextOnly; subTitle.font = rustFont; subTitle.normal.textColor = Color.white; // Button button = new GUIStyle(GUI.skin.button); button.fontSize = 20; button.fontStyle = FontStyle.Normal; button.alignment = TextAnchor.MiddleCenter; button.font = thapkieMGFont; button.fixedHeight = EditorGUIUtility.singleLineHeight * 2f; // Mini Button Left miniButtonLeft = new GUIStyle(EditorStyles.miniButtonLeft); miniButtonLeft.fontSize = 12; miniButtonLeft.fontStyle = FontStyle.Normal; miniButtonLeft.alignment = TextAnchor.MiddleCenter; miniButtonLeft.font = thapkieMGFont; buttonLeft = new GUIStyle(miniButtonLeft); buttonLeft.fontSize = 15; buttonLeft.fixedHeight = EditorGUIUtility.singleLineHeight * 2f; // Mini Button Middle miniButtonMiddle = new GUIStyle(EditorStyles.miniButtonMid); miniButtonMiddle.fontSize = 12; miniButtonMiddle.fontStyle = FontStyle.Normal; miniButtonMiddle.alignment = TextAnchor.MiddleCenter; miniButtonMiddle.font = thapkieMGFont; buttonMiddle = new GUIStyle(miniButtonMiddle); buttonMiddle.fontSize = 15; buttonMiddle.fixedHeight = EditorGUIUtility.singleLineHeight * 2f; // Mini Button Middle icon miniButtonLeftIcon = new GUIStyle(miniButtonLeft); miniButtonLeftIcon.fontSize = 13; miniButtonLeftIcon.stretchWidth = false; miniButtonLeftIcon.stretchHeight = true; miniButtonLeftIcon.font = m_FontAwesomeFont; // Mini Button Right miniButtonRight = new GUIStyle(EditorStyles.miniButtonRight); miniButtonRight.fontSize = 12; miniButtonRight.fontStyle = FontStyle.Normal; miniButtonRight.alignment = TextAnchor.MiddleCenter; miniButtonRight.font = thapkieMGFont; buttonRight = new GUIStyle(miniButtonRight); buttonRight.fontSize = 15; buttonRight.fixedHeight = EditorGUIUtility.singleLineHeight * 2f; // Widget Header Text widgetHeaderText = new GUIStyle(GUI.skin.label); widgetHeaderText.fontSize = 22; widgetHeaderText.alignment = TextAnchor.UpperLeft; widgetHeaderText.wordWrap = true; widgetHeaderText.richText = true; widgetHeaderText.contentOffset = new Vector2(8f, 1f); widgetHeaderText.font = rustFont; widgetHeaderIcon = new GUIStyle(widgetHeaderText); widgetHeaderIcon.fixedHeight = 28f; widgetHeaderIcon.fixedWidth = 28f; widgetHeaderIcon.font = fontAwesomeFont; widgetHeaderIcon.contentOffset = new Vector2(5, 2); scriptForgeIconSmall = new GUIStyle(); scriptForgeIconSmall.stretchWidth = true; scriptForgeIconSmall.stretchHeight = true; scriptForgeIconSmall.fixedHeight = 50; scriptForgeIconSmall.fixedWidth = 50; scriptForgeIconSmall.margin = new RectOffset(0, 0, 5, 5); // Icon Button fontAwesomeButton = new GUIStyle(GUI.skin.button); fontAwesomeButton.fontSize = 30; fontAwesomeButton.fontStyle = FontStyle.Normal; fontAwesomeButton.alignment = TextAnchor.MiddleCenter; fontAwesomeButton.wordWrap = false; fontAwesomeButton.clipping = TextClipping.Overflow; fontAwesomeButton.font = fontAwesomeFont; HierarchyProperty serach = new HierarchyProperty(HierarchyType.Assets); serach.SetSearchFilter("t:Texture ScriptForgeIcon", 0); serach.Next(null); if (serach.pptrValue != null) { scriptForgeIconSmall.normal.background = (Texture2D)serach.pptrValue; } }
private static void _SeprateScene(string path) { if (path.EndsWith("_add.unity")) { return; } string rootPath = "Assets/XSeperateScene/"; string name = path; int index = path.LastIndexOf("/"); if (index >= 0) { name = name.Substring(index + 1); } index = name.LastIndexOf("."); if (index >= 0) { name = name.Substring(0, index); } EditorSceneManager.OpenScene(path); GameObject go = GameObject.Find("Scene"); if (go != null) { //1.save as new scene string addpath = string.Format("{0}{1}_add.unity", rootPath, name); Scene addScene = EditorSceneManager.GetSceneByPath(addpath); EditorSceneManager.SaveScene(addScene); //2.save as old scene GameObject.DestroyImmediate(go); LightmapSettings.lightmaps = null; LightmapSettings.lightProbes = null; string origpath = string.Format("{0}{1}.unity", rootPath, name); Scene oriScene = EditorSceneManager.GetSceneByPath(origpath); EditorSceneManager.SaveScene(oriScene); addScene = EditorSceneManager.OpenScene(addpath); List <GameObject> gos = new List <GameObject>(); HierarchyProperty hp = new HierarchyProperty(HierarchyType.GameObjects); int[] expanded = new int[0]; while (hp.Next(expanded)) { gos.Add(hp.pptrValue as GameObject); } for (int i = gos.Count - 1; i >= 0; --i) { if (gos[i].name != "Scene") { GameObject.DestroyImmediate(gos[i]); } } StaticOcclusionCulling.Cancel(); EditorSceneManager.SaveScene(addScene, addpath); } else { LightmapSettings.lightmaps = null; LightmapSettings.lightProbes = null; string origpath = string.Format("{0}{1}.unity", rootPath, name); Scene oriScene = EditorSceneManager.GetSceneByPath(origpath); EditorSceneManager.SaveScene(oriScene); } }
HierarchyData CollectHierarchyData(ref bool hasNext, ref bool hasChanged, HierarchyData hd, HierarchyProperty hp) { var depth = hp.depth; var name = hp.name; var instanceID = hp.instanceID; List <HierarchyData> list = null; list = (hd == null || hd.children == null) ? new List <HierarchyData>() : hd.children; if (hp.hasChildren) { hasNext = hp.Next(null); var i = 0; while (hasNext && hp.depth > depth) { var go = EditorUtility.InstanceIDToObject(hp.instanceID); if (go == gameObject) { // skip children of EVR to prevent the display of EVR contents while (hp.Next(null) && hp.depth > depth + 1) { } name = hp.name; instanceID = hp.instanceID; } if (i >= list.Count) { list.Add(CollectHierarchyData(ref hasNext, ref hasChanged, null, hp)); hasChanged = true; } else if (list[i].instanceID != hp.instanceID) { list[i] = CollectHierarchyData(ref hasNext, ref hasChanged, null, hp); hasChanged = true; } else { list[i] = CollectHierarchyData(ref hasNext, ref hasChanged, list[i], hp); } if (hasNext) { hasNext = hp.Next(null); } i++; } if (i != list.Count) { list.RemoveRange(i, list.Count - i); hasChanged = true; } if (hasNext) { hp.Previous(null); } } else { list.Clear(); } List <HierarchyData> children = null; if (list.Count > 0) { children = list; } if (hd != null) { hd.children = children; hd.name = name; hd.instanceID = instanceID; } return(hd ?? new HierarchyData(name, instanceID, children)); }