public void OnAssetSearchBegin(SearchJob job)
 {
     foreach (SearchItem item in validatedItems)
     {
         item.OnAssetSearchBegin(job);
     }
 }
Example #2
0
        public static PathInfo InitWithScriptableObject(ScriptableObject so, SearchJob job)
        {
            PathInfo pi = GetPathInfo(so, job);

            pi.objectPath = "";
            return(pi);
        }
Example #3
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);
                }
            }
        }
Example #4
0
        public override bool caresAboutAsset(SearchJob job)
        {
            if (job.scope.projectScope == ProjectScope.CurrentSelection)
            {
                return(true);
            }
            if (job.scope.projectScope == ProjectScope.SpecificLocation)
            {
                if (job.scope.scopeObj.isDirectory)
                {
                    return(true);
                }
                if (job.scope.scopeObj.obj == null)
                {
                    return(false);
                }
                return(job.scope.scopeObj.obj is GameObject);
            }

            if ((job.assetData.assetScope & AssetScope.Scenes) == AssetScope.Scenes)
            {
                //ok, we're searching scenes or prefab stages....
                return(job.assetData.assetExtension == ".unity" || job.assetData.assetExtension == ".prefab");
            }

            return(false);
        }
Example #5
0
 public void SearchGameObject(SearchJob job, GameObject go)
 {
     foreach (SearchItem item in validatedItems)
     {
         item.SearchGameObject(job, go);
     }
 }
Example #6
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);
                    }
                }
            }
        }
Example #7
0
 public void SearchProperty(SearchJob job, SearchItem item, SerializedProperty prop)
 {
     if (typeData != null)
     {
         typeData.SearchProperty(job, item, prop);
     }
 }
    protected override void replace(SearchJob job, SerializedProperty prop, SearchResult result)
    {
#if PSR_FULL
      if(prop.name == "m_Script")
      {
        if(replaceValue.obj == null)
        {
          //don't do it.
          result.actionTaken = SearchAction.Error;
          result.replaceStrRep = "(null)";
          result.error = "Cannot set a MonoBehaviour's Script to null.";
          return;
        }
      }
      if(typeof(Component).IsAssignableFrom(type))
      {
        GameObject go = ObjectUtil.GetGameObject(prop.serializedObject.targetObject);

        UnityEngine.Object replaceVal = go.GetComponent(type);
        prop.objectReferenceValue = replaceVal;
        // prop.objectReferenceValue = replaceValue.obj;
        string objName = replaceVal == null ? "(null)" : replaceVal.ToString();
        result.replaceStrRep = objName;
      }
#endif 

    }
Example #9
0
        public static void SwapPrefab(SearchJob job, SearchResult result, GameObject gameObjToSwap, GameObject prefab, bool updateTransform, bool rename)
        {
            Transform swapParent = gameObjToSwap.transform.parent;
            int       index      = gameObjToSwap.transform.GetSiblingIndex();

            result.replaceStrRep = prefab.name;
            result.strRep        = gameObjToSwap.name;
            // Debug.Log("[ReplaceItemSwapObject] Instantiating:"  +prefab, prefab);
            GameObject newObj = PrefabUtility.InstantiatePrefab(prefab) as GameObject;

            if (newObj != null)
            {
                newObj.transform.parent = swapParent;
                newObj.transform.SetSiblingIndex(index);
                Transform oldT = gameObjToSwap.transform;
                if (updateTransform)
                {
                    newObj.transform.rotation      = oldT.rotation;
                    newObj.transform.localPosition = oldT.localPosition;
                    newObj.transform.localScale    = oldT.localScale;
                }
                if (rename)
                {
                    newObj.name = gameObjToSwap.name;
                }
                result.pathInfo = PathInfo.GetPathInfo(newObj, job);

                UnityEngine.Object.DestroyImmediate(gameObjToSwap);
            }
            else
            {
                Debug.Log("[Search & Replace] No object instantiated...hrm!");
            }
        }
Example #10
0
 public void SearchObject(SearchJob job, UnityEngine.Object obj)
 {
     foreach (SearchItem item in validatedItems)
     {
         item.SearchObject(job, obj);
     }
 }
Example #11
0
 public virtual void SearchGameObject(SearchJob job, SearchItem item, GameObject go)
 {
     if (typeData != null)
     {
         typeData.SearchGameObject(job, item, go);
     }
 }
Example #12
0
 public virtual void SearchObject(SearchJob job, SearchItem item, UnityEngine.Object obj)
 {
     if (typeData != null)
     {
         typeData.SearchObject(job, item, obj);
     }
 }
Example #13
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);
        }
Example #14
0
 public void OnSearchEnd(SearchJob job, SearchItem item)
 {
     if (typeData != null)
     {
         typeData.OnSearchEnd(job, item);
     }
 }
Example #15
0
    protected override void replace(SearchJob job, SerializedProperty prop, SearchResult result)
    {
#if PSR_FULL
      if(prop.name == "m_Script")
      {
        prop.objectReferenceValue = replaceValue.obj;
        result.replaceStrRep = type.Name;
        prop.serializedObject.ApplyModifiedProperties();
        result.actionTaken = SearchAction.Replaced;
      }else{
        bool isScript = typeof(ScriptableObject).IsAssignableFrom(type);
        if(isScript)
        {
          UnityEngine.Object obj = prop.objectReferenceValue;
          string path = AssetDatabase.GetAssetPath(obj.GetInstanceID());
          if(path == "")
          {
            // It looks like this is a scriptable object that is serialized within
            // another object and doesn't have a specific location on disk.
            SerializedObject so = new SerializedObject(obj);
            SerializedProperty m_Script = so.FindProperty("m_Script");
            m_Script.objectReferenceValue = replaceValue.obj;
            result.replaceStrRep = type.Name;
            so.ApplyModifiedProperties();
          }else{
            result.actionTaken = SearchAction.Ignored;
          }
        }else{
          result.actionTaken = SearchAction.InstanceFound;
        }
      }

#endif
    }
