public override void OnInspectorGUI()
    {
        UIInput input = target as UIInput;

        serializedObject.Update();
        GUILayout.Space(3f);
        NGUIEditorTools.SetLabelWidth(110f);
        //NGUIEditorTools.DrawProperty(serializedObject, "m_Script");

        EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
        SerializedProperty label = NGUIEditorTools.DrawProperty(serializedObject, "label");

        EditorGUI.EndDisabledGroup();

        EditorGUI.BeginDisabledGroup(label == null || label.objectReferenceValue == null);
        {
            if (Application.isPlaying)
            {
                NGUIEditorTools.DrawPaddedProperty("Value", serializedObject, "mValue");
            }
            else
            {
                NGUIEditorTools.DrawPaddedProperty("Starting Value", serializedObject, "mValue");
            }
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "savedAs");
            NGUIEditorTools.DrawProperty("Active Text Color", serializedObject, "activeTextColor");

            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
            {
                if (label != null && label.objectReferenceValue != null)
                {
                    SerializedObject ob = new SerializedObject(label.objectReferenceValue);
                    ob.Update();
                    NGUIEditorTools.DrawProperty("Inactive Color", ob, "mColor");
                    ob.ApplyModifiedProperties();
                }
                else
                {
                    EditorGUILayout.ColorField("Inactive Color", Color.white);
                }
            }
            EditorGUI.EndDisabledGroup();

            NGUIEditorTools.DrawProperty("Caret Color", serializedObject, "caretColor");
            NGUIEditorTools.DrawProperty("Selection Color", serializedObject, "selectionColor");
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "inputType");
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "validation");
            NGUIEditorTools.DrawPaddedProperty("Mobile Keyboard", serializedObject, "keyboardType");
            NGUIEditorTools.DrawPaddedProperty("  Hide Input", serializedObject, "hideInput");
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "onReturnKey");

            // Deprecated, use UIKeyNavigation instead.
            //NGUIEditorTools.DrawProperty(serializedObject, "selectOnTab");

            SerializedProperty sp = serializedObject.FindProperty("characterLimit");

            GUILayout.BeginHorizontal();

            if (sp.hasMultipleDifferentValues || input.characterLimit > 0)
            {
                EditorGUILayout.PropertyField(sp);
                NGUIEditorTools.DrawPadding();
            }
            else
            {
                EditorGUILayout.PropertyField(sp);
                GUILayout.Label("unlimited");
            }
            GUILayout.EndHorizontal();

            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
            NGUIEditorTools.DrawEvents("On Submit", input, input.onSubmit);
            NGUIEditorTools.DrawEvents("On Change", input, input.onChange);
            EditorGUI.EndDisabledGroup();
        }
        EditorGUI.EndDisabledGroup();
        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 2
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mLabel = mWidget as UILabel;

        GUILayout.BeginHorizontal();

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
#else
        mFontType = FontType.NGUI;
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f)))
#endif
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            GUI.changed = false;
            fnt         = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            GUI.changed = false;
            ttf         = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        if (mFontType == FontType.Unity)
        {
            EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" +
                                    "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning);
        }

        NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat");

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);

                if (!serializedObject.isEditingMultipleObjects)
                {
                    var printed = mLabel.finalFontSize;
                    var def     = mLabel.defaultFontSize;

                    if (mLabel.overflowMethod == UILabel.Overflow.ShrinkContent && printed != mLabel.fontSize)
                    {
                        GUILayout.Label(" Printed: " + printed);
                    }
                    else if (printed != def)
                    {
                        GUILayout.Label(" Default: " + def);
                    }
                }

                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
            SerializedProperty sp = serializedObject.FindProperty("mText");

            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }

            GUI.skin.textField.wordWrap = ww;

            NGUIEditorTools.DrawPaddedProperty("Modifier", serializedObject, "mModifier");

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;
            if (NGUISettings.overflowStyle == UILabel.Overflow.ClampContent)
            {
                NGUIEditorTools.DrawProperty("Use Ellipsis", serializedObject, "mOverflowEllipsis", GUILayout.Width(110f));
            }

            if (NGUISettings.overflowStyle == UILabel.Overflow.ResizeFreely)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty s = NGUIEditorTools.DrawPaddedProperty("Max Width", serializedObject, "mOverflowWidth");

                if (s != null)
                {
                    if (s.intValue < 0)
                    {
                        s.intValue = 0;
                    }
                    if (s.intValue == 0)
                    {
                        GUILayout.Label("unlimited");
                    }
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                s = NGUIEditorTools.DrawPaddedProperty("Max Height", serializedObject, "mOverflowHeight");

                if (s != null)
                {
                    if (s.intValue < 0)
                    {
                        s.intValue = 0;
                    }
                    if (s.intValue == 0)
                    {
                        GUILayout.Label("unlimited");
                    }
                }

                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader);
            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient",
                                                                 GUILayout.Width(95f));

            EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue);
            {
                NGUIEditorTools.SetLabelWidth(30f);
                NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                NGUIEditorTools.SetLabelWidth(50f);
                GUILayout.Space(79f);

                NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.SetLabelWidth(80f);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f));

            if (!sp.boolValue)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f));
            EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols);
            NGUIEditorTools.SetLabelWidth(60f);
            NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();
        return(isValid);
    }
