Exemplo n.º 1
0
        private static void AddToSceneInEditor()
        {
            AFPSCounter counter = FindObjectOfType <AFPSCounter>();

            if (counter != null)
            {
                if (counter.IsPlacedCorrectly())
                {
                    if (UnityEditor.EditorUtility.DisplayDialog("Remove " + COMPONENT_NAME + "?",
                                                                COMPONENT_NAME + " already exists in scene and placed correctly. Do you wish to remove it?", "Yes", "No"))
                    {
                        DestroyInEditorImmediate(counter);
                    }
                }
                else
                {
                    if (counter.MayBePlacedHere())
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Fix existing Game Object to work with " +
                                                                                          COMPONENT_NAME + "?",
                                                                                          COMPONENT_NAME + " already exists in scene and placed on Game Object \"" +
                                                                                          counter.name + "\" with minor errors.\nDo you wish to let plugin fix and use this Game Object further? " +
                                                                                          "Press Delete to remove plugin from scene at all.", "Fix", "Delete", "Cancel");

                        switch (dialogResult)
                        {
                        case 0:
                            counter.FixCurrentGameObject();
                            break;

                        case 1:
                            DestroyInEditorImmediate(counter);
                            break;
                        }
                    }
                    else
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Move existing " + COMPONENT_NAME +
                                                                                          " to own Game Object?",
                                                                                          "Looks like " + COMPONENT_NAME + " already exists in scene and placed incorrectly on Game Object \"" +
                                                                                          counter.name + "\".\nDo you wish to let plugin move itself onto separate correct Game Object \"" +
                                                                                          COMPONENT_NAME + "\"? Press Delete to remove plugin from scene at all.", "Move", "Delete", "Cancel");

                        switch (dialogResult)
                        {
                        case 0:
                            AFPSCounter newCounter = CreateInScene();
                            UnityEditor.EditorUtility.CopySerialized(counter, newCounter);
                            break;
                        }
                        DestroyInEditorImmediate(counter);
                    }
                }
            }
            else
            {
                CreateInScene();
                UnityEditor.EditorUtility.DisplayDialog("Advanced FPS Counter added!", "Advanced FPS Counter successfully added to the object \"" + COMPONENT_NAME + "\"", "OK");
            }
        }
Exemplo n.º 2
0
        private static void AddToScene()
        {
            AFPSCounter counter = (AFPSCounter)FindObjectOfType(typeof(AFPSCounter));

            if (counter != null)
            {
                if (counter.IsPlacedCorrectly())
                {
                    if (UnityEditor.EditorUtility.DisplayDialog("Remove Advanced FPS Counter?", "Advanced FPS Counter already exists in scene and placed correctly. Dou you wish to remove it?", "Yes", "No"))
                    {
                        DestroyImmediate(counter.gameObject);
                    }
                }
                else
                {
                    if (counter.MayBePlacedHere())
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Fix existing Game Object to work with Adavnced FPS Counter?", "Advanced FPS Counter already exists in scene and placed onto empty Game Object \"" + counter.name + "\".\nDo you wish to let plugin configure and use this Game Object further? Press Delete to remove plugin from scene at all.", "Fix", "Delete", "Cancel");

                        switch (dialogResult)
                        {
                        case 0:
                            counter.FixCurrentGameObject();
                            break;

                        case 1:
                            DestroyImmediate(counter);
                            break;
                        }
                    }
                    else
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Move existing Adavnced FPS Counter to own Game Object?", "Looks like Advanced FPS Counter plugin is already exists in scene and placed incorrectly on Game Object \"" + counter.name + "\".\nDo you wish to let plugin move itself onto separate configured Game Object \"" + CONTAINER_NAME + "\"? Press Delete to remove plugin from scene at all.", "Move", "Delete", "Cancel");
                        switch (dialogResult)
                        {
                        case 0:
                            GameObject go = new GameObject(CONTAINER_NAME);
                            go.layer = 5;
                            AFPSCounter newCounter = go.AddComponent <AFPSCounter>();
                            UnityEditor.EditorUtility.CopySerialized(counter, newCounter);

                            DestroyImmediate(counter);
                            break;

                        case 1:
                            DestroyImmediate(counter);
                            break;
                        }
                    }
                }
            }
            else
            {
                GameObject go = new GameObject(CONTAINER_NAME);
                go.layer = 5;
                go.AddComponent <AFPSCounter>();
            }
        }
