Esempio n. 1
0
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mButton = target as UIImageButton;
        mSprite = EditorGUILayout.ObjectField("Sprite", mButton.target, typeof(UISprite), true) as UISprite;

        if (mButton.target != mSprite)
        {
            NGUIEditorTools.RegisterUndo("Image Button Change", mButton);
            mButton.target = mSprite;
            if (mSprite != null)
            {
                mSprite.spriteName = mButton.normalSprite;
            }
        }

        if (mSprite != null)
        {
            ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);

            if (mSprite.atlas != null)
            {
                NGUIEditorTools.SpriteField("Normal", mSprite.atlas, mButton.normalSprite, OnNormal);
                NGUIEditorTools.SpriteField("Hover", mSprite.atlas, mButton.hoverSprite, OnHover);
                NGUIEditorTools.SpriteField("Pressed", mSprite.atlas, mButton.pressedSprite, OnPressed);
                NGUIEditorTools.SpriteField("Disabled", mSprite.atlas, mButton.disabledSprite, OnDisabled);
            }
        }
    }
Esempio n. 2
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        mButton = target as UIImageButton;
        mSprite = EditorGUILayout.ObjectField("Sprite", mButton.target, typeof(UISprite), true) as UISprite;

        if (mButton.target != mSprite)
        {
            NGUIEditorTools.RegisterUndo("Image Button Change", mButton);
            mButton.target = mSprite;
            if (mSprite != null)
            {
                mSprite.spriteName = mButton.normalSprite;
            }
        }

        if (mSprite != null)
        {
            ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);

            if (mSprite.atlas != null)
            {
                NGUIEditorTools.SpriteField("Normal", mSprite.atlas, mButton.normalSprite, OnNormal);
                NGUIEditorTools.SpriteField("Hover", mSprite.atlas, mButton.hoverSprite, OnHover);
                NGUIEditorTools.SpriteField("Pressed", mSprite.atlas, mButton.pressedSprite, OnPressed);
                mButton.makePixelPerfect = EditorGUILayout.Toggle("MakePixelPerfect", mButton.makePixelPerfect);
            }
        }
    }
Esempio n. 3
0
    void OnGUI()
    {
        NGUIEditorTools.BeginContents(false);
        ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false);
        NGUIEditorTools.EndContents();

        GUILayout.BeginHorizontal();
        bool select = GUILayout.Button("替换图集");

        if (select)
        {
            ReplaceNormalSpriteMethod();
        }
        bool select2 = GUILayout.Button("替换语言包");

        if (select2)
        {
            ReplaceLanguageSpriteMethod();
        }
        GUILayout.EndHorizontal();

        NGUIEditorTools.BeginContents(false);
        ComponentSelector.Draw <UIFont>(NGUISettings.uifont, OnSelectUIFont, false);
        NGUISettings.fontSize = EditorGUILayout.IntField("Size", NGUISettings.fontSize);
        NGUIEditorTools.EndContents();

        GUILayout.BeginVertical();
        bool select3 = GUILayout.Button("替换字体");

        if (select3)
        {
            ReplaceFontMethod();
        }
        GUILayout.EndVertical();
    }
    //函数自Editor,用于绘制自定的inspector。注意,这个函数只有在场景中选择了对象或都在检视面板中有单击或按钮时才会被执行,且执行次数往往会有三四次。
    public override void OnInspectorGUI()
    {
        //EditorGUIUtility类中用于设定Editor 的默认外观样式,这里是把标签(label)的宽度设为80f
        EditorGUIUtility.LookLikeControls(80f);
        //target是Editor中的成员变量,指向的是当前场景中被选中的对象
        mButton = target as UIImageButton;
        //在检视面板中创建一个对象域,可通过拖拽等方式进行赋值
        mSprite = EditorGUILayout.ObjectField("Sprite", mButton.target, typeof(UISprite), true) as UISprite;

        //当Sprite域中的值与当前button中的target不一值时,设置
        if (mButton.target != mSprite)
        {
            NGUIEditorTools.RegisterUndo("Image Button Change", mButton);
            mButton.target = mSprite;
            if (mSprite != null)
            {
                mSprite.spriteName = mButton.normalSprite;
            }
        }

        if (mSprite != null)
        {
            //由于EditorGUILayout.ObjectField 不支持自定义组件(components), 此函数自定义了对象域,但是仅支持从历史记录中选择
            ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);

            //创建三个sprite域,并分配回调函数
            if (mSprite.atlas != null)
            {
                NGUIEditorTools.SpriteField("Normal", mSprite.atlas, mButton.normalSprite, OnNormal);
                NGUIEditorTools.SpriteField("Hover", mSprite.atlas, mButton.hoverSprite, OnHover);
                NGUIEditorTools.SpriteField("Pressed", mSprite.atlas, mButton.pressedSprite, OnPressed);
            }
        }
    }
Esempio n. 5
0
 protected override void DrawComponentSelector()
 {
     ComponentSelector.Draw <UIAtlas>(m.atlas, OnSelectAtlas, true);
     if (m.atlas == null)
     {
         EditorGUILayout.HelpBox("You need to select an atlas first", MessageType.Warning);
     }
 }
Esempio n. 6
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        mSpriteSwith = target as SpriteSwith;
        EditorGUILayout.BeginHorizontal();
        mRecord.Clear();
        if (mSpriteSwith.SpriteArray != null)
        {
            mRecord = mSpriteSwith.SpriteArray.ToList();
        }
        mSpriteSwith.SpriteCount = EditorGUILayout.IntField("精灵数量:", mSpriteSwith.SpriteCount);
        if (GUILayout.Button("确定"))
        {
            mSpriteSwith.SpriteArray = new string[mSpriteSwith.SpriteCount];
            int newSpriteArrayLength = mSpriteSwith.SpriteCount;
            for (int i = 0; i < mRecord.Count; i++)
            {
                if (i < newSpriteArrayLength)
                {
                    mSpriteSwith.SpriteArray[i] = mRecord[i];
                }
            }
        }
        EditorGUILayout.EndHorizontal();
        mSprite = EditorGUILayout.ObjectField("Sprite", mSpriteSwith.target, typeof(UISprite), true) as UISprite;

        if (mSpriteSwith.target != mSprite)
        {
            NGUIEditorTools.RegisterUndo("Image Button Change", mSpriteSwith);
            mSpriteSwith.target = mSprite;
        }

        if (mSprite != null)
        {
            ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);

            if (mSprite.atlas != null)
            {
                if (mSpriteSwith.SpriteArray == null)
                {
                    mSpriteSwith.SpriteArray = new string[mSpriteSwith.SpriteCount];
                    int newSpriteArrayLength = mSpriteSwith.SpriteCount;
                    for (int i = 0; i < mRecord.Count; i++)
                    {
                        if (i < newSpriteArrayLength)
                        {
                            mSpriteSwith.SpriteArray[i] = mRecord[i];
                        }
                    }
                }

                for (int i = 0; i < mSpriteSwith.SpriteArray.Length; i++)
                {
                    NGUIEditorTools.SpriteField("Sprite0" + i, mSprite.atlas, mSpriteSwith.SpriteArray[i], OnSelecte, i);
                }
            }
        }
    }
Esempio n. 7
0
    /// <summary>
    /// Draw the atlas and sprite selection fields.
    /// </summary>

    override protected bool DrawProperties()
    {
        mSprite = mWidget as UISprite;
        ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);
        if (mSprite.atlas == null)
        {
            return(false);
        }
        NGUIEditorTools.AdvancedSpriteField(mSprite.atlas, mSprite.spriteName, SelectSprite, false);
        return(true);
    }
 public override void OnHeaderGUI()
 {
     EditorGUIUtil.ObjectField <GameObject>("Scene Root", ref sceneRoot, true);
     GUI.enabled = sceneRoot != null;
     ComponentSelector.Draw <UIAtlas>("Select", NGUISettings.atlas, OnSelectAtlas, true);
     EditorGUIUtil.TextField("Filter", ref filter);
     if (EditorGUIUtil.Toggle("Expand", ref expand))
     {
         foreach (string s in spriteMap.Keys)
         {
             foldMap[s] = expand;
         }
     }
     GUI.enabled = true;
     NGUIEditorTools.DrawSeparator();
 }
Esempio n. 9
0
    /// <summary>
    /// Draw the atlas and sprite selection fields.
    /// </summary>

    override protected bool OnDrawProperties()
    {
        mSprite = mWidget as UISprite;
        mSprite.IsKeepOriSize = EditorGUILayout.Toggle("保持原图大小", mSprite.IsKeepOriSize, GUILayout.Width(100f));
        ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);
        if (mSprite.atlas == null)
        {
            return(false);
        }

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

        NGUISettings.atlas = mSprite.atlas;
        //NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false);
        NGUIEditorTools.DrawAdvancedSpriteField(NGUISettings.atlas, sp.stringValue, SelectSprite, false);
        return(true);
    }
    public override void OnInspectorGUI()
    {
                #pragma warning disable 0618
        EditorGUIUtility.LookLikeControls(80f);
                #pragma warning restore 0618
        mButton = target as UIImageButton;

        UISprite sprite = EditorGUILayout.ObjectField("Sprite", mButton.target, typeof(UISprite), true) as UISprite;

        if (mButton.target != sprite)
        {
            NGUIEditorTools.RegisterUndo("Image Button Change", mButton);
            mButton.target = sprite;
            if (sprite != null)
            {
                sprite.spriteName = mButton.normalSprite;
            }
        }

        if (mButton.target != null)
        {
            ComponentSelector.Draw <UIAtlas>(sprite.atlas as UIAtlas, OnSelectAtlas);

            if (sprite.atlas != null)
            {
                string normal = UISpriteInspector.SpriteField(sprite.atlas as UIAtlas, "Normal", mButton.normalSprite);
                string hover  = UISpriteInspector.SpriteField(sprite.atlas as UIAtlas, "Hover", mButton.hoverSprite);
                string press  = UISpriteInspector.SpriteField(sprite.atlas as UIAtlas, "Pressed", mButton.pressedSprite);

                if (mButton.normalSprite != normal ||
                    mButton.hoverSprite != hover ||
                    mButton.pressedSprite != press)
                {
                    NGUIEditorTools.RegisterUndo("Image Button Change", mButton, mButton.gameObject, sprite);
                    mButton.normalSprite  = normal;
                    mButton.hoverSprite   = hover;
                    mButton.pressedSprite = press;
                    sprite.spriteName     = normal;
                    sprite.MakePixelPerfect();
                    NGUITools.AddWidgetCollider(mButton.gameObject);
                }
            }
        }
    }
Esempio n. 11
0
    public override void OnInspectorGUI()
    {
        //EditorGUIUtility.LookLikeControls(80f);
        EditorGUIUtility.labelWidth = 80;
        EditorGUIUtility.fieldWidth = 80;

        mButton = target as UIImageButton;
        mLabel  = EditorGUILayout.ObjectField("Label", mButton.label, typeof(UILabel), true) as UILabel;
        if (mLabel != null)
        {
            mButton.label = mLabel;
        }
        else
        {
            mButton.label = null;
        }

        mSprite = EditorGUILayout.ObjectField("Sprite", mButton.target, typeof(UISprite), true) as UISprite;

        if (mButton.target != mSprite)
        {
            NGUIEditorTools.RegisterUndo("Image Button Change", mButton);
            mButton.target = mSprite;
            if (mSprite != null)
            {
                mSprite.spriteName = mButton.normalSprite;
            }
        }

        if (mSprite != null)
        {
            ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);

            if (mSprite.atlas != null)
            {
                NGUIEditorTools.SpriteField("Normal", mSprite.atlas, mButton.normalSprite, OnNormal);
                NGUIEditorTools.SpriteField("Hover", mSprite.atlas, mButton.hoverSprite, OnHover);
                NGUIEditorTools.SpriteField("Pressed", mSprite.atlas, mButton.pressedSprite, OnPressed);
                NGUIEditorTools.SpriteField("Disabled", mSprite.atlas, mButton.disabledSprite, OnDisabled);
            }
        }
    }
Esempio n. 12
0
    /// <summary>
    /// Draw the atlas and sprite selection fields.
    /// </summary>

    override protected bool OnDrawProperties()
    {
        mSprite = mWidget as UISprite;
        ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);
        if (mSprite.atlas == null)
        {
            return(false);
        }

        string spriteName = SpriteField(mSprite.atlas, mSprite.spriteName);

        if (mSprite.spriteName != spriteName)
        {
            NGUIEditorTools.RegisterUndo("Sprite Change", mSprite);
            mSprite.spriteName = spriteName;
            mSprite.MakePixelPerfect();
            EditorUtility.SetDirty(mSprite.gameObject);
        }
        return(true);
    }
Esempio n. 13
0
    void OnGUI()
    {
        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.LabelField("原图集 ");
            EditorGUILayout.LabelField("新图集 ");
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        {
            ComponentSelector.Draw <UIAtlas>(oldAtlas, OnSelectOldAtlas);
            ComponentSelector.Draw <UIAtlas>(newAtlas, OnSelectNewAtlas);
        }
        GUILayout.EndHorizontal();

        if (GUILayout.Button("一键替换"))
        {
            GameObject beChangeObj = Selection.activeGameObject;
            if (beChangeObj == null)
            {
                Debug.Log("没有选中任何东西,不能开始替换。");
            }
            int        j    = 0;
            UISprite[] sprs = beChangeObj.GetComponentsInChildren <UISprite>(true);
            foreach (UISprite spr in sprs)
            {
                if (spr.atlas == oldAtlas)
                {
                    j++;
                    spr.atlas = newAtlas;
                    Debug.Log(spr.name + "的atals被替换成功了。");
                }

                EditorUtility.SetDirty(spr);
            }

            Debug.Log(j + "个Sprite的atlas被替换了。");

            AssetDatabase.SaveAssets();
        }
    }
Esempio n. 14
0
    /// <summary>UI绘制区域.</summary>
    void OnGUI()
    {
        try
        {
            EditorGUIUtility.labelWidth = 80f;
            NGUIEditorTools.DrawHeader("选择断开(关联)字体");
            ComponentSelector.Draw <Font>("Font", (Font)NGUISettings.ambigiousFont, OnSelectNewFont, true, GUILayout.MinWidth(200f));

            //EditorGUIUtility.labelWidth = 160f;
            //NGUIEditorTools.DrawHeader("选择图集");
            //ComponentSelector.Draw<UIAtlas>("UIAtlas", NGUISettings.atlas, OnSelectAtlas, true, GUILayout.MinWidth(200f));

            NGUIEditorTools.DrawSeparator();
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.Message);
            NGUISettings.ambigiousFont = null;
            NGUISettings.atlas         = null;
        }
    }
