Пример #1
0
        public void OnGUI()
        {
            if (GUILayout.Button("Run"))
            {
                GUI.FocusControl("");
                ProcessObjects();
                GUIUtility.ExitGUI();
                return;
            }
            EditorGUILayout.Space();

            if (r.Count > 0)
            {
                scroll = EditorGUILayout.BeginScrollView(scroll);
                {
                    foreach (Info nfo in r)
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            if (GUILayout.Button("*", GUILayout.Width(25)))
                            {
                                if (!string.IsNullOrEmpty(nfo.scene))
                                {
                                    if (RPGEditorGlobal.SaveCurrentSceneIfUserWantsTo())
                                    {
                                        if (RPGEditorGlobal.OpenScene(nfo.scene))
                                        {
                                            GameObject go = GameObject.Find(nfo.objName);
                                            EditorGUIUtility.PingObject(go);
                                        }
                                    }
                                }
                                else
                                {
                                    EditorGUIUtility.PingObject(nfo.mainObj);
                                }
                            }

                            GUILayout.Label(nfo.path);
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.EndScrollView();
            }

            else if (hasRun)
            {
                GUILayout.Label("All good");
            }
        }
Пример #2
0
        private void ProcessObjects()
        {
            string currScene = RPGEditorGlobal.CurrentScene();

            if (!RPGEditorGlobal.SaveCurrentSceneIfUserWantsTo())
            {
                return;
            }

            r = new List <Info>();
            string progressbarTitle = "Please wait";
            string progressbarInfo  = "Searching ...";

            EditorUtility.DisplayProgressBar(progressbarTitle, progressbarInfo, 0f);

            // First look in all prefabs
            progressbarInfo = "Looking in Prefabs ...";
            DirectoryInfo dir = new DirectoryInfo(Application.dataPath);

            FileInfo[] files    = dir.GetFiles("*.prefab", SearchOption.AllDirectories);
            string     fn       = "";
            float      progress = 0f;
            float      step     = 1f / (float)files.Length;

            EditorUtility.DisplayProgressBar(progressbarTitle, progressbarInfo, progress);

            for (int i = 0; i < files.Length; i++)
            {
                progress += step;
                EditorUtility.DisplayProgressBar(progressbarTitle, progressbarInfo, progress);
                if (files[i] == null)
                {
                    continue;
                }
                fn = ProjectRelativePath(files[i].FullName);
                if (!string.IsNullOrEmpty(fn))
                {
                    GameObject obj = AssetDatabase.LoadAssetAtPath(fn, typeof(GameObject)) as GameObject;
                    CheckGo(null, fn, obj);
                }
            }
            EditorUtility.ClearProgressBar();

            // Now look in all scenes
            progressbarInfo = "Looking in Scenes ...";
            files           = dir.GetFiles("*.unity", SearchOption.AllDirectories);
            fn       = "";
            progress = 0f;
            step     = 1f / (float)files.Length;
            EditorUtility.DisplayProgressBar(progressbarTitle, progressbarInfo, progress);

            for (int i = 0; i < files.Length; i++)
            {
                progress += step;
                EditorUtility.DisplayProgressBar(progressbarTitle, progressbarInfo, progress);
                if (files[i] == null)
                {
                    continue;
                }
                fn = ProjectRelativePath(files[i].FullName);
                if (!string.IsNullOrEmpty(fn))
                {
                    if (RPGEditorGlobal.OpenScene(fn))
                    {
                        Object[] objs = GameObject.FindObjectsOfType(typeof(GameObject));
                        for (int j = 0; j < objs.Length; j++)
                        {
                            CheckGo(fn, fn, objs[j] as GameObject);
                        }
                    }
                }
            }

            EditorUtility.ClearProgressBar();

            if (string.IsNullOrEmpty(currScene))
            {
                RPGEditorGlobal.NewScene();
            }
            else
            {
                RPGEditorGlobal.OpenScene(currScene);
            }

            hasRun = true;
        }