Exemplo n.º 3
0
        private static void AddToSceneInEditor()
        {
            AFPSCounter counter = FindObjectOfType <AFPSCounter>();

            if (counter != null)
            {
                if (counter.IsPlacedCorrectly())
                {
                    if (UnityEditor.EditorUtility.DisplayDialog("Remove " + COMPONENT_NAME + "?",
                                                                COMPONENT_NAME + " already exists in scene and placed correctly. Do you wish to remove it?", "Yes", "No"))
                    {
                        DestroyInEditorImmediate(counter);
                    }
                }
                else
                {
                    if (counter.MayBePlacedHere())
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Fix existing Game Object to work with " +
                                                                                          COMPONENT_NAME + "?",
                                                                                          COMPONENT_NAME + " already exists in scene and placed on Game Object \"" +
                                                                                          counter.name + "\" with minor errors.\nDo you wish to let plugin fix and use this Game Object further? " +
                                                                                          "Press Delete to remove plugin from scene at all.", "Fix", "Delete", "Cancel");

                        switch (dialogResult)
                        {
                        case 0:
                            counter.FixCurrentGameObject();
                            break;

                        case 1:
                            DestroyInEditorImmediate(counter);
                            break;
                        }
                    }
                    else
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Move existing " + COMPONENT_NAME +
                                                                                          " to own Game Object?",
                                                                                          "Looks like " + COMPONENT_NAME + " already exists in scene and placed incorrectly on Game Object \"" +
                                                                                          counter.name + "\".\nDo you wish to let plugin move itself onto separate correct Game Object \"" +
                                                                                          COMPONENT_NAME + "\"? Press Delete to remove plugin from scene at all.", "Move", "Delete", "Cancel");

                        switch (dialogResult)
                        {
                        case 0:
                            AFPSCounter newCounter = CreateInScene(false);
                            UnityEditor.EditorUtility.CopySerialized(counter, newCounter);
                            DestroyInEditorImmediate(counter);
                            break;

                        case 1:
                            DestroyInEditorImmediate(counter);
                            break;
                        }
                    }
                }
            }
            else
            {
                var newCounter = CreateInScene();

                var fonts = UnityEditor.AssetDatabase.FindAssets("t:Font, VeraMono");
                if (fonts != null && fonts.Length != 0)
                {
                    string veraMonoPath = null;
                    foreach (var font in fonts)
                    {
                        var fontPath     = UnityEditor.AssetDatabase.GUIDToAssetPath(font);
                        var fontFileName = System.IO.Path.GetFileName(fontPath);
                        if (fontFileName == "VeraMono.ttf")
                        {
                            veraMonoPath = fontPath;
                            break;
                        }
                    }

                    if (!string.IsNullOrEmpty(veraMonoPath))
                    {
                        var font = (Font)UnityEditor.AssetDatabase.LoadAssetAtPath(veraMonoPath, typeof(Font));
                        var so   = new UnityEditor.SerializedObject(newCounter);
                        so.FindProperty("labelsFont").objectReferenceValue = font;
                        so.ApplyModifiedProperties();
                        UnityEditor.EditorUtility.SetDirty(newCounter);
                    }
                }
                UnityEditor.EditorUtility.DisplayDialog("Advanced FPS Counter added!", "Advanced FPS Counter successfully added to the object \"" + COMPONENT_NAME + "\"", "OK");
            }
        }
Exemplo n.º 4
0
        private static void AddToSceneInEditor()
        {
            AFPSCounter counter = FindObjectOfType <AFPSCounter>();

            if (counter != null)
            {
                if (counter.IsPlacedCorrectly())
                {
                    if (UnityEditor.EditorUtility.DisplayDialog("Remove Advanced FPS Counter?", "Advanced FPS Counter already exists in scene and placed correctly. Dou you wish to remove it?", "Yes", "No"))
                    {
                        DestroyInEditorImmediate(counter);
                    }
                }
                else
                {
                    if (counter.MayBePlacedHere())
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Fix existing Game Object to work with Adavnced FPS Counter?", "Advanced FPS Counter already exists in scene and placed onto  Game Object \"" + counter.name + "\".\nDo you wish to let plugin configure and use this Game Object further? Press Delete to remove plugin from scene at all.", "Fix", "Delete", "Cancel");

                        switch (dialogResult)
                        {
                        case 0:
                            counter.FixCurrentGameObject();
                            break;

                        case 1:
                            DestroyInEditorImmediate(counter);
                            break;
                        }
                    }
                    else
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Move existing Adavnced FPS Counter to own Game Object?", "Looks like Advanced FPS Counter plugin already exists in scene and placed incorrectly on Game Object \"" + counter.name + "\".\nDo you wish to let plugin move itself onto separate configured Game Object \"" + CONTAINER_NAME + "\"? Press Delete to remove plugin from scene at all.", "Move", "Delete", "Cancel");
                        switch (dialogResult)
                        {
                        case 0:
                            GameObject go = new GameObject(CONTAINER_NAME);
                            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + CONTAINER_NAME);
                            UnityEditor.Selection.activeObject = go;
                            AFPSCounter newCounter = go.AddComponent <AFPSCounter>();
                            UnityEditor.EditorUtility.CopySerialized(counter, newCounter);
                            DestroyInEditorImmediate(counter);
                            break;

                        case 1:
                            DestroyInEditorImmediate(counter);
                            break;
                        }
                    }
                }
            }
            else
            {
                GameObject container = GameObject.Find(CONTAINER_NAME);
                if (container == null)
                {
                    container = new GameObject(CONTAINER_NAME);
                    UnityEditor.Undo.RegisterCreatedObjectUndo(container, "Create " + CONTAINER_NAME);
                    UnityEditor.Selection.activeObject = container;
                }
                container.AddComponent <AFPSCounter>();

                UnityEditor.EditorUtility.DisplayDialog("Adavnced FPS Counter added!", "Adavnced FPS Counter successfully added to the object \"" + CONTAINER_NAME + "\"", "OK");
            }
        }