public override void SearchProperty(SearchJob job, SearchItem item, SerializedProperty prop) { //Time for some freakish magic! SerializedProperty iterator = prop.Copy(); while (iterator.NextVisible(true)) { if (typeField.PropertyType() == iterator.propertyType) { if (isSearchByName) { // path = prop.propertyPath + .data[x].second var path = iterator.propertyPath; // path = data[x].second path = path.Substring(prop.propertyPath.Length + 1); // path = data[x] const string endOfPath = "]."; path = path.Substring(0, path.LastIndexOf(endOfPath) + endOfPath.Length); if (prop.FindPropertyRelative(path + "first").stringValue != searchByNameValue) { continue; } } //might need to add a guard against collections or something? typeField.SearchProperty(job, item, iterator); } } // iterator.Next(true); // iterator.Next(true); // int count = iterator.intValue; // for(int i=0;i < count; i++) // { // iterator.Next(false); // typeField.SearchProperty(job, item, iterator); // } }
public override void SearchGameObject(SearchJob job, SearchItem item, GameObject go) { //Make sure we don't attempt to search for ScriptableObjects in GameObjects, but allow null search. if (searchValue.isDirectory || typeof(Component).IsAssignableFrom(type) || type == null) { Component[] components = null; if (searchValue.isDirectory || type == null) { components = go.GetComponents <Component>(); } else { components = go.GetComponents(type); } foreach (Component c in components) { if (c == null) { if (type == null) { SearchResult result = new SearchResult(); result.pathInfo = PathInfo.InitWithComponent(c, go, job); result.strRep = "Missing Component"; result.actionTaken = SearchAction.Found; job.MatchFound(result, item); } else { } continue; } Type cType = c.GetType(); //The above GetComponents Calls will include inherited children. if (typeMatches(cType)) { if (!showUnusedScripts) { SearchResult result = new SearchResult(); result.pathInfo = PathInfo.InitWithComponent(c, go, job); result.strRep = cType.Name; result.actionTaken = SearchAction.Found; if (PrefabUtil.isInPrefabInstance(c)) { //Don't modify monoscripts in prefabs!!! } else { if (job.options.searchType == SearchType.SearchAndReplace) { SerializedObject so = new SerializedObject(c); SerializedProperty m_Script = so.FindProperty("m_Script"); if (replaceItem != null) { replaceItem.ReplaceProperty(job, m_Script, result); } } } job.MatchFound(result, item); } } } } }
public override void Draw(SearchOptions options) { GUIStyle boxStyle = depth == 0 ? SRWindow.searchBox : SRWindow.searchInnerDepthBox; GUILayout.BeginHorizontal(boxStyle); GUILayout.BeginVertical(); SRWindow.Instance.CVS(); drawSubsearch(); GUILayout.BeginHorizontal(); float lw = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = SRWindow.compactLabelWidth; string typeLabel = depth == 0 ? "Type:" : "Subtype:"; string[] tOptions = depth == 0 ? typeOptions : subTypeOptions; int newIndex = EditorGUILayout.Popup(typeLabel, typeIndex, tOptions, GUILayout.MaxWidth(SRWindow.Instance.position.width - 40)); EditorGUIUtility.labelWidth = lw; // i love stateful gui! :( if (newIndex != typeIndex) { typeIndex = newIndex; initializationContext = new InitializationContext(typeHash[tOptions[typeIndex]]); typeField.SetType(initializationContext); SRWindow.Instance.PersistCurrentSearch(); } if (depth == 0) { if (typeField.hasAdvancedOptions()) { bool newShowMoreOptions = EditorGUILayout.Toggle(showMoreOptions, SRWindow.optionsToggle, GUILayout.Width(15)); if (newShowMoreOptions != showMoreOptions) { showMoreOptions = newShowMoreOptions; typeField.showMoreOptions = showMoreOptions; SRWindow.Instance.PersistCurrentSearch(); } } } else { // Debug.Log("[SearchItemGlobal] depth:"+depth); //show more options is controlled by this search item's parent. } GUILayout.EndHorizontal(); typeField.showMoreOptions = showMoreOptions; SearchOptions typeFieldOptions = options.Copy(); if (subsearch != null) { typeFieldOptions.searchType = SearchType.Search; } typeField.Draw(typeFieldOptions); if (depth == 0) { if (subsearch != null) { SearchItem item = (SearchItem)subsearch; item.Draw(options); } drawAddRemoveButtons(); } GUILayout.EndVertical(); SRWindow.Instance.CVE(); GUILayout.EndHorizontal(); }
public void SearchProperty(SearchJob job, SearchItem item, SerializedProperty prop) { bool onlyVisible = !AnimationUtil.isAnimationObject(prop.serializedObject.targetObject); bool isScene = job.assetData.assetScope == AssetScope.Scenes; SerializedProperty iterator = prop.Copy(); SerializedProperty endProperty = null; if (depth == 0) { } else { endProperty = iterator.GetEndProperty(); } // if(endProperty != null) // { // Debug.Log("[SearchItemGlobal] STARTING on "+iterator.propertyPath + " ENDING on "+endProperty.propertyPath); // } while (Next(iterator, onlyVisible)) { if (ignorePropertyOfType(iterator)) { continue; } if (endProperty != null && SerializedProperty.EqualContents(iterator, endProperty)) { return; } // Its possible that we may have sub-objects that are serialized // scriptable objects within a scene. These aren't scriptable objects // on disk, and so we need to create a SerializedObject representation // and go a bit deeper. if (isScene) { if (iterator.propertyType == SerializedPropertyType.ObjectReference && iterator.objectReferenceValue is ScriptableObject) { string path = AssetDatabase.GetAssetPath(iterator.objectReferenceValue.GetInstanceID()); if (path == "") { // Debug.Log("[SearchItemGlobal] found scriptable object serialized within a scene."+iterator.propertyPath); SerializedObject so = new SerializedObject(iterator.objectReferenceValue); recursiveDepth++; if (recursiveDepth < 100) { string internalID = job.assetData.assetPath + so.targetObject.GetInstanceID(); SearchAssetData internalObjectData = null; if (!job.searchAssetsData.TryGetValue(internalID, out internalObjectData)) { // Debug.Log("Searching:"+ iterator.propertyPath + " " +so.targetObject.GetInstanceID()); job.addInternalAsset(job.assetData.assetPath, so.targetObject.GetInstanceID()); SearchProperty(job, item, so.GetIterator()); } // else{ // Debug.Log("Already searched this internal object:"+so.targetObject.GetInstanceID()); // } } else { // hit recursive depth! Debug.Log("[Search & Replace] Recursive depth hit!"); } recursiveDepth--; } } } searchPropertyInternal(job, item, prop, iterator); } if (typeHidesName(prop.serializedObject.targetObject)) { SerializedProperty nameProp = prop.serializedObject.FindProperty("m_Name"); searchPropertyInternal(job, item, prop, nameProp); } }
public void duplicateSearchItem(SearchItem item) { currentSearch.AddCopy(item); }
public void RemoveSearchItem(SearchItem item) { currentSearch.Remove(item, true); PersistCurrentSearch(); }
public void Remove(SearchItem item, bool immediately) { itemsToRemove.Add(item); }
public void AddNew(SearchItem item) { item.OnDeserialization(); //reduces the need for redundant ctor init. items.Add(item); sortItems(); }
public override void Draw(SearchOptions options) { GUILayout.BeginHorizontal(SRWindow.searchBox); // 1 GUILayout.BeginVertical(); drawSubsearch(); GUILayout.BeginHorizontal(); Rect r = EditorGUILayout.BeginHorizontal(); Event e = Event.current; bool acceptingDrag = (e.type == EventType.DragUpdated || e.type == EventType.DragPerform) && r.Contains(e.mousePosition); if (acceptingDrag) { if (DragAndDrop.objectReferences.Length == 1) { UnityEngine.Object firstObj = DragAndDrop.objectReferences[0]; SRWindow.Instance.Repaint(); DragAndDrop.AcceptDrag(); DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (e.type == EventType.DragPerform) { draggedObj = firstObj; } } else { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } } string dragText = null; if (objID.obj != null) { if (objID.obj is MonoScript) { MonoScript m = (MonoScript)objID.obj; dragText = "Currently searching " + m.GetClass().Name + "s."; } else { dragText = "Currently searching " + objID.obj.GetType().Name + "s."; } dragText += "\n(Drag an object here to change search)"; } else { dragText = "Drag an object here."; } if (r.Contains(e.mousePosition) && DragAndDrop.visualMode == DragAndDropVisualMode.Link) { GUILayout.BeginVertical(SRWindow.searchBoxDragHighlight); GUILayout.Label(new GUIContent(dragText), SRWindow.richTextStyle); GUILayout.EndVertical(); } else { GUILayout.BeginVertical(SRWindow.searchBox); GUILayout.Label(new GUIContent(dragText), SRWindow.richTextStyle); GUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); if (propertyCriteria.hasAdvancedOptions()) { bool newShowMoreOptions = EditorGUILayout.Toggle(showMoreOptions, SRWindow.optionsToggle, GUILayout.Width(15)); if (newShowMoreOptions != showMoreOptions) { showMoreOptions = newShowMoreOptions; propertyCriteria.showMoreOptions = showMoreOptions; SRWindow.Instance.PersistCurrentSearch(); } } GUILayout.EndHorizontal(); if (objID.obj != null) { string typeInfo = ""; if (searchProperty.HasOptions()) { typeInfo = "Searching the " + searchProperty.fieldData.objectType.Name + " property <b>" + searchProperty.fieldData.fieldName + propertyCriteria.StringValueWithConditional() + "</b>"; } string warningInfo = ""; PrefabType pType = PrefabUtility.GetPrefabType(objID.obj); if (pType == PrefabType.None) { if (objID.obj is GameObject || objID.obj is Component) { warningInfo = "Referencing a scene component, your search will not be saved on scene change."; } else if (SRWindow.Instance.isSearchingInScene() && !SRWindow.Instance.isSearchingDependencies()) { warningInfo = "Searching in a scene but this is not a scene object. No results will be found."; } } string ssw = subsearchWarning(); if (ssw != string.Empty) { warningInfo += " " + ssw; } if (warningInfo.Length > 0) { EditorGUILayout.HelpBox(warningInfo, MessageType.Warning); } if (typeInfo.Length > 0) { EditorGUILayout.LabelField(typeInfo, SRWindow.richTextStyle); } searchProperty.Draw(); if (searchProperty.HasOptions()) { initializationContext.updateFieldData(searchProperty.fieldData); propertyCriteria.SetType(initializationContext); initializationContext.forceUpdate = false; SearchOptions typeFieldOptions = options.Copy(); if (subsearch != null) { typeFieldOptions.searchType = SearchType.Search; } propertyCriteria.Draw(typeFieldOptions); } } if (subsearch != null) { SearchItem child = (SearchItem)subsearch; child.Draw(options); } drawAddRemoveButtons(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); // 1 if (e.type == EventType.DragExited && draggedObj != null && objID.obj != draggedObj) { ObjectUtil.ValidateAndAssign(draggedObj, objID, searchProperty, ref initializationContext); draggedObj = null; propertyCriteria.SetType(initializationContext); } }
public override void SearchProperty(SearchJob job, SearchItem item, SerializedProperty prop) { subField.SearchProperty(job, item, prop); }
public void SearchProperty(SearchJob job, SearchItem item, SerializedProperty prop) { }
public override void OnAssetSearchBegin(SearchJob job, SearchItem item) { assetMissingScript = true; }
public SearchResultGroup(SearchItem si) { //don't keep a ref to search item! Copy the data we are interested in to this object. groupName = si.GetDescription(); }