Exemple #1
0
 void searchPropertyInternal(SearchJob job, SearchItem item, SerializedProperty prop, SerializedProperty iterator)
 {
     if (iterator.propertyType == typeField.PropertyType())
     {
         // Debug.Log("[SearchItemGlobal] Searching:"+iterator.propertyPath);
         if (typeField.ValueEqualsWithConditional(iterator))
         {
             if (item.subsearch != null)
             {
                 SearchItem subItem = (SearchItem)item.subsearch;
                 subItem.SubsearchProperty(job, prop);
             }
             else
             {
                 SearchResultProperty result = new SearchResultProperty(iterator, typeField.StringValueFor(iterator), job);
                 // If the prefab type is 'instance' then only add the
                 // search result if it is a modification to the original
                 // prefab.
                 // We iterate over prefab separately and the PrefabType will simply
                 // be 'Prefab' and we should handle that before we handle scenes.
                 if (result.pathInfo.prefabType == PrefabType.PrefabInstance)
                 {
                     if (job.options.searchType == SearchType.SearchAndReplace)
                     {
                         result.actionTaken = SearchAction.InstanceReplaced;
                     }
                     else
                     {
                         result.actionTaken = SearchAction.InstanceFound;
                     }
                     // if(item.subsearch == null && PrefabUtil.isInstanceModification(iterator))
                     // {
                     //Apply change, only if change already exists!
                     typeField.ReplaceProperty(job, iterator, result);
                     // }
                     job.MatchFound(result, item);
                 }
                 else
                 {
                     if (item.subsearch == null)
                     {
                         typeField.ReplaceProperty(job, iterator, result);
                     }
                     job.MatchFound(result, item);
                 }
             }
         }
     }
 }
Exemple #2
0
        public override void SearchObject(SearchJob job, SearchItem item, UnityEngine.Object obj)
        {
            if (obj is ScriptableObject)
            {
                ScriptableObject sObj = (ScriptableObject)obj;
                Type             t    = MonoScript.FromScriptableObject(sObj).GetClass();
                if (typeMatches(t))
                {
                    if (!showUnusedScripts)
                    {
                        SearchResult result = new SearchResult();
                        result.pathInfo = PathInfo.InitWithScriptableObject(sObj, job);
                        result.strRep   = t.Name;

                        if (job.options.searchType == SearchType.SearchAndReplace)
                        {
                            SerializedObject   so       = new SerializedObject(sObj);
                            SerializedProperty m_Script = so.FindProperty("m_Script");
                            if (replaceItem != null)
                            {
                                replaceItem.ReplaceProperty(job, m_Script, result);
                            }
                        }
                        job.MatchFound(result, item);
                    }
                }
            }
        }
Exemple #3
0
        public override void SearchGameObject(SearchJob job, GameObject go)
        {
            job.assetData.searchExecuted = true;
            //We only do this search if its a game object AND its a search (NOT a replace).
            if (searchAsGameObject != null && job.options.searchType == SearchType.Search && subsearch == null)
            {
                // if(searchAsGameObject == go)
                // {
                //   Debug.Log("[SearchItemGlobal] FOUND THING");
                // }
#if UNITY_2018_2 || UNITY_2018_3 || UNITY_2018_4
                UnityEngine.Object goPrefab = PrefabUtility.GetCorrespondingObjectFromSource(go);
#else
                UnityEngine.Object goPrefab = PrefabUtility.GetPrefabParent(go);
#endif

                // Debug.Log("[SearchItemGlobal] goPrefab:"+goPrefab);
                if (goPrefab != null && goPrefab == searchAsGameObject)
                {
                    SearchResult result = new SearchResult();
                    result.strRep      = "";
                    result.pathInfo    = PathInfo.GetPathInfo(go, job);
                    result.actionTaken = SearchAction.InstanceFound;
                    job.MatchFound(result, this);
                }
            }
            typeField.SearchGameObject(job, this, go);
        }
