Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        NGUIEditorTools.SetLabelWidth(80f);

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

        string text = "";

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

        GUILayout.Space(-14f);
        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.value) || !mList.items.Contains(mList.value))
            {
                mList.value = mList.items.Count > 0 ? mList.items[0] : "";
            }
        }

        GUI.changed = false;
        string sel = NGUIEditorTools.DrawList("Default", mList.items.ToArray(), mList.value);

        if (GUI.changed)
        {
            serializedObject.FindProperty("mSelectedItem").stringValue = sel;
        }

        NGUIEditorTools.DrawProperty("Position", serializedObject, "position");
        NGUIEditorTools.DrawProperty("Alignment", serializedObject, "alignment");
        NGUIEditorTools.DrawProperty("Open on", serializedObject, "openOn");
        NGUIEditorTools.DrawProperty("Localized", serializedObject, "isLocalized");

        DrawAtlas();
        DrawFont();

        NGUIEditorTools.DrawEvents("On Value Change", mList, mList.onChange);

        serializedObject.ApplyModifiedProperties();
    }
Ejemplo n.º 2
0
    override protected bool OnDrawProperties()
    {
        ///////////////////////////////////////////////////////////////////////////////
        ////////////////////////////// New ///////////////////////////////////////////
        mTexture          = mWidget as UITexture;
        mTexture.UVOffset = EditorGUILayout.Vector4Field("UV偏移", mTexture.UVOffset);
        mTexture.MarkAsChanged();
        EditorGUILayout.LabelField("TexturePath", mTexture.MaterialPath);
        string path = NGUIEditorTools.DrawList("Panel", FolderList, pathSelection);

        if (path != pathSelection)
        {
            pathSelection = path;
            TextureList   = NGUIEditorTools.GetFilesInDirectoryWithoutPathAndExtension(UITextureParentPath + pathSelection, ".png");
        }
        string texture = NGUIEditorTools.DrawList("Texture", TextureList, textureSelection);

        if (texture != textureSelection)
        {
            if (texture != NONE)
            {
                textureSelection      = texture;
                mTexture.MaterialPath = UITextureParentPathWithoutRes + pathSelection + "/" + textureSelection;
                mTexture.MaterialPath.Replace('\\', '/');
                if (mTexture.material == null)
                {
                    Shader s = Shader.Find("Unlit/Transparent Colored");
                    mTexture.material = new Material(s);
                }
                Resources.UnloadAsset(mTexture.material.mainTexture);
                Material tmpMat = new Material(mTexture.material);
                tmpMat.mainTexture = mTexture.AysnLoadTex(mTexture.MaterialPath) as Texture;
                mTexture.material  = tmpMat;
                EditorUtility.SetDirty(mWidget);
            }
        }

        //////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////// Before ////////////////////////////////////////////////////////////////
        if (mWidget.IsHidePanel != EditorGUILayout.Toggle("Hide Panel", mWidget.IsHidePanel))
        {
            mWidget.IsHidePanel = !mWidget.IsHidePanel;
            EditorUtility.SetDirty(mWidget);
            EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
        }

        Material mat = EditorGUILayout.ObjectField("Material", mWidget.material, typeof(Material), false) as Material;

        if (mWidget.material != mat)
        {
            NGUIEditorTools.RegisterUndo("Material Selection", mWidget);
            mWidget.material = mat;
        }
        return(true);
    }
    public override void OnInspectorGUI()
    {
        //EditorGUIUtility.LookLikeControls(80f);
        EditorGUIUtility.labelWidth = 80;
        EditorGUIUtility.fieldWidth = 80;
        mList = target as UIPopupList;

        ComponentSelector.Draw <UIAtlas>(mList.atlas, OnSelectAtlas);
        ComponentSelector.Draw <UIFont>(mList.font, OnSelectFont);

        GUILayout.BeginHorizontal();
        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;
            }
        }
        GUILayout.Space(44f);
        GUILayout.EndHorizontal();

        if (mList.atlas != null)
        {
            NGUIEditorTools.SpriteField("Background", mList.atlas, mList.backgroundSprite, OnBackground);
            NGUIEditorTools.SpriteField("Highlight", mList.atlas, mList.highlightSprite, OnHighlight);

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

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

            GUILayout.Space(-14f);
            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;
            }

            UIPopupList.Position pos = (UIPopupList.Position)EditorGUILayout.EnumPopup("Position", mList.position);

            if (mList.position != pos)
            {
                RegisterUndo();
                mList.position = pos;
            }

            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;
            }

            //EditorGUIUtility.LookLikeControls(100f);
            EditorGUIUtility.labelWidth = 100;
            EditorGUIUtility.fieldWidth = 100;

            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;
            }
        }
    }