Exemplo n.º 3
0
    public void DrawAnchorTransform()
    {
        #region  Draw Anchors

        if (NGUIEditorTools.DrawHeader("Anchors"))
        {
            NGUIEditorTools.BeginContents();
            NGUIEditorTools.SetLabelWidth(NGUISettings.minimalisticLook ? 69f : 62f);

            EditorGUI.BeginDisabledGroup(!((target as UIRect).canBeAnchored));
            GUILayout.BeginHorizontal();
            AnchorType type = (AnchorType)EditorGUILayout.EnumPopup("Type", mAnchorType);
            NGUIEditorTools.DrawPadding();
            GUILayout.EndHorizontal();

            SerializedProperty[] tg = new SerializedProperty[4];
            for (int i = 0; i < 4; ++i)
            {
                tg[i] = serializedObject.FindProperty(FieldName[i] + ".target");
            }

            if (mAnchorType == AnchorType.None && type != AnchorType.None)
            {
                if (type == AnchorType.Unified)
                {
                    if (mTarget[0] == null && mTarget[1] == null && mTarget[2] == null && mTarget[3] == null)
                    {
                        UIRect rect   = target as UIRect;
                        UIRect parent = NGUITools.FindInParents <UIRect>(rect.cachedTransform.parent);

                        if (parent != null)
                        {
                            for (int i = 0; i < 4; ++i)
                            {
                                mTarget[i] = parent.cachedTransform;
                            }
                        }
                    }
                }

                for (int i = 0; i < 4; ++i)
                {
                    tg[i].objectReferenceValue = mTarget[i];
                    mTarget[i] = null;
                }
                UpdateAnchors(true);
            }

            if (type != AnchorType.None)
            {
                NGUIEditorTools.DrawPaddedProperty("Execute", serializedObject, "updateAnchors");
            }

            if (type == AnchorType.Advanced)
            {
                DrawAnchor(0, true);
                DrawAnchor(1, true);
                DrawAnchor(2, true);
                DrawAnchor(3, true);
            }
            else if (type == AnchorType.Unified)
            {
                DrawSingleAnchorSelection();

                DrawAnchor(0, false);
                DrawAnchor(1, false);
                DrawAnchor(2, false);
                DrawAnchor(3, false);
            }
            else if (type == AnchorType.None && mAnchorType != type)
            {
                // Save values to make it easy to "go back"
                for (int i = 0; i < 4; ++i)
                {
                    mTarget[i] = tg[i].objectReferenceValue as Transform;
                    tg[i].objectReferenceValue = null;
                }

                serializedObject.FindProperty("leftAnchor.relative").floatValue   = 0f;
                serializedObject.FindProperty("bottomAnchor.relative").floatValue = 0f;
                serializedObject.FindProperty("rightAnchor.relative").floatValue  = 1f;
                serializedObject.FindProperty("topAnchor.relative").floatValue    = 1f;
            }

            mAnchorType = type;
            OnDrawFinalProperties();
            EditorGUI.EndDisabledGroup();
            NGUIEditorTools.EndContents();
        }

        #endregion
    }