Esempio n. 15
0
    void OnGUI()
    {
        if (!loaded)
        {
            loaded = true; Load();
        }

        EditorGUIUtility.LookLikeControls(80f);
        GameObject go = NGUIEditorTools.SelectedRoot();

        GUILayout.BeginHorizontal();
        ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, true, GUILayout.Width(140f));
        GUILayout.Label("Texture atlas used by widgets", GUILayout.MinWidth(10000f));
        GUILayout.EndHorizontal();

        GUILayout.Space(-2f);
        NGUIEditorTools.DrawSeparator();

        GUILayout.BeginHorizontal();
        template = (BarType)EditorGUILayout.EnumPopup("Template", template, GUILayout.Width(200f));
        GUILayout.Space(20f);
        GUILayout.Label("Select a widget template to use");
        GUILayout.EndHorizontal();

        switch (template)
        {
        case BarType.Filled:
            CreateFilled(go);
            break;

        case BarType.Repeated:
            CreateRepeated(go);
            break;

        case BarType.Sequence:
            CreateSequence(go);
            break;
        }
    }
Esempio n. 16
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mAtlas = target as UIAtlas;

        UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        GUILayout.Space(6f);

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        GUILayout.BeginHorizontal();
        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                mType = AtlasType.Normal;
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one atlas simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "atlas with another one, for example for " +
                                    "swapping an SD atlas with an HD one, or " +
                                    "replacing an English atlas with a Chinese " +
                                    "one. All the sprites referencing this atlas " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                NGUITools.SetDirty(mAtlas);
            }
            return;
        }

        //GUILayout.Space(6f);
        Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

        if (mAtlas.spriteMaterial != mat)
        {
            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
            mAtlas.spriteMaterial = mat;

            // Ensure that this atlas has valid import settings
            if (mAtlas.texture != null)
            {
                NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
            }

            mAtlas.MarkAsChanged();
        }

        if (mat != null)
        {
            TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

            if (ta != null)
            {
                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
                }

                NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                NGUIJson.LoadSpriteData(mAtlas, ta);
                if (sprite != null)
                {
                    sprite = mAtlas.GetSprite(sprite.name);
                }
                mAtlas.MarkAsChanged();
            }

            float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

            if (pixelSize != mAtlas.pixelSize)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.pixelSize = pixelSize;
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blueColor  = new Color(0f, 0.7f, 1f, 1f);
            Color greenColor = new Color(0.4f, 1f, 0f, 1f);

            if (sprite == null && mAtlas.spriteList.Count > 0)
            {
                string spriteName = NGUISettings.selectedSprite;
                if (!string.IsNullOrEmpty(spriteName))
                {
                    sprite = mAtlas.GetSprite(spriteName);
                }
                if (sprite == null)
                {
                    sprite = mAtlas.spriteList[0];
                }
            }

            if (sprite != null)
            {
                if (sprite == null)
                {
                    return;
                }

                Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                if (tex != null)
                {
                    if (!NGUIEditorTools.DrawHeader("Sprite Details"))
                    {
                        return;
                    }

                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);
                    NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);
                    GUILayout.Space(6f);

                    GUI.changed = false;

                    GUI.backgroundColor = greenColor;
                    NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y);
                    NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = blueColor;
                    NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight);
                    NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = Color.white;
                    NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight);
                    NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop);

                    if (GUI.changed)
                    {
                        NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);

                        sprite.x      = sizeA.x;
                        sprite.y      = sizeA.y;
                        sprite.width  = sizeB.x;
                        sprite.height = sizeB.y;

                        sprite.paddingLeft   = padA.x;
                        sprite.paddingRight  = padA.y;
                        sprite.paddingBottom = padB.x;
                        sprite.paddingTop    = padB.y;

                        sprite.borderLeft   = borderA.x;
                        sprite.borderRight  = borderA.y;
                        sprite.borderBottom = borderB.x;
                        sprite.borderTop    = borderB.y;

                        MarkSpriteAsDirty();
                    }

                    GUILayout.Space(3f);

                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button("Duplicate"))
                    {
                        UIAtlasMaker.SpriteEntry se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name);
                        if (se != null)
                        {
                            NGUISettings.selectedSprite = se.name;
                        }
                    }

                    if (GUILayout.Button("Save As..."))
                    {
                        string path = EditorUtility.SaveFilePanel("Save As",
                                                                  NGUISettings.currentPath, sprite.name + ".png", "png");

                        if (!string.IsNullOrEmpty(path))
                        {
                            NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                            UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, sprite.name);

                            if (se != null)
                            {
                                byte[] bytes = se.tex.EncodeToPNG();
                                File.WriteAllBytes(path, bytes);
                                AssetDatabase.ImportAsset(path);
                                if (se.temporaryTexture)
                                {
                                    DestroyImmediate(se.tex);
                                }
                            }
                        }
                    }
                    if (GUILayout.Button("Save As All"))
                    {
                        string path = EditorUtility.SaveFolderPanel("Save As All",
                                                                    NGUISettings.currentPath, "");
                        if (!string.IsNullOrEmpty(path))
                        {
                            var list = mAtlas.spriteList;
                            foreach (var uiSpriteData in list)
                            {
                                var spName = uiSpriteData.name;
                                NGUISettings.currentPath = path;
                                UIAtlasMaker.SpriteEntry se = UIAtlasMaker.ExtractSprite(mAtlas, spName);
                                if (se != null)
                                {
                                    var    filePath = string.Format("{0}/{1}.png", path, spName);
                                    byte[] bytes    = se.tex.EncodeToPNG();
                                    File.WriteAllBytes(filePath, bytes);
                                    AssetDatabase.ImportAsset(filePath);
                                    if (se.temporaryTexture)
                                    {
                                        DestroyImmediate(se.tex);
                                    }
                                }
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                    NGUIEditorTools.EndContents();
                }

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

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20f);
                    EditorGUILayout.BeginVertical();

                    NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor);

                    if (GUILayout.Button("Add a Shadow"))
                    {
                        AddShadow(sprite);
                    }
                    if (GUILayout.Button("Add a Soft Outline"))
                    {
                        AddOutline(sprite);
                    }

                    if (GUILayout.Button("Add a Transparent Border"))
                    {
                        AddTransparentBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Clamped Border"))
                    {
                        AddClampedBorder(sprite);
                    }
                    if (GUILayout.Button("Add a Tiled Border"))
                    {
                        AddTiledBorder(sprite);
                    }
                    EditorGUI.BeginDisabledGroup(!sprite.hasBorder);
                    if (GUILayout.Button("Crop Border"))
                    {
                        CropBorder(sprite);
                    }
                    EditorGUI.EndDisabledGroup();

                    EditorGUILayout.EndVertical();
                    GUILayout.Space(20f);
                    EditorGUILayout.EndHorizontal();

                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.previousSelection != null)
                {
                    GUILayout.Space(3f);
                    GUI.backgroundColor = Color.green;

                    if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                    {
                        NGUIEditorTools.SelectPrevious();
                    }
                    GUI.backgroundColor = Color.white;
                }
            }
        }
    }