Exemple #4
0
        public override void SearchGameObject(SearchJob job, GameObject go)
        {
            job.assetData.searchExecuted = true;
            // Debug.Log("[SearchItemInstances] GO:"+go.name);
            PrefabType goType = PrefabUtility.GetPrefabType(go);

            if (goType == PrefabType.PrefabInstance)
            {
#if UNITY_2018_2 || UNITY_2018_3 || UNITY_2018_4
                UnityEngine.Object goPrefabObj = PrefabUtility.GetCorrespondingObjectFromSource(go);
#else
                UnityEngine.Object goPrefabObj = PrefabUtility.GetPrefabParent(go);
#endif
                GameObject root           = PrefabUtility.FindPrefabRoot(go);
                bool       isRootOfPrefab = root == go;
                if (isRootOfPrefab && goPrefabObj == objID.obj)
                {
                    //Instance found!
                    // Debug.Log("[SearchItemInstances] instance found!"+go.name);
                    SearchResult result = new SearchResult();
                    result.strRep      = "";
                    result.pathInfo    = PathInfo.GetPathInfo(go, job);
                    result.actionTaken = SearchAction.InstanceFound;
                    job.MatchFound(result, this);
                    replaceItem.ReplaceInstance(job, go, result);
                }
            }
        }
Exemple #5
0
 public override void OnAssetSearchEnd(SearchJob job, SearchItem item)
 {
     if (job.searchIncludesScripts && matchAssetMissingScript && assetMissingScript)
     {
         SearchResult result = new SearchResult();
         result.strRep      = job.assetData.assetPath;
         result.pathInfo    = PathInfo.GetPathInfo(AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(job.assetData.assetPath), job.assetData);
         result.actionTaken = SearchAction.AssetMissingScript;
         job.MatchFound(result, item);
     }
 }
Exemple #6
0
 public override void OnSearchEnd(SearchJob job, SearchItem item)
 {
     if (showUnusedScripts)
     {
         foreach (var kvp in typeHash)
         {
             ClassSearchInfo csi = kvp.Value;
             if (csi.numFound == 0)
             {
                 SearchResult result = new SearchResult();
                 result.pathInfo    = PathInfo.GetPathInfo(csi.script, job);
                 result.actionTaken = SearchAction.NotFound;
                 result.strRep      = kvp.Key.ToString();
                 job.MatchFound(result, item);
             }
         }
     }
 }
Exemple #7
0
        public override void SearchGameObject(SearchJob job, GameObject go)
        {
            job.assetData.searchExecuted = true;
            PrefabTypes goType = PrefabUtil.GetPrefabType(go);

            if (goType == PrefabTypes.PrefabInstance || goType == PrefabTypes.NestedPrefabInstance || goType == PrefabTypes.PrefabVariantInstance)
            {
                GameObject goPrefabObj = null;
#if UNITY_2018_3_OR_NEWER
                if (goType == PrefabTypes.PrefabInstance || goType == PrefabTypes.NestedPrefabInstance)
                {
                    // nested prefabs or normal instances means we should search for the *original* source.
                    // prefab variant instances will show up here as nestedprefab instances
                    // if the variants are in variants. :P
                    goPrefabObj = PrefabUtility.GetCorrespondingObjectFromOriginalSource(go);
                }
                else
                {
                    // PrefabVariantInstance means we need the corresponding source.
                    goPrefabObj = PrefabUtility.GetCorrespondingObjectFromSource(go);
                }
                GameObject root = go;
#else
                goPrefabObj = (GameObject)PrefabUtility.GetPrefabParent(go);
                GameObject root = PrefabUtility.FindPrefabRoot(go);
#endif
                bool isRootOfPrefab = root == go;
                if (isRootOfPrefab && goPrefabObj == objID.obj)
                {
                    //Instance found!
                    // Debug.Log("[SearchItemInstances] instance found!"+go.name);
                    SearchResult result = new SearchResult();
                    result.strRep      = "";
                    result.pathInfo    = PathInfo.GetPathInfo(go, job.assetData);
                    result.actionTaken = SearchAction.InstanceFound;
                    job.MatchFound(result, this);
                    replaceItem.ReplaceInstance(job, this, go, result);
                }
            }
        }
Exemple #8
0
 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);
                 }
             }
         }
     }
 }