Example #16
0
        protected override void replace(SearchJob job, SerializedProperty prop, SearchResult result)
        {
#if PSR_FULL
            prop.boolValue       = replaceValue;
            result.replaceStrRep = replaceValue.ToString();
#endif
        }
Example #17
0
        public override void ProcessAsset(SearchJob job)
        {
#if UNITY_2018_3_OR_NEWER
            PrefabStage stage = PrefabStageUtility.GetPrefabStage(sceneObjects[0]);
            if (stage != null)
            {
                isInPrefabStage = true;
            }
#endif

            roots = sceneObjects.ToArray();

            job.OnAssetSearchBegin();
            foreach (GameObject root in roots)
            {
                job.searchGameObject(root);
            }

#if UNITY_2018_3_OR_NEWER
            if (assetIsDirty && isInPrefabStage)
            {
                EditorSceneManager.MarkSceneDirty(stage.scene);
            }
#endif
        }
Example #18
0
 public void SearchProperty(SearchJob job, SerializedProperty prop)
 {
     foreach (SearchItem item in validatedItems)
     {
         item.SearchProperty(job, prop);
     }
 }
Example #19
0
 public void OnSearchEnd(SearchJob job)
 {
     foreach (SearchItem item in validatedItems)
     {
         item.OnSearchEnd(job);
     }
 }
Example #20
0
 public void OnAssetSearchBegin(SearchJob job, SearchItem item)
 {
     if (typeData != null)
     {
         typeData.OnAssetSearchBegin(job, item);
     }
 }
Example #21
0
 public override bool caresAboutAsset(SearchJob job)
 {
     if (job.scope.projectScope != ProjectScope.EntireProject && job.scope.searchDependencies)
     {
         return(true);
     }
     return((searchScope & job.assetData.assetScope) != AssetScope.None);
 }
Example #22
0
        public void ReplaceProperty(SearchJob job, SerializedProperty prop, SearchResult result)
        {
#if PSR_FULL
            if (typeData != null)
            {
                typeData.ReplaceProperty(job, prop, result);
            }
#endif
        }
Example #23
0
 private void doSearchAndReplace()
 {
     if (currentSearch.CanSearchAndReplace(searchOptions))
     {
         SearchOptions options = searchOptions.Copy();
         options.searchType = SearchType.SearchAndReplace;
         searchJob          = new SearchJob(currentSearch, options, currentSearch.searchScope.ToData(options));
     }
 }
Example #24
0
 public SceneSubJob(SearchJob j, AssetScope sc, string[] allAssets, string[] s) : base(j, sc, allAssets, s, false)
 {
     sceneSetups = EditorSceneManager.GetSceneManagerSetup();
     foreach (SceneSetup sceneSetup in sceneSetups)
     {
         loadScenesHash[sceneSetup.path] = sceneSetup;
         // Debug.Log("[SceneSubJob] scene:"+sceneSetup.path);
     }
 }
        protected override void replace(SearchJob job, SerializedProperty prop, SearchResult result)
        {
#if PSR_FULL
            Vector2 v2 = prop.vector2Value;
            v2.x = xField.Replace(v2.x);
            v2.y = yField.Replace(v2.y);
            prop.vector2Value    = v2;
            result.replaceStrRep = v2.ToString();
#endif
        }
Example #26
0
 public override bool caresAboutAsset(SearchJob job)
 {
     //we only care about scenes, because that is only where instances can live.
     if ((job.assetData.assetScope & AssetScope.Scenes) == AssetScope.Scenes)
     {
         //ok, we're searching scenes...
         return(job.assetData.assetExtension == ".unity");
     }
     return(false);
 }
Example #27
0
 private void doSearch()
 {
     // Just in case I'm wrapping this!
     if (currentSearch.CanSearch(searchOptions))
     {
         SearchOptions options = searchOptions.Copy();
         options.searchType = SearchType.Search;
         searchJob          = new SearchJob(currentSearch, options, currentSearch.searchScope.ToData(options));
     }
 }
        public override void ProcessAsset(SearchJob job)
        {
            ScriptableObject root = (ScriptableObject)AssetDatabase.LoadAssetAtPath(assetPath, typeof(ScriptableObject));

            if (root != null)
            {
                job.OnAssetSearchBegin();
                job.searchObject(root); // todo: cache for subjobs?
                job.OnAssetSearchEnd();
            }
        }
        protected override void replace(SearchJob job, SerializedProperty prop, SearchResult result)
        {
#if PSR_FULL
            Vector3 v3 = prop.vector3Value;
            v3.x = xField.Replace(v3.x);
            v3.y = yField.Replace(v3.y);
            v3.z = zField.Replace(v3.z);
            prop.vector3Value    = v3;
            result.replaceStrRep = v3.ToString();
#endif
        }
Example #30
0
 public override void ProcessAsset(SearchJob job)
 {
     foreach (GameObject root in roots)
     {
         job.searchGameObject(root);
     }
     if (assetIsDirty)
     {
         EditorSceneManager.MarkSceneDirty(scene);
     }
 }