Esempio n. 17
0
    /// <summary>
    /// Draw the UI for this tool.
    /// </summary>

    void OnGUI()
    {
        bool create  = false;
        bool update  = false;
        bool replace = false;

        string prefabPath = "";
        string matPath    = "";

        // If we have an atlas to work with, see if we can figure out the path for it and its material
        if (NGUISettings.atlas != null && NGUISettings.atlas.name == NGUISettings.atlasName)
        {
            prefabPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.gameObject.GetInstanceID());
            if (NGUISettings.atlas.spriteMaterial != null)
            {
                matPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.spriteMaterial.GetInstanceID());
            }
        }

        // Assume default values if needed
        if (string.IsNullOrEmpty(NGUISettings.atlasName))
        {
            NGUISettings.atlasName = "New Atlas";
        }
        if (string.IsNullOrEmpty(prefabPath))
        {
            prefabPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.atlasName + ".prefab";
        }
        if (string.IsNullOrEmpty(matPath))
        {
            matPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.atlasName + ".mat";
        }

        // Try to load the prefab
        GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

        if (NGUISettings.atlas == null && go != null)
        {
            NGUISettings.atlas = go.GetComponent <UIAtlas>();
        }

        EditorGUIUtility.LookLikeControls(80f);

        GUILayout.Space(6f);
        GUILayout.BeginHorizontal();

        if (go == null)
        {
            GUI.backgroundColor = Color.green;
            create = GUILayout.Button("Create", GUILayout.Width(76f));
        }
        else
        {
            GUI.backgroundColor = Color.red;
            create = GUILayout.Button("Replace", GUILayout.Width(76f));
        }

        GUI.backgroundColor    = Color.white;
        NGUISettings.atlasName = GUILayout.TextField(NGUISettings.atlasName);
        GUILayout.EndHorizontal();

        if (create)
        {
            // If the prefab already exists, confirm that we want to overwrite it
            if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " +
                                                          NGUISettings.atlasName + " atlas with the textures currently selected in the Project View? All other sprites will be deleted.", "Yes", "No"))
            {
                replace = true;

                // Try to load the material
                Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;

                // If the material doesn't exist, create it
                if (mat == null)
                {
                    Shader shader = Shader.Find("Unlit/Transparent Colored");
                    mat = new Material(shader);

                    // Save the material
                    AssetDatabase.CreateAsset(mat, matPath);
                    AssetDatabase.Refresh();

                    // Load the material so it's usable
                    mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;
                }

                if (NGUISettings.atlas == null || NGUISettings.atlas.name != NGUISettings.atlasName)
                {
                    // Create a new prefab for the atlas
#if UNITY_3_4
                    Object prefab = (go != null) ? go : EditorUtility.CreateEmptyPrefab(prefabPath);
#else
                    Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(prefabPath);
#endif
                    // Create a new game object for the atlas
                    go = new GameObject(NGUISettings.atlasName);
                    go.AddComponent <UIAtlas>().spriteMaterial = mat;

                    // Update the prefab
#if UNITY_3_4
                    EditorUtility.ReplacePrefab(go, prefab);
#else
                    PrefabUtility.ReplacePrefab(go, prefab);
#endif
                    DestroyImmediate(go);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    // Select the atlas
                    go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
                    NGUISettings.atlas = go.GetComponent <UIAtlas>();
                }
            }
        }

        ComponentSelector.Draw <UIAtlas>("...or select", NGUISettings.atlas, OnSelectAtlas);

        List <Texture> textures = GetSelectedTextures();

        if (NGUISettings.atlas != null && NGUISettings.atlas.name == NGUISettings.atlasName)
        {
            Material mat = NGUISettings.atlas.spriteMaterial;
            Texture  tex = NGUISettings.atlas.texture;

            // Material information
            GUILayout.BeginHorizontal();
            {
                if (mat != null)
                {
                    if (GUILayout.Button("Material", GUILayout.Width(76f)))
                    {
                        Selection.activeObject = mat;
                    }
                    GUILayout.Label(" " + mat.name);
                }
                else
                {
                    GUI.color = Color.grey;
                    GUILayout.Button("Material", GUILayout.Width(76f));
                    GUI.color = Color.white;
                    GUILayout.Label(" N/A");
                }
            }
            GUILayout.EndHorizontal();

            // Texture atlas information
            GUILayout.BeginHorizontal();
            {
                if (tex != null)
                {
                    if (GUILayout.Button("Texture", GUILayout.Width(76f)))
                    {
                        Selection.activeObject = tex;
                    }
                    GUILayout.Label(" " + tex.width + "x" + tex.height);
                }
                else
                {
                    GUI.color = Color.grey;
                    GUILayout.Button("Texture", GUILayout.Width(76f));
                    GUI.color = Color.white;
                    GUILayout.Label(" N/A");
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            NGUISettings.atlasPadding = Mathf.Clamp(EditorGUILayout.IntField("Padding", NGUISettings.atlasPadding, GUILayout.Width(100f)), 0, 8);
            GUILayout.Label("in pixels in-between of sprites");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            NGUISettings.atlasTrimming = EditorGUILayout.Toggle("Trim Alpha", NGUISettings.atlasTrimming, GUILayout.Width(100f));
            GUILayout.Label("Remove empty space");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            NGUISettings.unityPacking = EditorGUILayout.Toggle("Unity Packer", NGUISettings.unityPacking, GUILayout.MinWidth(100f));
            GUILayout.Label("if off, use a custom packer");
            GUILayout.EndHorizontal();

            if (textures.Count > 0)
            {
                GUI.backgroundColor = Color.green;
                update = GUILayout.Button("Add/Update All");
                GUI.backgroundColor = Color.white;
            }
            else
            {
                NGUIEditorTools.DrawSeparator();
                GUILayout.Label("You can reveal more options by selecting\none or more textures in the Project View\nwindow.");
            }
        }
        else
        {
            NGUIEditorTools.DrawSeparator();
            GUILayout.Label("You can create a new atlas by selecting\none or more textures in the Project View\nwindow, then clicking \"Create\".");
        }

        Dictionary <string, int> spriteList = GetSpriteList(textures);

        if (spriteList.Count > 0)
        {
            NGUIEditorTools.DrawHeader("Sprites");
            GUILayout.Space(-7f);

            mScroll = GUILayout.BeginScrollView(mScroll);

            string delSprite = null;
            int    index     = 0;
            foreach (KeyValuePair <string, int> iter in spriteList)
            {
                ++index;
                NGUIEditorTools.HighlightLine(new Color(0.6f, 0.6f, 0.6f));
                GUILayout.BeginHorizontal();
                GUILayout.Label(index.ToString(), GUILayout.Width(24f));
                GUILayout.Label(iter.Key);

                if (iter.Value == 2)
                {
                    GUI.color = Color.green;
                    GUILayout.Label("Add", GUILayout.Width(27f));
                    GUI.color = Color.white;
                }
                else if (iter.Value == 1)
                {
                    GUI.color = Color.cyan;
                    GUILayout.Label("Update", GUILayout.Width(45f));
                    GUI.color = Color.white;
                }
                else
                {
                    if (string.IsNullOrEmpty(mDelName) || mDelName != iter.Key)
                    {
                        // If we have not yet selected a sprite for deletion, show a small "X" button
                        if (GUILayout.Button("X", GUILayout.Width(22f)))
                        {
                            mDelName = iter.Key;
                        }
                    }
                    else
                    {
                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("Delete", GUILayout.Width(60f)))
                        {
                            // Confirmation button clicked on -- delete this sprite
                            delSprite = iter.Key;
                            mDelName  = null;
                        }
                        GUI.backgroundColor = Color.white;
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            // If this sprite was marked for deletion, remove it from the atlas
            if (!string.IsNullOrEmpty(delSprite))
            {
                List <UIAtlas.Sprite> list = NGUISettings.atlas.spriteList;

                foreach (UIAtlas.Sprite sp in list)
                {
                    if (sp.name == delSprite)
                    {
                        list.Remove(sp);
                        List <SpriteEntry> sprites = new List <SpriteEntry>();
                        ExtractSprites(NGUISettings.atlas, sprites);
                        UpdateAtlas(NGUISettings.atlas, sprites);
                        mDelName = null;
                        return;
                    }
                }
            }
            else if (update)
            {
                UpdateAtlas(textures, true);
            }
            else if (replace)
            {
                UpdateAtlas(textures, false);
            }
            return;
        }
    }
Esempio n. 18
0
    /// <summary>
    /// Draw the UI for this tool.
    /// </summary>

    void OnGUI()
    {
        string prefabPath = "";
        string matPath    = "";

        if (NGUISettings.font != null && NGUISettings.font.name == NGUISettings.fontName)
        {
            prefabPath = AssetDatabase.GetAssetPath(NGUISettings.font.gameObject.GetInstanceID());
            if (NGUISettings.font.material != null)
            {
                matPath = AssetDatabase.GetAssetPath(NGUISettings.font.material.GetInstanceID());
            }
        }

        // Assume default values if needed
        if (string.IsNullOrEmpty(NGUISettings.fontName))
        {
            NGUISettings.fontName = "New Font";
        }
        if (string.IsNullOrEmpty(prefabPath))
        {
            prefabPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.fontName + ".prefab";
        }
        if (string.IsNullOrEmpty(matPath))
        {
            matPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.fontName + ".mat";
        }

        NGUIEditorTools.SetLabelWidth(80f);
        NGUIEditorTools.DrawHeader("Input", true);
        NGUIEditorTools.BeginContents();

        GUILayout.BeginHorizontal();
        mType = (FontType)EditorGUILayout.EnumPopup("Type", mType);
        GUILayout.Space(18f);
        GUILayout.EndHorizontal();
        int create = 0;

        if (mType == FontType.Dynamic)
        {
            NGUISettings.dynamicFont = EditorGUILayout.ObjectField("Font TTF", NGUISettings.dynamicFont, typeof(Font), false) as Font;

            GUILayout.BeginHorizontal();
            NGUISettings.dynamicFontSize  = EditorGUILayout.IntField("Font Size", NGUISettings.dynamicFontSize, GUILayout.Width(120f));
            NGUISettings.dynamicFontStyle = (FontStyle)EditorGUILayout.EnumPopup(NGUISettings.dynamicFontStyle);
            GUILayout.Space(18f);
            GUILayout.EndHorizontal();
            NGUIEditorTools.EndContents();

            if (NGUISettings.dynamicFont != null)
            {
                NGUIEditorTools.DrawHeader("Output", true);

                NGUIEditorTools.BeginContents();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Font Name", GUILayout.Width(76f));
                GUI.backgroundColor   = Color.white;
                NGUISettings.fontName = GUILayout.TextField(NGUISettings.fontName);

#if !UNITY_3_5
                if (NGUISettings.dynamicFont != null)
                {
                    GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

                    if (go != null)
                    {
                        if (go.GetComponent <UIFont>() != null)
                        {
                            GUI.backgroundColor = Color.red;
                            if (GUILayout.Button("Replace", GUILayout.Width(70f)))
                            {
                                create = 1;
                            }
                        }
                        else
                        {
                            GUI.backgroundColor = Color.grey;
                            GUILayout.Button("Rename", GUILayout.Width(70f));
                        }
                    }
                    else
                    {
                        GUI.backgroundColor = Color.green;
                        if (GUILayout.Button("Create", GUILayout.Width(70f)))
                        {
                            create = 1;
                        }
                    }

                    GUI.backgroundColor = Color.white;
                }
#endif
                GUILayout.EndHorizontal();
                NGUIEditorTools.EndContents();
            }

#if UNITY_3_5
            EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
            // Helpful info
            if (NGUISettings.dynamicFont == null)
            {
                EditorGUILayout.HelpBox("Dynamic font creation happens right in Unity. Simply specify the TrueType font to be used as source.", MessageType.Info);
            }
            EditorGUILayout.HelpBox("Please note that dynamic fonts can't be made a part of an atlas, and using dynamic fonts will result in at least one extra draw call.", MessageType.Warning);
#endif
        }
        else
        {
            NGUISettings.fontData    = EditorGUILayout.ObjectField("Font Data", NGUISettings.fontData, typeof(TextAsset), false) as TextAsset;
            NGUISettings.fontTexture = EditorGUILayout.ObjectField("Texture", NGUISettings.fontTexture, typeof(Texture2D), false) as Texture2D;
            NGUIEditorTools.EndContents();

            // Draw the atlas selection only if we have the font data and texture specified, just to make it easier
            if (NGUISettings.fontData != null && NGUISettings.fontTexture != null)
            {
                NGUIEditorTools.DrawHeader("Output", true);
                NGUIEditorTools.BeginContents();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Font Name", GUILayout.Width(76f));
                GUI.backgroundColor   = Color.white;
                NGUISettings.fontName = GUILayout.TextField(NGUISettings.fontName);
                GUILayout.EndHorizontal();

                ComponentSelector.Draw <UIFont>("Select", NGUISettings.font, OnSelectFont);
                ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas);
                NGUIEditorTools.EndContents();
            }

            // Helpful info
            if (NGUISettings.fontData == null)
            {
                EditorGUILayout.HelpBox("The bitmap font creation mostly takes place outside of Unity. You can use BMFont on " +
                                        "Windows or your choice of Glyph Designer or the less expensive bmGlyph on the Mac.\n\n" +
                                        "Either of these tools will create a FNT file for you that you will drag & drop into the field above.", MessageType.Info);
            }
            else if (NGUISettings.fontTexture == null)
            {
                EditorGUILayout.HelpBox("When exporting your font, you should get two files: the TXT, and the texture. Only one texture can be used per font.", MessageType.Info);
            }
            else if (NGUISettings.atlas == null)
            {
                EditorGUILayout.HelpBox("You can create a font that doesn't use a texture atlas. This will mean that the text " +
                                        "labels using this font will generate an extra draw call, and will need to be sorted by " +
                                        "adjusting the Z instead of the Depth.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info);

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("Create a Font without an Atlas", GUILayout.Width(200f)))
                {
                    create = 2;
                }
                GUI.backgroundColor = Color.white;
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

                if (go != null)
                {
                    if (go.GetComponent <UIFont>() != null)
                    {
                        GUI.backgroundColor = Color.red;
                        if (GUILayout.Button("Replace the Font", GUILayout.Width(140f)))
                        {
                            create = 3;
                        }
                    }
                    else
                    {
                        GUI.backgroundColor = Color.grey;
                        GUILayout.Button("Rename Your Font", GUILayout.Width(140f));
                    }
                }
                else
                {
                    GUI.backgroundColor = Color.green;
                    if (GUILayout.Button("Create the Font", GUILayout.Width(140f)))
                    {
                        create = 3;
                    }
                }
                GUI.backgroundColor = Color.white;
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
        }

        if (create != 0)
        {
            GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

            if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " +
                                                          NGUISettings.fontName + " font with the currently selected values? This action can't be undone.", "Yes", "No"))
            {
                // Try to load the material
                Material mat = null;

                // Non-atlased font
                if (create == 2)
                {
                    mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;

                    // If the material doesn't exist, create it
                    if (mat == null)
                    {
                        Shader shader = Shader.Find("Unlit/Transparent Colored");
                        mat = new Material(shader);

                        // Save the material
                        AssetDatabase.CreateAsset(mat, matPath);
                        AssetDatabase.Refresh();

                        // Load the material so it's usable
                        mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;
                    }
                    mat.mainTexture = NGUISettings.fontTexture;
                }
                else if (create != 1)
                {
                    UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, NGUISettings.fontTexture);
                }

                // Font doesn't exist yet
                if (go == null || go.GetComponent <UIFont>() == null)
                {
                    // Create a new prefab for the atlas
                    Object prefab = PrefabUtility.CreateEmptyPrefab(prefabPath);

                    // Create a new game object for the font
                    go = new GameObject(NGUISettings.fontName);
                    NGUISettings.font = go.AddComponent <UIFont>();
                    CreateFont(NGUISettings.font, create, mat);

                    // Update the prefab
                    PrefabUtility.ReplacePrefab(go, prefab);
                    DestroyImmediate(go);
                    AssetDatabase.Refresh();

                    // Select the atlas
                    go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
                    NGUISettings.font = go.GetComponent <UIFont>();
                }
                else
                {
                    NGUISettings.font = go.GetComponent <UIFont>();
                    CreateFont(NGUISettings.font, create, mat);
                }
                MarkAsChanged();
            }
        }
    }
Esempio n. 19
0
    public override void OnInspectorGUI()
    {
        mFont = target as UIFont;
        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.Space(6f);

        if (mFont.replacement != null)
        {
            mType        = FontType.Reference;
            mReplacement = mFont.replacement;
        }
        else if (mFont.dynamicFont != null)
        {
            mType = FontType.Dynamic;
        }

        GUI.changed = false;
        GUILayout.BeginHorizontal();
        mType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);
        GUILayout.Space(18f);
        GUILayout.EndHorizontal();

        if (GUI.changed)
        {
            if (mType == FontType.Bitmap)
            {
                OnSelectFont(null);
            }

            if (mType != FontType.Dynamic && mFont.dynamicFont != null)
            {
                mFont.dynamicFont = null;
            }
        }

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont, true);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one font simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "font with another one, for example for " +
                                    "swapping an SD font with an HD one, or " +
                                    "replacing an English font with a Chinese " +
                                    "one. All the labels referencing this font " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mFont && mFont.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Font Change", mFont);
                mFont.replacement = mReplacement;
                NGUITools.SetDirty(mFont);
            }
            return;
        }
        else if (mType == FontType.Dynamic)
        {
#if UNITY_3_5
            EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
            Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font;

            if (fnt != mFont.dynamicFont)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFont = fnt;
            }

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

            if (mFont.material != mat)
            {
                NGUIEditorTools.RegisterUndo("Font Material", mFont);
                mFont.material = mat;
            }

            GUILayout.BeginHorizontal();
            int       size  = EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f));
            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle);
            GUILayout.Space(18f);
            GUILayout.EndHorizontal();

            if (size != mFont.defaultSize)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.defaultSize = size;
            }

            if (style != mFont.dynamicFontStyle)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontStyle = style;
            }
