Exemple #1
0
 void Awake()
 {
     if (!Instance)
     {
         Instance   = this;
         transition = GetComponent <UITransition>();
         text       = GetComponentInChildren <RTLTMPro.RTLTextMeshPro>();
     }
 }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            tmpro = (RTLTextMeshPro)target;

            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(originalTextProp, new GUIContent("RTL Text Input Box"));

            ListenForZeroWidthNoJoiner();

            if (EditorGUI.EndChangeCheck())
            {
                inputSourceProp.enumValueIndex      = 0;
                isInputPasingRequiredProp.boolValue = true;
                changed = true;
            }

            if (changed)
            {
                OnChanged();
            }

            serializedObject.ApplyModifiedProperties();

            base.OnInspectorGUI();

            foldout = EditorGUILayout.Foldout(foldout, "RTL Settings");
            if (foldout)
            {
                DrawOptions();

                if (GUILayout.Button("Re-Fix"))
                {
                    changed = true;
                }

                if (EditorGUI.EndChangeCheck())
                {
                    changed = true;
                }
            }

            if (changed)
            {
                OnChanged();
            }

            serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            tmpro = (RTLTextMeshPro)target;

            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(originalTextProp, new GUIContent("RTL Text Input Box"));

            ListenForZeroWidthNoJoiner();

            if (EditorGUI.EndChangeCheck())
            {
                OnChanged();
            }

            serializedObject.ApplyModifiedProperties();

            base.OnInspectorGUI();

            foldout = EditorGUILayout.Foldout(foldout, "RTL Settings", TMP_UIStyleManager.boldFoldout);
            if (foldout)
            {
                DrawOptions();

                if (GUILayout.Button("Re-Fix"))
                {
                    m_HavePropertiesChanged = true;
                }

                if (EditorGUI.EndChangeCheck())
                {
                    m_HavePropertiesChanged = true;
                }
            }

            if (m_HavePropertiesChanged)
            {
                OnChanged();
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemple #4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            tmpro = (RTLTextMeshPro)target;

            // Copy Default GUI Toggle Style
            if (fixNumberStyle == null)
            {
                fixNumberStyle = new GUIStyle(GUI.skin.label)
                {
                    fontSize = 12,
                    normal   = { textColor = TMP_UIStyleManager.Section_Label.normal.textColor },
                    richText = true
                };
            }

            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            farsiProp.boolValue           = GUILayout.Toggle(farsiProp.boolValue, new GUIContent("Farsi"));
            forceFixProp.boolValue        = GUILayout.Toggle(forceFixProp.boolValue, new GUIContent("Force Fix"));
            preserveNumbersProp.boolValue = GUILayout.Toggle(preserveNumbersProp.boolValue, new GUIContent("Preserve Numbers"));

            if (tmpro.richText)
            {
                fixTagsProp.boolValue = GUILayout.Toggle(fixTagsProp.boolValue, new GUIContent("FixTags"));
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Re-Fix"))
            {
                changed = true;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();


            if (EditorGUI.EndChangeCheck())
            {
                changed = true;
            }

            Rect rect = EditorGUILayout.GetControlRect(false, 25);

            rect.y += 2;

            GUI.Label(rect, "<b>RTL TEXT INPUT BOX</b>" + (foldout ? UIStateLabel[1] : UIStateLabel[0]), TMP_UIStyleManager.Section_Label);
            if (GUI.Button(new Rect(rect.x, rect.y, rect.width - 150, rect.height), GUIContent.none, GUI.skin.label))
            {
                foldout = !foldout;
            }

            if (foldout)
            {
                EditorGUI.BeginChangeCheck();
                originalTextProp.stringValue = EditorGUILayout.TextArea(originalTextProp.stringValue, TMP_UIStyleManager.TextAreaBoxEditor, GUILayout.Height(125), GUILayout.ExpandWidth(true));

                if (EditorGUI.EndChangeCheck())
                {
                    inputSourceProp.enumValueIndex      = 0;
                    isInputPasingRequiredProp.boolValue = true;
                    changed = true;
                }
            }

            serializedObject.ApplyModifiedProperties();

            if (changed)
            {
                tmpro.UpdateText();

                havePropertiesChangedProp.boolValue = true;
                changed = false;
                EditorUtility.SetDirty(target);
            }

            serializedObject.ApplyModifiedProperties();

            base.OnInspectorGUI();
        }
Exemple #5
0
        public static GameObject CreateDropdown(Resources resources)
        {
            GameObject root = CreateUIElementRoot("Dropdown - RTLTMP", s_ThickElementSize);

            GameObject label          = CreateUIObject("Label", root);
            GameObject arrow          = CreateUIObject("Arrow", root);
            GameObject template       = CreateUIObject("Template", root);
            GameObject viewport       = CreateUIObject("Viewport", template);
            GameObject content        = CreateUIObject("Content", viewport);
            GameObject item           = CreateUIObject("Item", content);
            GameObject itemBackground = CreateUIObject("Item Background", item);
            GameObject itemCheckmark  = CreateUIObject("Item Checkmark", item);
            GameObject itemLabel      = CreateUIObject("Item Label", item);

            // Sub controls.

            GameObject scrollbar = CreateScrollbar(resources);

            scrollbar.name = "Scrollbar";
            SetParentAndAlign(scrollbar, template);

            Scrollbar scrollbarScrollbar = scrollbar.GetComponent <Scrollbar>();

            scrollbarScrollbar.SetDirection(Scrollbar.Direction.BottomToTop, true);

            RectTransform vScrollbarRT = scrollbar.GetComponent <RectTransform>();

            vScrollbarRT.anchorMin = Vector2.right;
            vScrollbarRT.anchorMax = Vector2.one;
            vScrollbarRT.pivot     = Vector2.one;
            vScrollbarRT.sizeDelta = new Vector2(vScrollbarRT.sizeDelta.x, 0);

            // Setup item UI components.

            RTLTextMeshPro itemLabelText = itemLabel.AddComponent <RTLTextMeshPro>();

            SetDefaultTextValues(itemLabelText);
            itemLabelText.alignment = TextAlignmentOptions.Right;

            Image itemBackgroundImage = itemBackground.AddComponent <Image>();

            itemBackgroundImage.color = new Color32(245, 245, 245, 255);

            Image itemCheckmarkImage = itemCheckmark.AddComponent <Image>();

            itemCheckmarkImage.sprite = resources.checkmark;

            Toggle itemToggle = item.AddComponent <Toggle>();

            itemToggle.targetGraphic = itemBackgroundImage;
            itemToggle.graphic       = itemCheckmarkImage;
            itemToggle.isOn          = true;

            // Setup template UI components.

            Image templateImage = template.AddComponent <Image>();

            templateImage.sprite = resources.standard;
            templateImage.type   = Image.Type.Sliced;

            ScrollRect templateScrollRect = template.AddComponent <ScrollRect>();

            templateScrollRect.content                     = (RectTransform)content.transform;
            templateScrollRect.viewport                    = (RectTransform)viewport.transform;
            templateScrollRect.horizontal                  = false;
            templateScrollRect.movementType                = ScrollRect.MovementType.Clamped;
            templateScrollRect.verticalScrollbar           = scrollbarScrollbar;
            templateScrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
            templateScrollRect.verticalScrollbarSpacing    = -3;

            Mask scrollRectMask = viewport.AddComponent <Mask>();

            scrollRectMask.showMaskGraphic = false;

            Image viewportImage = viewport.AddComponent <Image>();

            viewportImage.sprite = resources.mask;
            viewportImage.type   = Image.Type.Sliced;

            // Setup dropdown UI components.

            RTLTextMeshPro labelText = label.AddComponent <RTLTextMeshPro>();

            SetDefaultTextValues(labelText);
            labelText.alignment = TextAlignmentOptions.Right;

            Image arrowImage = arrow.AddComponent <Image>();

            arrowImage.sprite = resources.dropdown;

            Image backgroundImage = root.AddComponent <Image>();

            backgroundImage.sprite = resources.standard;
            backgroundImage.color  = s_DefaultSelectableColor;
            backgroundImage.type   = Image.Type.Sliced;

            TMP_Dropdown dropdown = root.AddComponent <TMP_Dropdown>();

            dropdown.targetGraphic = backgroundImage;
            SetDefaultColorTransitionValues(dropdown);
            dropdown.template    = template.GetComponent <RectTransform>();
            dropdown.captionText = labelText;
            dropdown.itemText    = itemLabelText;

            // Setting default Item list.
            itemLabelText.text = "Option A";
            dropdown.options.Add(new TMP_Dropdown.OptionData {
                text = "Option A"
            });
            dropdown.options.Add(new TMP_Dropdown.OptionData {
                text = "Option B"
            });
            dropdown.options.Add(new TMP_Dropdown.OptionData {
                text = "Option C"
            });
            dropdown.RefreshShownValue();

            // Set up RectTransforms.

            RectTransform labelRT = label.GetComponent <RectTransform>();

            labelRT.anchorMin = Vector2.zero;
            labelRT.anchorMax = Vector2.one;
            labelRT.offsetMin = new Vector2(10, 6);
            labelRT.offsetMax = new Vector2(-25, -7);

            RectTransform arrowRT = arrow.GetComponent <RectTransform>();

            arrowRT.anchorMin        = new Vector2(1, 0.5f);
            arrowRT.anchorMax        = new Vector2(1, 0.5f);
            arrowRT.sizeDelta        = new Vector2(20, 20);
            arrowRT.anchoredPosition = new Vector2(-15, 0);

            RectTransform templateRT = template.GetComponent <RectTransform>();

            templateRT.anchorMin        = new Vector2(0, 0);
            templateRT.anchorMax        = new Vector2(1, 0);
            templateRT.pivot            = new Vector2(0.5f, 1);
            templateRT.anchoredPosition = new Vector2(0, 2);
            templateRT.sizeDelta        = new Vector2(0, 150);

            RectTransform viewportRT = viewport.GetComponent <RectTransform>();

            viewportRT.anchorMin = new Vector2(0, 0);
            viewportRT.anchorMax = new Vector2(1, 1);
            viewportRT.sizeDelta = new Vector2(-18, 0);
            viewportRT.pivot     = new Vector2(0, 1);

            RectTransform contentRT = content.GetComponent <RectTransform>();

            contentRT.anchorMin        = new Vector2(0f, 1);
            contentRT.anchorMax        = new Vector2(1f, 1);
            contentRT.pivot            = new Vector2(0.5f, 1);
            contentRT.anchoredPosition = new Vector2(0, 0);
            contentRT.sizeDelta        = new Vector2(0, 28);

            RectTransform itemRT = item.GetComponent <RectTransform>();

            itemRT.anchorMin = new Vector2(0, 0.5f);
            itemRT.anchorMax = new Vector2(1, 0.5f);
            itemRT.sizeDelta = new Vector2(0, 20);

            RectTransform itemBackgroundRT = itemBackground.GetComponent <RectTransform>();

            itemBackgroundRT.anchorMin = Vector2.zero;
            itemBackgroundRT.anchorMax = Vector2.one;
            itemBackgroundRT.sizeDelta = Vector2.zero;

            RectTransform itemCheckmarkRT = itemCheckmark.GetComponent <RectTransform>();

            itemCheckmarkRT.anchorMin        = new Vector2(0, 0.5f);
            itemCheckmarkRT.anchorMax        = new Vector2(0, 0.5f);
            itemCheckmarkRT.sizeDelta        = new Vector2(20, 20);
            itemCheckmarkRT.anchoredPosition = new Vector2(10, 0);

            RectTransform itemLabelRT = itemLabel.GetComponent <RectTransform>();

            itemLabelRT.anchorMin = Vector2.zero;
            itemLabelRT.anchorMax = Vector2.one;
            itemLabelRT.offsetMin = new Vector2(20, 1);
            itemLabelRT.offsetMax = new Vector2(-10, -2);

            template.SetActive(false);

            return(root);
        }
Exemple #6
0
        public static GameObject CreateInputField(Resources resources)
        {
            GameObject root = CreateUIElementRoot("InputField - RTLTMP", s_ThickElementSize);

            GameObject textArea         = CreateUIObject("Text Area", root);
            GameObject childPlaceholder = CreateUIObject("Placeholder", textArea);
            GameObject childText        = CreateUIObject("Text", textArea);

            Image image = root.AddComponent <Image>();

            image.sprite = resources.inputField;
            image.type   = Image.Type.Sliced;
            image.color  = s_DefaultSelectableColor;

            TMP_InputField inputField = root.AddComponent <TMP_InputField>();

            SetDefaultColorTransitionValues(inputField);

            // Use UI.Mask for Unity 5.0 - 5.1 and 2D RectMask for Unity 5.2 and up
            textArea.AddComponent <RectMask2D>();

            RectTransform textAreaRectTransform = textArea.GetComponent <RectTransform>();

            textAreaRectTransform.anchorMin = Vector2.zero;
            textAreaRectTransform.anchorMax = Vector2.one;
            textAreaRectTransform.sizeDelta = Vector2.zero;
            textAreaRectTransform.offsetMin = new Vector2(10, 6);
            textAreaRectTransform.offsetMax = new Vector2(-10, -7);


            RTLTextMeshPro text = childText.AddComponent <RTLTextMeshPro>();

            text.text = "";
            text.enableWordWrapping    = false;
            text.extraPadding          = true;
            text.richText              = true;
            text.autoSizeTextContainer = true;
            text.enableAutoSizing      = true;
            text.fontSizeMin           = 10;
            text.fontSizeMax           = 100;
            text.margin    = new Vector4(0, 0, 0, 4.5f);
            text.alignment = TextAlignmentOptions.Right;
            SetDefaultTextValues(text);

            RTLTextMeshPro placeholder = childPlaceholder.AddComponent <RTLTextMeshPro>();

            placeholder.text     = "Enter Text...";
            placeholder.fontSize = 14;
            placeholder.autoSizeTextContainer = true;
            placeholder.enableAutoSizing      = true;
            placeholder.fontSizeMin           = 10;
            placeholder.fontSizeMax           = 100;
            placeholder.fontStyle             = FontStyles.Italic;
            placeholder.enableWordWrapping    = false;
            placeholder.extraPadding          = true;
            placeholder.alignment             = TextAlignmentOptions.Right;

            // Make placeholder color half as opaque as normal text color.
            Color placeholderColor = text.color;

            placeholderColor.a *= 0.5f;
            placeholder.color   = placeholderColor;

            RectTransform textRectTransform = childText.GetComponent <RectTransform>();

            textRectTransform.anchorMin = Vector2.zero;
            textRectTransform.anchorMax = Vector2.one;
            textRectTransform.sizeDelta = Vector2.zero;
            textRectTransform.offsetMin = new Vector2(0, 0);
            textRectTransform.offsetMax = new Vector2(0, 0);

            RectTransform placeholderRectTransform = childPlaceholder.GetComponent <RectTransform>();

            placeholderRectTransform.anchorMin = Vector2.zero;
            placeholderRectTransform.anchorMax = Vector2.one;
            placeholderRectTransform.sizeDelta = Vector2.zero;
            placeholderRectTransform.offsetMin = new Vector2(0, 0);
            placeholderRectTransform.offsetMax = new Vector2(0, 0);

            inputField.textViewport  = textAreaRectTransform;
            inputField.textComponent = text;
            inputField.placeholder   = placeholder;
            inputField.fontAsset     = text.font;

            return(root);
        }