Exemplo n.º 4
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mLabel = mWidget as UILabel;

        GUILayout.BeginHorizontal();

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
#else
        mFontType = FontType.NGUI;
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f)))
#endif
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    GUILayout.Space(18f);
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();

                NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial");
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);
                if (!serializedObject.isEditingMultipleObjects)
                {
                    GUILayout.Label(" Default: " + mLabel.defaultFontSize);
                }
                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
            SerializedProperty sp = serializedObject.FindProperty("mText");
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2
            GUI.changed = false;
            string text = EditorGUILayout.TextArea(sp.stringValue, GUI.skin.textArea, GUILayout.Height(100f));
            if (GUI.changed)
            {
                sp.stringValue = text;
            }
#else
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
            GUILayout.Space(-16f);
#endif
            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }
#endif
            GUI.skin.textField.wordWrap = ww;

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader);
            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient",
#if UNITY_3_5
                                                                 GUILayout.Width(93f));
#else
                                                                 GUILayout.Width(95f));
#endif
            EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue);
            {
                NGUIEditorTools.SetLabelWidth(30f);
                NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                NGUIEditorTools.SetLabelWidth(50f);
#if UNITY_3_5
                GUILayout.Space(81f);
#else
                GUILayout.Space(79f);
#endif
                NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.SetLabelWidth(80f);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    GUILayout.Space(18f);
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Spacing", GUILayout.Width(56f));
            NGUIEditorTools.SetLabelWidth(20f);
            NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
            NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
            GUILayout.Space(18f);
            NGUIEditorTools.SetLabelWidth(80f);
            GUILayout.EndHorizontal();

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f));
            EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols);
            NGUIEditorTools.SetLabelWidth(60f);
            NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();
        return(isValid);
    }
Exemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        PropertyBinding pb = target as PropertyBinding;

        NGUIEditorTools.SetLabelWidth(80f);

        serializedObject.Update();

        if (pb.direction == PropertyBinding.Direction.TargetUpdatesSource && pb.target != null)
        {
            PropertyReferenceDrawer.filter = pb.target.GetPropertyType();
        }

        GUILayout.Space(3f);
        PropertyBinding.Direction dir = (target as PropertyBinding).direction;

        PropertyReferenceDrawer.mustRead = (dir == PropertyBinding.Direction.SourceUpdatesTarget ||
                                            dir == PropertyBinding.Direction.BiDirectional);
        PropertyReferenceDrawer.mustWrite = (dir == PropertyBinding.Direction.TargetUpdatesSource ||
                                             dir == PropertyBinding.Direction.BiDirectional);

        NGUIEditorTools.DrawProperty(serializedObject, "source");

        if (pb.direction == PropertyBinding.Direction.SourceUpdatesTarget && pb.source != null)
        {
            PropertyReferenceDrawer.filter = pb.source.GetPropertyType();
        }

        if (pb.source.target != null)
        {
            GUILayout.Space(-18f);

            if (pb.direction == PropertyBinding.Direction.TargetUpdatesSource)
            {
                GUILayout.Label("   \u25B2");                 // Up
            }
            else if (pb.direction == PropertyBinding.Direction.SourceUpdatesTarget)
            {
                GUILayout.Label("   \u25BC");                 // Down
            }
            else
            {
                GUILayout.Label("  \u25B2\u25BC");
            }
        }

        GUILayout.Space(1f);

        PropertyReferenceDrawer.mustRead = (dir == PropertyBinding.Direction.TargetUpdatesSource ||
                                            dir == PropertyBinding.Direction.BiDirectional);
        PropertyReferenceDrawer.mustWrite = (dir == PropertyBinding.Direction.SourceUpdatesTarget ||
                                             dir == PropertyBinding.Direction.BiDirectional);

        NGUIEditorTools.DrawProperty(serializedObject, "target");

        PropertyReferenceDrawer.mustRead  = false;
        PropertyReferenceDrawer.mustWrite = false;
        PropertyReferenceDrawer.filter    = typeof(void);

        GUILayout.Space(1f);
        NGUIEditorTools.DrawPaddedProperty(serializedObject, "direction");
        NGUIEditorTools.DrawPaddedProperty(serializedObject, "update");
        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty(" ", serializedObject, "editMode", GUILayout.Width(100f));
        GUILayout.Label("Update in Edit Mode");
        GUILayout.EndHorizontal();

        if (!serializedObject.isEditingMultipleObjects)
        {
            if (pb.source != null && pb.target != null && pb.source.GetPropertyType() != pb.target.GetPropertyType())
            {
                if (pb.direction == PropertyBinding.Direction.BiDirectional)
                {
                    EditorGUILayout.HelpBox("Bi-Directional updates require both Source and Target to reference values of the same type.", MessageType.Error);
                }
                else if (pb.direction == PropertyBinding.Direction.SourceUpdatesTarget)
                {
                    if (!PropertyReference.Convert(pb.source.Get(), pb.target.GetPropertyType()))
                    {
                        EditorGUILayout.HelpBox("Unable to convert " + pb.source.GetPropertyType() + " to " + pb.target.GetPropertyType(), MessageType.Error);
                    }
                }
                else if (!PropertyReference.Convert(pb.target.Get(), pb.source.GetPropertyType()))
                {
                    EditorGUILayout.HelpBox("Unable to convert " + pb.target.GetPropertyType() + " to " + pb.source.GetPropertyType(), MessageType.Error);
                }
            }
        }
        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 6
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mLabel = mWidget as UILabel;

        GUILayout.BeginHorizontal();

        if (NGUIEditorTools.DrawPrefixButton("Font"))
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, GUILayout.Width(62f));
#else
        mFontType = FontType.NGUI;