#endif
        }
        else
        {
            ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas, true);

            if (mFont.atlas != null)
            {
                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.DrawAdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
                EditorGUILayout.Space();
            }
            else
            {
                // No atlas specified -- set the material and texture rectangle directly
                Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

                if (mFont.material != mat)
                {
                    NGUIEditorTools.RegisterUndo("Font Material", mFont);
                    mFont.material = mat;
                }
            }

            // For updating the font's data when importing from an external source, such as the texture packer
            bool resetWidthHeight = false;

            if (mFont.atlas != null || mFont.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset;

                if (data != null)
                {
                    NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
                    BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
                    mFont.MarkAsChanged();
                    resetWidthHeight = true;
                    ClientLog.Instance.Log("Imported " + mFont.bmFont.glyphCount + " characters");
                }
            }

            if (mFont.bmFont.isValid)
            {
                Texture2D tex = mFont.texture;

                if (tex != null && mFont.atlas == null)
                {
                    // Pixels are easier to work with than UVs
                    Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

                    // Automatically set the width and height of the rectangle to be the original font texture's dimensions
                    if (resetWidthHeight)
                    {
                        pixels.width  = mFont.texWidth;
                        pixels.height = mFont.texHeight;
                    }

                    // Font sprite rectangle
                    pixels = EditorGUILayout.RectField("Pixel Rect", pixels);

                    // Convert the pixel coordinates back to UV coordinates
                    Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

                    if (mFont.uvRect != uvRect)
                    {
                        NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
                        mFont.uvRect = uvRect;
                    }
                    //NGUIEditorTools.DrawSeparator();
                    EditorGUILayout.Space();
                }
            }
        }

        // Dynamic fonts don't support emoticons
        if (!mFont.isDynamic && mFont.bmFont.isValid)
        {
            if (mFont.atlas != null)
            {
                if (NGUIEditorTools.DrawHeader("Symbols and Emoticons"))
                {
                    NGUIEditorTools.BeginContents();

                    List <BMSymbol> symbols = mFont.symbols;

                    for (int i = 0; i < symbols.Count;)
                    {
                        BMSymbol sym = symbols[i];

                        GUILayout.BeginHorizontal();
                        GUILayout.Label(sym.sequence, GUILayout.Width(40f));
                        if (NGUIEditorTools.DrawSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite, GUILayout.MinWidth(100f)))
                        {
                            mSelectedSymbol = sym;
                        }

                        if (GUILayout.Button("Edit", GUILayout.Width(40f)))
                        {
                            if (mFont.atlas != null)
                            {
                                NGUISettings.atlas          = mFont.atlas;
                                NGUISettings.selectedSprite = sym.spriteName;
                                NGUIEditorTools.Select(mFont.atlas.gameObject);
                            }
                        }

                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("X", GUILayout.Width(22f)))
                        {
                            NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
                            mSymbolSequence = sym.sequence;
                            mSymbolSprite   = sym.spriteName;
                            symbols.Remove(sym);
                            mFont.MarkAsChanged();
                        }
                        GUI.backgroundColor = Color.white;
                        GUILayout.EndHorizontal();
                        GUILayout.Space(4f);
                        ++i;
                    }

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

                    GUILayout.BeginHorizontal();
                    mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
                    NGUIEditorTools.DrawSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

                    bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
                    GUI.backgroundColor = isValid ? Color.green : Color.grey;

                    if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                    {
                        NGUIEditorTools.RegisterUndo("Add symbol", mFont);
                        mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
                        mFont.MarkAsChanged();
                        mSymbolSequence = "";
                        mSymbolSprite   = "";
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();

                    if (symbols.Count == 0)
                    {
                        EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
                    }
                    else
                    {
                        GUILayout.Space(4f);
                    }

                    NGUIEditorTools.EndContents();
                }
            }
        }

        if (mFont.bmFont != null && mFont.bmFont.isValid)
        {
            if (NGUIEditorTools.DrawHeader("Modify"))
            {
                NGUIEditorTools.BeginContents();

                UISpriteData sd = mFont.sprite;

                bool disable = (sd != null && (sd.paddingLeft != 0 || sd.paddingBottom != 0));
                EditorGUI.BeginDisabledGroup(disable || mFont.packedFontShader);

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20f);
                EditorGUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                GUILayout.BeginVertical();
                NGUISettings.foregroundColor = EditorGUILayout.ColorField("Foreground", NGUISettings.foregroundColor);
                NGUISettings.backgroundColor = EditorGUILayout.ColorField("Background", NGUISettings.backgroundColor);
                GUILayout.EndVertical();
                mCurve = EditorGUILayout.CurveField("", mCurve, GUILayout.Width(40f), GUILayout.Height(40f));
                GUILayout.EndHorizontal();

                if (GUILayout.Button("Add a Shadow"))
                {
                    ApplyEffect(Effect.Shadow, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Add a Soft Outline"))
                {
                    ApplyEffect(Effect.Outline, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Rebalance Colors"))
                {
                    ApplyEffect(Effect.Rebalance, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Apply Curve to Alpha"))
                {
                    ApplyEffect(Effect.AlphaCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Apply Curve to Foreground"))
                {
                    ApplyEffect(Effect.ForegroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Apply Curve to Background"))
                {
                    ApplyEffect(Effect.BackgroundCurve, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }

                GUILayout.Space(10f);
                if (GUILayout.Button("Add Transparent Border (+1)"))
                {
                    ApplyEffect(Effect.Border, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }
                if (GUILayout.Button("Remove Border (-1)"))
                {
                    ApplyEffect(Effect.Crop, NGUISettings.foregroundColor, NGUISettings.backgroundColor);
                }

                EditorGUILayout.EndVertical();
                GUILayout.Space(20f);
                EditorGUILayout.EndHorizontal();

                EditorGUI.EndDisabledGroup();

                if (disable)
                {
                    GUILayout.Space(3f);
                    EditorGUILayout.HelpBox("The sprite used by this font has been trimmed and is not suitable for modification. " +
                                            "Try re-adding this sprite with 'Trim Alpha' disabled.", MessageType.Warning);
                }

                NGUIEditorTools.EndContents();
            }
        }

        // The font must be valid at this point for the rest of the options to show up
        if (mFont.isDynamic || mFont.bmFont.isValid)
        {
            if (mFont.atlas == null)
            {
                mView      = View.Font;
                mUseShader = false;
            }
        }

        // Preview option
        if (!mFont.isDynamic && mFont.atlas != null)
        {
            GUILayout.BeginHorizontal();
            {
                mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                GUILayout.Label("Shader", GUILayout.Width(45f));
                mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
            }
            GUILayout.EndHorizontal();
        }
    }
Esempio n. 20
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        // Load the saved preferences
        if (!mLoaded)
        {
            mLoaded = true;
            Load();
#if DYNAMIC_FONT
            Object font = NGUISettings.ambigiousFont;
            mType = ((font != null) && (font is UIFont)) ? UILabelInspector.FontType.NGUI : UILabelInspector.FontType.Unity;
#else
            mType = UILabelInspector.FontType.NGUI;
#endif
        }

        NGUIEditorTools.SetLabelWidth(80f);
        GameObject go = NGUIEditorTools.SelectedRoot();

        if (go == null)
        {
            GUILayout.Label("You must create a UI first.");

            if (GUILayout.Button("Open the New UI Wizard"))
            {
                EditorWindow.GetWindow <UICreateNewUIWizard>(false, "New UI", true);
            }
        }
        else
        {
            GUILayout.Space(4f);

            GUILayout.BeginHorizontal();
            ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false, GUILayout.Width(140f));
            GUILayout.Label("Texture atlas used by widgets", GUILayout.Width(10000f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

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

#if DYNAMIC_FONT
            GUI.changed = false;

            if (mType == UILabelInspector.FontType.Unity)
            {
                NGUISettings.ambigiousFont = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont, typeof(Font), false, GUILayout.Width(140f));
            }
            else
            {
                NGUISettings.ambigiousFont = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont, typeof(UIFont), false, GUILayout.Width(140f));
            }
            mType = (UILabelInspector.FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f));
#else
            NGUISettings.ambigiousFont = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont, typeof(UIFont), false, GUILayout.Width(140f));
#endif
            GUILayout.Label("size", GUILayout.Width(30f));
            EditorGUI.BeginDisabledGroup(mType == UILabelInspector.FontType.NGUI);
            NGUISettings.fontSize = EditorGUILayout.IntField(NGUISettings.fontSize, GUILayout.Width(30f));
            EditorGUI.EndDisabledGroup();
            GUILayout.Label("font used by the labels");
            GUILayout.EndHorizontal();
            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            WidgetType wt = (WidgetType)EditorGUILayout.EnumPopup("Template", mWidgetType, GUILayout.Width(200f));
            GUILayout.Space(20f);
            GUILayout.Label("Select a widget template to use");
            GUILayout.EndHorizontal();

            if (mWidgetType != wt)
            {
                mWidgetType = wt; Save();
            }

            switch (mWidgetType)
            {
            case WidgetType.Label:                  CreateLabel(go); break;

            case WidgetType.Sprite:                 CreateSprite(go); break;

            case WidgetType.Texture:                CreateSimpleTexture(go); break;

            case WidgetType.Button:                 CreateButton(go); break;

            case WidgetType.ImageButton:    CreateImageButton(go); break;

            case WidgetType.Toggle:                 CreateToggle(go); break;

            case WidgetType.ProgressBar:    CreateSlider(go, false); break;

            case WidgetType.Slider:                 CreateSlider(go, true); break;

            case WidgetType.Input:                  CreateInput(go); break;

            case WidgetType.PopupList:              CreatePopup(go, true); break;

            case WidgetType.PopupMenu:              CreatePopup(go, false); break;

            case WidgetType.ScrollBar:              CreateScrollBar(go); break;
            }

            EditorGUILayout.HelpBox("Widget Tool has become far less useful with NGUI 3.0.6. Search the Project view for 'Control', then simply drag & drop one of them into your Scene View.", MessageType.Warning);
        }
    }
    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;
            }
        }
    }
Esempio n. 22
0
    /// <summary>
    /// Draw the UI for this tool.
    /// </summary>

    void OnGUI()
    {
        if (mLastAtlas != NGUISettings.atlas)
        {
            mLastAtlas = NGUISettings.atlas;
            atlasName  = (NGUISettings.atlas != null) ? NGUISettings.atlas.name : "New Atlas";
        }

        bool create  = false;
        bool update  = false;
        bool replace = false;

        string prefabPath = "";
        string matPath    = "";

        // If we have an atlas to work with, see if we can figure out the path for it and its material
        if (NGUISettings.atlas != null && NGUISettings.atlas.name == atlasName)
        {
            prefabPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.gameObject.GetInstanceID());
            if (NGUISettings.atlas.spriteMaterial != null)
            {
                matPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.spriteMaterial.GetInstanceID());
            }
        }

        // Assume default values if needed
        if (string.IsNullOrEmpty(atlasName))
        {
            atlasName = "New Atlas";
        }
        if (string.IsNullOrEmpty(prefabPath))
        {
            prefabPath = NGUIEditorTools.GetSelectionFolder() + atlasName + ".prefab";
        }
        if (string.IsNullOrEmpty(matPath))
        {
            matPath = NGUIEditorTools.GetSelectionFolder() + atlasName + ".mat";
        }

        // Try to load the prefab
        GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

        if (NGUISettings.atlas == null && go != null)
        {
            NGUISettings.atlas = go.GetComponent <UIAtlas>();
        }

        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.Space(6f);
        GUILayout.BeginHorizontal();

        if (go == null)
        {
            GUI.backgroundColor = Color.green;
            create = GUILayout.Button("Create", GUILayout.Width(76f));
        }
        else
        {
            GUI.backgroundColor = Color.red;
            create = GUILayout.Button("Replace", GUILayout.Width(76f));
        }

        GUI.backgroundColor = Color.white;
        atlasName           = GUILayout.TextField(atlasName);
        GUILayout.EndHorizontal();

        if (create)
        {
            // If the prefab already exists, confirm that we want to overwrite it
            if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " +
                                                          atlasName + " atlas with the textures currently selected in the Project View? All other sprites will be deleted.", "Yes", "No"))
            {
                replace = true;

                // Try to load the material
                Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;

                // If the material doesn't exist, create it
                if (mat == null)
                {
                    Shader shader = Shader.Find(NGUISettings.atlasPMA ? "Unlit/Premultiplied Colored" : "Unlit/Transparent Colored");
                    mat = new Material(shader);

                    // Save the material
                    AssetDatabase.CreateAsset(mat, matPath);
                    AssetDatabase.Refresh();

                    // Load the material so it's usable
                    mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;
                }

                if (NGUISettings.atlas == null || NGUISettings.atlas.name != atlasName)
                {
                    // Create a new prefab for the atlas
                    Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(prefabPath);

                    // Create a new game object for the atlas
                    go = new GameObject(atlasName);
                    go.AddComponent <UIAtlas>().spriteMaterial = mat;

                    // Update the prefab
                    PrefabUtility.ReplacePrefab(go, prefab);
                    DestroyImmediate(go);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    // Select the atlas
                    go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
                    NGUISettings.atlas = go.GetComponent <UIAtlas>();
                }
            }
        }

        ComponentSelector.Draw <UIAtlas>("Select", NGUISettings.atlas, OnSelectAtlas, true);

        List <Texture> textures = GetSelectedTextures();

        if (NGUISettings.atlas != null && NGUISettings.atlas.name == atlasName)
        {
            Material mat = NGUISettings.atlas.spriteMaterial;
            Texture  tex = NGUISettings.atlas.texture;

            // Material information
            GUILayout.BeginHorizontal();
            {
                if (mat != null)
                {
                    if (GUILayout.Button("Material", GUILayout.Width(76f)))
                    {
                        Selection.activeObject = mat;
                    }
                    GUILayout.Label(" " + mat.name);
                }
                else
                {
                    GUI.color = Color.grey;
                    GUILayout.Button("Material", GUILayout.Width(76f));
                    GUI.color = Color.white;
                    GUILayout.Label(" N/A");
                }
            }
            GUILayout.EndHorizontal();

            // Texture atlas information
            GUILayout.BeginHorizontal();
            {
                if (tex != null)
                {
                    if (GUILayout.Button("Texture", GUILayout.Width(76f)))
                    {
                        Selection.activeObject = tex;
                    }
                    GUILayout.Label(" " + tex.width + "x" + tex.height);
                }
                else
                {
                    GUI.color = Color.grey;
                    GUILayout.Button("Texture", GUILayout.Width(76f));
                    GUI.color = Color.white;
                    GUILayout.Label(" N/A");
                }
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        NGUISettings.atlasPadding = Mathf.Clamp(EditorGUILayout.IntField("Padding", NGUISettings.atlasPadding, GUILayout.Width(100f)), 0, 8);
        GUILayout.Label((NGUISettings.atlasPadding == 1 ? "pixel" : "pixels") + " in-between of sprites");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.atlasTrimming = EditorGUILayout.Toggle("Trim Alpha", NGUISettings.atlasTrimming, GUILayout.Width(100f));
        GUILayout.Label("Remove empty space");
        GUILayout.EndHorizontal();

        bool fixedShader = false;

        if (go != null && NGUISettings.atlas != null)
        {
            Material mat = NGUISettings.atlas.spriteMaterial;

            if (mat != null)
            {
                Shader shader = mat.shader;

                if (shader != null)
                {
                    if (shader.name == "Unlit/Transparent Colored")
                    {
                        NGUISettings.atlasPMA = false;
                        fixedShader           = true;
                    }
                    else if (shader.name == "Unlit/Premultiplied Colored")
                    {
                        NGUISettings.atlasPMA = true;
                        fixedShader           = true;
                    }
                }
            }
        }

        if (!fixedShader)
        {
            GUILayout.BeginHorizontal();
            NGUISettings.atlasPMA = EditorGUILayout.Toggle("PMA Shader", NGUISettings.atlasPMA, GUILayout.Width(100f));
            GUILayout.Label("Pre-multiply color by alpha");
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        NGUISettings.unityPacking = EditorGUILayout.Toggle("Unity Packer", NGUISettings.unityPacking, GUILayout.Width(100f));
        GUILayout.Label("if off, use a custom packer");
        GUILayout.EndHorizontal();

        if (!NGUISettings.unityPacking)
        {
            GUILayout.BeginHorizontal();
            NGUISettings.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", NGUISettings.forceSquareAtlas, GUILayout.Width(100f));
            GUILayout.Label("if on, forces a square atlas texture");
            GUILayout.EndHorizontal();
        }

#if UNITY_IPHONE || UNITY_ANDROID
        GUILayout.BeginHorizontal();
        NGUISettings.allow4096 = EditorGUILayout.Toggle("4096x4096", NGUISettings.allow4096, GUILayout.Width(100f));
        GUILayout.Label("if off, limit atlases to 2048x2048");
        GUILayout.EndHorizontal();
#endif
        if (NGUISettings.atlas != null && NGUISettings.atlas.name == atlasName)
        {
            if (textures.Count > 0)
            {
                GUI.backgroundColor = Color.green;
                update = GUILayout.Button("Add/Update All");
                GUI.backgroundColor = Color.white;
            }
            else
            {
                if (GUILayout.Button("View Sprites"))
                {
                    SpriteSelector.ShowSelected();
                }
                EditorGUILayout.HelpBox("You can reveal more options by selecting one or more textures in the Project View window.", MessageType.Info);
            }
        }
        else
        {
            EditorGUILayout.HelpBox("You can create a new atlas by selecting one or more textures in the Project View window, then clicking \"Create\".", MessageType.Info);
        }

        string selection = null;
        Dictionary <string, int> spriteList = GetSpriteList(textures);

        if (spriteList.Count > 0)
        {
            NGUIEditorTools.DrawHeader("Sprites", true);
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(3f);
                GUILayout.BeginVertical();

                mScroll = GUILayout.BeginScrollView(mScroll);

                bool delete = false;
                int  index  = 0;
                foreach (KeyValuePair <string, int> iter in spriteList)
                {
                    ++index;

                    GUILayout.Space(-1f);
                    bool highlight = (UIAtlasInspector.instance != null) && (NGUISettings.selectedSprite == iter.Key);
                    GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);
                    GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f));
                    GUI.backgroundColor = Color.white;
                    GUILayout.Label(index.ToString(), GUILayout.Width(24f));

                    if (GUILayout.Button(iter.Key, "OL TextField", GUILayout.Height(20f)))
                    {
                        selection = iter.Key;
                    }

                    if (iter.Value == 2)
                    {
                        GUI.color = Color.green;
                        GUILayout.Label("Add", GUILayout.Width(27f));
                        GUI.color = Color.white;
                    }
                    else if (iter.Value == 1)
                    {
                        GUI.color = Color.cyan;
                        GUILayout.Label("Update", GUILayout.Width(45f));
                        GUI.color = Color.white;
                    }
                    else
                    {
                        if (mDelNames.Contains(iter.Key))
                        {
                            GUI.backgroundColor = Color.red;

                            if (GUILayout.Button("Delete", GUILayout.Width(60f)))
                            {
                                delete = true;
                            }
                            GUI.backgroundColor = Color.green;
                            if (GUILayout.Button("X", GUILayout.Width(22f)))
                            {
                                mDelNames.Remove(iter.Key);
                                delete = false;
                            }
                            GUI.backgroundColor = Color.white;
                        }
                        else
                        {
                            // If we have not yet selected a sprite for deletion, show a small "X" button
                            if (GUILayout.Button("X", GUILayout.Width(22f)))
                            {
                                mDelNames.Add(iter.Key);
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
                GUILayout.Space(3f);
                GUILayout.EndHorizontal();

                // If this sprite was marked for deletion, remove it from the atlas
                if (delete)
                {
                    List <SpriteEntry> sprites = new List <SpriteEntry>();
                    ExtractSprites(NGUISettings.atlas, sprites);

                    for (int i = sprites.Count; i > 0;)
                    {
                        SpriteEntry ent = sprites[--i];
                        if (mDelNames.Contains(ent.name))
                        {
                            sprites.RemoveAt(i);
                        }
                    }
                    UpdateAtlas(NGUISettings.atlas, sprites);
                    mDelNames.Clear();
                    NGUIEditorTools.RepaintSprites();
                }
                else if (update)
                {
                    UpdateAtlas(textures, true);
                }
                else if (replace)
                {
                    UpdateAtlas(textures, false);
                }

                if (NGUISettings.atlas != null && !string.IsNullOrEmpty(selection))
                {
                    NGUIEditorTools.SelectSprite(selection);
                }
                else if (update || replace)
                {
                    NGUIEditorTools.UpgradeTexturesToSprites(NGUISettings.atlas);
                    NGUIEditorTools.RepaintSprites();
                }
            }
        }

        // Uncomment this line if you want to be able to force-sort the atlas
        //if (NGUISettings.atlas != null && GUILayout.Button("Sort Alphabetically")) NGUISettings.atlas.SortAlphabetically();
    }
Esempio n. 23
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        mAtlas = target as UIAtlas;

        NGUIEditorTools.DrawSeparator();

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement as UIAtlas;
        }

        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement as UIAtlas, OnSelectAtlas);

            NGUIEditorTools.DrawSeparator();
            GUILayout.Label("You can have one atlas simply point to\n" +
                            "another one. This is useful if you want to be\n" +
                            "able to quickly replace the contents of one\n" +
                            "atlas with another one, for example for\n" +
                            "swapping an SD atlas with an HD one, or\n" +
                            "replacing an English atlas with a Chinese\n" +
                            "one. All the sprites referencing this atlas\n" +
                            "will update their references to the new one.");

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mAtlas);
            }
            return;
        }

        if (!mConfirmDelete)
        {
            NGUIEditorTools.DrawSeparator();
            Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

            if (mAtlas.spriteMaterial != mat)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.spriteMaterial = mat;

                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);
                }

                mAtlas.MarkAsDirty();
                mConfirmDelete = false;
            }

            if (mat != null)
            {
                TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

                if (ta != null)
                {
                    // Ensure that this atlas has valid import settings
                    if (mAtlas.texture != null)
                    {
                        NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);
                    }

                    NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                    NGUIJson.LoadSpriteData(mAtlas, ta);
                    if (mSprite != null)
                    {
                        mSprite = mAtlas.GetSprite(mSprite.name);
                    }
                    mAtlas.MarkAsDirty();
                }

                UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates);

                if (coords != mAtlas.coordinates)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.coordinates = coords;
                    mConfirmDelete     = false;
                }

                float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize);

                if (pixelSize != mAtlas.pixelSize)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.pixelSize = pixelSize;
                    mConfirmDelete   = false;
                }
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blue  = new Color(0f, 0.7f, 1f, 1f);
            Color green = new Color(0.4f, 1f, 0f, 1f);

            if (mConfirmDelete)
            {
                if (mSprite != null)
                {
                    // Show the confirmation dialog
                    NGUIEditorTools.DrawSeparator();
                    GUILayout.Label("Are you sure you want to delete '" + mSprite.name + "'?");
                    NGUIEditorTools.DrawSeparator();

                    GUILayout.BeginHorizontal();
                    {
                        GUI.backgroundColor = Color.green;
                        if (GUILayout.Button("Cancel"))
                        {
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("Delete"))
                        {
                            NGUIEditorTools.RegisterUndo("Delete Sprite", mAtlas);
                            mAtlas.spriteList.Remove(mSprite);
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    mConfirmDelete = false;
                }
            }
            else
            {
                if (mSprite == null && mAtlas.spriteList.Count > 0)
                {
                    string spriteName = EditorPrefs.GetString("NGUI Selected Sprite");
                    if (!string.IsNullOrEmpty(spriteName))
                    {
                        mSprite = mAtlas.GetSprite(spriteName);
                    }
                    if (mSprite == null)
                    {
                        mSprite = mAtlas.spriteList[0];
                    }
                }

                GUI.backgroundColor = Color.green;

                GUILayout.BeginHorizontal();
                {
                    EditorGUILayout.PrefixLabel("Add/Delete");

                    if (GUILayout.Button("New Sprite"))
                    {
                        NGUIEditorTools.RegisterUndo("Add Sprite", mAtlas);
                        UIAtlas.Sprite newSprite = new UIAtlas.Sprite();

                        if (mSprite != null)
                        {
                            newSprite.name  = "Copy of " + mSprite.name;
                            newSprite.outer = mSprite.outer;
                            newSprite.inner = mSprite.inner;
                        }
                        else
                        {
                            newSprite.name = "New Sprite";
                        }

                        mAtlas.spriteList.Add(newSprite);
                        mSprite = newSprite;
                    }

                    // Show the delete button
                    GUI.backgroundColor = Color.red;

                    if (mSprite != null && GUILayout.Button("Delete", GUILayout.Width(55f)))
                    {
                        mConfirmDelete = true;
                    }
                    GUI.backgroundColor = Color.white;
                }
                GUILayout.EndHorizontal();

                if (!mConfirmDelete && mSprite != null)
                {
                    NGUIEditorTools.DrawSeparator();

                    string spriteName = UISpriteInspector.SpriteField(mAtlas, mSprite.name);

                    if (spriteName != mSprite.name)
                    {
                        mSprite = mAtlas.GetSprite(spriteName);
                        EditorPrefs.SetString("NGUI Selected Sprite", spriteName);
                    }

                    if (mSprite == null)
                    {
                        return;
                    }

                    Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                    if (tex != null)
                    {
                        Rect inner = mSprite.inner;
                        Rect outer = mSprite.outer;

                        string name = EditorGUILayout.TextField("Edit Name", mSprite.name);

                        if (mSprite.name != name && !string.IsNullOrEmpty(name))
                        {
                            bool found = false;

                            foreach (UIAtlas.Sprite sp in mAtlas.spriteList)
                            {
                                if (sp.name == name)
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (!found)
                            {
                                NGUIEditorTools.RegisterUndo("Edit Sprite Name", mAtlas);
                                mSprite.name = name;
                            }
                        }

                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            GUI.backgroundColor = green;
                            outer = NGUIEditorTools.IntRect("Dimensions", mSprite.outer);

                            Vector4 border = new Vector4(
                                mSprite.inner.xMin - mSprite.outer.xMin,
                                mSprite.inner.yMin - mSprite.outer.yMin,
                                mSprite.outer.xMax - mSprite.inner.xMax,
                                mSprite.outer.yMax - mSprite.inner.yMax);

                            GUI.backgroundColor = blue;
                            border = NGUIEditorTools.IntPadding("Border", border);
                            GUI.backgroundColor = Color.white;

                            inner.xMin = mSprite.outer.xMin + border.x;
                            inner.yMin = mSprite.outer.yMin + border.y;
                            inner.xMax = mSprite.outer.xMax - border.z;
                            inner.yMax = mSprite.outer.yMax - border.w;
                        }
                        else
                        {
                            // Draw the inner and outer rectangle dimensions
                            GUI.backgroundColor = green;
                            outer = EditorGUILayout.RectField("Outer Rect", mSprite.outer);
                            GUI.backgroundColor = blue;
                            inner = EditorGUILayout.RectField("Inner Rect", mSprite.inner);
                            GUI.backgroundColor = Color.white;
                        }

                        if (outer.xMax < outer.xMin)
                        {
                            outer.xMax = outer.xMin;
                        }
                        if (outer.yMax < outer.yMin)
                        {
                            outer.yMax = outer.yMin;
                        }

                        if (outer != mSprite.outer)
                        {
                            float x = outer.xMin - mSprite.outer.xMin;
                            float y = outer.yMin - mSprite.outer.yMin;

                            inner.x += x;
                            inner.y += y;
                        }

                        // Sanity checks to ensure that the inner rect is always inside the outer
                        inner.xMin = Mathf.Clamp(inner.xMin, outer.xMin, outer.xMax);
                        inner.xMax = Mathf.Clamp(inner.xMax, outer.xMin, outer.xMax);
                        inner.yMin = Mathf.Clamp(inner.yMin, outer.yMin, outer.yMax);
                        inner.yMax = Mathf.Clamp(inner.yMax, outer.yMin, outer.yMax);

                        EditorGUILayout.Separator();

                        // Padding is mainly meant to be used by the 'trimmed' feature of TexturePacker
                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            int left   = Mathf.RoundToInt(mSprite.paddingLeft * mSprite.outer.width);
                            int right  = Mathf.RoundToInt(mSprite.paddingRight * mSprite.outer.width);
                            int top    = Mathf.RoundToInt(mSprite.paddingTop * mSprite.outer.height);
                            int bottom = Mathf.RoundToInt(mSprite.paddingBottom * mSprite.outer.height);

                            NGUIEditorTools.IntVector a = NGUIEditorTools.IntPair("Padding", "Left", "Top", left, top);
                            NGUIEditorTools.IntVector b = NGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom);

                            if (a.x != left || a.y != top || b.x != right || b.y != bottom)
                            {
                                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                                mSprite.paddingLeft   = a.x / mSprite.outer.width;
                                mSprite.paddingTop    = a.y / mSprite.outer.width;
                                mSprite.paddingRight  = b.x / mSprite.outer.height;
                                mSprite.paddingBottom = b.y / mSprite.outer.height;
                                MarkSpriteAsDirty();
                            }
                        }
                        else
                        {
                            // Create a button that can make the coordinates pixel-perfect on click
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.Label("Correction", GUILayout.Width(75f));

                                Rect corrected0 = outer;
                                Rect corrected1 = inner;

                                if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                                {
                                    corrected0 = NGUIMath.MakePixelPerfect(corrected0);
                                    corrected1 = NGUIMath.MakePixelPerfect(corrected1);
                                }
                                else
                                {
                                    corrected0 = NGUIMath.MakePixelPerfect(corrected0, tex.width, tex.height);
                                    corrected1 = NGUIMath.MakePixelPerfect(corrected1, tex.width, tex.height);
                                }

                                if (corrected0 == mSprite.outer && corrected1 == mSprite.inner)
                                {
                                    GUI.color = Color.grey;
                                    GUILayout.Button("Make Pixel-Perfect");
                                    GUI.color = Color.white;
                                }
                                else if (GUILayout.Button("Make Pixel-Perfect"))
                                {
                                    outer       = corrected0;
                                    inner       = corrected1;
                                    GUI.changed = true;
                                }
                            }
                            GUILayout.EndHorizontal();
                        }

                        GUILayout.BeginHorizontal();
                        {
                            mView = (View)EditorGUILayout.EnumPopup("Show", mView);
                            GUILayout.Label("Shader", GUILayout.Width(45f));

                            if (mUseShader != EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)))
                            {
                                mUseShader = !mUseShader;

                                if (mUseShader && mView == View.Sprite)
                                {
                                    // TODO: Remove this when Unity fixes the bug with DrawPreviewTexture not being affected by BeginGroup
                                    Debug.LogWarning("There is a bug in Unity that prevents the texture from getting clipped properly.\n" +
                                                     "Until it's fixed by Unity, your texture may spill onto the rest of the Unity's GUI while using this mode.");
                                }
                            }
                        }
                        GUILayout.EndHorizontal();

                        if (mSprite.outer != outer || mSprite.inner != inner)
                        {
                            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                            mSprite.outer  = outer;
                            mSprite.inner  = inner;
                            mConfirmDelete = false;
                            MarkSpriteAsDirty();
                        }

                        Rect uv0 = outer;
                        Rect uv1 = inner;

                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            uv0 = NGUIMath.ConvertToTexCoords(uv0, tex.width, tex.height);
                            uv1 = NGUIMath.ConvertToTexCoords(uv1, tex.width, tex.height);
                        }

                        // Draw the atlas
                        EditorGUILayout.Separator();
                        Material m    = mUseShader ? mAtlas.spriteMaterial : null;
                        Rect     rect = (mView == View.Atlas) ? NGUIEditorTools.DrawAtlas(tex, m) : NGUIEditorTools.DrawSprite(tex, uv0, m);

                        // Draw the sprite outline
                        NGUIEditorTools.DrawOutline(rect, uv0, uv1);
                        EditorGUILayout.Separator();
                    }
                }
            }
        }
    }
