/// <summary>
    /// Show the selection wizard.
    /// </summary>

    static public void Show <T> (OnSelectionCallback cb) where T : Object
    {
        System.Type          type = typeof(T);
        ComponentSelectorNew comp = ScriptableWizard.DisplayWizard <ComponentSelectorNew>("Select " + type.ToString());

        comp.mType     = type;
        comp.mCallback = cb;
        comp.mObjects  = Resources.FindObjectsOfTypeAll(type) as Object[];
    }
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mList = target as UIPopupList;

        ComponentSelector.Draw <UIAtlas>(mList.atlas, OnSelectAtlas);
        ComponentSelectorNew.Draw <Font>(mList.font.TrueTypeFont, OnSelectFont);

        UILabel lbl = EditorGUILayout.ObjectField("Text Label", mList.textLabel, typeof(UILabel), true) as UILabel;

        if (mList.textLabel != lbl)
        {
            RegisterUndo();
            mList.textLabel = lbl;
            if (lbl != null)
            {
                lbl.text = mList.selection;
            }
        }

        if (mList.atlas != null)
        {
            NGUIEditorTools.DrawSpriteField("Background", "Foreground sprite (shown on the button)", mList.atlas, mList.backgroundSprite, (name) =>
            {
                if (name != mList.backgroundSprite)
                {
                    RegisterUndo(); mList.backgroundSprite = name;
                }
            }, GUILayout.Width(120f));

            NGUIEditorTools.DrawSpriteField("Highlight", "Sprite used to highlight the selected option", mList.atlas, mList.highlightSprite, (name) =>
            {
                if (name != mList.highlightSprite)
                {
                    RegisterUndo(); mList.highlightSprite = name;
                }
            }, GUILayout.Width(120f));

            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);
            GUILayout.Label("Options");
            GUILayout.EndHorizontal();

            string text = "";
            foreach (string s in mList.items)
            {
                text += s + "\n";
            }

            GUILayout.Space(-22f);
            GUILayout.BeginHorizontal();
            GUILayout.Space(84f);
            string modified = EditorGUILayout.TextArea(text, GUILayout.Height(100f));
            GUILayout.EndHorizontal();

            if (modified != text)
            {
                RegisterUndo();
                string[] split = modified.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
                mList.items.Clear();
                foreach (string s in split)
                {
                    mList.items.Add(s);
                }

                if (string.IsNullOrEmpty(mList.selection) || !mList.items.Contains(mList.selection))
                {
                    mList.selection = mList.items.Count > 0 ? mList.items[0] : "";
                }
            }

            string sel = NGUIEditorTools.DrawList("Selection", mList.items.ToArray(), mList.selection);

            if (mList.selection != sel)
            {
                RegisterUndo();
                mList.selection = sel;
            }

            float ts = EditorGUILayout.FloatField("Text Scale", mList.textScale);
            Color tc = EditorGUILayout.ColorField("Text Color", mList.textColor);
            Color bc = EditorGUILayout.ColorField("Background", mList.backgroundColor);
            Color hc = EditorGUILayout.ColorField("Highlight", mList.highlightColor);

            GUILayout.BeginHorizontal();
            bool isLocalized = EditorGUILayout.Toggle("Localized", mList.isLocalized, GUILayout.Width(100f));
            bool isAnimated  = EditorGUILayout.Toggle("Animated", mList.isAnimated);
            GUILayout.EndHorizontal();

            if (mList.textScale != ts ||
                mList.textColor != tc ||
                mList.highlightColor != hc ||
                mList.backgroundColor != bc ||
                mList.isLocalized != isLocalized ||
                mList.isAnimated != isAnimated)
            {
                RegisterUndo();
                mList.textScale       = ts;
                mList.textColor       = tc;
                mList.backgroundColor = bc;
                mList.highlightColor  = hc;
                mList.isLocalized     = isLocalized;
                mList.isAnimated      = isAnimated;
            }

            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);
            GUILayout.Label("Padding", GUILayout.Width(76f));
            GUILayout.BeginVertical();
            GUILayout.Space(-12f);
            Vector2 padding = EditorGUILayout.Vector2Field("", mList.padding);
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            if (mList.padding != padding)
            {
                RegisterUndo();
                mList.padding = padding;
            }

            NGUIEditorTools.SetLabelWidth(100f);

            GameObject go = EditorGUILayout.ObjectField("Event Receiver", mList.eventReceiver,
                                                        typeof(GameObject), true) as GameObject;

            string fn = EditorGUILayout.TextField("Function Name", mList.functionName);

            if (mList.eventReceiver != go || mList.functionName != fn)
            {
                RegisterUndo();
                mList.eventReceiver = go;
                mList.functionName  = fn;
            }
        }
    }