#endif
        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    GUILayout.Space(18f);
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();

                NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial");
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);
                if (!serializedObject.isEditingMultipleObjects)
                {
                    GUILayout.Label(" Default: " + mLabel.defaultFontSize);
                }
                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
#if UNITY_3_5
            GUI.changed = false;
            SerializedProperty textField = serializedObject.FindProperty("mText");
            string             text      = EditorGUILayout.TextArea(textField.stringValue, GUI.skin.textArea, GUILayout.Height(100f));
            if (GUI.changed)
            {
                textField.stringValue = text;
            }
#else
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2
            GUILayout.Space(-16f);
#endif
            GUILayout.BeginHorizontal();
            GUILayout.Space(4f);
            NGUIEditorTools.DrawProperty("", serializedObject, "mText", GUILayout.Height(80f));
            GUILayout.Space(4f);
            GUILayout.EndHorizontal();
#endif
            GUI.skin.textField.wordWrap = ww;

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Spacing", GUILayout.Width(56f));
            NGUIEditorTools.SetLabelWidth(20f);
            NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
            NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
            GUILayout.Space(18f);
            NGUIEditorTools.SetLabelWidth(80f);
            GUILayout.EndHorizontal();

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Encoding", serializedObject, "mEncoding", GUILayout.Width(100f));
            GUILayout.Label("use emoticons and colors");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient", GUILayout.Width(100f));
            if (gr.hasMultipleDifferentValues || gr.boolValue)
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(4f);

            if (mLabel.supportEncoding && mLabel.bitmapFont != null && mLabel.bitmapFont.hasSymbols)
            {
                NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            }

            GUILayout.BeginHorizontal();
            SerializedProperty sp = NGUIEditorTools.DrawProperty("Effect", serializedObject, "mEffectStyle", GUILayout.MinWidth(170f));
            GUILayout.Space(18f);
            GUILayout.EndHorizontal();

            if (sp.hasMultipleDifferentValues || sp.boolValue)
            {
                NGUIEditorTools.DrawProperty("Effect Color", serializedObject, "mEffectColor", GUILayout.MinWidth(30f));
            }

            if (sp.hasMultipleDifferentValues || sp.boolValue)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Distance", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                GUILayout.Space(18f);
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
        }
        EditorGUI.EndDisabledGroup();
        return(isValid);
    }
Exemplo n.º 7
0
    /// <summary>
    /// Draw the label's properties.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        mRichTextLabel = mWidget as UIRichTextLabel;

        GUILayout.BeginHorizontal();

#if DYNAMIC_FONT
        mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f));
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f)))
#else
        mFontType = FontType.NGUI;
        if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f)))