Esempio n. 24
0
    override public void OnInspectorGUI()
    {
        mFont = target as UIFont;
        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

        //Lindean
        if (mFont.dynamicFont != null)
        {
            mType = FontType.Dynamic;
        }

        if (mFont.replacement != null)
        {
            mType        = FontType.Reference;
            mReplacement = mFont.replacement;
        }
        else if (mFont.dynamicFont_1 != null)
        {
            mType = FontType.Dynamic;
        }

        GUILayout.BeginHorizontal();
        FontType fontType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);

        GUILayout.Space(18f);
        GUILayout.EndHorizontal();

        if (mType != fontType)
        {
            if (fontType == FontType.Normal)
            {
                OnSelectFont(null);
            }
            else
            {
                mType = fontType;
            }

            //Lindean
            if (mType != FontType.Dynamic && mFont.dynamicFont_1 != null)
            {
                mFont.dynamicFont_1 = null;
            }
        }

        //Lindean
        if (mType == FontType.Dynamic)
        {
            //Lindean - Draw settings for dynamic font
            bool changed = false;
            Font f       = EditorGUILayout.ObjectField("Font", mFont.dynamicFont, typeof(Font), false) as Font;
            if (f != mFont.dynamicFont)
            {
                mFont.dynamicFont = f;
                changed           = true;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.dynamicFontMaterial_1, typeof(Material), false) as Material;
            if (mat != mFont.dynamicFontMaterial_1)
            {
                mFont.dynamicFontMaterial_1 = mat;
                changed = true;
            }
            if (mFont.dynamicFontMaterial_1 == null)
            {
                GUILayout.Label("Warning: no coloring or clipping when using default font material");
            }

            int i = EditorGUILayout.IntField("Size", mFont.dynamicFontSize);
            if (i != mFont.dynamicFontSize)
            {
                mFont.dynamicFontSize = i;
                changed = true;
            }

            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup("Style", mFont.dynamicFontStyle);
            if (style != mFont.dynamicFontStyle)
            {
                mFont.dynamicFontStyle = style;
                changed = true;
            }

            if (changed)
            {
                //force access to material property as it refreshes the texture assignment
                Debug.Log("font changed...");
                Material fontMat = mFont.material;
                if (fontMat.mainTexture == null)
                {
                    Debug.Log("font material texture issue...");
                }
                UIFont.OnFontRebuilt(mFont);
            }

            NGUIEditorTools.DrawSeparator();

            // Font spacing
            GUILayout.BeginHorizontal();
            {
                EditorGUIUtility.LookLikeControls(0f);
                GUILayout.Label("Spacing", GUILayout.Width(60f));
                GUILayout.Label("X", GUILayout.Width(12f));
                int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
                GUILayout.Label("Y", GUILayout.Width(12f));
                int y = EditorGUILayout.IntField(mFont.verticalSpacing);
                EditorGUIUtility.LookLikeControls(80f);

                if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
                {
                    NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
                    mFont.horizontalSpacing = x;
                    mFont.verticalSpacing   = y;
                }
            }
            GUILayout.EndHorizontal();
        }
        //Lindean

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont);

            NGUIEditorTools.DrawSeparator();
            GUILayout.Label("You can have one font simply point to\n" +
                            "another one. This is useful if you want to be\n" +
                            "able to quickly replace the contents of one\n" +
                            "font with another one, for example for\n" +
                            "swapping an SD font with an HD one, or\n" +
                            "replacing an English font with a Chinese\n" +
                            "one. All the labels referencing this font\n" +
                            "will update their references to the new one.");

            if (mReplacement != mFont && mFont.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Font Change", mFont);
                mFont.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mFont);
            }
            return;
        }
        else if (mType == FontType.Dynamic)
        {
#if UNITY_3_5
            EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
            NGUIEditorTools.DrawSeparator();
            Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont_1, typeof(Font), false) as Font;

            if (fnt != mFont.dynamicFont_1)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFont_1 = fnt;
            }

            GUILayout.BeginHorizontal();
            int       size  = EditorGUILayout.IntField("Size", mFont.dynamicFontSize_1, GUILayout.Width(120f));
            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle_1);
            GUILayout.Space(18f);
            GUILayout.EndHorizontal();

            if (size != mFont.dynamicFontSize_1)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontSize_1 = size;
            }

            if (style != mFont.dynamicFontStyle_1)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontStyle_1 = style;
            }

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

            if (mFont.material != mat)
            {
                NGUIEditorTools.RegisterUndo("Font Material", mFont);
                mFont.material = mat;
            }
