コード例 #1
0
        static void CreateTextMeshProGuiObjectPerform(MenuCommand menuCommand)
        {
            GameObject go = TMP_DefaultControls.CreateText(GetStandardResources());

            // Override text color and font size
            TextMeshProUGUI textComponent = go.GetComponent <TextMeshProUGUI>();

            if (textComponent.m_isWaitingOnResourceLoad == false)
            {
                // Apply TMP Settings Defaults if no Preset is defined
                if (Preset.GetDefaultForObject(textComponent) == null)
                {
                    textComponent.fontSize = TMP_Settings.defaultFontSize;
                    textComponent.color    = Color.white;
                    textComponent.text     = "New Text";
                }

                if (TMP_Settings.autoSizeTextContainer)
                {
                    Vector2 size = textComponent.GetPreferredValues(TMP_Math.FLOAT_MAX, TMP_Math.FLOAT_MAX);
                    textComponent.rectTransform.sizeDelta = size;
                }
                else
                {
                    textComponent.rectTransform.sizeDelta = TMP_Settings.defaultTextMeshProUITextContainerSize;
                }
            }

            PlaceUIElementRoot(go, menuCommand);
        }
コード例 #2
0
        static void CreateTextMeshProGuiObjectPerform(MenuCommand menuCommand)
        {
            GameObject go = TMP_DefaultControls.CreateText(GetStandardResources());

            // Override text color and font size
            TextMeshProUGUI textComponent = go.GetComponent <TextMeshProUGUI>();

            if (textComponent.m_isWaitingOnResourceLoad == false)
            {
                // Get reference to potential Presets for <TextMeshProUGUI> component
                #if UNITY_2019_3_OR_NEWER
                Preset[] presets = Preset.GetDefaultPresetsForObject(textComponent);

                if (presets == null || presets.Length == 0)
                {
                    textComponent.fontSize = TMP_Settings.defaultFontSize;
                    textComponent.color    = Color.white;
                    textComponent.text     = "New Text";
                }
                #else
                if (Preset.GetDefaultForObject(textComponent) == null)
                {
                    textComponent.fontSize = TMP_Settings.defaultFontSize;
                    textComponent.color    = Color.white;
                    textComponent.text     = "New Text";
                }
                #endif

                if (TMP_Settings.autoSizeTextContainer)
                {
                    Vector2 size = textComponent.GetPreferredValues(TMP_Math.FLOAT_MAX, TMP_Math.FLOAT_MAX);
                    textComponent.rectTransform.sizeDelta = size;
                }
                else
                {
                    textComponent.rectTransform.sizeDelta = TMP_Settings.defaultTextMeshProUITextContainerSize;
                }

                //默认关闭设置
                textComponent.richText      = false;
                textComponent.raycastTarget = false;
            }
            else
            {
                textComponent.fontSize = -99;
                textComponent.color    = Color.white;
                textComponent.text     = "New Text";
            }

            PlaceUIElementRoot(go, menuCommand);
        }
コード例 #3
0
        static void CreateTextMeshProGuiObjectPerform(MenuCommand menuCommand)
        {
            GameObject go = TMP_DefaultControls.CreateText(GetStandardResources());

            // Override text color and font size
            TMP_Text textComponent = go.GetComponent <TMP_Text>();

            textComponent.color = Color.white;
            if (textComponent.m_isWaitingOnResourceLoad == false)
            {
                textComponent.fontSize = TMP_Settings.defaultFontSize;
            }

            PlaceUIElementRoot(go, menuCommand);
        }