Exemple #1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_ColorMode, new GUIContent("Color Mode"));
            if (EditorGUI.EndChangeCheck())
            {
                switch ((ColorMode)m_ColorMode.enumValueIndex)
                {
                case ColorMode.Single:
                    m_TopRightColor.colorValue    = m_TopLeftColor.colorValue;
                    m_BottomLeftColor.colorValue  = m_TopLeftColor.colorValue;
                    m_BottomRightColor.colorValue = m_TopLeftColor.colorValue;
                    break;

                case ColorMode.HorizontalGradient:
                    m_BottomLeftColor.colorValue  = m_TopLeftColor.colorValue;
                    m_BottomRightColor.colorValue = m_TopRightColor.colorValue;
                    break;

                case ColorMode.VerticalGradient:
                    m_TopRightColor.colorValue    = m_TopLeftColor.colorValue;
                    m_BottomRightColor.colorValue = m_BottomLeftColor.colorValue;
                    break;
                }
            }
            Rect rect;

            switch ((ColorMode)m_ColorMode.enumValueIndex)
            {
            case ColorMode.Single:
                EditorGUI.BeginChangeCheck();
                rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
                EditorGUI.PrefixLabel(rect, new GUIContent("Colors"));
                rect.x    += EditorGUIUtility.labelWidth;
                rect.width = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f);
                TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor);
                if (EditorGUI.EndChangeCheck())
                {
                    m_TopRightColor.colorValue    = m_TopLeftColor.colorValue;
                    m_BottomLeftColor.colorValue  = m_TopLeftColor.colorValue;
                    m_BottomRightColor.colorValue = m_TopLeftColor.colorValue;
                }
                break;

            case ColorMode.HorizontalGradient:
                rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
                EditorGUI.PrefixLabel(rect, new GUIContent("Colors"));
                rect.x    += EditorGUIUtility.labelWidth;
                rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f;

                EditorGUI.BeginChangeCheck();
                TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor);
                if (EditorGUI.EndChangeCheck())
                {
                    m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue;
                }

                rect.x += rect.width;

                EditorGUI.BeginChangeCheck();
                TMP_EditorUtility.DrawColorProperty(rect, m_TopRightColor);
                if (EditorGUI.EndChangeCheck())
                {
                    m_BottomRightColor.colorValue = m_TopRightColor.colorValue;
                }
                break;

            case ColorMode.VerticalGradient:
                rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
                EditorGUI.PrefixLabel(rect, new GUIContent("Colors"));
                rect.x     += EditorGUIUtility.labelWidth;
                rect.width  = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f);
                rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2);

                EditorGUI.BeginChangeCheck();
                TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor);
                if (EditorGUI.EndChangeCheck())
                {
                    m_TopRightColor.colorValue = m_TopLeftColor.colorValue;
                }

                rect        = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
                rect.x     += EditorGUIUtility.labelWidth;
                rect.width  = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f);
                rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2);

                EditorGUI.BeginChangeCheck();
                TMP_EditorUtility.DrawColorProperty(rect, m_BottomLeftColor);
                if (EditorGUI.EndChangeCheck())
                {
                    m_BottomRightColor.colorValue = m_BottomLeftColor.colorValue;
                }
                break;

            case ColorMode.FourCornersGradient:
                rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
                EditorGUI.PrefixLabel(rect, new GUIContent("Colors"));
                rect.x     += EditorGUIUtility.labelWidth;
                rect.width  = (rect.width - EditorGUIUtility.labelWidth) / 2f;
                rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2);

                TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor);
                rect.x += rect.width;
                TMP_EditorUtility.DrawColorProperty(rect, m_TopRightColor);

                rect        = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
                rect.x     += EditorGUIUtility.labelWidth;
                rect.width  = (rect.width - EditorGUIUtility.labelWidth) / 2f;
                rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2);

                TMP_EditorUtility.DrawColorProperty(rect, m_BottomLeftColor);
                rect.x += rect.width;
                TMP_EditorUtility.DrawColorProperty(rect, m_BottomRightColor);
                break;
            }

            if (serializedObject.ApplyModifiedProperties())
            {
                TMPro_EventManager.ON_COLOR_GRAIDENT_PROPERTY_CHANGED(target as TMP_ColorGradient);
            }
        }
        void DrawColor()
        {
            // FACE VERTEX COLOR
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_FontColorProp, k_BaseColorLabel);

            EditorGUILayout.PropertyField(m_EnableVertexGradientProp, k_ColorGradientLabel);
            if (EditorGUI.EndChangeCheck())
            {
                m_HavePropertiesChanged = true;
            }

            EditorGUIUtility.fieldWidth = 0;

            if (m_EnableVertexGradientProp.boolValue)
            {
                EditorGUI.indentLevel += 1;

                EditorGUI.BeginChangeCheck();

                EditorGUILayout.PropertyField(m_FontColorGradientPresetProp, k_ColorPresetLabel);

                SerializedObject obj = null;

                SerializedProperty colorMode;

                SerializedProperty topLeft;
                SerializedProperty topRight;
                SerializedProperty bottomLeft;
                SerializedProperty bottomRight;

                if (m_FontColorGradientPresetProp.objectReferenceValue == null)
                {
                    colorMode   = m_ColorModeProp;
                    topLeft     = m_FontColorGradientProp.FindPropertyRelative("topLeft");
                    topRight    = m_FontColorGradientProp.FindPropertyRelative("topRight");
                    bottomLeft  = m_FontColorGradientProp.FindPropertyRelative("bottomLeft");
                    bottomRight = m_FontColorGradientProp.FindPropertyRelative("bottomRight");
                }
                else
                {
                    obj         = new SerializedObject(m_FontColorGradientPresetProp.objectReferenceValue);
                    colorMode   = obj.FindProperty("colorMode");
                    topLeft     = obj.FindProperty("topLeft");
                    topRight    = obj.FindProperty("topRight");
                    bottomLeft  = obj.FindProperty("bottomLeft");
                    bottomRight = obj.FindProperty("bottomRight");
                }

                EditorGUILayout.PropertyField(colorMode, k_ColorModeLabel);

                var rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));

                EditorGUI.PrefixLabel(rect, k_CorenerColorsLabel);

                rect.x    += EditorGUIUtility.labelWidth;
                rect.width = rect.width - EditorGUIUtility.labelWidth;

                switch ((ColorMode)colorMode.enumValueIndex)
                {
                case ColorMode.Single:
                    TMP_EditorUtility.DrawColorProperty(rect, topLeft);

                    topRight.colorValue    = topLeft.colorValue;
                    bottomLeft.colorValue  = topLeft.colorValue;
                    bottomRight.colorValue = topLeft.colorValue;
                    break;

                case ColorMode.HorizontalGradient:
                    rect.width /= 2f;

                    TMP_EditorUtility.DrawColorProperty(rect, topLeft);

                    rect.x += rect.width;

                    TMP_EditorUtility.DrawColorProperty(rect, topRight);

                    bottomLeft.colorValue  = topLeft.colorValue;
                    bottomRight.colorValue = topRight.colorValue;
                    break;

                case ColorMode.VerticalGradient:
                    TMP_EditorUtility.DrawColorProperty(rect, topLeft);

                    rect    = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
                    rect.x += EditorGUIUtility.labelWidth;

                    TMP_EditorUtility.DrawColorProperty(rect, bottomLeft);

                    topRight.colorValue    = topLeft.colorValue;
                    bottomRight.colorValue = bottomLeft.colorValue;
                    break;

                case ColorMode.FourCornersGradient:
                    rect.width /= 2f;

                    TMP_EditorUtility.DrawColorProperty(rect, topLeft);

                    rect.x += rect.width;

                    TMP_EditorUtility.DrawColorProperty(rect, topRight);

                    rect       = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
                    rect.x    += EditorGUIUtility.labelWidth;
                    rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f;

                    TMP_EditorUtility.DrawColorProperty(rect, bottomLeft);

                    rect.x += rect.width;

                    TMP_EditorUtility.DrawColorProperty(rect, bottomRight);
                    break;
                }

                if (EditorGUI.EndChangeCheck())
                {
                    m_HavePropertiesChanged = true;
                    if (obj != null)
                    {
                        obj.ApplyModifiedProperties();
                        TMPro_EventManager.ON_COLOR_GRAIDENT_PROPERTY_CHANGED(m_FontColorGradientPresetProp.objectReferenceValue as TMP_ColorGradient);
                    }
                }

                EditorGUI.indentLevel -= 1;
            }

            EditorGUILayout.PropertyField(m_OverrideHtmlColorProp, k_OverrideTagsLabel);

            EditorGUILayout.Space();
        }