#endif
        }
        else
        {
            NGUIEditorTools.DrawSeparator();

            ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas);

            if (mFont.atlas != null)
            {
                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
                EditorGUILayout.Space();
            }
            else
            {
                // No atlas specified -- set the material and texture rectangle directly
                Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

                if (mFont.material != mat)
                {
                    NGUIEditorTools.RegisterUndo("Font Material", mFont);
                    mFont.material = mat;
                }
            }

            // For updating the font's data when importing from an external source, such as the texture packer
            bool resetWidthHeight = false;

            if (mFont.atlas != null || mFont.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset;

                if (data != null)
                {
                    NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
                    BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
                    mFont.MarkAsDirty();
                    resetWidthHeight = true;
                    Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters");
                }
            }

            if (mFont.bmFont.isValid)
            {
                Color     green = new Color(0.4f, 1f, 0f, 1f);
                Texture2D tex   = mFont.texture;

                if (tex != null)
                {
                    if (mFont.atlas == null)
                    {
                        // Pixels are easier to work with than UVs
                        Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

                        // Automatically set the width and height of the rectangle to be the original font texture's dimensions
                        if (resetWidthHeight)
                        {
                            pixels.width  = mFont.texWidth;
                            pixels.height = mFont.texHeight;
                        }

                        // Font sprite rectangle
                        GUI.backgroundColor = green;
                        pixels = EditorGUILayout.RectField("Pixel Rect", pixels);
                        GUI.backgroundColor = Color.white;

                        // Create a button that can make the coordinates pixel-perfect on click
                        GUILayout.BeginHorizontal();
                        {
                            Rect corrected = NGUIMath.MakePixelPerfect(pixels);

                            if (corrected == pixels)
                            {
                                GUI.color = Color.grey;
                                GUILayout.Button("Make Pixel-Perfect");
                                GUI.color = Color.white;
                            }
                            else if (GUILayout.Button("Make Pixel-Perfect"))
                            {
                                pixels      = corrected;
                                GUI.changed = true;
                            }
                        }
                        GUILayout.EndHorizontal();

                        // Convert the pixel coordinates back to UV coordinates
                        Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

                        if (mFont.uvRect != uvRect)
                        {
                            NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
                            mFont.uvRect = uvRect;
                        }
                        //NGUIEditorTools.DrawSeparator();
                        EditorGUILayout.Space();
                    }
                }
            }
        }

        // The font must be valid at this point for the rest of the options to show up
        if (mFont.isDynamic || mFont.bmFont.isValid)
        {
            // Font spacing
            GUILayout.BeginHorizontal();
            {
                EditorGUIUtility.LookLikeControls(0f);
                GUILayout.Label("Spacing", GUILayout.Width(60f));
                GUILayout.Label("X", GUILayout.Width(12f));
                int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
                GUILayout.Label("Y", GUILayout.Width(12f));
                int y = EditorGUILayout.IntField(mFont.verticalSpacing);
                GUILayout.Space(18f);
                EditorGUIUtility.LookLikeControls(80f);

                if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
                {
                    NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
                    mFont.horizontalSpacing = x;
                    mFont.verticalSpacing   = y;
                }
            }
            GUILayout.EndHorizontal();

            if (mFont.atlas == null)
            {
                mView      = View.Font;
                mUseShader = false;

                float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f));

                if (pixelSize != mFont.pixelSize)
                {
                    NGUIEditorTools.RegisterUndo("Font Change", mFont);
                    mFont.pixelSize = pixelSize;
                }
            }
            EditorGUILayout.Space();
        }

        // Preview option
        if (!mFont.isDynamic && mFont.atlas != null)
        {
            GUILayout.BeginHorizontal();
            {
                mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                GUILayout.Label("Shader", GUILayout.Width(45f));
                mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
            }
            GUILayout.EndHorizontal();
        }

        // Dynamic fonts don't support emoticons
        if (!mFont.isDynamic && mFont.bmFont.isValid)
        {
            if (mFont.atlas != null)
            {
                NGUIEditorTools.DrawHeader("Symbols and Emoticons");

                List <BMSymbol> symbols = mFont.symbols;

                for (int i = 0; i < symbols.Count;)
                {
                    BMSymbol sym = symbols[i];

                    GUILayout.BeginHorizontal();
                    GUILayout.Label(sym.sequence, GUILayout.Width(40f));
                    if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite))
                    {
                        mSelectedSymbol = sym;
                    }

                    if (GUILayout.Button("Edit", GUILayout.Width(40f)))
                    {
                        if (mFont.atlas != null)
                        {
                            EditorPrefs.SetString("NGUI Selected Sprite", sym.spriteName);
                            NGUIEditorTools.Select(mFont.atlas.gameObject);
                        }
                    }

                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
                        mSymbolSequence = sym.sequence;
                        mSymbolSprite   = sym.spriteName;
                        symbols.Remove(sym);
                        mFont.MarkAsDirty();
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();
                    GUILayout.Space(4f);
                    ++i;
                }

                if (symbols.Count > 0)
                {
                    NGUIEditorTools.DrawSeparator();
                }

                GUILayout.BeginHorizontal();
                mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
                NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

                bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
                GUI.backgroundColor = isValid ? Color.green : Color.grey;

                if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                {
                    NGUIEditorTools.RegisterUndo("Add symbol", mFont);
                    mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
                    mFont.MarkAsDirty();
                    mSymbolSequence = "";
                    mSymbolSprite   = "";
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                if (symbols.Count == 0)
                {
                    EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
                }
                else
                {
                    GUILayout.Space(4f);
                }
            }
        }
    }
Esempio n. 25
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        mAtlas = target as UIAtlas;

        UIAtlas.Sprite sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        NGUIEditorTools.DrawSeparator();

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas);

            NGUIEditorTools.DrawSeparator();
            EditorGUILayout.HelpBox("You can have one atlas simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "atlas with another one, for example for " +
                                    "swapping an SD atlas with an HD one, or " +
                                    "replacing an English atlas with a Chinese " +
                                    "one. All the sprites referencing this atlas " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mAtlas);
            }
            return;
        }

        if (!mConfirmDelete)
        {
            NGUIEditorTools.DrawSeparator();
            Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

            if (mAtlas.spriteMaterial != mat)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.spriteMaterial = mat;

                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);
                }

                mAtlas.MarkAsDirty();
                mConfirmDelete = false;
            }

            if (mat != null)
            {
                TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

                if (ta != null)
                {
                    // Ensure that this atlas has valid import settings
                    if (mAtlas.texture != null)
                    {
                        NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);
                    }

                    NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                    NGUIJson.LoadSpriteData(mAtlas, ta);
                    if (sprite != null)
                    {
                        sprite = mAtlas.GetSprite(sprite.name);
                    }
                    mAtlas.MarkAsDirty();
                }

                UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates);

                if (coords != mAtlas.coordinates)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.coordinates = coords;
                    mConfirmDelete     = false;
                }

                float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

                if (pixelSize != mAtlas.pixelSize)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.pixelSize = pixelSize;
                    mConfirmDelete   = false;
                }
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blue  = new Color(0f, 0.7f, 1f, 1f);
            Color green = new Color(0.4f, 1f, 0f, 1f);

            if (mConfirmDelete)
            {
                if (sprite != null)
                {
                    // Show the confirmation dialog
                    NGUIEditorTools.DrawSeparator();
                    GUILayout.Label("Are you sure you want to delete '" + sprite.name + "'?");
                    NGUIEditorTools.DrawSeparator();

                    GUILayout.BeginHorizontal();
                    {
                        GUI.backgroundColor = Color.green;
                        if (GUILayout.Button("Cancel"))
                        {
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("Delete"))
                        {
                            NGUIEditorTools.RegisterUndo("Delete Sprite", mAtlas);
                            mAtlas.spriteList.Remove(sprite);
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    mConfirmDelete = false;
                }
            }
            else
            {
                if (sprite == null && mAtlas.spriteList.Count > 0)
                {
                    string spriteName = NGUISettings.selectedSprite;
                    if (!string.IsNullOrEmpty(spriteName))
                    {
                        sprite = mAtlas.GetSprite(spriteName);
                    }
                    if (sprite == null)
                    {
                        sprite = mAtlas.spriteList[0];
                    }
                }

                if (!mConfirmDelete && sprite != null)
                {
                    NGUIEditorTools.DrawSeparator();
                    NGUIEditorTools.AdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);

                    if (sprite == null)
                    {
                        return;
                    }

                    Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                    if (tex != null)
                    {
                        Rect inner = sprite.inner;
                        Rect outer = sprite.outer;

                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            GUI.backgroundColor = green;
                            outer = NGUIEditorTools.IntRect("Dimensions", sprite.outer);

                            Vector4 border = new Vector4(
                                sprite.inner.xMin - sprite.outer.xMin,
                                sprite.inner.yMin - sprite.outer.yMin,
                                sprite.outer.xMax - sprite.inner.xMax,
                                sprite.outer.yMax - sprite.inner.yMax);

                            GUI.backgroundColor = blue;
                            border = NGUIEditorTools.IntPadding("Border", border);
                            GUI.backgroundColor = Color.white;

                            inner.xMin = sprite.outer.xMin + border.x;
                            inner.yMin = sprite.outer.yMin + border.y;
                            inner.xMax = sprite.outer.xMax - border.z;
                            inner.yMax = sprite.outer.yMax - border.w;
                        }
                        else
                        {
                            // Draw the inner and outer rectangle dimensions
                            GUI.backgroundColor = green;
                            outer = EditorGUILayout.RectField("Outer Rect", sprite.outer);
                            GUI.backgroundColor = blue;
                            inner = EditorGUILayout.RectField("Inner Rect", sprite.inner);
                            GUI.backgroundColor = Color.white;
                        }

                        if (outer.xMax < outer.xMin)
                        {
                            outer.xMax = outer.xMin;
                        }
                        if (outer.yMax < outer.yMin)
                        {
                            outer.yMax = outer.yMin;
                        }

                        if (outer != sprite.outer)
                        {
                            float x = outer.xMin - sprite.outer.xMin;
                            float y = outer.yMin - sprite.outer.yMin;

                            inner.x += x;
                            inner.y += y;
                        }

                        // Sanity checks to ensure that the inner rect is always inside the outer
                        inner.xMin = Mathf.Clamp(inner.xMin, outer.xMin, outer.xMax);
                        inner.xMax = Mathf.Clamp(inner.xMax, outer.xMin, outer.xMax);
                        inner.yMin = Mathf.Clamp(inner.yMin, outer.yMin, outer.yMax);
                        inner.yMax = Mathf.Clamp(inner.yMax, outer.yMin, outer.yMax);

                        bool changed = false;

                        if (sprite.inner != inner || sprite.outer != outer)
                        {
                            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                            sprite.inner = inner;
                            sprite.outer = outer;
                            MarkSpriteAsDirty();
                            changed = true;
                        }

                        EditorGUILayout.Separator();

                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            int left   = Mathf.RoundToInt(sprite.paddingLeft * sprite.outer.width);
                            int right  = Mathf.RoundToInt(sprite.paddingRight * sprite.outer.width);
                            int top    = Mathf.RoundToInt(sprite.paddingTop * sprite.outer.height);
                            int bottom = Mathf.RoundToInt(sprite.paddingBottom * sprite.outer.height);

                            NGUIEditorTools.IntVector a = NGUIEditorTools.IntPair("Padding", "Left", "Top", left, top);
                            NGUIEditorTools.IntVector b = NGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom);

                            if (changed || a.x != left || a.y != top || b.x != right || b.y != bottom)
                            {
                                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                                sprite.paddingLeft   = a.x / sprite.outer.width;
                                sprite.paddingTop    = a.y / sprite.outer.height;
                                sprite.paddingRight  = b.x / sprite.outer.width;
                                sprite.paddingBottom = b.y / sprite.outer.height;
                                MarkSpriteAsDirty();
                            }
                        }
                        else
                        {
                            // Create a button that can make the coordinates pixel-perfect on click
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.Label("Correction", GUILayout.Width(75f));

                                Rect corrected0 = outer;
                                Rect corrected1 = inner;

                                if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                                {
                                    corrected0 = NGUIMath.MakePixelPerfect(corrected0);
                                    corrected1 = NGUIMath.MakePixelPerfect(corrected1);
                                }
                                else
                                {
                                    corrected0 = NGUIMath.MakePixelPerfect(corrected0, tex.width, tex.height);
                                    corrected1 = NGUIMath.MakePixelPerfect(corrected1, tex.width, tex.height);
                                }

                                if (corrected0 == sprite.outer && corrected1 == sprite.inner)
                                {
                                    GUI.color = Color.grey;
                                    GUILayout.Button("Make Pixel-Perfect");
                                    GUI.color = Color.white;
                                }
                                else if (GUILayout.Button("Make Pixel-Perfect"))
                                {
                                    outer       = corrected0;
                                    inner       = corrected1;
                                    GUI.changed = true;
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                    }

                    // This functionality is no longer used. It became obsolete when the Atlas Maker was added.

                    /*NGUIEditorTools.DrawSeparator();
                     *
                     * GUILayout.BeginHorizontal();
                     * {
                     *      EditorGUILayout.PrefixLabel("Add/Delete");
                     *
                     *      if (GUILayout.Button("Clone Sprite"))
                     *      {
                     *              NGUIEditorTools.RegisterUndo("Add Sprite", mAtlas);
                     *              UIAtlas.Sprite newSprite = new UIAtlas.Sprite();
                     *
                     *              if (sprite != null)
                     *              {
                     *                      newSprite.name = "Copy of " + sprite.name;
                     *                      newSprite.outer = sprite.outer;
                     *                      newSprite.inner = sprite.inner;
                     *              }
                     *              else
                     *              {
                     *                      newSprite.name = "New Sprite";
                     *              }
                     *
                     *              mAtlas.spriteList.Add(newSprite);
                     *              sprite = newSprite;
                     *      }
                     *
                     *      // Show the delete button
                     *      GUI.backgroundColor = Color.red;
                     *
                     *      if (sprite != null && GUILayout.Button("Delete", GUILayout.Width(55f)))
                     *      {
                     *              mConfirmDelete = true;
                     *      }
                     *      GUI.backgroundColor = Color.white;
                     * }
                     * GUILayout.EndHorizontal();*/

                    if (NGUIEditorTools.previousSelection != null)
                    {
                        NGUIEditorTools.DrawSeparator();

                        GUI.backgroundColor = Color.green;

                        if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                        {
                            NGUIEditorTools.SelectPrevious();
                        }
                        GUI.backgroundColor = Color.white;
                    }
                }
            }
        }
    }