#endif
        {
            if (mFontType == FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnNGUIFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }
        }

        bool isValid           = false;
        SerializedProperty fnt = null;
        SerializedProperty ttf = null;

        if (mFontType == FontType.NGUI)
        {
            GUI.changed = false;
            fnt         = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f));

            if (fnt.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = fnt.objectReferenceValue;
                isValid = true;
            }
        }
        else
        {
            GUI.changed = false;
            ttf         = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f));

            if (ttf.objectReferenceValue != null)
            {
                if (GUI.changed)
                {
                    serializedObject.FindProperty("mFont").objectReferenceValue = null;
                }
                NGUISettings.ambigiousFont = ttf.objectReferenceValue;
                isValid = true;
            }
        }

        GUILayout.EndHorizontal();

        if (mFontType == FontType.Unity)
        {
            EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" +
                                    "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning);
        }

        NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat");

        EditorGUI.BeginDisabledGroup(!isValid);
        {
            UIFont uiFont  = (fnt != null) ? fnt.objectReferenceValue as UIFont : null;
            Font   dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null;

            if (uiFont != null && uiFont.isDynamic)
            {
                dynFont = uiFont.dynamicFont;
                uiFont  = null;
            }

            if (dynFont != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues);

                    SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));
                    NGUISettings.fontSize = prop.intValue;

                    prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f));
                    NGUISettings.fontStyle = (FontStyle)prop.intValue;

                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
            }
            else if (uiFont != null)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f));

                EditorGUI.BeginDisabledGroup(true);
                if (!serializedObject.isEditingMultipleObjects)
                {
                    if (mRichTextLabel.overflowMethod == UIRichTextLabel.Overflow.ShrinkContent)
                    {
                        GUILayout.Label(" Actual: " + mRichTextLabel.finalFontSize + "/" + mRichTextLabel.defaultFontSize);
                    }
                    else
                    {
                        GUILayout.Label(" Default: " + mRichTextLabel.defaultFontSize);
                    }
                }
                EditorGUI.EndDisabledGroup();

                NGUISettings.fontSize = prop.intValue;
                GUILayout.EndHorizontal();
            }

            bool ww = GUI.skin.textField.wordWrap;
            GUI.skin.textField.wordWrap = true;
            SerializedProperty sp = serializedObject.FindProperty("mText");

            if (sp.hasMultipleDifferentValues)
            {
                NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f));
            }
            else
            {
                GUIStyle style = new GUIStyle(EditorStyles.textField);
                style.wordWrap = true;

                float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f);
                bool  offset = true;

                if (height > 90f)
                {
                    offset = false;
                    height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f);
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.BeginVertical(GUILayout.Width(76f));
                    GUILayout.Space(3f);
                    GUILayout.Label("Text");
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                }
                Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));

                GUI.changed = false;
                string text = EditorGUI.TextArea(rect, sp.stringValue, style);
                if (GUI.changed)
                {
                    sp.stringValue = text;
                }

                if (offset)
                {
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }
            }

            GUI.skin.textField.wordWrap = ww;

            NGUIEditorTools.DrawPaddedProperty("Modifier", serializedObject, "mModifier");

            SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow");
            NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue;
            if (NGUISettings.overflowStyle == UILabel.Overflow.ClampContent)
            {
                NGUIEditorTools.DrawProperty("Use Ellipsis", serializedObject, "mOverflowEllipsis", GUILayout.Width(110f));
            }

            if (NGUISettings.overflowStyle == UILabel.Overflow.ResizeFreely)
            {
                GUILayout.BeginHorizontal();
                SerializedProperty s = NGUIEditorTools.DrawPaddedProperty("Max Width", serializedObject, "mOverflowWidth");
                if (s != null && s.intValue < 1)
                {
                    GUILayout.Label("unlimited");
                }
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment");

            if (dynFont != null)
            {
                NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk");
            }

            EditorGUI.BeginDisabledGroup(mRichTextLabel.bitmapFont != null && mRichTextLabel.bitmapFont.packedFontShader);
            GUILayout.BeginHorizontal();
            SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient",
                                                                 GUILayout.Width(95f));

            EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue);
            {
                NGUIEditorTools.SetLabelWidth(30f);
                NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                NGUIEditorTools.SetLabelWidth(50f);
                GUILayout.Space(79f);

                NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f));
                NGUIEditorTools.SetLabelWidth(80f);
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Effect", GUILayout.Width(76f));
            sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f));

            EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue);
            {
                NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                    NGUIEditorTools.SetLabelWidth(20f);
                    NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    NGUIEditorTools.SetLabelWidth(80f);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f));

            if (!sp.boolValue)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Spacing", GUILayout.Width(56f));
                NGUIEditorTools.SetLabelWidth(20f);
                NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f));
                NGUIEditorTools.DrawPadding();
                NGUIEditorTools.SetLabelWidth(80f);
                GUILayout.EndHorizontal();
            }

            NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f));

            GUILayout.BeginHorizontal();
            sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f));
            EditorGUI.BeginDisabledGroup(!sp.boolValue || mRichTextLabel.bitmapFont == null || !mRichTextLabel.bitmapFont.hasSymbols);
            NGUIEditorTools.SetLabelWidth(60f);
            NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols");
            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();

        if (NGUIEditorTools.DrawHeader("RichTextPrefabs"))
        {
            NGUIEditorTools.BeginContents();

            List <RichTextPrefabItem> prefabs = mRichTextLabel.Prefabs;
            for (int i = prefabs.Count - 1; i >= 0; i--)
            {
                RichTextPrefabItem prefab = prefabs[i];
                if (prefab.prefabObject == null)
                {
                    prefabs.RemoveAt(i);
                }
            }
            for (int i = 0; i < prefabs.Count; i++)
            {
                RichTextPrefabItem prefab = prefabs[i];
                if (prefab.prefabObject == null)
                {
                    continue;
                }
                GUILayout.BeginHorizontal();
                GUILayout.Label(prefab.sequence, GUILayout.Width(100f));
                GUILayout.Label(prefab.prefabObject.name, GUILayout.Width(100f));
                GUILayout.Label("width:" + prefab.width);
                GUILayout.Label("height:" + prefab.height);
                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("X", GUILayout.Width(22f)))
                {
                    NGUIEditorTools.RegisterUndo("Remove prefab", mRichTextLabel);
                    mPrefabSequence = prefab.sequence;
                    //mPrefabGameObject = prefab.prefab;
                    prefabs.Remove(prefab);
                    mRichTextLabel.MarkAsChanged();
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();
                GUILayout.Space(4f);
            }

            if (prefabs.Count > 0)
            {
                GUILayout.Space(6f);
            }

            GUILayout.BeginHorizontal();
            mPrefabSequence     = EditorGUILayout.TextField(mPrefabSequence, GUILayout.Width(100f));
            mPrefabGameObject   = (GameObject)EditorGUILayout.ObjectField(mPrefabGameObject, typeof(GameObject), GUILayout.Width(100f));
            mPrefabWidth        = EditorGUILayout.FloatField(mPrefabWidth);
            mPrefabHeight       = EditorGUILayout.FloatField(mPrefabHeight);
            isValid             = (!string.IsNullOrEmpty(mPrefabSequence)) && (mPrefabGameObject != null);
            GUI.backgroundColor = isValid ? Color.green : Color.grey;

            if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
            {
                NGUIEditorTools.RegisterUndo("Add prefab", mRichTextLabel);
                RichTextPrefabItem tprefab = new RichTextPrefabItem();
                tprefab.sequence     = mPrefabSequence;
                tprefab.prefabObject = mPrefabGameObject;
                tprefab.width        = mPrefabWidth;
                tprefab.height       = mPrefabHeight;
                mRichTextLabel.Prefabs.Add(tprefab);
                mRichTextLabel.MarkAsChanged();
                mPrefabSequence   = "";
                mPrefabGameObject = null;
            }
            GUI.backgroundColor = Color.white;
            GUILayout.EndHorizontal();

            if (prefabs.Count == 0)
            {
                EditorGUILayout.HelpBox("In the field above type ':)', choose a Prefab, then hit the Add button.", MessageType.Info);
            }
            else
            {
                GUILayout.Space(4f);
            }

            NGUIEditorTools.EndContents();
        }

        if (NGUIEditorTools.DrawHeader("RichTextEmotion"))
        {
            NGUIEditorTools.BeginContents();
            GUILayout.BeginHorizontal();
            if (NGUIEditorTools.DrawPrefixButton("Atlas"))
            {
                ComponentSelector.Show <UIAtlas>(OnSelectAtlas);
            }
            SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mEmotionAtlas", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mRichTextLabel.EmotionAtlas != null)
            {
                List <RichTextEmotionItem> emotions = mRichTextLabel.Emotions;
                for (int i = 0; i < emotions.Count; i++)
                {
                    RichTextEmotionItem emotion = emotions[i];

                    GUILayout.BeginHorizontal();
                    GUILayout.Label(emotion.sequence, GUILayout.Width(40f));
                    GUILayout.Label(emotion.spriteName);
                    GUI.backgroundColor = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        NGUIEditorTools.RegisterUndo("Remove emotion", mRichTextLabel);
                        mEmotionSequence = emotion.sequence;
                        emotions.Remove(emotion);
                        mRichTextLabel.MarkAsChanged();
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();
                    GUILayout.Space(4f);
                }

                if (emotions.Count > 0)
                {
                    GUILayout.Space(6f);
                }

                GUILayout.BeginHorizontal();
                mEmotionSequence = EditorGUILayout.TextField(mEmotionSequence, GUILayout.Width(40f));
                NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, mSpriteName, SelectSprite, false);
                isValid             = (!string.IsNullOrEmpty(mEmotionSequence)) && (!string.IsNullOrEmpty(mSpriteName));
                GUI.backgroundColor = isValid ? Color.green : Color.grey;

                if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                {
                    NGUIEditorTools.RegisterUndo("Add Sprite", mRichTextLabel);
                    RichTextEmotionItem temotion = new RichTextEmotionItem();
                    temotion.sequence   = mEmotionSequence;
                    temotion.spriteName = mSpriteName;
                    mRichTextLabel.Emotions.Add(temotion);
                    mRichTextLabel.MarkAsChanged();
                    mEmotionSequence = "";
                    mSpriteName      = "";
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                if (emotions.Count == 0)
                {
                    EditorGUILayout.HelpBox("In the field above type ':)', choose a Sprite, then hit the Add button.", MessageType.Info);
                }
                else
                {
                    GUILayout.Space(4f);
                }
            }



            NGUIEditorTools.EndContents();
        }

        isValid = true;


        return(isValid);
    }