Ejemplo n.º 4
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        NGUIEditorTools.SetLabelWidth(80f);
        mList = target as UIPopupList;

        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.value;
            }
        }

        if (mList.textLabel == null)
        {
            EditorGUILayout.HelpBox("This popup list has no label to update, so it will behave like a menu.", MessageType.Info);
        }

        if (mList.atlas != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);
            GUILayout.Label("Options");
            GUILayout.EndHorizontal();

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

            GUILayout.Space(-14f);
            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.value) || !mList.items.Contains(mList.value))
                {
                    mList.value = mList.items.Count > 0 ? mList.items[0] : "";
                }
            }

            GUI.changed = false;
            string sel = NGUIEditorTools.DrawList("Default", mList.items.ToArray(), mList.value);
            if (GUI.changed)
            {
                serializedObject.FindProperty("mSelectedItem").stringValue = sel;
            }

            NGUIEditorTools.DrawProperty("Position", serializedObject, "position");
            NGUIEditorTools.DrawProperty("Localized", serializedObject, "isLocalized");

            DrawAtlas();
            DrawFont();

            NGUIEditorTools.DrawEvents("On Value Change", mList, mList.onChange);
        }
        serializedObject.ApplyModifiedProperties();
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Convenience function that displays a list of sprites and returns the selected value.
    /// </summary>

    static public string SpriteField(UIAtlas atlas, string field, string name, params GUILayoutOption[] options)
    {
        List <string> sprites = atlas.GetListOfSprites();

        return((sprites != null && sprites.Count > 0) ? NGUIEditorTools.DrawList(field, sprites.ToArray(), name, options) : null);
    }
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mList = target as UIPopupList;

        ComponentSelector.Draw <UIAtlas>(mList.atlas, OnSelectAtlas);
        ComponentSelector.Draw <UIFont>(mList.font, OnSelectFont);

        GUILayout.BeginHorizontal();
        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.value;
            }
        }
        GUILayout.Space(44f);
        GUILayout.EndHorizontal();

        if (mList.textLabel == null)
        {
            EditorGUILayout.HelpBox("This popup list has no label to update, so it will behave like a menu.", MessageType.Info);
        }

        if (mList.atlas != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);
            GUILayout.Label("Options");
            GUILayout.EndHorizontal();

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

            GUILayout.Space(-14f);
            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.value) || !mList.items.Contains(mList.value))
                {
                    mList.value = mList.items.Count > 0 ? mList.items[0] : "";
                }
            }

            string sel = NGUIEditorTools.DrawList("Default", mList.items.ToArray(), mList.value);

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

            UIPopupList.Position pos = (UIPopupList.Position)EditorGUILayout.EnumPopup("Position", mList.position);

            if (mList.position != pos)
            {
                RegisterUndo();
                mList.position = pos;
            }

            bool isLocalized = EditorGUILayout.Toggle("Localized", mList.isLocalized);

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

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

                NGUIEditorTools.SpriteField("Background", mList.atlas, mList.backgroundSprite, OnBackground);
                NGUIEditorTools.SpriteField("Highlight", mList.atlas, mList.highlightSprite, OnHighlight);

                EditorGUILayout.Space();

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

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

                EditorGUILayout.Space();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Padding", GUILayout.Width(76f));
                Vector2 padding = mList.padding;
                padding.x = EditorGUILayout.FloatField(padding.x);
                padding.y = EditorGUILayout.FloatField(padding.y);
                GUILayout.Space(18f);
                GUILayout.EndHorizontal();

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

                float ts = EditorGUILayout.FloatField("Text Scale", mList.textScale, GUILayout.Width(120f));

                if (mList.textScale != ts)
                {
                    RegisterUndo();
                    mList.textScale = ts;
                }

                bool isAnimated = EditorGUILayout.Toggle("Animated", mList.isAnimated);

                if (mList.isAnimated != isAnimated)
                {
                    RegisterUndo();
                    mList.isAnimated = isAnimated;
                }
                NGUIEditorTools.EndContents();
            }

            NGUIEditorTools.DrawEvents("On Value Change", mList, mList.onChange);
        }
    }