Esempio n. 26
0
    override protected bool DrawProperties()
    {
        mLabel = mWidget as UILabel;
        ComponentSelector.Draw <UIFont>(mLabel.font, OnSelectFont);



        if (mLabel.font != null)
        {
            GUI.skin.textArea.wordWrap = true;
            string text = string.IsNullOrEmpty(mLabel.text) ? "" : mLabel.text;
            text = EditorGUILayout.TextArea(mLabel.text, GUI.skin.textArea, GUILayout.Height(100f));
            if (!text.Equals(mLabel.text))
            {
                RegisterUndo(); mLabel.text = text;
            }
            GUILayout.Label("Language Key");
            string language = string.IsNullOrEmpty(mLabel.language) ? "" : mLabel.language;
            language = EditorGUILayout.TextArea(mLabel.language, GUI.skin.textArea, GUILayout.Height(30f));
            if (!language.Equals(mLabel.language))
            {
                RegisterUndo(); mLabel.language = language;
            }

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

            int count = EditorGUILayout.IntField("Max Lines", mLabel.maxLineCount, GUILayout.Width(100f));
            if (count != mLabel.maxLineCount)
            {
                RegisterUndo(); mLabel.maxLineCount = count;
            }

            GUILayout.BeginHorizontal();
            bool shrinkToFit = EditorGUILayout.Toggle("Shrink to Fit", mLabel.shrinkToFit, GUILayout.Width(100f));
            GUILayout.Label("- adjust scale if doesn't fit");
            GUILayout.EndHorizontal();
            if (shrinkToFit != mLabel.shrinkToFit)
            {
                RegisterUndo(); mLabel.shrinkToFit = shrinkToFit;
            }

            GUILayout.BeginHorizontal();
            bool password = EditorGUILayout.Toggle("Password", mLabel.password, GUILayout.Width(100f));
            GUILayout.Label("- hide characters");
            GUILayout.EndHorizontal();
            if (password != mLabel.password)
            {
                RegisterUndo(); mLabel.password = password;
            }

            GUILayout.BeginHorizontal();
            bool encoding = EditorGUILayout.Toggle("Encoding", mLabel.supportEncoding, GUILayout.Width(100f));
            GUILayout.Label("- use emoticons and colors");
            GUILayout.EndHorizontal();
            if (encoding != mLabel.supportEncoding)
            {
                RegisterUndo(); mLabel.supportEncoding = encoding;
            }

            GUILayout.BeginHorizontal();
            bool isReload = EditorGUILayout.Toggle("Reload Language", false, GUILayout.Width(130f));
            if (isReload)
            {
                ReLoadLanguage(); if (mLabel.language != "")
                {
                    mLabel.language = mLabel.language;
                }
            }
            GUILayout.EndHorizontal();


            //GUILayout.EndHorizontal();

            if (encoding && mLabel.font.hasSymbols)
            {
                UIFont.SymbolStyle sym = (UIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f));
                if (sym != mLabel.symbolStyle)
                {
                    RegisterUndo(); mLabel.symbolStyle = sym;
                }
            }

            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();

            if (mLabel.effectStyle != UILabel.Effect.None)
            {
                GUILayout.Label("Distance", GUILayout.Width(70f));
                //GUILayout.Space(-34f);
                //GUILayout.BeginHorizontal();
                //GUILayout.Space(70f);
                Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance);
                //GUILayout.Space(20f);

                if (offset != mLabel.effectDistance)
                {
                    RegisterUndo();
                    mLabel.effectDistance = offset;
                }
                //GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GameColor.GColor mLabelColor = (GameColor.GColor)EditorGUILayout.EnumPopup("LabelColor", mLabel.labelColor, GUILayout.Width(170f));
            if (mLabelColor != mLabel.labelColor)
            {
                mLabel.color = GameColor.GetColor(mLabelColor); RegisterUndo(); mLabel.labelColor = mLabelColor;
            }
            GUILayout.EndHorizontal();
            return(true);
        }
        EditorGUILayout.Space();
        return(false);
    }
