public static SearchItemSet PopulateFromDisk(string key) { SearchItemSet sis = null; string path = GetSearchPath(key); //Debug.Log("[SearchItemSet] path:" + path); try{ sis = (SearchItemSet)SerializationUtil.Deserialize(path); if (sis != null) { sis.OnDeserialization(); sis.SetPath(key); } }catch (System.Exception ex) { Debug.LogException(ex); } if (sis == null) { sis = new SearchItemSet(); sis.OnDeserialization(); sis.SetPath(key); sis.AddNew(key); return(sis); } else { return(sis); } }
public SearchItemSet Clone() { SearchItemSet copy = (SearchItemSet)SerializationUtil.Copy(this); copy.OnDeserialization(); return(copy); }
void saveAndClose(string name, SearchItemSet set, SearchOptions options) { SavedSearch ss = new SavedSearch(name, parent.currentSearch.Clone(), parent.searchOptions.Copy()); parent.SaveSearch(ss); Close(); }
public SearchJob(SearchItemSet s, SearchOptions o, SearchScopeData sc) { search = s; options = o; scope = sc; Execute(); }
public SearchResultSet(SearchItemSet searchSet) { for (int i = 0; i < 10; i++) { results.Add(null); } foreach (SearchItem item in searchSet.validatedItems) { results[item.sortIndex] = new SearchResultGroup(item); } }
static void replaceInstances(SearchJob parentJob, SearchItem item, GameObject oldValue, GameObject newValue) { SearchItemSet searchSet = new SearchItemSet(); searchSet.OnDeserialization(); searchSet.AddNew(Keys.Global, false); SearchItemGlobal searchItem = (SearchItemGlobal)searchSet.items[0]; searchItem.SetType("Object"); DynamicTypeObject dto = (DynamicTypeObject)searchItem.GetDTDFor(typeof(UnityEngine.Object)); dto.SearchSubObjects = true; dto.SetObject(oldValue); ReplaceItemObject replaceItem = (ReplaceItemObject)dto.ReplaceItem; replaceItem.SetObject(newValue); SearchOptions options = new SearchOptions(); options.searchType = SearchType.SearchAndReplace; // does this matter anymore since asset scope is now essentially defined by what assets are passed in? SearchScopeData searchScope = new SearchScopeData(ProjectScope.SpecificLocation, AssetScope.Prefabs, new ObjectID(AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(parentJob.assetData.assetPath)), false, parentJob.scope.loadPrefab); SearchJob subJob = new SearchJob(searchSet, options, searchScope); SearchAssetData assetData = parentJob.assetData.Clone(); subJob.AddAsset(assetData); subJob.Execute(); // Now that we've executed the job we have to save a list of all objects from search results, because as soon as // we swap out the new object, the old object's position may shift in the hierarchy, making the PathInfo stale. SearchResultGroup group = subJob.resultSet.results[searchItem.sortIndex]; List <UnityEngine.Object> resultObjects = new List <Object>(); foreach (SearchResult result in group.results) { UnityEngine.Object resultObj = EditorUtility.InstanceIDToObject(result.pathInfo.objectID); resultObjects.Add(resultObj); } UnityEngine.Object.DestroyImmediate(oldValue); // now that we've deleted the object, let's rebuild the objects. for (int i = 0; i < resultObjects.Count; i++) { SearchResult result = group.results[i]; result.pathInfo = PathInfo.GetPathInfo(resultObjects[i], assetData); } parentJob.AddResultsFromSubsearch(item, subJob.resultSet.results[searchItem.sortIndex]); }
public void LoadSearch(SavedSearch search) { SavedSearch newSearch = search.Clone(); currentSearch = newSearch.search; currentSearch.SetPath(Keys.SavedSearch); searchOptions = newSearch.options; #if !PSR_FULL searchOptions.searchType = SearchType.Search; #endif updateReplaceMode(); PersistCurrentSearch(); }
public SearchJob(SearchItemSet s, SearchOptions o, SearchScopeData sc) { search = s; options = o; scope = sc; foreach (string blacklistedType in blacklistedList) { Type t = Type.GetType(blacklistedType); if (t != null) { blacklistedTypes.Add(t); } } // this.searchAssets = searchAssets; // foreach(SearchAssetData asset in searchAssets) // { // searchAssetsData[asset.assetPath] = asset; // } }
public void PersistSearch(SearchItemSet search) { searchesToPersist.Add(search); persist = true; }
void OnGUI() { init(); // dirty flag means this only runs once. Instance = this; float topViewPercent = searchJob == null ? 1.0f : dividePercentY; bool canInteract = searchJob == null || searchJob.SearchStatus != SearchStatus.InProgress; GUI.enabled = canInteract; scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(position.height * topViewPercent)); GUILayout.BeginHorizontal(); CVS(); Event e = Event.current; bool searchWhilePlaying = !Application.isPlaying; #if PSR_FULL searchWhilePlaying = true; #endif if (e.type == EventType.KeyDown && searchWhilePlaying) { if (e.keyCode == KeyCode.Return && metaKeyDown(e) && !(e.shift)) { e.Use(); if (continueSearch()) { doSearch(); return;//searching wipes the layout!!! } } if (e.keyCode == KeyCode.Return && metaKeyDown(e) && e.shift && searchOptions.searchType == SearchType.SearchAndReplace) { e.Use(); if (continueSearch()) { doSearchAndReplace(); return;//searching wipes the layout!!! } } if (e.keyCode == KeyCode.Backspace && metaKeyDown(e) && e.shift) { e.Use(); searchJob = null; return;//searching wipes the layout!!! } } GUILayout.BeginHorizontal(); float lw = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = SRWindow.compactLabelWidth; List <GUIContent> searchLabels = new List <GUIContent>(); //searchLabels.AddRange(searchForOptionLabels); foreach (string label in searchForOptionLabels) { searchLabels.Add(SRLoc.GUI(label)); } searchLabels.Add(new GUIContent("------")); if (savedSearches.searches.Count > 0) { foreach (SavedSearch ss in savedSearches.searches) { searchLabels.Add(new GUIContent(ss.name)); } searchLabels.Add(new GUIContent("-------")); searchLabels.Add(new GUIContent("Edit Searches")); } searchLabels.Add(new GUIContent("Save Search")); int newSearchForIndex = EditorGUILayout.Popup(SRLoc.GUI("search.popup"), searchForIndex, searchLabels.ToArray()); if (newSearchForIndex != searchForIndex) { if (newSearchForIndex == 3) { // Ignore! This is a divider. } else { if (newSearchForIndex < 3) { searchForIndex = newSearchForIndex; EditorPrefs.SetInt(Keys.prefSearchFor, searchForIndex); //search is one of the normal persistent searches. currentSearch = searches[searchForIndex]; } else { // either loading a search, or saving the current search. if (newSearchForIndex == searchLabels.Count - 1) { //show save search window. childWindow = (SearchWindow)ScriptableObject.CreateInstance(typeof(SaveSearchWindow)); childWindow.parent = this; childWindow.ShowUtility(); } else if (newSearchForIndex == searchLabels.Count - 2) { childWindow = (SearchWindow)ScriptableObject.CreateInstance(typeof(LoadSearchWindow)); childWindow.parent = this; childWindow.ShowUtility(); } else { int savedSearchIndex = newSearchForIndex - 4; if (savedSearchIndex < savedSearches.searches.Count) { searchForIndex = newSearchForIndex; EditorPrefs.SetInt(Keys.prefSearchFor, searchForIndex); SavedSearch ss = savedSearches.searches[searchForIndex - 4]; LoadSearch(ss); } } } } } EditorGUIUtility.labelWidth = lw; // i love stateful gui! :( updateSearchType(); drawHelp(); GUILayout.EndHorizontal(); // GUILayout.BeginHorizontal(); // GUILayout.EndHorizontal(); CVE(); GUILayout.EndHorizontal(); // GUILayout.Space(10); GUILayout.BeginVertical(); currentSearch.Draw(searchOptions); GUI.enabled = canInteract && currentSearch.CanSearch(searchOptions) && searchWhilePlaying; //NOTE: whether we can search while the application is playing is controlled by the search scope. GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); CVS(); if (GUILayout.Button("Search", GUILayout.Width(200.0f))) { if (continueSearch()) { doSearch(); return; // We have to return immediately because all our guilayout is wiped } } #if PSR_FULL GUI.enabled = canInteract && currentSearch.CanSearchAndReplace(searchOptions) && searchWhilePlaying; //NOTE: whether we can search while the application is playing is controlled by the search scope. if (searchOptions.searchType == SearchType.SearchAndReplace) { if (GUILayout.Button("Search And Replace", GUILayout.Width(200.0f))) { if (continueSearch()) { doSearchAndReplace(); return; } } } #endif GUI.enabled = canInteract; CVE(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (searchJob == null) { GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }// else searchjob will draw it! GUILayout.EndVertical(); GUILayout.EndScrollView(); GUI.enabled = true; float dividerHeight = 7.0f; Color c = GUI.backgroundColor; if (resizing) { GUI.color = Color.green; } if (GUILayout.RepeatButton(thumb, dragDivider, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(dividerHeight) })) { resizing = true; } GUI.color = c; if (resizing) { float minSplitViewSize = 60.0f; // The smallest we will allow the 'split' to be sized. float maxY = Mathf.Min(SRWindow.Instance.position.height - minSplitViewSize, Event.current.mousePosition.y); float mouseY = Mathf.Max(minSplitViewSize, maxY); mouseY -= dividerHeight * 0.5f; dividePercentY = mouseY / SRWindow.Instance.position.height; Repaint(); if (Event.current.type == EventType.Used) { resizing = false; } } if (searchJob != null) { searchJob.Draw(); } GUILayout.Space(10); if (persist) { persist = false; // currentSearch.Persist(); foreach (SearchItemSet sis in searchesToPersist) { sis.Persist(); } } }
void init() { if (searchOptions == null) { _initialized = false; } if (!_initialized) { _initialized = true; Instance = this; searchType = new PopupData(0, new string[] { Keys.search, Keys.searchAndReplace }, Keys.prefSearchType, ""); searchType.boxPad = 10; int replacePref = EditorPrefs.GetInt(Keys.prefSearchType, 0); replaceMode = replacePref == 0 ? false : true; searchForIndex = EditorPrefs.GetInt(Keys.prefSearchFor, 0); //This throws errors if done in Ctor! yay. searches = new List <SearchItemSet>(); searchesToPersist = new HashSet <SearchItemSet>(); foreach (string searchKey in searchForOptions) { SearchItemSet s = SearchItemSet.PopulateFromDisk(searchKey); searches.Add(s); } SearchItemSet savedSearch = SearchItemSet.PopulateFromDisk(Keys.SavedSearch); searches.Add(savedSearch); searchOptions = SearchOptions.PopulateFromDisk(); searchOptions.searchType = replaceMode ? SearchType.SearchAndReplace : SearchType.Search; savedSearches = SavedSearches.PopulateFromDisk(); // now that we've loaded all potential searches, which one has the user // selected? if (searchForIndex < 3) { currentSearch = searches[searchForIndex]; } else { // If the index is above, then we have a saved search selected. The fourth // sis is the currently loaded saved search. currentSearch = searches[3]; } //EditorStyles does not exist in Constructor?? richTextStyle = new GUIStyle(EditorStyles.label); richTextStyle.richText = true; richTextStyle.wordWrap = true; searchBox = new GUIStyle(EditorStyles.helpBox); searchBox.padding = new RectOffset(10, 10, 10, 10); searchBoxDragHighlight = new GUIStyle(EditorStyles.helpBox); searchBoxDragHighlight.normal.background = EditorGUIUtility.FindTexture("BoxCollider2D Icon"); searchBoxDragHighlight.border = new RectOffset(10, 10, 10, 10); searchBoxDragHighlight.padding = new RectOffset(10, 10, 10, 10); searchInnerDepthBox = new GUIStyle(EditorStyles.inspectorFullWidthMargins); searchInnerDepthBox.padding = new RectOffset(0, 0, 0, 0); resultsBox = new GUIStyle(EditorStyles.helpBox); resultsBox.padding = new RectOffset(0, 0, 10, 10); divider = new GUIStyle("box"); divider.border.top = divider.border.bottom = 1; divider.margin.top = 10; dragDivider = new GUIStyle(); dragDivider.border = new RectOffset(1, 1, 1, 1); dragDivider.margin = new RectOffset(0, 0, 0, 0); dragDivider.alignment = TextAnchor.MiddleCenter; Texture2D thumbbg = (Texture2D)findObject(EditorGUIUtility.isProSkin ? "com.eh.searchandreplace.thumbbg" : "com.eh.searchandreplace.thumbbglight"); dragDivider.normal.background = thumbbg; Texture2D thumbTex = (Texture2D)findObject("com.eh.searchandreplace.thumb"); thumb = new GUIContent(thumbTex); dragDividerNormal = dragDivider.normal.background; plusButton = new GUIStyle(GUI.skin.button); plusButton.margin.top = 2; toolbarButton = new GUIStyle(EditorStyles.toolbarButton); toolbarButton.fixedHeight = 20; toolbarButton.padding = new RectOffset(0, 0, 2, 2); resultStyle1 = new GUIStyle(); resultStyle1.margin = new RectOffset(1, 1, 0, 0); float lightgray = EditorGUIUtility.isProSkin ? 0.22f : 0.8f; resultStyle1.normal.background = MakeTex(1, 1, new Color(lightgray, lightgray, lightgray)); resultStyle2 = new GUIStyle(); float gray = EditorGUIUtility.isProSkin ? 0.26f : 0.77f; resultStyle2.normal.background = MakeTex(1, 1, new Color(gray, gray, gray)); resultStyle2.margin = new RectOffset(1, 1, 0, 0); selectedStyle = new GUIStyle(); selectedStyle.margin = new RectOffset(1, 1, 0, 0); float selectGray = EditorGUIUtility.isProSkin ? 0.22f : 0.8f; float selectBlue = EditorGUIUtility.isProSkin ? 0.4f : 0.9f; selectedStyle.normal.background = MakeTex(1, 1, new Color(selectGray, selectBlue, selectGray)); swapToggle = new GUIStyle(); swapToggle.fixedWidth = 15; swapToggle.fixedHeight = 15; swapToggle.normal.background = (Texture2D)findObject("com.eh.swap"); swapToggle.hover.background = (Texture2D)findObject("com.eh.swap.hover"); swapToggle.margin = new RectOffset(0, 4, 2, 0); errorStyle = new GUIStyle(); errorStyle.normal.background = EditorGUIUtility.FindTexture("d_console.erroricon.sml"); errorStyle.fixedWidth = 17; errorStyle.fixedHeight = 15; errorStyle.margin = new RectOffset(0, 0, 0, 0); errorStyle.padding = new RectOffset(0, 0, 0, 0); olPlusPlus = new GUIStyle((GUIStyle)"OL Plus"); olPlusPlus.margin = new RectOffset(0, 0, 2, 0); olPlusPlus.fixedWidth = 15; olPlusPlus.fixedHeight = 15; olMinusMinus = new GUIStyle((GUIStyle)"OL Minus"); olMinusMinus.margin = new RectOffset(0, 0, 2, 0); olMinusMinus.fixedWidth = 15; olMinusMinus.fixedHeight = 15; optionsToggle = new GUIStyle(); optionsToggle.normal.background = (Texture2D)findObject("com.eh.options.normal"); optionsToggle.onNormal.background = (Texture2D)findObject("com.eh.options.onNormal"); optionsToggle.fixedWidth = 15; optionsToggle.fixedHeight = 15; #if UNITY_2018_3_OR_NEWER prefabIcon = EditorGUIUtility.FindTexture("Prefab Icon"); #else prefabIcon = EditorGUIUtility.FindTexture("PrefabNormal Icon"); #endif scriptIcon = EditorGUIUtility.FindTexture("cs Script Icon"); #if UNITY_2018_3_OR_NEWER goIcon = EditorGUIUtility.FindTexture("UnityEngine/GameObject Icon"); #else goIcon = EditorGUIUtility.FindTexture("GameObject Icon"); #endif if (goIcon == null) { goIcon = EditorGUIUtility.FindTexture("Prefab Icon"); } materialIcon = EditorGUIUtility.FindTexture("Material Icon"); sceneAssetIcon = EditorGUIUtility.FindTexture("SceneAsset Icon"); viewToolZoomIcon = EditorGUIUtility.FindTexture("d_ViewToolZoom"); Texture2D downArrowTex = (Texture2D)findObject("com.eh.down"); downArrow = new GUIStyle(); downArrow.margin = new RectOffset(0, 0, 3, 0); downArrow.normal.background = downArrowTex; downArrow.fixedWidth = 15; downArrow.fixedHeight = 15; Texture2D upArrowTex = (Texture2D)findObject("com.eh.up"); upArrow = new GUIStyle(); upArrow.margin = new RectOffset(0, 0, 3, 0); upArrow.normal.background = upArrowTex; upArrow.fixedWidth = 15; upArrow.fixedHeight = 15; edit = new GUIStyle(); edit.margin = new RectOffset(1, 4, 3, 0); edit.normal.background = (Texture2D)findObject("com.eh.edit"); edit.fixedWidth = 15; edit.fixedHeight = 15; save = new GUIStyle(); save.margin = new RectOffset(1, 1, 3, 0); save.normal.background = (Texture2D)findObject("com.eh.save"); save.fixedWidth = 15; save.fixedHeight = 15; rename = new GUIStyle(); rename.margin = new RectOffset(1, 1, 3, 0); rename.normal.background = (Texture2D)findObject("com.eh.rename"); rename.fixedWidth = 15; rename.fixedHeight = 15; load = new GUIStyle(); load.margin = new RectOffset(1, 1, 3, 0); load.normal.background = (Texture2D)findObject("com.eh.load"); load.fixedWidth = 15; load.fixedHeight = 15; loadSearch = new GUIStyle(); loadSearch.margin = new RectOffset(1, 5, 3, 0); loadSearch.normal.background = (Texture2D)findObject("com.eh.loadSearch"); loadSearch.fixedWidth = 15; loadSearch.fixedHeight = 15; } }