Exemple #3
0
    override protected bool OnDrawProperties()
    {
        mLabel = mWidget as UILabel;
        if (GUILayout.Button("Font", GUILayout.Width(76f)))
        {
            ComponentSelectorNew.Show <Font>(OnSelectFont);
        }

        int fontSize = EditorGUILayout.IntField("FontSize:", mLabel.FontSize);

        if (fontSize != mLabel.FontSize)
        {
            RegisterUndo(); mLabel.FontSize = fontSize;
        }

        Font font = EditorGUILayout.ObjectField("", mLabel.TrueTypeFont, typeof(Font), false) as Font;

        if (font != mLabel.TrueTypeFont)
        {
            mLabel.TrueTypeFont = font;
        }

        EditorGUILayout.ObjectField("Material", mLabel.material, typeof(Material), false);

        if (mLabel.font == null)
        {
            return(false);
        }

        string text = EditorGUILayout.TextArea(mLabel.text, GUILayout.Height(100f));

        if (!text.Equals(mLabel.text))
        {
            RegisterUndo(); mLabel.text = text;
        }

        GUILayout.BeginHorizontal();
        {
            int len = EditorGUILayout.IntField("Line Width", mLabel.lineWidth, GUILayout.Width(120f));
            if (len != mLabel.lineWidth)
            {
                RegisterUndo(); mLabel.lineWidth = len;
            }

            bool multi = EditorGUILayout.Toggle("Multi-line", mLabel.multiLine, GUILayout.Width(100f));
            if (multi != mLabel.multiLine)
            {
                RegisterUndo(); mLabel.multiLine = multi;
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        {
            int len = EditorGUILayout.IntField("Fixed Chinese", mLabel.FixedWidthForChinese, GUILayout.Width(120f));
            if (len != mLabel.FixedWidthForChinese)
            {
                RegisterUndo(); mLabel.FixedWidthForChinese = len;
            }
        }
        GUILayout.EndHorizontal();

        int spaceingY = EditorGUILayout.IntField("LineSpacingY", mLabel.lineSpacingY);

        if (spaceingY != mLabel.lineSpacingY)
        {
            RegisterUndo(); mLabel.lineSpacingY = spaceingY;
        }

        int spaceingX = EditorGUILayout.IntField("FontSpacingX", mLabel.FontSpacingX);

        if (spaceingX != mLabel.FontSpacingX)
        {
            RegisterUndo(); mLabel.FontSpacingX = spaceingX;
        }

        GUILayout.BeginHorizontal();
        {
            bool password = EditorGUILayout.Toggle("Password", mLabel.password, GUILayout.Width(120f));
            if (password != mLabel.password)
            {
                RegisterUndo(); mLabel.password = password;
            }

            bool encoding = EditorGUILayout.Toggle("Encoding", mLabel.supportEncoding, GUILayout.Width(100f));
            if (encoding != mLabel.supportEncoding)
            {
                RegisterUndo(); mLabel.supportEncoding = encoding;
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        {
            UILabel.Effect effect = (UILabel.Effect)EditorGUILayout.EnumPopup("Effect", mLabel.effectStyle, GUILayout.Width(170f));
            if (effect != mLabel.effectStyle)
            {
                RegisterUndo(); mLabel.effectStyle = effect;
            }

            if (effect != UILabel.Effect.None)
            {
                Color c = EditorGUILayout.ColorField(mLabel.effectColor);
                if (mLabel.effectColor != c)
                {
                    RegisterUndo(); mLabel.effectColor = c;
                }
            }
        }
        GUILayout.EndHorizontal();
        FontStyle style = (FontStyle)EditorGUILayout.EnumPopup("FontStyle:", mLabel.FontStyle, GUILayout.Width(200f));

        if (style != mLabel.FontStyle)
        {
            RegisterUndo();
            mLabel.FontStyle = style;
        }

        GUILayout.BeginHorizontal();
        Color color = EditorGUILayout.ColorField("Top Color", mLabel.TopColor);

        uint colorIntValue = (uint)NGUIMath.ColorToInt(color);

        colorIntValue &= 0xFFFFFFFF;
        string colorRGBA  = colorIntValue.ToString("X8");
        string ncolorRGBA = EditorGUILayout.TextField("RGBA:", colorRGBA);

        if (ncolorRGBA != colorRGBA)
        {
            color = ColorOperation.GetColorFromRGBAStr(ncolorRGBA);
        }

        if (mLabel.TopColor != color)
        {
            NGUIEditorTools.RegisterUndo("Color Change", mLabel);
            mLabel.TopColor = color;
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        color = EditorGUILayout.ColorField("Bottom Color", mLabel.BottomColor);

        colorIntValue  = (uint)NGUIMath.ColorToInt(color);
        colorIntValue &= 0xFFFFFFFF;
        colorRGBA      = colorIntValue.ToString("X8");
        ncolorRGBA     = EditorGUILayout.TextField("RGBA:", colorRGBA);
        if (ncolorRGBA != colorRGBA)
        {
            color = ColorOperation.GetColorFromRGBAStr(ncolorRGBA);
        }

        if (mLabel.BottomColor != color)
        {
            NGUIEditorTools.RegisterUndo("Color Change", mLabel);
            mLabel.BottomColor = color;
        }
        GUILayout.EndHorizontal();

        return(true);
    }