Esempio n. 1
0
 public ValueReference(Object obj, object value, SceneAsset scene, string path)
 {
     Obj         = obj;
     Value       = value;
     Scene       = scene;
     Path        = path;
     ValueString = value == null ? "NULL" : value.ToString();
 }
Esempio n. 2
0
        public static void PerformActionInScenes(string progressBarTitle, Predicate <string> scenePathFilter, SceneProcessingAction action)
        {
            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                string originalScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().path;

                try
                {
                    string[] scenesGUIDs = AssetDatabase.FindAssets("t:Scene");

                    List <string> scenePaths = new List <string>();
                    for (int i = 0; i < scenesGUIDs.Length; i++)
                    {
                        string path = AssetDatabase.GUIDToAssetPath(scenesGUIDs[i]);
                        if (path.StartsWith("Assets/") && (scenePathFilter == null || scenePathFilter(path)))
                        {
                            scenePaths.Add(path);
                        }
                    }

                    for (int i = 0; i < scenePaths.Count; i++)
                    {
                        SceneAsset scene = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePaths[i]);

                        if (EditorUtility.DisplayCancelableProgressBar(progressBarTitle, "(" + (i + 1) + " / " + scenePaths.Count + ") " + scene.name, ((float)i) / scenePaths.Count))
                        {
                            break;
                        }


                        if (EditorSceneManager.OpenScene(scenePaths[i], OpenSceneMode.Single).IsValid())
                        {
                            action(scene, scenePaths[i]);
                        }
                    }

                    EditorUtility.ClearProgressBar();
                }
                catch (Exception e)
                {
                    UnityEngine.Debug.LogException(e);
                }
                finally
                {
                    EditorSceneManager.OpenScene(originalScene, OpenSceneMode.Single);
                    EditorUtility.ClearProgressBar();
                }
            }
        }
Esempio n. 3
0
        public static List <ValueReference> FindComponentFieldValuesInCurrentScene(Type type, FieldInfo field)
        {
            List <ValueReference> references = new List <ValueReference>();

            SceneAsset scene = GetCurrentScene();

            Object[] usages = Object.FindObjectsOfType(type);

            for (int i = 0; i < usages.Length; i++)
            {
                references.Add(new ValueReference(usages[i], field.GetValue(usages[i]), scene, (usages[i] as Component).gameObject.GetPath()));
            }

            return(references);
        }
Esempio n. 4
0
        public static List <AssetReference> FindPrefabInstancesInCurrentScene(GameObject prefab)
        {
            List <AssetReference> references = new List <AssetReference>();

            SceneAsset scene = GetCurrentScene();

            GameObject[] objects = Object.FindObjectsOfType <GameObject>();

            for (int i = 0; i < objects.Length; i++)
            {
                if (PrefabUtility.GetPrefabInstanceStatus(objects[i]) == PrefabInstanceStatus.Connected && PrefabUtility.GetCorrespondingObjectFromOriginalSource(objects[i]) == prefab)
                {
                    references.Add(new AssetReference(objects[i], scene, objects[i].GetPath()));
                }
            }

            return(references);
        }
Esempio n. 5
0
        public static void PerformActionInScenes(string progressBarTitle, IList <string> scenePaths, SceneProcessingAction action)
        {
            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                string originalScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().path;

                try
                {
                    for (int i = 0; i < scenePaths.Count; i++)
                    {
                        SceneAsset scene = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePaths[i]);

                        if (EditorUtility.DisplayCancelableProgressBar(progressBarTitle, "(" + (i + 1) + "/" + scenePaths.Count + ") " + scene.name, ((float)i) / scenePaths.Count))
                        {
                            break;
                        }


                        if (EditorSceneManager.OpenScene(scenePaths[i], OpenSceneMode.Single).IsValid())
                        {
                            action(scene, scenePaths[i]);
                        }
                    }

                    EditorUtility.ClearProgressBar();
                }
                catch (Exception e)
                {
                    UnityEngine.Debug.LogException(e);
                }
                finally
                {
                    EditorSceneManager.OpenScene(originalScene, OpenSceneMode.Single);
                    EditorUtility.ClearProgressBar();
                }
            }
        }
Esempio n. 6
0
        public void AsnycLoadLevel(string _levelName, OnLevelLoad onLoad = null)
        {
            if (isLoading)
            {
                return;
            }
            isLoading = true;
            if (null != sceneAsset)
            {
                sceneAsset.Release();
                sceneAsset = null;
            }
            levelName   = _levelName;
            this.onLoad = onLoad;
            bool isAdded = string.IsNullOrEmpty(levelName) || AppEnv.IsSceneInBuild(levelName);

                        #if UNITY_EDITOR
            if (!AppEnv.UseBundleInEditor && !isAdded)
            {
                //在编辑器里使用非bundle模式的场景,目前已知必须要在build setting里
                Debug.LogError("if use raw asset in editor,you must add scene to buildsetting");
                return;
            }
                        #endif
            if (isAdded)
            {
                StartCoroutine(LoadScene());
            }
            else
            {
                sceneAsset = new SceneAsset();
                sceneAsset.Load(levelName, () =>
                {
                    StartCoroutine(LoadScene(sceneAsset.asset));
                });
            }
        }
Esempio n. 7
0
 public AssetReference(Object obj, SceneAsset scene, string path)
 {
     Obj   = obj;
     Scene = scene;
     Path  = path;
 }