static void ConvertToTextFX()
        {
            GameObject            activeGO   = Selection.activeGameObject;
            TextMeshProUGUI       uguiText   = activeGO.GetComponent <TextMeshProUGUI> ();
            TextFxTextMeshProUGUI textfxUGUI = activeGO.GetComponent <TextFxTextMeshProUGUI> ();

            if (textfxUGUI != null)
            {
                return;
            }

            GameObject tempObject = new GameObject("temp");

            textfxUGUI = tempObject.AddComponent <TextFxTextMeshProUGUI>();

            CopyComponent(uguiText, textfxUGUI);

            DestroyImmediate(uguiText);

            TextFxTextMeshProUGUI newUGUIEffect = activeGO.AddComponent <TextFxTextMeshProUGUI> ();

            CopyComponent(textfxUGUI, newUGUIEffect);

            DestroyImmediate(tempObject);

            // Forces the mesh to be redrawn, taking into account the material settings.
            newUGUIEffect.Reset();

            Debug.Log(activeGO.name + "'s TextMeshProUGUI component converted into a TextFxTextMeshProUGUI component");
        }
Exemplo n.º 2
0
        public static void CreateTextMeshProGuiObjectPerform(MenuCommand command)
        {
            // Check if there is a Canvas in the scene
            Canvas canvas = Object.FindObjectOfType <Canvas>();

            if (canvas == null)
            {
                // Create new Canvas since none exists in the scene.
                GameObject canvasObject = new GameObject("Canvas");
                canvas            = canvasObject.AddComponent <Canvas>();
                canvas.renderMode = RenderMode.ScreenSpaceOverlay;

                // Add a Graphic Raycaster Component as well
                canvas.gameObject.AddComponent <GraphicRaycaster>();

                Undo.RegisterCreatedObjectUndo(canvasObject, "Create " + canvasObject.name);
            }


            // Create the TextFxTextMeshProUGUI Object
            GameObject    go = new GameObject(NEW_INSTANCE_NAME_TMP_UGUI);
            RectTransform goRectTransform = go.AddComponent <RectTransform>();

            Undo.RegisterCreatedObjectUndo((Object)go, "Create " + go.name);

            // Check if object is being create with left or right click
            GameObject contextObject = command != null ? command.context as GameObject : null;

            if (contextObject == null)
            {
                //goRectTransform.sizeDelta = new Vector2(200f, 50f);
                GameObjectUtility.SetParentAndAlign(go, canvas.gameObject);

                TextFxTextMeshProUGUI textMeshPro = go.AddComponent <TextFxTextMeshProUGUI>();
                textMeshPro.text      = "New Text";
                textMeshPro.alignment = TextAlignmentOptions.TopLeft;
            }
            else
            {
                if (contextObject.GetComponent <Button>() != null)
                {
                    goRectTransform.sizeDelta = Vector2.zero;
                    goRectTransform.anchorMin = Vector2.zero;
                    goRectTransform.anchorMax = Vector2.one;

                    GameObjectUtility.SetParentAndAlign(go, contextObject);

                    TextFxTextMeshProUGUI textMeshPro = go.AddComponent <TextFxTextMeshProUGUI>();
                    textMeshPro.text      = "Button";
                    textMeshPro.fontSize  = 24;
                    textMeshPro.alignment = TextAlignmentOptions.Center;
                }
                else
                {
                    //goRectTransform.sizeDelta = new Vector2(200f, 50f);

                    GameObjectUtility.SetParentAndAlign(go, contextObject);

                    TextFxTextMeshProUGUI textMeshPro = go.AddComponent <TextFxTextMeshProUGUI>();
                    textMeshPro.text      = "New Text";
                    textMeshPro.alignment = TextAlignmentOptions.TopLeft;
                }
            }


            // Check if an event system already exists in the scene
            if (!Object.FindObjectOfType <EventSystem>())
            {
                GameObject eventObject = new GameObject("EventSystem", typeof(EventSystem));
                eventObject.AddComponent <StandaloneInputModule>();
#if UNITY_5_3_OR_NEWER
                // Nothing
#else
                eventObject.AddComponent <TouchInputModule>();
#endif
                Undo.RegisterCreatedObjectUndo(eventObject, "Create " + eventObject.name);
            }

            Selection.activeGameObject = go;
        }