Esempio n. 27
0
    /// <summary>
    /// Draw the UI for this tool.
    /// </summary>
    private void OnGUI()
    {
        gAtlasWindowOpended = true;

        if (mLastAtlas != NGUISettings.atlas)
        {
            mLastAtlas = NGUISettings.atlas;
        }

        bool update  = false;
        bool replace = false;

        NGUIEditorTools.SetLabelWidth(84f);
        GUILayout.Space(3f);

        NGUIEditorTools.DrawHeader("Input", true);
        NGUIEditorTools.BeginContents(false);

        GUILayout.BeginHorizontal();
        {
            ComponentSelector.Draw <UIAtlas>("Atlas", NGUISettings.atlas, OnSelectAtlas, true, GUILayout.MinWidth(80f));

            EditorGUI.BeginDisabledGroup(NGUISettings.atlas == null);
            if (GUILayout.Button("New", GUILayout.Width(40f)))
            {
                NGUISettings.atlas = null;
            }
            EditorGUI.EndDisabledGroup();
        }
        GUILayout.EndHorizontal();

        List <Texture> textures = GetSelectedTextures();

        if (NGUISettings.atlas != null)
        {
            Material mat = NGUISettings.atlas.spriteMaterial;
            Texture  tex = NGUISettings.atlas.texture;

            // Material information
            GUILayout.BeginHorizontal();
            {
                if (mat != null)
                {
                    if (GUILayout.Button("Material", GUILayout.Width(76f)))
                    {
                        Selection.activeObject = mat;
                    }
                    GUILayout.Label(" " + mat.name);
                }
                else
                {
                    GUI.color = Color.grey;
                    GUILayout.Button("Material", GUILayout.Width(76f));
                    GUI.color = Color.white;
                    GUILayout.Label(" N/A");
                }
            }
            GUILayout.EndHorizontal();

            // Texture atlas information
            GUILayout.BeginHorizontal();
            {
                if (tex != null)
                {
                    if (GUILayout.Button("Texture", GUILayout.Width(76f)))
                    {
                        Selection.activeObject = tex;
                    }
                    GUILayout.Label(" " + tex.width + "x" + tex.height);
                }
                else
                {
                    GUI.color = Color.grey;
                    GUILayout.Button("Texture", GUILayout.Width(76f));
                    GUI.color = Color.white;
                    GUILayout.Label(" N/A");
                }
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        NGUISettings.atlasPadding = Mathf.Clamp(EditorGUILayout.IntField("Padding", NGUISettings.atlasPadding, GUILayout.Width(100f)), 0, 8);
        GUILayout.Label((NGUISettings.atlasPadding == 1 ? "pixel" : "pixels") + " between sprites");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.atlasTrimming = EditorGUILayout.Toggle("Trim Alpha", NGUISettings.atlasTrimming, GUILayout.Width(100f));
        GUILayout.Label("Remove empty space");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.atlasSplit = EditorGUILayout.Toggle("Split Texture", NGUISettings.atlasSplit, GUILayout.Width(100f));
        GUILayout.Label("RGB/A 分离");
        GUILayout.EndHorizontal();

        bool fixedShader = false;

        if (NGUISettings.atlas != null)
        {
            Material mat = NGUISettings.atlas.spriteMaterial;

            if (mat != null)
            {
                Shader shader = mat.shader;

                if (shader != null)
                {
                    if (shader.name == "Unlit/Transparent Colored")
                    {
                        NGUISettings.atlasPMA = false;
                        fixedShader           = true;
                    }
                    else if (shader.name == "Unlit/Premultiplied Colored")
                    {
                        NGUISettings.atlasPMA = true;
                        fixedShader           = true;
                    }
                }
            }
        }

        if (!fixedShader)
        {
            GUILayout.BeginHorizontal();
            NGUISettings.atlasPMA = EditorGUILayout.Toggle("PMA Shader", NGUISettings.atlasPMA, GUILayout.Width(100f));
            GUILayout.Label("Pre-multiplied alpha", GUILayout.MinWidth(70f));
            GUILayout.EndHorizontal();
        }

        //GUILayout.BeginHorizontal();
        //NGUISettings.keepPadding = EditorGUILayout.Toggle("Keep Padding", NGUISettings.keepPadding, GUILayout.Width(100f));
        //GUILayout.Label("or replace with trimmed pixels", GUILayout.MinWidth(70f));
        //GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.unityPacking = EditorGUILayout.Toggle("Unity Packer", NGUISettings.unityPacking, GUILayout.Width(100f));
        GUILayout.Label("or custom packer", GUILayout.MinWidth(70f));
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.trueColorAtlas = EditorGUILayout.Toggle("Truecolor", NGUISettings.trueColorAtlas, GUILayout.Width(100f));
        GUILayout.Label("force ARGB32 textures", GUILayout.MinWidth(70f));
        GUILayout.EndHorizontal();

        if (!NGUISettings.unityPacking)
        {
            GUILayout.BeginHorizontal();
            NGUISettings.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", NGUISettings.forceSquareAtlas, GUILayout.Width(100f));
            GUILayout.Label("if on, forces a square atlas texture", GUILayout.MinWidth(70f));
            GUILayout.EndHorizontal();
        }

#if UNITY_IPHONE || UNITY_ANDROID
        GUILayout.BeginHorizontal();
        NGUISettings.allow4096 = EditorGUILayout.Toggle("4096x4096", NGUISettings.allow4096, GUILayout.Width(100f));
        GUILayout.Label("if off, limit atlases to 2048x2048");
        GUILayout.EndHorizontal();
#endif
        NGUIEditorTools.EndContents();

        if (NGUISettings.atlas != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(20f);

            if (textures.Count > 0)
            {
                update = GUILayout.Button("Add/Update");
            }
            else if (GUILayout.Button("View Sprites"))
            {
                SpriteSelector.ShowSelected();
            }

            GUILayout.Space(20f);
            GUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.HelpBox("You can create a new atlas by selecting one or more textures in the Project View window, then clicking \"Create\".", MessageType.Info);

            EditorGUI.BeginDisabledGroup(textures.Count == 0);
            GUILayout.BeginHorizontal();
            GUILayout.Space(20f);
            bool create = GUILayout.Button("Create");
            GUILayout.Space(20f);
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            if (create)
            {
                string path = EditorUtility.SaveFilePanelInProject("Save As",
                                                                   "New Atlas.prefab", "prefab", "Save atlas as...", NGUISettings.currentPath);

                if (!string.IsNullOrEmpty(path))
                {
                    NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                    GameObject go      = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
                    string     matPath = path.Replace(".prefab", ".mat");
                    replace = true;

                    // Try to load the material
                    Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;

                    // If the material doesn't exist, create it
                    if (mat == null)
                    {
                        Shader shader = Shader.Find(NGUISettings.atlasPMA ? "Unlit/Premultiplied Colored" : "Unlit/Transparent Colored");
                        mat = new Material(shader);

                        // Save the material
                        AssetDatabase.CreateAsset(mat, matPath);
                        AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

                        // Load the material so it's usable
                        mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;
                    }

                    // Create a new prefab for the atlas
                    Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(path);

                    // Create a new game object for the atlas
                    string atlasName = path.Replace(".prefab", "");
                    atlasName = atlasName.Substring(path.LastIndexOfAny(new char[] { '/', '\\' }) + 1);
                    go        = new GameObject(atlasName);
                    go.AddComponent <UIAtlas>().spriteMaterial = mat;

                    // Update the prefab
                    PrefabUtility.ReplacePrefab(go, prefab);
                    DestroyImmediate(go);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

                    // Select the atlas
                    go = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
                    NGUISettings.atlas         = go.GetComponent <UIAtlas>();
                    Selection.activeGameObject = go;
                }
            }
        }

        string selection = null;
        Dictionary <string, int> spriteList = GetSpriteList(textures);

        if (spriteList.Count > 0)
        {
            NGUIEditorTools.DrawHeader("Sprites", true);
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(3f);
                GUILayout.BeginVertical();

                mScroll = GUILayout.BeginScrollView(mScroll);

                bool delete = false;
                int  index  = 0;
                foreach (KeyValuePair <string, int> iter in spriteList)
                {
                    ++index;

                    GUILayout.Space(-1f);
                    bool highlight = (UIAtlasInspector.instance != null) && (NGUISettings.selectedSprite == iter.Key);
                    GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);
                    GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f));
                    GUI.backgroundColor = Color.white;
                    GUILayout.Label(index.ToString(), GUILayout.Width(24f));

                    if (GUILayout.Button(iter.Key, "OL TextField", GUILayout.Height(20f)))
                    {
                        selection = iter.Key;
                    }

                    if (iter.Value == 2)
                    {
                        GUI.color = Color.green;
                        GUILayout.Label("Add", GUILayout.Width(27f));
                        GUI.color = Color.white;
                    }
                    else if (iter.Value == 1)
                    {
                        GUI.color = Color.cyan;
                        GUILayout.Label("Update", GUILayout.Width(45f));
                        GUI.color = Color.white;
                    }
                    else
                    {
                        if (mDelNames.Contains(iter.Key))
                        {
                            GUI.backgroundColor = Color.red;

                            if (GUILayout.Button("Delete", GUILayout.Width(60f)))
                            {
                                delete = true;
                            }
                            GUI.backgroundColor = Color.green;
                            if (GUILayout.Button("X", GUILayout.Width(22f)))
                            {
                                mDelNames.Remove(iter.Key);
                                delete = false;
                            }
                            GUI.backgroundColor = Color.white;
                        }
                        else
                        {
                            // If we have not yet selected a sprite for deletion, show a small "X" button
                            if (GUILayout.Button("X", GUILayout.Width(22f)))
                            {
                                mDelNames.Add(iter.Key);
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
                GUILayout.Space(3f);
                GUILayout.EndHorizontal();

                // If this sprite was marked for deletion, remove it from the atlas
                if (delete)
                {
                    List <SpriteEntry> sprites = new List <SpriteEntry>();
                    ExtractSprites(NGUISettings.atlas, sprites);

                    for (int i = sprites.Count; i > 0;)
                    {
                        SpriteEntry ent = sprites[--i];
                        if (mDelNames.Contains(ent.name))
                        {
                            sprites.RemoveAt(i);
                        }
                    }
                    UpdateAtlas(NGUISettings.atlas, sprites);
                    mDelNames.Clear();
                    NGUIEditorTools.RepaintSprites();
                }
                else if (update)
                {
                    UpdateAtlas(textures, true);
                }
                else if (replace)
                {
                    UpdateAtlas(textures, false);
                }

                if (NGUISettings.atlas != null && !string.IsNullOrEmpty(selection))
                {
                    NGUIEditorTools.SelectSprite(selection);
                }
                else if (update || replace)
                {
                    NGUIEditorTools.UpgradeTexturesToSprites(NGUISettings.atlas);
                    NGUIEditorTools.RepaintSprites();
                }
            }
        }

        if (NGUISettings.atlas != null && textures.Count == 0)
        {
            EditorGUILayout.HelpBox("You can reveal more options by selecting one or more textures in the Project View window.", MessageType.Info);
        }

        // Uncomment this line if you want to be able to force-sort the atlas
        //if (NGUISettings.atlas != null && GUILayout.Button("Sort Alphabetically")) NGUISettings.atlas.SortAlphabetically();
    }
Esempio n. 28
0
    protected override bool DrawProperties()
    {
        mLabel = mWidget as UILabel;
        ComponentSelector.Draw <UIFont>(mLabel.font, OnSelectFont);

        if (mLabel.font != null)
        {
            GUI.skin.textArea.wordWrap = true;
            string text = string.IsNullOrEmpty(mLabel.text) ? "" : mLabel.text;
            text = EditorGUILayout.TextArea(mLabel.text, GUI.skin.textArea, GUILayout.Height(100f));
            if (!text.Equals(mLabel.text))
            {
                RegisterUndo(); mLabel.text = text;
            }

            GUILayout.BeginHorizontal();
            int len = EditorGUILayout.IntField("Max Width", mLabel.lineWidth, GUILayout.Width(120f));
            GUILayout.Label("pixels");
            GUILayout.EndHorizontal();
            if (len != mLabel.lineWidth && len >= 0f)
            {
                RegisterUndo(); mLabel.lineWidth = len;
            }

            GUILayout.BeginHorizontal();
            len = EditorGUILayout.IntField("Max Height", mLabel.lineHeight, GUILayout.Width(120f));
            GUILayout.Label("pixels");
            GUILayout.EndHorizontal();
            if (len != mLabel.lineHeight && len >= 0f)
            {
                RegisterUndo(); mLabel.lineHeight = len;
            }

            int count = EditorGUILayout.IntField("Max Lines", mLabel.maxLineCount, GUILayout.Width(100f));
            if (count != mLabel.maxLineCount)
            {
                RegisterUndo(); mLabel.maxLineCount = count;
            }

            GUILayout.BeginHorizontal();
            bool shrinkToFit = EditorGUILayout.Toggle("Shrink to Fit", mLabel.shrinkToFit, GUILayout.Width(100f));
            GUILayout.Label("- adjust scale to fit");
            GUILayout.EndHorizontal();

            // Gradual Color
            GUILayout.BeginHorizontal();
            bool gradual = EditorGUILayout.Toggle("Gradual Color", mLabel.EnableGradual, GUILayout.Width(100f));
            if (gradual)
            {
                Color c = EditorGUILayout.ColorField("Start Color", mLabel.GradualColor);
                if (mLabel.GradualColor != c)
                {
                    RegisterUndo();
                    mLabel.GradualColor = c;
                }
            }
            if (mLabel.EnableGradual != gradual)
            {
                RegisterUndo();
                mLabel.EnableGradual = gradual;
            }
            GUILayout.EndHorizontal();

            if (shrinkToFit != mLabel.shrinkToFit)
            {
                RegisterUndo();
                mLabel.shrinkToFit = shrinkToFit;
                if (!shrinkToFit)
                {
                    mLabel.MakePixelPerfect();
                }
            }

            // Only input fields need this setting exposed, and they have their own "is password" setting, so hiding it here.
            //GUILayout.BeginHorizontal();
            //bool password = EditorGUILayout.Toggle("Password", mLabel.password, GUILayout.Width(100f));
            //GUILayout.Label("- hide characters");
            //GUILayout.EndHorizontal();
            //if (password != mLabel.password) { RegisterUndo(); mLabel.password = password; }

            GUILayout.BeginHorizontal();
            bool encoding = EditorGUILayout.Toggle("Encoding", mLabel.supportEncoding, GUILayout.Width(100f));
            GUILayout.Label("- use emoticons and colors");
            GUILayout.EndHorizontal();
            if (encoding != mLabel.supportEncoding)
            {
                RegisterUndo(); mLabel.supportEncoding = encoding;
            }

            //GUILayout.EndHorizontal();

            if (encoding && mLabel.font.hasSymbols)
            {
                UIFont.SymbolStyle sym = (UIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f));
                if (sym != mLabel.symbolStyle)
                {
                    RegisterUndo(); mLabel.symbolStyle = sym;
                }
            }

            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();

            if (mLabel.effectStyle != UILabel.Effect.None)
            {
                GUILayout.Label("Distance", GUILayout.Width(70f));
                GUILayout.Space(-10f);
                GUILayout.BeginHorizontal();
                GUILayout.Space(70f);
                Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance);
                GUILayout.Space(20f);

                if (offset != mLabel.effectDistance)
                {
                    RegisterUndo();
                    mLabel.effectDistance = offset;
                }
                GUILayout.EndHorizontal();
            }
            return(true);
        }
        EditorGUILayout.Space();
        return(false);
    }
Esempio n. 29
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        // Load the saved preferences
        if (!mLoaded)
        {
            mLoaded = true; Load();
        }

        EditorGUIUtility.LookLikeControls(80f);
        GameObject go = NGUIEditorTools.SelectedRoot();

        if (go == null)
        {
            GUILayout.Label("You must create a UI first.");

            if (GUILayout.Button("Open the New UI Wizard"))
            {
                EditorWindow.GetWindow <UICreateNewUIWizard>(false, "New UI", true);
            }
        }
        else
        {
            GUILayout.Space(4f);

            GUILayout.BeginHorizontal();
            ComponentSelector.Draw <UIAtlas>(UISettings.atlas, OnSelectAtlas, GUILayout.Width(140f));
            GUILayout.Label("Texture atlas used by widgets", GUILayout.MinWidth(10000f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            ComponentSelector.Draw <UIFont>(UISettings.font, OnSelectFont, GUILayout.Width(140f));
            GUILayout.Label("Font used by labels", GUILayout.MinWidth(10000f));
            GUILayout.EndHorizontal();

            GUILayout.Space(-2f);
            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            WidgetType wt = (WidgetType)EditorGUILayout.EnumPopup("Template", mType, GUILayout.Width(200f));
            GUILayout.Space(20f);
            GUILayout.Label("Select a widget template to use");
            GUILayout.EndHorizontal();

            if (mType != wt)
            {
                mType = wt; Save();
            }

            switch (mType)
            {
            case WidgetType.Label:                  CreateLabel(go); break;

            case WidgetType.Sprite:                 CreateSprite <UISprite>(go, ref mSprite); break;

            case WidgetType.SlicedSprite:   CreateSprite <UISlicedSprite>(go, ref mSliced); break;

            case WidgetType.TiledSprite:    CreateSprite <UITiledSprite>(go, ref mTiled); break;

            case WidgetType.FilledSprite:   CreateSprite <UIFilledSprite>(go, ref mFilled); break;

            case WidgetType.SimpleTexture:  CreateSimpleTexture(go); break;

            case WidgetType.Button:                 CreateButton(go); break;

            case WidgetType.ImageButton:    CreateImageButton(go); break;

            case WidgetType.Checkbox:               CreateCheckbox(go); break;

            case WidgetType.ProgressBar:    CreateSlider(go, false); break;

            case WidgetType.Slider:                 CreateSlider(go, true); break;

            case WidgetType.Input:                  CreateInput(go); break;

            case WidgetType.PopupList:              CreatePopup(go, true); break;

            case WidgetType.PopupMenu:              CreatePopup(go, false); break;

            case WidgetType.ScrollBar:              CreateScrollBar(go); break;
            }
        }
    }
Esempio n. 30
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mAtlas = target as UIAtlas;

        UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        GUILayout.Space(6f);

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        GUILayout.BeginHorizontal();
        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        GUILayout.Space(18f);
        GUILayout.EndHorizontal();

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                mType = AtlasType.Normal;
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas, true);

            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("You can have one atlas simply point to " +
                                    "another one. This is useful if you want to be " +
                                    "able to quickly replace the contents of one " +
                                    "atlas with another one, for example for " +
                                    "swapping an SD atlas with an HD one, or " +
                                    "replacing an English atlas with a Chinese " +
                                    "one. All the sprites referencing this atlas " +
                                    "will update their references to the new one.", MessageType.Info);

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mAtlas);
            }
            return;
        }

        //GUILayout.Space(6f);
        Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

        if (mAtlas.spriteMaterial != mat)
        {
            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
            mAtlas.spriteMaterial = mat;

            // Ensure that this atlas has valid import settings
            if (mAtlas.texture != null)
            {
                NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
            }

            mAtlas.MarkAsDirty();
        }

        if (mat != null)
        {
            TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

            if (ta != null)
            {
                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
                }

                NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                NGUIJson.LoadSpriteData(mAtlas, ta);
                if (sprite != null)
                {
                    sprite = mAtlas.GetSprite(sprite.name);
                }
                mAtlas.MarkAsDirty();
            }

            float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

            if (pixelSize != mAtlas.pixelSize)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.pixelSize = pixelSize;
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blue  = new Color(0f, 0.7f, 1f, 1f);
            Color green = new Color(0.4f, 1f, 0f, 1f);

            if (sprite == null && mAtlas.spriteList.Count > 0)
            {
                string spriteName = NGUISettings.selectedSprite;
                if (!string.IsNullOrEmpty(spriteName))
                {
                    sprite = mAtlas.GetSprite(spriteName);
                }
                if (sprite == null)
                {
                    sprite = mAtlas.spriteList[0];
                }
            }

            if (sprite != null)
            {
                if (sprite == null)
                {
                    return;
                }

                Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                if (tex != null)
                {
                    if (!NGUIEditorTools.DrawHeader("Sprite Details"))
                    {
                        return;
                    }

                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);
                    NGUIEditorTools.DrawAdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);
                    GUILayout.Space(6f);

                    GUI.changed = false;

                    GUI.backgroundColor = green;
                    NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y);
                    NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = blue;
                    NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight);
                    NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = Color.white;
                    NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight);
                    NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop);

                    if (GUI.changed)
                    {
                        NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);

                        sprite.x      = sizeA.x;
                        sprite.y      = sizeA.y;
                        sprite.width  = sizeB.x;
                        sprite.height = sizeB.y;

                        sprite.paddingLeft   = padA.x;
                        sprite.paddingRight  = padA.y;
                        sprite.paddingBottom = padB.x;
                        sprite.paddingTop    = padB.y;

                        sprite.borderLeft   = borderA.x;
                        sprite.borderRight  = borderA.y;
                        sprite.borderBottom = borderB.x;
                        sprite.borderTop    = borderB.y;

                        MarkSpriteAsDirty();
                    }
                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.previousSelection != null)
                {
                    GUI.backgroundColor = Color.green;

                    if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                    {
                        NGUIEditorTools.SelectPrevious();
                    }
                    GUI.backgroundColor = Color.white;
                }
            }
        }
    }