public static IEnumerator CreateRootFolderData(HashSet <string> assetTypes, Action <FolderData> callback) { var hp = new HierarchyProperty(HierarchyType.Assets); hp.SetSearchFilter("t:object", 0); var folderStack = new Stack <FolderData>(); var folder = new FolderData(hp.name, hp.guid.GetHashCode(), hp.depth); while (hp.Next(null)) { while (hp.depth <= folder.m_Depth) { folder = folderStack.Pop(); } if (hp.isFolder) { var folderList = folder.m_Children; if (folderList == null) { folderList = new List <FolderData>(); folder.m_Children = folderList; } folderStack.Push(folder); folder = new FolderData(hp.name, hp.guid.GetHashCode(), hp.depth); folderList.Add(folder); } else if (hp.isMainRepresentation) // Ignore sub-assets (mixer children, terrain splats, etc.) { var assetList = folder.m_Assets; if (assetList == null) { assetList = new List <AssetData>(); folder.m_Assets = assetList; } assetList.Add(CreateAssetData(hp, assetTypes)); } // Spend a minimum amount of time in this function, and if we have extra time in the frame, use it var time = Time.realtimeSinceStartup; if (time - s_ProjectFolderLoadYieldTime > k_MaxFrameTime && time - s_ProjectFolderLoadStartTime > k_MinFrameTime) { s_ProjectFolderLoadYieldTime = time; yield return(null); s_ProjectFolderLoadStartTime = time; } } while (folderStack.Count > 0) { folder = folderStack.Pop(); } callback(folder); }
private FolderData CreateFolderData(HashSet <string> assetTypes, HierarchyProperty hp = null) { if (hp == null) { hp = new HierarchyProperty(HierarchyType.Assets); hp.SetSearchFilter("t:object", 0); } var name = hp.name; var depth = hp.depth; var folderList = new List <FolderData>(); var assetList = new List <AssetData>(); while (hp.Next(null) && hp.depth > depth) { if (hp.isFolder) { folderList.Add(CreateFolderData(assetTypes, hp)); } else if (hp.isMainRepresentation) // Ignore sub-assets (mixer children, terrain splats, etc.) { assetList.Add(CreateAssetData(assetTypes, hp)); } } hp.Previous(null); return(new FolderData(name, folderList.Count > 0 ? folderList.ToArray() : null, assetList.ToArray())); }
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(); } }
void DoObjectSearchInChild(Transform[] objects, string filter) { var props = new HierarchyProperty(HierarchyType.GameObjects); props.SetSearchFilter(filter, 0); props.Reset(); while (props.Next(null)) { if (res.Count >= kMaxLists) { return; } var obj = ((GameObject)EditorUtility.InstanceIDToObject(props.instanceID)); if (!obj || (objects.Length > 0 && !objects.Any(x => x && obj.transform.IsChildOf(x)))) { continue; } res.Add(new ID() { name = props.name, gui = new GUIContent(props.name, AssetPreview.GetMiniThumbnail(props.pptrValue)), obj = props.instanceID }); } }
void DoComponentSearch(string filter) { InitTypeIndexing(); var types = components.Where((x) => StringContains(x.name, filter)); var props = new HierarchyProperty(HierarchyType.GameObjects); foreach (var type in types) { props.SetSearchFilter("t:" + type.name, 0); props.Reset(); while (props.Next(null)) { if (res.Count >= kMaxLists) { return; } if (!res.Any((x) => props.instanceID == (int)x.obj)) { res.Add(new ID() { name = props.name, gui = new GUIContent(props.name, AssetPreview.GetMiniThumbnail( (props.pptrValue as GameObject).GetComponent(type.type))), obj = props.instanceID }); } } } }
void DoObjectSubstractiveSearch(string filter) { var sel = Selection.instanceIDs; if (sel.Length == 0) { return; } var props = new HierarchyProperty(HierarchyType.GameObjects); props.SetSearchFilter(filter, 0); props.Reset(); while (props.Next(null)) { if (res.Count >= kMaxLists) { return; } if (sel.Contains(props.instanceID)) { res.Add(new ID() { name = props.name, gui = new GUIContent(props.name, AssetPreview.GetMiniThumbnail(props.pptrValue)), obj = props.instanceID }); } } }
static void SeeAssetsInPrefab(Object prefab, string asset) { GameObject obj = GameObject.Instantiate(prefab) as GameObject; obj.transform.parent = Parent; HierarchyProperty h = new HierarchyProperty(HierarchyType.Assets); h.SetSearchFilter("x", 0); }
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())); } }
IEnumerator CreateFolderData(Action <FolderData, bool> callback, HashSet <string> assetTypes, bool hasNext = true, HierarchyProperty hp = null) { if (hp == null) { hp = new HierarchyProperty(HierarchyType.Assets); hp.SetSearchFilter("t:object", 0); } var name = hp.name; var guid = hp.guid; var depth = hp.depth; var folderList = new List <FolderData>(); var assetList = new List <AssetData>(); if (hasNext) { hasNext = hp.Next(null); while (hasNext && hp.depth > depth) { if (hp.isFolder) { yield return(StartCoroutine(CreateFolderData((data, next) => { folderList.Add(data); hasNext = next; }, assetTypes, hasNext, hp))); } else if (hp.isMainRepresentation) // Ignore sub-assets (mixer children, terrain splats, etc.) { assetList.Add(CreateAssetData(hp, assetTypes)); } if (hasNext) { hasNext = hp.Next(null); } // Spend a minimum amount of time in this function, and if we have extra time in the frame, use it if (Time.realtimeSinceStartup - m_ProjectFolderLoadYieldTime > k_MaxFrameTime && Time.realtimeSinceStartup - m_ProjectFolderLoadStartTime > k_MinProjectFolderLoadTime) { m_ProjectFolderLoadYieldTime = Time.realtimeSinceStartup; yield return(null); m_ProjectFolderLoadStartTime = Time.realtimeSinceStartup; } } if (hasNext) { hp.Previous(null); } } callback(new FolderData(name, folderList.Count > 0 ? folderList : null, assetList, guid), hasNext); }
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); }
/// <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; } } }
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 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; } }