Exemplo n.º 8
0
    public override void OnInspectorGUI()
    {
        UIInput input = target as UIInput;

        serializedObject.Update();
        GUILayout.Space(3f);
        NGUIEditorTools.SetLabelWidth(110f);
        //NGUIEditorTools.DrawProperty(serializedObject, "m_Script");

        EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
        SerializedProperty label = NGUIEditorTools.DrawProperty(serializedObject, "label");

        EditorGUI.EndDisabledGroup();

        EditorGUI.BeginDisabledGroup(label == null || label.objectReferenceValue == null);
        {
            if (Application.isPlaying)
            {
                NGUIEditorTools.DrawPaddedProperty("Value", serializedObject, "mValue");
            }
            else
            {
                NGUIEditorTools.DrawPaddedProperty("Starting Value", serializedObject, "mValue");
            }
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "savedAs");
            NGUIEditorTools.DrawProperty("Active Text Color", serializedObject, "activeTextColor");

            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
            {
                if (label != null && label.objectReferenceValue != null)
                {
                    SerializedObject ob = new SerializedObject(label.objectReferenceValue);
                    ob.Update();
                    NGUIEditorTools.DrawProperty("Inactive Color", ob, "mColor");
                    ob.ApplyModifiedProperties();
                }
                else
                {
                    EditorGUILayout.ColorField("Inactive Color", Color.white);
                }
            }
            EditorGUI.EndDisabledGroup();

            NGUIEditorTools.DrawProperty("Caret Color", serializedObject, "caretColor");
            NGUIEditorTools.DrawProperty("Selection Color", serializedObject, "selectionColor");
#if !MOBILE
            NGUIEditorTools.DrawProperty(serializedObject, "selectOnTab");
#endif
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "inputType");
#if MOBILE
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "keyboardType");
#endif
            NGUIEditorTools.DrawPaddedProperty(serializedObject, "validation");

            SerializedProperty sp = serializedObject.FindProperty("characterLimit");

            GUILayout.BeginHorizontal();

            if (sp.hasMultipleDifferentValues || input.characterLimit > 0)
            {
                EditorGUILayout.PropertyField(sp);
                GUILayout.Space(18f);
            }
            else
            {
                EditorGUILayout.PropertyField(sp);
                GUILayout.Label("unlimited");
            }
            if (input.validation == UIInput.Validation.ClampedInteger)
            {
                input.minInt = EditorGUILayout.FloatField("Min Int: ", input.minInt);
                input.maxInt = EditorGUILayout.FloatField("Max Int: ", input.maxInt);
            }
            GUILayout.EndHorizontal();

            NGUIEditorTools.SetLabelWidth(80f);
            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
            NGUIEditorTools.DrawEvents("On Submit", input, input.onSubmit);
            EditorGUI.EndDisabledGroup();
        }
        EditorGUI.EndDisabledGroup();
        serializedObject.ApplyModifiedProperties();
    }