Example #1
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;
                    Debug.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();
                }
            }
        }

        // 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;
            }
            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)
            {
                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();
                }
            }
        }
    }
Example #2
0
    protected override void DrawProperties()
    {
        var sp = serializedObject.FindProperty("dragHighlight");
        var ht = sp.boolValue ? Highlight.Press : Highlight.DoNothing;

        GUILayout.BeginHorizontal();
        var highlight = (Highlight)EditorGUILayout.EnumPopup("Drag Over", ht) == Highlight.Press;

        NGUIEditorTools.DrawPadding();
        GUILayout.EndHorizontal();
        if (sp.boolValue != highlight)
        {
            sp.boolValue = highlight;
        }

        DrawTransition();
        DrawColors();

        var btn = target as UIButton;

        if (btn.tweenTarget != null)
        {
            var sprite = btn.tweenTarget.GetComponent <UISprite>();
            var s2d    = btn.tweenTarget.GetComponent <UI2DSprite>();

            if (sprite != null)
            {
                if (NGUIEditorTools.DrawHeader("Sprites", "Sprites", false, true))
                {
                    NGUIEditorTools.BeginContents(true);
                    EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
                    {
                        var obj = new SerializedObject(sprite);
                        obj.Update();
                        var atlas = obj.FindProperty("mAtlas");
                        NGUIEditorTools.DrawSpriteField("Normal", obj, atlas, obj.FindProperty("mSpriteName"));
                        obj.ApplyModifiedProperties();

                        NGUIEditorTools.DrawSpriteField("Hover", serializedObject, atlas, serializedObject.FindProperty("hoverSprite"), true);
                        NGUIEditorTools.DrawSpriteField("Pressed", serializedObject, atlas, serializedObject.FindProperty("pressedSprite"), true);
                        NGUIEditorTools.DrawSpriteField("Disabled", serializedObject, atlas, serializedObject.FindProperty("disabledSprite"), true);
                    }
                    EditorGUI.EndDisabledGroup();

                    NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "pixelSnap");
                    NGUIEditorTools.EndContents();
                }
            }
            else if (s2d != null)
            {
                if (NGUIEditorTools.DrawHeader("Sprites", "Sprites", false, true))
                {
                    NGUIEditorTools.BeginContents(true);
                    EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
                    {
                        var obj = new SerializedObject(s2d);
                        obj.Update();
                        NGUIEditorTools.DrawProperty("Normal", obj, "mSprite");
                        obj.ApplyModifiedProperties();

                        NGUIEditorTools.DrawProperty("Hover", serializedObject, "hoverSprite2D");
                        NGUIEditorTools.DrawProperty("Pressed", serializedObject, "pressedSprite2D");
                        NGUIEditorTools.DrawProperty("Disabled", serializedObject, "disabledSprite2D");
                    }
                    EditorGUI.EndDisabledGroup();

                    NGUIEditorTools.DrawProperty("Pixel Snap", serializedObject, "pixelSnap");
                    NGUIEditorTools.EndContents();
                }
            }
        }

        var button = target as UIButton;

        NGUIEditorTools.DrawEvents("On Click", button, button.onClick, false);
    }
Example #3
0
    /// <summary>
    /// Draw the UI for this tool.
    /// </summary>

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

        bool update  = false;
        bool replace = false;

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

        NGUIEditorTools.DrawHeader("Input");
        NGUIEditorTools.BeginContents();

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

        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.unityPacking = EditorGUILayout.Toggle("Unity Packer", NGUISettings.unityPacking, GUILayout.Width(100f));
        GUILayout.Label("or custom packer", 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 prefabPath = EditorUtility.SaveFilePanelInProject("Save As", "New Atlas.prefab", "prefab", "Save atlas as...");

                if (!string.IsNullOrEmpty(prefabPath))
                {
                    GameObject go      = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
                    string     matPath = prefabPath.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(prefabPath);

                    // Create a new game object for the atlas
                    string atlasName = prefabPath.Replace(".prefab", "");
                    atlasName = atlasName.Substring(prefabPath.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(prefabPath, 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();
    }
Example #4
0
    public void DrawAnchorTransform()
    {
        if (NGUIEditorTools.DrawHeader("Anchors"))
        {
            NGUIEditorTools.BeginContents();
            NGUIEditorTools.SetLabelWidth(NGUISettings.minimalisticLook ? 69f : 62f);

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

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

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

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

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

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

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

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

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

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

            mAnchorType = type;
            OnDrawFinalProperties();
            EditorGUI.EndDisabledGroup();
            NGUIEditorTools.EndContents();
        }
    }
Example #5
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..."))
                    {
#if UNITY_3_5
                        string path = EditorUtility.SaveFilePanel("Save As",
                                                                  NGUISettings.currentPath, sprite.name + ".png", "png");
#else
                        string path = EditorUtility.SaveFilePanelInProject("Save As",
                                                                           sprite.name + ".png", "png",
                                                                           "Extract sprite into which file?", NGUISettings.currentPath);
#endif

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

                if (NGUIEditorTools.DrawHeader("Texture Optimization"))
                {
                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);

                    EditorGUILayout.BeginHorizontal();
                    NGUIEditorTools.DrawPadding();
                    TextureCompressionQuality afterType = (TextureCompressionQuality)EditorGUILayout.EnumPopup("Quality Type", NGUIEditorTools.mTextureType);
                    NGUIEditorTools.DrawPadding();

                    if (afterType != NGUIEditorTools.mTextureType)
                    {
                        NGUIEditorTools.mTextureType = afterType;
                    }

                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();

                    NGUIEditorTools.DrawPadding();

                    EditorGUILayout.BeginVertical();
                    EditorGUI.BeginDisabledGroup(mat.shader.name != "My Shaders/UITextureBinding");
                    if (GUILayout.Button("원본 사용"))
                    {
                        NGUIEditorTools.SetTextureOptimization(mAtlas, false);
                    }
                    EditorGUI.EndDisabledGroup();
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical();
                    EditorGUI.BeginDisabledGroup(mat.shader.name != "Unlit/Transparent Colored");
                    if (GUILayout.Button("최적화 사용"))
                    {
                        NGUIEditorTools.SetTextureOptimization(mAtlas, true);
                    }
                    EditorGUI.EndDisabledGroup();
                    EditorGUILayout.EndVertical();
                    NGUIEditorTools.DrawPadding();
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    NGUIEditorTools.DrawPadding();
                    EditorGUILayout.BeginVertical();
                    if (GUILayout.Button("전체 원본으로"))
                    {
                        string[] aAtlasFiles = Directory.GetFiles("Assets/Resources/Prefabs/UI_Data/UI_Atlas", "*.prefab", SearchOption.AllDirectories);

                        for (int i = 0; i < aAtlasFiles.Length; ++i)
                        {
                            EditorUtility.DisplayProgressBar("Texture Optimization", "Combine...", ((i + 1) / (float)aAtlasFiles.Length));
                            UIAtlas sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas;

                            NGUIEditorTools.SetTextureOptimization(sourceAtlas, false);
                        }
                        EditorUtility.ClearProgressBar();
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical();

                    if (GUILayout.Button("전체 최적화"))
                    {
                        string[] aAtlasFiles = Directory.GetFiles("Assets/Resources/Prefabs/UI_Data/UI_Atlas", "*.prefab", SearchOption.AllDirectories);

                        for (int i = 0; i < aAtlasFiles.Length; ++i)
                        {
                            EditorUtility.DisplayProgressBar("Texture Optimization", string.Format("Devide..."), ((i + 1) / (float)aAtlasFiles.Length));

                            UIAtlas sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas;
                            shaderTextureBinding = shaderTextureBinding == null?Shader.Find("My Shaders/UITextureBinding") : shaderTextureBinding;

                            sourceAtlas.spriteMaterial.shader = shaderTextureBinding;
                            NGUIEditorTools.CopyAndChangeTexture(sourceAtlas, true);
                            sourceAtlas = (UIAtlas)AssetDatabase.LoadAssetAtPath(aAtlasFiles[i], typeof(UIAtlas)) as UIAtlas;
                            NGUIEditorTools.CopyAndChangeTexture(sourceAtlas, false);
                        }
                        EditorUtility.ClearProgressBar();
                    }
                    EditorGUILayout.EndVertical();
                    NGUIEditorTools.DrawPadding();
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.HelpBox("Quality Type : 텍스쳐의 Compression Quality (Best는 속도가 느리기 때문에 빌드할 때만 한다.)\n" +
                                            "원본, 최적화 사용 : 해당 아틀라스의 텍스쳐를 원본, 최적화 상태로 변경한다.\n" +
                                            "전체 원본, 전체 최적화 : UI_Atlas 폴더에 있는 모든 아틀라스를 일괄 원본, 최적화 상태로 변경한다.", MessageType.Info);

                    NGUIEditorTools.EndContents();
                }
            }
        }
    }
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

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

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

        GUILayout.Space(6f);

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

        GUILayout.BeginHorizontal();
        var 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);
        var 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)
        {
            var 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();
            }

            var 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)
        {
            var blueColor  = new Color(0f, 0.7f, 1f, 1f);
            var greenColor = new Color(0.4f, 1f, 0f, 1f);

            if (sprite == null && mAtlas.spriteList.Count > 0)
            {
                var 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;
                }

                var 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;
                    var sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y);
                    var sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height);

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

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = Color.white;
                    var padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight);
                    var 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"))
                    {
                        var se = UIAtlasMaker.DuplicateSprite(mAtlas, sprite.name);
                        if (se != null)
                        {
                            NGUISettings.selectedSprite = se.name;
                        }
                    }

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

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

                            if (se != null)
                            {
                                var bytes = se.tex.EncodeToPNG();
                                File.WriteAllBytes(path, bytes);
                                AssetDatabase.ImportAsset(path);
                                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;
                }
            }
        }
    }
Example #7
0
    public override void OnInspectorGUI()
    {
        UICamera cam = target as UICamera;

        GUILayout.Space(3f);

        serializedObject.Update();

        SerializedProperty et = serializedObject.FindProperty("eventType");

        if (et.hasMultipleDifferentValues)
        {
            EditorGUILayout.PropertyField(et);
        }
        else
        {
            string[] options = new string[] { "3D World", "3D UI", "2D World", "2D UI" };
            int      val     = EditorGUILayout.Popup("Event Type", et.intValue, options);
            if (val != et.intValue)
            {
                et.intValue = val;
            }
        }

        if (UICamera.eventHandler != cam)
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("eventReceiverMask"), new GUIContent("Event Mask"));
            serializedObject.ApplyModifiedProperties();

            EditorGUILayout.HelpBox("All other settings are inherited from the First Camera.", MessageType.Info);

            if (GUILayout.Button("Select the First Camera"))
            {
                Selection.activeGameObject = UICamera.eventHandler.gameObject;
            }
        }
        else
        {
            SerializedProperty mouse      = serializedObject.FindProperty("useMouse");
            SerializedProperty touch      = serializedObject.FindProperty("useTouch");
            SerializedProperty keyboard   = serializedObject.FindProperty("useKeyboard");
            SerializedProperty controller = serializedObject.FindProperty("useController");

            EditorGUILayout.PropertyField(serializedObject.FindProperty("eventReceiverMask"), new GUIContent("Event Mask"));

            SerializedProperty ev = serializedObject.FindProperty("eventsGoToColliders");

            if (ev != null)
            {
                bool val    = ev.boolValue;
                bool newVal = EventsGo.Colliders == (EventsGo)EditorGUILayout.EnumPopup("Events go to...",
                                                                                        ev.boolValue ? EventsGo.Colliders : EventsGo.Rigidbodies);
                if (val != newVal)
                {
                    ev.boolValue = newVal;
                }
            }

            EditorGUILayout.PropertyField(serializedObject.FindProperty("debug"));

            GUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("commandClick"), GUILayout.Width(140f));
            GUILayout.Label("= Right-Click on OSX", GUILayout.MinWidth(30f));
            GUILayout.EndHorizontal();

            EditorGUI.BeginDisabledGroup(!mouse.boolValue && !touch.boolValue);
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("allowMultiTouch"));
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(!(mouse.boolValue && (touch.boolValue || controller.boolValue)));
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("autoHideCursor"));
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(!mouse.boolValue);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("stickyTooltip"));
            EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("longPressTooltip"));
            GUILayout.EndHorizontal();

            EditorGUI.BeginDisabledGroup(!mouse.boolValue);
            GUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("tooltipDelay"));
            GUILayout.Label("seconds", GUILayout.MinWidth(60f));
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            SerializedProperty rd = serializedObject.FindProperty("rangeDistance");
            EditorGUILayout.PropertyField(rd, new GUIContent("Raycast Range"));
            GUILayout.Label(rd.floatValue < 0f ? "unlimited" : "units", GUILayout.MinWidth(60f));
            GUILayout.EndHorizontal();

            NGUIEditorTools.SetLabelWidth(80f);

            if (NGUIEditorTools.DrawHeader("Event Sources"))
            {
                NGUIEditorTools.BeginContents();
                {
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(mouse, new GUIContent("Mouse"), GUILayout.MinWidth(100f));
                    EditorGUILayout.PropertyField(touch, new GUIContent("Touch"), GUILayout.MinWidth(100f));
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(keyboard, new GUIContent("Keyboard"), GUILayout.MinWidth(100f));
                    EditorGUILayout.PropertyField(controller, new GUIContent("Controller"), GUILayout.MinWidth(100f));
                    GUILayout.EndHorizontal();
                }
                NGUIEditorTools.EndContents();
            }

            if ((mouse.boolValue || touch.boolValue) && NGUIEditorTools.DrawHeader("Thresholds"))
            {
                NGUIEditorTools.BeginContents();
                {
                    EditorGUI.BeginDisabledGroup(!mouse.boolValue);
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("mouseDragThreshold"), new GUIContent("Mouse Drag"), GUILayout.Width(120f));
                    GUILayout.Label("pixels");
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("mouseClickThreshold"), new GUIContent("Mouse Click"), GUILayout.Width(120f));
                    GUILayout.Label("pixels");
                    GUILayout.EndHorizontal();
                    EditorGUI.EndDisabledGroup();

                    EditorGUI.BeginDisabledGroup(!touch.boolValue);
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("touchDragThreshold"), new GUIContent("Touch Drag"), GUILayout.Width(120f));
                    GUILayout.Label("pixels");
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("touchClickThreshold"), new GUIContent("Touch Tap"), GUILayout.Width(120f));
                    GUILayout.Label("pixels");
                    GUILayout.EndHorizontal();
                    EditorGUI.EndDisabledGroup();
                }
                NGUIEditorTools.EndContents();
            }

            if ((mouse.boolValue || keyboard.boolValue || controller.boolValue) && NGUIEditorTools.DrawHeader("Axes and Keys"))
            {
                NGUIEditorTools.BeginContents();
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("horizontalAxisName"), new GUIContent("Navigate X"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("verticalAxisName"), new GUIContent("Navigate Y"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("horizontalPanAxisName"), new GUIContent("Pan X"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("verticalPanAxisName"), new GUIContent("Pan Y"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("scrollAxisName"), new GUIContent("Scroll"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("submitKey0"), new GUIContent("Submit 1"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("submitKey1"), new GUIContent("Submit 2"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("cancelKey0"), new GUIContent("Cancel 1"));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("cancelKey1"), new GUIContent("Cancel 2"));
                }
                NGUIEditorTools.EndContents();
            }
            serializedObject.ApplyModifiedProperties();
        }
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        GUILayout.Space(6f);
        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.BeginHorizontal();
        // Key not found in the localization file -- draw it as a text field
        SerializedProperty sp = NGUIEditorTools.DrawProperty("Key", serializedObject, "playerBuildingId");

        string myKey     = sp.stringValue;
        bool   isPresent = (mKeys != null) && mKeys.Contains(myKey);

        GUI.color = isPresent ? Color.green : Color.red;
        GUILayout.BeginVertical(GUILayout.Width(22f));
        GUILayout.Space(2f);
#if UNITY_3_5
        GUILayout.Label(isPresent? "ok" : "!!", GUILayout.Height(20f));
#else
        GUILayout.Label(isPresent? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f));
#endif
        GUILayout.EndVertical();
        GUI.color = Color.white;
        GUILayout.EndHorizontal();

        if (isPresent)
        {
            if (NGUIEditorTools.DrawHeader("Preview"))
            {
                NGUIEditorTools.BeginContents();

                string[] keys;
                string[] values;

                if (Localization.dictionary.TryGetValue("KEY", out keys) && Localization.dictionary.TryGetValue(myKey, out values))
                {
                    for (int i = 0; i < keys.Length; ++i)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(keys[i], GUILayout.Width(70f));

                        if (GUILayout.Button(values[i], "AS TextArea", GUILayout.MinWidth(80f), GUILayout.MaxWidth(Screen.width - 110f)))
                        {
                            (target as UILocalize).value = values[i];
                            GUIUtility.hotControl        = 0;
                            GUIUtility.keyboardControl   = 0;
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                else
                {
                    GUILayout.Label("No preview available");
                }

                NGUIEditorTools.EndContents();
            }
        }
        else if (mKeys != null && !string.IsNullOrEmpty(myKey))
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            GUILayout.BeginVertical();
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f);

            int matches = 0;

            for (int i = 0; i < mKeys.size; ++i)
            {
                if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey))
                {
#if UNITY_3_5
                    if (GUILayout.Button(mKeys[i] + " \u25B2"))
#else
                    if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge"))
#endif
                    {
                        sp.stringValue             = mKeys[i];
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                    }

                    if (++matches == 8)
                    {
                        GUILayout.Label("...and more");
                        break;
                    }
                }
            }
            GUI.backgroundColor = Color.white;
            GUILayout.EndVertical();
            GUILayout.Space(22f);
            GUILayout.EndHorizontal();
        }

        serializedObject.ApplyModifiedProperties();
    }
Example #9
0
    /// <summary>
    /// All widgets have depth, color and make pixel-perfect options
    /// </summary>

    protected override void DrawCustomProperties()
    {
        PrefabType type = PrefabUtility.GetPrefabType(mWidget.gameObject);

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

            if (drawColor)
            {
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_1
                // Color tint
                GUILayout.BeginHorizontal();
                SerializedProperty sp = NGUIEditorTools.DrawProperty("Color", serializedObject, "mColor", GUILayout.MinWidth(20f));
                if (GUILayout.Button("Copy", GUILayout.Width(50f)))
                {
                    NGUISettings.color = sp.colorValue;
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                NGUISettings.color = EditorGUILayout.ColorField("Clipboard", NGUISettings.color);
                if (GUILayout.Button("Paste", GUILayout.Width(50f)))
                {
                    sp.colorValue = NGUISettings.color;
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(6f);
#else
                NGUIEditorTools.DrawProperty("Color", serializedObject, "mColor", GUILayout.MinWidth(20f));
#endif
            }
            else if (serializedObject.isEditingMultipleObjects)
            {
                NGUIEditorTools.DrawProperty("Alpha", serializedObject, "mColor.a", GUILayout.Width(120f));
            }
            else
            {
                GUI.changed = false;
                float alpha = EditorGUILayout.Slider("Alpha", mWidget.alpha, 0f, 1f);

                if (GUI.changed)
                {
                    NGUIEditorTools.RegisterUndo("Alpha change", mWidget);
                    mWidget.alpha = alpha;
                }
            }

            DrawPivot();
            DrawDepth(type == PrefabType.Prefab);
            DrawDimensions(type == PrefabType.Prefab);

            if (serializedObject.isEditingMultipleObjects || mWidget.hasBoxCollider)
            {
                GUILayout.BeginHorizontal();
                NGUIEditorTools.DrawProperty("Box Collider", serializedObject, "autoResizeBoxCollider", GUILayout.Width(100f));
                GUILayout.Label("auto-adjust to match");
                GUILayout.EndHorizontal();
            }
            NGUIEditorTools.EndContents();
        }
    }
Example #10
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        UIPanel panel = target as UIPanel;
        BetterList <UIDrawCall> drawcalls = panel.drawCalls;

        drawcalls.Sort(delegate(UIDrawCall w1, UIDrawCall w2) { return(w1.depth.CompareTo(w2.depth)); });
        EditorGUIUtility.fieldWidth = 0f;
        EditorGUIUtility.labelWidth = 80f;

        //NGUIEditorTools.DrawSeparator();
        EditorGUILayout.Space();

        float alpha = EditorGUILayout.Slider("Alpha", panel.alpha, 0f, 1f);

        if (alpha != panel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", panel);
            panel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        bool norms = EditorGUILayout.Toggle("Normals", panel.generateNormals, GUILayout.Width(100f));

        GUILayout.Label("Needed for lit shaders");
        GUILayout.EndHorizontal();

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        // No one seems to know how to use this properly correctly. Solution? Removing it.
        // If you know wtf you're doing, you're welcome to uncomment it.

        //GUILayout.BeginHorizontal();
        //bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f));
        //GUILayout.Label("Doubles draw calls, saves fillrate");
        //GUILayout.EndHorizontal();

        //if (panel.depthPass != depth)
        //{
        //    panel.depthPass = depth;
        //    panel.UpdateDrawcalls();
        //    EditorUtility.SetDirty(panel);
        //}

        //if (depth)
        //{
        //    UICamera cam = UICamera.FindCameraForLayer(panel.gameObject.layer);

        //    if (cam == null || cam.camera.isOrthoGraphic)
        //    {
        //        EditorGUILayout.HelpBox("Please note that depth pass will only save fillrate when used with 3D UIs, and only UIs drawn by the game camera. If you are using a separate camera for the UI, you will not see any benefit!", MessageType.Warning);
        //    }
        //}

        GUILayout.BeginHorizontal();
        bool sort = EditorGUILayout.Toggle("Depth Sort", panel.sortByDepth, GUILayout.Width(100f));

        GUILayout.Label("Sort widgets by depth (ignore Z)");
        GUILayout.EndHorizontal();

        if (panel.sortByDepth != sort)
        {
            panel.sortByDepth = sort;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        if (!sort)
        {
            EditorGUILayout.HelpBox("Keep the 'Depth Sort' flag turned on, unless you are working with a UI created prior to NGUI 2.7.0 and want to sort by Z in addition to Depth.", MessageType.Warning);
        }

        GUILayout.BeginHorizontal();
        bool cull = EditorGUILayout.Toggle("Cull", panel.cullWhileDragging, GUILayout.Width(100f));

        GUILayout.Label("Cull widgets while dragging them");
        GUILayout.EndHorizontal();

        if (panel.cullWhileDragging != cull)
        {
            panel.cullWhileDragging = cull;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool stat = EditorGUILayout.Toggle("Static", panel.widgetsAreStatic, GUILayout.Width(100f));

        GUILayout.Label("Check if widgets won't move");
        GUILayout.EndHorizontal();

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        if (stat)
        {
            EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
        }

        if (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool))
        {
            panel.showInPanelTool = !panel.showInPanelTool;
            EditorUtility.SetDirty(panel);
            EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
        }

        UIPanel.DebugInfo di = (UIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

        if (panel.debugInfo != di)
        {
            panel.debugInfo = di;
            EditorUtility.SetDirty(panel);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", panel.clipping);

        if (panel.clipping != clipping)
        {
            panel.clipping = clipping;
            EditorUtility.SetDirty(panel);
        }

        if (panel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = panel.clipRange;

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

            if (panel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", panel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (panel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                    panel.clipSoftness = soft;
                    EditorUtility.SetDirty(panel);
                }
            }

#if !UNITY_3_5 && !UNITY_4_0 && (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY)
            if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_2_0)
            {
                EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error);
            }
#endif
        }

        if (clipping == UIDrawCall.Clipping.HardClip)
        {
            EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning);
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(panel.gameObject);
            }
        }

        if (panel.drawCalls.size > 0 && NGUIEditorTools.DrawHeader(panel.drawCalls.size + " draw calls from " + panel.widgets.size + " widgets", "DrawCalls"))
        {
            NGUIEditorTools.BeginContents();

            foreach (UIDrawCall dc in drawcalls)
            {
                EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
                EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());

                if (clipping != UIDrawCall.Clipping.None && !dc.isClipped)
                {
                    EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.",
                                            MessageType.Warning);
                }
            }
            NGUIEditorTools.EndContents();
        }
    }
Example #11
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);

            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.AdvancedSpriteField(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;
                }
            }
        }
    }
Example #12
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        mScroll = GUILayout.BeginScrollView(mScroll);

        GameObject      tempPanel = null;
        bool            bBegin    = false;
        bool            bOpen     = false;
        EAtlasLayers    tempLayer = EAtlasLayers.Common_1;
        ItemDepthConfig tempConfig;

        for (int i = 0; i < _allItemsConfig.Count; i++)
        {
            tempConfig = _allItemsConfig[i];
            if ((tempPanel != null && tempPanel != tempConfig.panel) || (tempPanel != null && tempLayer != tempConfig.belongTo))
            {
                if (bBegin)
                {
                    NGUIEditorTools.EndContents();
                }
                bBegin = false;
            }

            if (tempPanel == null || tempPanel != tempConfig.panel)
            {
                DrawOnePanelName(tempConfig.panel);
            }
            if (tempPanel == null || tempLayer != tempConfig.belongTo)
            {
                //DrawOneTitle(tempConfig);
                string sTitle = GetLayerName(tempConfig.belongTo);
                string sKey   = tempConfig.panel.name + tempConfig.belongTo.ToString();
                bOpen = NGUIEditorTools.DrawHeader(sTitle, sKey);
                if (bOpen)
                {
                    NGUIEditorTools.BeginContents();
                    bBegin = true;
//                     GUILayout.BeginHorizontal();
//                     GUILayout.FlexibleSpace();
//                     bool bClick = GUILayout.Button("重置选中项depth", "LargeButton", GUILayout.Width(160f), GUILayout.Height(25f));
//                     if (bClick)
//                     {
//                         int layers = 1 << (int)tempConfig.belongTo;
//
//                         count_common1 = 0;
//                         count_common2 = 0;
//                         count_common3 = 0;
//                         count_uiatlas = 0;
//                         EachChildrenDepth(tempConfig.panel, tempConfig.panel, layers, true, true);
//                         SortAllItems();
//                     }
//                     GUILayout.FlexibleSpace();
//                     GUILayout.EndHorizontal();
                }
                else
                {
                    bBegin = false;
                }
            }
            if (bBegin)
            {
                DrawOneItem(ref tempConfig);
            }

            tempPanel = tempConfig.panel;
            tempLayer = tempConfig.belongTo;
        }
        if (bBegin)
        {
            NGUIEditorTools.EndContents();
        }

        GUILayout.EndScrollView();
        GUILayout.Space(6f);
        GUILayout.BeginHorizontal();
        GUILayout.Space(6f);
        bool bSelect = EditorGUILayout.ToggleLeft("选中所有", bSelectAll, GUILayout.Width(60f));

        if (bSelectAll != bSelect)
        {
            if (bSelect)
            {
                SelectAllItem();
            }
            else
            {
                UnSelectAllItem();
            }
            bSelectAll = bSelect;
        }
        GUILayout.FlexibleSpace();
        bool change = GUILayout.Button("自动适配所有选中项", "LargeButton", GUILayout.Width(160f));

        if (change)
        {
            SetChildrenDepth();
            ReadAllChildrenDepth();
        }
        GUILayout.FlexibleSpace();
        GUILayout.Space(-90f);
        bool bClickInstruction = GUILayout.Button("分段说明", "LargeButton", GUILayout.Width(90f));

        if (bClickInstruction)
        {
            NGUIDepthInstruction.ShowDialog();
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(10f);
    }
Example #13
0
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(130f);

        GUILayout.Space(3f);
        serializedObject.Update();

        SerializedProperty sppv = serializedObject.FindProperty("contentPivot");

        UIWidget.Pivot before = (UIWidget.Pivot)sppv.intValue;

        NGUIEditorTools.DrawProperty("Content Origin", sppv, false);

        SerializedProperty sp = NGUIEditorTools.DrawProperty("Movement", serializedObject, "movement");

        if (((UIScrollView.Movement)sp.intValue) == UIScrollView.Movement.Custom)
        {
            NGUIEditorTools.SetLabelWidth(20f);

            GUILayout.BeginHorizontal();
            GUILayout.Space(114f);
            NGUIEditorTools.DrawProperty("X", serializedObject, "customMovement.x", GUILayout.MinWidth(20f));
            NGUIEditorTools.DrawProperty("Y", serializedObject, "customMovement.y", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();
        }

        NGUIEditorTools.SetLabelWidth(130f);

        NGUIEditorTools.DrawProperty("Drag Effect", serializedObject, "dragEffect");
        NGUIEditorTools.DrawProperty("Scroll Wheel Factor", serializedObject, "scrollWheelFactor");
        NGUIEditorTools.DrawProperty("Momentum Amount", serializedObject, "momentumAmount");

        NGUIEditorTools.DrawProperty("Restrict Within Panel", serializedObject, "restrictWithinPanel");
        NGUIEditorTools.DrawProperty("Cancel Drag If Fits", serializedObject, "disableDragIfFits");
        NGUIEditorTools.DrawProperty("Smooth Drag Start", serializedObject, "smoothDragStart");
        NGUIEditorTools.DrawProperty("IOS Drag Emulation", serializedObject, "iOSDragEmulation");
        NGUIEditorTools.DrawProperty("Reset Offset OnEnable", serializedObject, "resetOffsetOnEnable");

        NGUIEditorTools.SetLabelWidth(100f);

        if (NGUIEditorTools.DrawHeader("Scroll Bars"))
        {
            NGUIEditorTools.BeginContents();
            NGUIEditorTools.DrawProperty("Horizontal", serializedObject, "horizontalScrollBar");
            NGUIEditorTools.DrawProperty("Vertical", serializedObject, "verticalScrollBar");
            NGUIEditorTools.DrawProperty("Show Condition", serializedObject, "showScrollBars");

            NGUIEditorTools.DrawProperty("Darg Begin", serializedObject, "DargBegin");
            NGUIEditorTools.DrawProperty("Darg End", serializedObject, "DargEnd");
            NGUIEditorTools.DrawProperty("Undarg Begin", serializedObject, "UndargBegin");
            NGUIEditorTools.DrawProperty("UndargEnd", serializedObject, "UndargEnd");

            NGUIEditorTools.EndContents();
        }
        serializedObject.ApplyModifiedProperties();

        if (before != (UIWidget.Pivot)sppv.intValue)
        {
            (target as UIScrollView).ResetPosition();
        }
    }
Example #14
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        UIPanel panel = target as UIPanel;

        NGUIEditorTools.SetLabelWidth(80f);
        EditorGUILayout.Space();

        float alpha = EditorGUILayout.Slider("Alpha", panel.alpha, 0f, 1f);

        if (alpha != panel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", panel);
            panel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = panel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (panel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", panel);
                panel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0; i < UIPanel.list.size; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && panel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + panel.depth, MessageType.Info);
        }

        GUILayout.BeginHorizontal();
        bool norms = EditorGUILayout.Toggle("Normals", panel.generateNormals, GUILayout.Width(100f));

        GUILayout.Label("Needed for lit shaders");
        GUILayout.EndHorizontal();

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            UIPanel.SetDirty();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool cull = EditorGUILayout.Toggle("Cull", panel.cullWhileDragging, GUILayout.Width(100f));

        GUILayout.Label("Cull widgets while dragging them");
        GUILayout.EndHorizontal();

        if (panel.cullWhileDragging != cull)
        {
            panel.cullWhileDragging = cull;
            UIPanel.SetDirty();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool stat = EditorGUILayout.Toggle("Static", panel.widgetsAreStatic, GUILayout.Width(100f));

        GUILayout.Label("Check if widgets won't move");
        GUILayout.EndHorizontal();

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            UIPanel.SetDirty();
            EditorUtility.SetDirty(panel);
        }

        if (stat)
        {
            EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
        }

        GUILayout.BeginHorizontal();
        if (NGUISettings.showAllDCs != EditorGUILayout.Toggle("Show All", NGUISettings.showAllDCs, GUILayout.Width(100f)))
        {
            NGUISettings.showAllDCs = !NGUISettings.showAllDCs;
        }
        GUILayout.Label("Show all draw calls");
        GUILayout.EndHorizontal();

        if (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool))
        {
            panel.showInPanelTool = !panel.showInPanelTool;
            EditorUtility.SetDirty(panel);
            EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", panel.clipping);

        if (panel.clipping != clipping)
        {
            panel.clipping = clipping;
            EditorUtility.SetDirty(panel);
        }

        if (panel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = panel.clipRange;

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

            if (panel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", panel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (panel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                    panel.clipSoftness = soft;
                    EditorUtility.SetDirty(panel);
                }
            }

#if !UNITY_3_5 && !UNITY_4_0 && (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY)
            if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_1_x)
            {
                EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error);
            }
#endif
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(panel.gameObject);
            }
        }

        for (int i = 0; i < UIDrawCall.list.size; ++i)
        {
            UIDrawCall dc = UIDrawCall.list[i];

            if (dc.panel != panel)
            {
                if (!NGUISettings.showAllDCs)
                {
                    continue;
                }
                if (dc.showDetails)
                {
                    GUI.color = new Color(0.85f, 0.85f, 0.85f);
                }
                else
                {
                    GUI.contentColor = new Color(0.85f, 0.85f, 0.85f);
                }
            }
            else
            {
                GUI.contentColor = Color.white;
            }

            string key  = dc.keyName;
            string name = key + " of " + UIDrawCall.list.size;
            if (!dc.isActive)
            {
                name = name + " (HIDDEN)";
            }
            else if (dc.panel != panel)
            {
                name = name + " (" + dc.panel.name + ")";
            }

            if (NGUIEditorTools.DrawHeader(name, key))
            {
                GUI.color = (dc.panel == panel) ? Color.white : new Color(0.8f, 0.8f, 0.8f);

                NGUIEditorTools.BeginContents();
                EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);

                int count = 0;

                for (int b = 0; b < UIWidget.list.size; ++b)
                {
                    UIWidget w = UIWidget.list[b];
                    if (w.drawCall == dc)
                    {
                        ++count;
                    }
                }

                string   myPath = NGUITools.GetHierarchy(dc.panel.cachedGameObject);
                string   remove = myPath + "\\";
                string[] list   = new string[count + 1];
                list[0] = count.ToString();
                count   = 0;

                for (int b = 0; b < UIWidget.list.size; ++b)
                {
                    UIWidget w = UIWidget.list[b];

                    if (w.drawCall == dc)
                    {
                        string path = NGUITools.GetHierarchy(w.cachedGameObject);
                        list[++count] = count + ". " + (string.Equals(path, myPath) ? w.name : path.Replace(remove, ""));
                    }
                }

                GUILayout.BeginHorizontal();
                int sel = EditorGUILayout.Popup("Widgets", 0, list);
                GUILayout.Space(18f);
                GUILayout.EndHorizontal();

                if (sel != 0)
                {
                    count = 0;

                    for (int b = 0; b < UIWidget.list.size; ++b)
                    {
                        UIWidget w = UIWidget.list[b];

                        if (w.drawCall == dc && ++count == sel)
                        {
                            Selection.activeGameObject = w.gameObject;
                            break;
                        }
                    }
                }

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Triangles", dc.triangles.ToString(), GUILayout.Width(120f));

                if (dc.panel != panel)
                {
                    if (GUILayout.Button("Select the Panel"))
                    {
                        Selection.activeGameObject = dc.panel.gameObject;
                    }
                    GUILayout.Space(18f);
                }
                GUILayout.EndHorizontal();

                bool draw = !EditorGUILayout.Toggle("Hide", !dc.isActive);

                if (dc.isActive != draw)
                {
                    dc.isActive = draw;
                    UnityEditor.EditorUtility.SetDirty(dc.panel);
                }

                if (dc.panel.clipping != UIDrawCall.Clipping.None && !dc.isClipped)
                {
                    EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.",
                                            MessageType.Warning);
                }

                NGUIEditorTools.EndContents();
                GUI.color = Color.white;
            }
        }
    }
Example #15
0
    public override void OnInspectorGUI()
    {
        RMERoomEdit cam = target as RMERoomEdit;

        DrawDefaultInspector();

        if (null == asset)
        {
            TextAsset obj = GameData.LoadConfig <TextAsset>("RoomTagTable");
            asset = new RoomTagTable();
            asset.Load(obj.bytes);
        }

        if (null == RoomTagInfoList)
        {
            RoomTagInfoList = new Dictionary <int, List <RoomTagInfo> >();
            int index = 1;
            int key   = 0;
            foreach (KeyValuePair <int, RoomTagInfo> item in asset.list)
            {
                if (RoomTagInfoList.ContainsKey(key))
                {
                    RoomTagInfoList[key].Add(item.Value);
                    //  Debug.Log("index:" + index + ",key:" + key + "gengxin");
                }
                else
                {
                    List <RoomTagInfo> list = new List <RoomTagInfo>();
                    list.Add(item.Value);
                    RoomTagInfoList.Add(key, list);
                    //  Debug.Log("index:" + index + ",key:" + key + "xinjian");
                }
                // Debug.Log("index:" + index + ",key:" + key + "");
                if ((index % 2) == 0)
                {
                    key++;
                }
                index++;
            }
        }

        if (NGUIEditorTools.DrawHeader("Tag"))
        {
            NGUIEditorTools.BeginContents();
            {
                foreach (KeyValuePair <int, List <RoomTagInfo> > item in RoomTagInfoList)
                {
                    GUILayout.BeginHorizontal();
                    foreach (RoomTagInfo info in item.Value)
                    {
                        EditorGUILayout.PropertyField(serializedObject.FindProperty(info.name), new GUIContent(info.name), GUILayout.MinWidth(20f));
                    }
                    GUILayout.EndHorizontal();
                }
            }
            NGUIEditorTools.EndContents();
        }

        serializedObject.ApplyModifiedProperties();


        if (null == IdList)
        {
            IdList = new List <int>();
        }

        IdList.Clear();

        foreach (KeyValuePair <int, RoomTagInfo> item in asset.list)
        {
            if (serializedObject.FindProperty(item.Value.name).boolValue)
            {
                IdList.Add(item.Key);;
                //Debug.Log("item.Value.name:" + item.Value.name);
            }
        }
        cam.SaveData(IdList);

        //EditorGUILayout.
        if (GUILayout.Button("Update"))
        {
            asset.list.Clear();

            TextAsset obj = GameData.LoadConfig <TextAsset>("RoomTagTable");

            asset.Load(obj.bytes);

            int index = 1;
            int key   = 0;
            RoomTagInfoList.Clear();

            foreach (KeyValuePair <int, RoomTagInfo> item in asset.list)
            {
                if (RoomTagInfoList.ContainsKey(key))
                {
                    RoomTagInfoList[key].Add(item.Value);
                    //  Debug.Log("index:" + index + ",key:" + key + "gengxin");
                }
                else
                {
                    List <RoomTagInfo> list = new List <RoomTagInfo>();
                    list.Add(item.Value);
                    RoomTagInfoList.Add(key, list);
                    //  Debug.Log("index:" + index + ",key:" + key + "xinjian");
                }
                // Debug.Log("index:" + index + ",key:" + key + "");
                if ((index % 2) == 0)
                {
                    key++;
                }
                index++;
            }
        }
    }
Example #16
0
    void OnGUI()
    {
        Event e = Event.current;

        //trunk/branches
        //GUI.color = Color.white;
        //Dictionary<string, ProxyBool> fs = YangMenuHelper.helperIns.switchFloders;
        m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);
        //if (NGUIEditorTools.DrawHeader("切换主分支", "切换主分支key"))
        //{
        //    NGUIEditorTools.BeginContents();
        //    int index = 0;
        //    foreach (var item in fs)//用复选框实现单选按钮
        //    {

        //        if (item.Value.m_bool != EditorGUILayout.ToggleLeft(item.Key, item.Value.m_bool))
        //        {
        //            if (!item.Value.m_bool)
        //            {
        //                UnityEngine.Debug.Log("item:" + item.Key + "  item.Value.m_bool:" + item.Value.m_bool);
        //                item.Value.m_bool = true;
        //                YangMenuHelper.helperIns.projMiniPath = item.Key;//选中.
        //                YangMenuHelper.helperIns.WriteConfigLine(0, "switchFloder.txt", "path=" + YangMenuHelper.helperIns.projMiniPath);
        //            }
        //        }
        //        else
        //        {
        //            //UnityEngine.Debug.Log(" false !!!item:" + item.Key + "  item.Value.m_bool:" + item.Value.m_bool);

        //            if (!item.Key.Equals(YangMenuHelper.helperIns.projMiniPath))
        //            {
        //                item.Value.m_bool = false;
        //            }
        //        }
        //        index++;
        //    }
        //    NGUIEditorTools.EndContents();
        //}
        //server list
        GUI.color = Color.white;
        Dictionary <ServerInfo, ProxyBool> serverf = YangMenuHelper.helperIns.serverFloders;

        if (NGUIEditorTools.DrawHeader("切换服务器", "切换服务器key"))
        {
            NGUIEditorTools.BeginContents();
            GUILayout.BeginHorizontal();
            bool selectSelf = YangMenuHelper.helperIns.currentServerIP.Equals(selfIP);
            if (selectSelf != EditorGUILayout.ToggleLeft(selfIP, selectSelf))
            {
                if (!string.IsNullOrEmpty(selfIP))
                {
                    YangMenuHelper.helperIns.currentServerIP = selfIP;
                    WriteIP();
                }
            }

            newSelfIp = GUILayout.TextField(newSelfIp, 25);
            if (GUILayout.Button("保存"))
            {
                if (!string.IsNullOrEmpty(newSelfIp) && !selfIP.Equals(newSelfIp) && YangMenuHelper.helperIns.IsIP(newSelfIp))
                {
                    selfIP = newSelfIp;

                    YangMenuHelper.helperIns.WriteConfigLine(0, "temp/selfIp.txt", selfIP);
                }
            }
            GUILayout.EndHorizontal();

            int index = 0;
            foreach (var item in serverf)//用复选框实现单选按钮
            {
                if (item.Key.connectioned)
                {
                    GUI.color = Color.green;
                }
                else
                {
                    GUI.color = Color.red;
                }
                if (item.Value.m_bool != EditorGUILayout.ToggleLeft(item.Key.content + ":" + (item.Key.connectioned ? "已开" : "未开"), item.Value.m_bool))
                {
                    if (!item.Value.m_bool)
                    {
                        UnityEngine.Debug.Log("item:" + item.Key + "  item.Value.m_bool:" + item.Value.m_bool);
                        item.Value.m_bool = true;
                        YangMenuHelper.helperIns.currentServerIP = item.Key.ip;//选中.
                        WriteIP();
                    }
                }
                else
                {
                    if (!item.Key.ip.Equals(YangMenuHelper.helperIns.currentServerIP))
                    {
                        item.Value.m_bool = false;
                    }
                }
                index++;
            }

            NGUIEditorTools.EndContents();
        }
        //log level
        GUI.color = Color.white;
        Dictionary <int, LineConfigInfo> clientConfig = YangMenuHelper.helperIns.ywindow_clientConfigBean.configDic;

        if (NGUIEditorTools.DrawHeader("修改ClientConfig", "修改ClientConfigkey"))
        {
            NGUIEditorTools.BeginContents();
            foreach (var item in clientConfig)//用复选框实现单选按钮
            {
                if (item.Value.myType == CONFIG_TYPE.STRING || item.Value.myType == CONFIG_TYPE.BOOL)
                {
                    if (GUILayout.Button(item.Value.lineValue))
                    {
                        if (item.Value.myType == CONFIG_TYPE.STRING)
                        {
                            GenericMenu menu = new GenericMenu();
                            for (int i = 0; i < item.Value.lineValues.Count; i++)
                            {
                                menu.AddItem(new GUIContent(item.Value.lineValues[i]), false, StringChangeCallBack, new object[] { item.Value, item.Value.lineValues[i] });
                            }
                            menu.ShowAsContext();
                        }
                        else
                        {
                            item.Value.OnBoolChange();
                        }
                    }
                }
                else if (item.Value.myType == CONFIG_TYPE.INT || item.Value.myType == CONFIG_TYPE.INPUT)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(item.Value.lineValue);
                    item.Value.xmlValue = GUILayout.TextField(item.Value.xmlValue, 25);

                    if (GUILayout.Button("更改"))
                    {
                        item.Value.OnInputChange();
                    }

                    GUILayout.EndHorizontal();
                }
            }
            //ButtonCtrl layoutBtn = new ButtonCtrl();
            //layoutBtn.Caption = "操作区布局";
            //layoutBtn.Name = "LayoutButton";
            //layoutBtn.Size = btnRect;
            //layoutBtn.onClick = OnLayoutBtnClick;
            NGUIEditorTools.EndContents();
        }
        EditorGUILayout.EndScrollView();
    }
    protected override void DrawCustomProperties()
    {
        if (Application.isPlaying)
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Start Particle"))
            {
                (target as UIParticleSystem).ResetSystem();
            }

            if (GUILayout.Button("Stop Particle"))
            {
                (target as UIParticleSystem).StopSystem();
            }
            GUILayout.EndHorizontal();

            if (GUILayout.Button("Save"))
            {
                var cache  = new Cache();
                var fileds = typeof(UIParticleSystem).GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                foreach (var filed in fileds)
                {
                    if (filed.GetCustomAttributes(typeof(System.NonSerializedAttribute), true).Length != 0)
                    {
                        continue;
                    }

                    var value = GetSerializedPropertyValue(serializedObject, filed);
                    if (value != null)
                    {
                        cache.Items[filed.Name] = value;
                    }
                }

                var system = target as UIParticleSystem;
                cache.Postion  = system.transform.localPosition;
                cache.Rotation = system.transform.localRotation;
                cache.Scale    = system.transform.localScale;

                CachedValues[target.GetInstanceID()] = cache;
            }
        }
        else
        {
            var   id = target.GetInstanceID();
            Cache cache;
            if (CachedValues.TryGetValue(id, out cache))
            {
                var system = target as UIParticleSystem;
                system.transform.localPosition = cache.Postion;
                system.transform.localRotation = cache.Rotation;
                system.transform.localScale    = cache.Scale;

                foreach (var item in cache.Items)
                {
                    SetSerializedPropertyValue(serializedObject, item.Key, item.Value);
                }

                CachedValues.Remove(id);
            }
        }


        if (NGUIEditorTools.DrawHeader("Position"))
        {
            NGUIEditorTools.BeginContents();
            NGUIEditorTools.DrawProperty("Start postion", serializedObject, "SourcePosition");
            NGUIEditorTools.DrawProperty("±", serializedObject, "SourcePositionVariance");
            NGUIEditorTools.EndContents();
            NGUIEditorTools.DrawProperty("Space", serializedObject, "SimulationSpace");
        }

        NGUIEditorTools.DrawProperty("Emit rate", serializedObject, "EmissionRate");
        NGUIEditorTools.DrawProperty("Duration", serializedObject, "Duration");
        NGUIEditorTools.DrawProperty("Total particles", serializedObject, "MaxParticles");

        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty("Life", serializedObject, "ParticleLifespan");
        NGUIEditorTools.DrawProperty("±", serializedObject, "ParticleLifespanVariance");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty("Start size", serializedObject, "StartParticleSize");
        NGUIEditorTools.DrawProperty("±", serializedObject, "StartParticleSizeVariance");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty("End Size", serializedObject, "FinishParticleSize");
        NGUIEditorTools.DrawProperty("±", serializedObject, "FinishParticleSizeVariance");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty("Start spin", serializedObject, "RotationStart");
        NGUIEditorTools.DrawProperty("±", serializedObject, "RotationStartVariance");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty("End spin", serializedObject, "RotationEnd");
        NGUIEditorTools.DrawProperty("±", serializedObject, "RotationEndVariance");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty("Angle", serializedObject, "Angle");
        NGUIEditorTools.DrawProperty("±", serializedObject, "AngleVariance");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty("Start color", serializedObject, "StartColor");
        NGUIEditorTools.DrawProperty("±", serializedObject, "StartColorVariance");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUIEditorTools.DrawProperty("End color", serializedObject, "FinishColor");
        NGUIEditorTools.DrawProperty("±", serializedObject, "FinishColorVariance");
        GUILayout.EndHorizontal();

        var sp = NGUIEditorTools.DrawProperty("Mode", serializedObject, "EmitterType");

        switch ((UIParticleMode)sp.enumValueIndex)
        {
        case UIParticleMode.Gravity:
            NGUIEditorTools.DrawProperty("Gravity", serializedObject, "Gravity");

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Speed", serializedObject, "Speed");
            NGUIEditorTools.DrawProperty("±", serializedObject, "SpeedVariance");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Tang. acc", serializedObject, "TangentialAcceleration");
            NGUIEditorTools.DrawProperty("±", serializedObject, "TangentialAccelVariance");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Radia acc", serializedObject, "RadialAcceleration");
            NGUIEditorTools.DrawProperty("±", serializedObject, "RadialAccelVariance");
            GUILayout.EndHorizontal();

            NGUIEditorTools.DrawProperty("IsDir", serializedObject, "RotationIsDir");
            break;

        case UIParticleMode.Radius:
            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Start radius", serializedObject, "StartRadius");
            NGUIEditorTools.DrawProperty("±", serializedObject, "StartRadiusVariance");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("End radius", serializedObject, "FinishRadius");
            NGUIEditorTools.DrawProperty("±", serializedObject, "FinishRadiusVariance");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Rotate", serializedObject, "RotatePerSecond");
            NGUIEditorTools.DrawProperty("±", serializedObject, "RotatePerSecondVariance");
            GUILayout.EndHorizontal();
            break;
        }

        if (NGUIEditorTools.DrawHeader("Particle sprite"))
        {
            NGUIEditorTools.BeginContents();
            ShowParticleSprite();
            base.DrawCustomProperties();
            NGUIEditorTools.EndContents();
        }
    }
    /// <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();
            }
        }
    }
Example #19
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;
                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 (NGUIEditorTools.DrawHeader("Scale Factor"))
            {
                NGUIEditorTools.BeginContents();
                {
                    EditorGUILayout.HelpBox(
                        "If the image size(pixel size in photoshop) is not equal to texture size(pixel size in unity), you should set the scale factor to help NGUI to adjust uv.",
                        MessageType.Info, true
                        );

                    EditorGUILayout.HelpBox(
                        "You should click the the button below to recalculate scale factor for atlas when the atlas' texture is changed. For example, when you add sprite, remove sprite, set compressed format or change maxsize etc.",
                        MessageType.Warning, true
                        );

                    if (GUILayout.Button("Calculate Scale Factor Automatically"))
                    {
                        if (mAtlas.texture != null)
                        {
                            string path     = AssetDatabase.GetAssetPath(mAtlas.texture);
                            string fullPath = Application.dataPath + path.Substring("Assets".Length);
                            if (File.Exists(fullPath))
                            {
                                MemoryStream memoryStream = null;
                                BinaryReader binaryReader = null;
                                try
                                {
                                    byte[] bytes = File.ReadAllBytes(fullPath);
                                    memoryStream = new MemoryStream(bytes);
                                    binaryReader = new BinaryReader(memoryStream);
                                    // Is PNG
                                    if (binaryReader.ReadByte() == 0x89 && binaryReader.ReadByte() == 0x50 && binaryReader.ReadByte() == 0x4E &&
                                        binaryReader.ReadByte() == 0x47 && binaryReader.ReadByte() == 0x0D && binaryReader.ReadByte() == 0x0A &&
                                        binaryReader.ReadByte() == 0x1A && binaryReader.ReadByte() == 0x0A)
                                    {
                                        binaryReader.ReadUInt32();
                                        binaryReader.ReadUInt32();
                                        uint            width           = LittleEndianToBigEndian(binaryReader.ReadUInt32());
                                        uint            height          = LittleEndianToBigEndian(binaryReader.ReadUInt32());
                                        TextureImporter textureImporter = (TextureImporter)TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(mAtlas.texture));

                                        System.Action <string, UIAtlas.SCALE_PLATFORM, BuildTarget> processScale = delegate(string platformName, UIAtlas.SCALE_PLATFORM platformAtlasEnum, BuildTarget platformEnum)
                                        {
                                            if (mAtlas.scales == null || mAtlas.scales.Length != (int)UIAtlas.SCALE_PLATFORM.SIZE * 2)
                                            {
                                                mAtlas.scales = new float[(int)UIAtlas.SCALE_PLATFORM.SIZE * 2] {
                                                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1
                                                };
                                            }

                                            //      TextureImportInstructions info = new TextureImportInstructions();
                                            //      textureImporter.ReadTextureImportInstructions(info, platformEnum);
                                            int maxSize;
                                            TextureImporterFormat format;
                                            if (textureImporter.GetPlatformTextureSettings(platformName, out maxSize, out format))
                                            {
                                                float len = width > height ? width : height;
                                                mAtlas.scales[(int)platformAtlasEnum * 2]     = len / (float)width;
                                                mAtlas.scales[(int)platformAtlasEnum * 2 + 1] = len / (float)height;
                                            }
                                            else
                                            {
                                                mAtlas.scales[(int)platformAtlasEnum * 2]     = 1;
                                                mAtlas.scales[(int)platformAtlasEnum * 2 + 1] = 1;
                                            }
                                        };

                                        processScale("Web", UIAtlas.SCALE_PLATFORM.WEB, BuildTarget.WebPlayer);
                                        processScale("Standalone", UIAtlas.SCALE_PLATFORM.STANDALONE, BuildTarget.StandaloneWindows);
                                        processScale("iPhone", UIAtlas.SCALE_PLATFORM.IPHONE, BuildTarget.iOS);
                                        processScale("Android", UIAtlas.SCALE_PLATFORM.ANDROID, BuildTarget.Android);

                                        NGUITools.SetDirty(mAtlas);
                                    }
                                }
                                catch (System.Exception exception)
                                {
                                    Debug.LogError(exception.StackTrace);
                                    UnityEditor.EditorUtility.DisplayDialog("Error", "Error:Set the scale factor mamually.", "ok");
                                }
                                finally
                                {
                                    if (memoryStream != null)
                                    {
                                        memoryStream.Close();
                                        memoryStream.Dispose();
                                        memoryStream = null;
                                    }
                                    if (binaryReader != null)
                                    {
                                        binaryReader.Close();
                                        binaryReader = null;
                                    }
                                }
                            }
                            else
                            {
                                UnityEditor.EditorUtility.DisplayDialog("Alert", "File is not exists\n" + fullPath, "ok");
                            }
                        }
                        else
                        {
                            UnityEditor.EditorUtility.DisplayDialog("Alert", "Null Texture", "ok");
                        }
                    }
                }
                NGUIEditorTools.EndContents();
            }
        }

        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.SaveFilePanelInProject("Save As", sprite.name + ".png", "png", "Extract sprite into which file?");

                        if (!string.IsNullOrEmpty(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);
                                }
                            }
                        }
                    }
                    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;
                }
            }
        }
    }
Example #20
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        NGUIEditorTools.SetLabelWidth(100f);
        UIToggle toggle = target as UIToggle;

        GUILayout.Space(6f);
        GUI.changed = false;

        GUILayout.BeginHorizontal();
        SerializedProperty sp = NGUIEditorTools.DrawProperty("Group", serializedObject, "group", GUILayout.Width(120f));

        GUILayout.Label(" - zero means 'none'");
        GUILayout.EndHorizontal();

        EditorGUI.BeginDisabledGroup(sp.intValue == 0);
        NGUIEditorTools.DrawProperty("  State of 'None'", serializedObject, "optionCanBeNone");
        EditorGUI.EndDisabledGroup();

        NGUIEditorTools.DrawProperty("Starting State", serializedObject, "startsActive");
        NGUIEditorTools.SetLabelWidth(80f);

        if (NGUIEditorTools.DrawMinimalisticHeader("State Transition"))
        {
            NGUIEditorTools.BeginContents(true);

            SerializedProperty sprite    = serializedObject.FindProperty("activeSprite");
            SerializedProperty animator  = serializedObject.FindProperty("animator");
            SerializedProperty animation = serializedObject.FindProperty("activeAnimation");
            SerializedProperty tween     = serializedObject.FindProperty("tween");

            if (sprite.objectReferenceValue != null)
            {
                NGUIEditorTools.DrawProperty("Sprite", sprite, false);
                serializedObject.DrawProperty("invertSpriteState");
            }
            else if (animator.objectReferenceValue != null)
            {
                NGUIEditorTools.DrawProperty("Animator", animator, false);
            }
            else if (animation.objectReferenceValue != null)
            {
                NGUIEditorTools.DrawProperty("Animation", animation, false);
            }
            else if (tween.objectReferenceValue != null)
            {
                NGUIEditorTools.DrawProperty("Tween", tween, false);
            }
            else
            {
                NGUIEditorTools.DrawProperty("Sprite", serializedObject, "activeSprite");
                NGUIEditorTools.DrawProperty("Animator", animator, false);
                NGUIEditorTools.DrawProperty("Animation", animation, false);
                NGUIEditorTools.DrawProperty("Tween", tween, false);
            }

            if (serializedObject.isEditingMultipleObjects)
            {
                NGUIEditorTools.DrawProperty("Instant", serializedObject, "instantTween");
            }
            else
            {
                GUI.changed = false;
                Transition tr = toggle.instantTween ? Transition.Instant : Transition.Smooth;
                GUILayout.BeginHorizontal();
                tr = (Transition)EditorGUILayout.EnumPopup("Transition", tr);
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();

                if (GUI.changed)
                {
                    NGUIEditorTools.RegisterUndo("Toggle Change", toggle);
                    toggle.instantTween = (tr == Transition.Instant);
                    NGUITools.SetDirty(toggle);
                }
            }
            NGUIEditorTools.EndContents();
        }

        NGUIEditorTools.DrawEvents("On Value Change", toggle, toggle.onChange);
        serializedObject.ApplyModifiedProperties();
    }
    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mList = target as UIPopupList;

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

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

        if (mList.textLabel != lbl)
        {
            RegisterUndo();
            mList.textLabel = lbl;
            if (lbl != null)
            {
                lbl.text = mList.value;
            }
        }
        GUILayout.Space(44f);
        GUILayout.EndHorizontal();

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

        GUILayout.BeginHorizontal();
        bool useTableDic = EditorGUILayout.Toggle("UseTableDic", mList.useDicTable, GUILayout.Width(100f));

        GUILayout.EndHorizontal();
        mList.useDicTable = useTableDic;

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

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

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

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

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

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

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

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

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

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

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

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

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

                EditorGUILayout.Space();

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

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

                EditorGUILayout.Space();

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

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

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

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

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

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

            NGUIEditorTools.DrawEvents("On Value Change", mList, mList.onChange);
        }
    }
Example #22
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        EditorGUILayout.Space();

        float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f);

        if (alpha != mPanel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel);
            mPanel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = mPanel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (mPanel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", mPanel);
                mPanel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0; i < UIPanel.list.size; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && mPanel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping);

        if (mPanel.clipping != clipping)
        {
            mPanel.clipping = clipping;
            EditorUtility.SetDirty(mPanel);
        }

        if (mPanel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = mPanel.clipRange;

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (mPanel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.clipRange = range;
                EditorUtility.SetDirty(mPanel);
            }

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (mPanel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipSoftness = soft;
                    EditorUtility.SetDirty(mPanel);
                }
            }
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(mPanel.gameObject);
            }
        }

        if (NGUIEditorTools.DrawHeader("Advanced Options"))
        {
            NGUIEditorTools.BeginContents();

            GUILayout.BeginHorizontal();
            bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f));
            GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.generateNormals != norms)
            {
                mPanel.generateNormals = norms;
                UIPanel.RebuildAllDrawCalls(true);
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f));
            GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.cullWhileDragging != cull)
            {
                mPanel.cullWhileDragging = cull;
                UIPanel.RebuildAllDrawCalls(true);
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.alwaysOnScreen != alw)
            {
                mPanel.alwaysOnScreen = alw;
                UIPanel.RebuildAllDrawCalls(true);
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.widgetsAreStatic != stat)
            {
                mPanel.widgetsAreStatic = stat;
                UIPanel.RebuildAllDrawCalls(true);
                EditorUtility.SetDirty(mPanel);
            }

            if (stat)
            {
                EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
            }

            GUILayout.BeginHorizontal();
            bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f));
            GUILayout.Label("Show in panel tool");
            GUILayout.EndHorizontal();

            if (mPanel.showInPanelTool != tool)
            {
                mPanel.showInPanelTool = !mPanel.showInPanelTool;
                EditorUtility.SetDirty(mPanel);
                EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
            }
            NGUIEditorTools.EndContents();
        }

        if (GUILayout.Button("Show Draw Calls"))
        {
            NGUISettings.showAllDCs = false;

            if (UIDrawCallViewer.instance != null)
            {
                UIDrawCallViewer.instance.Focus();
                UIDrawCallViewer.instance.Repaint();
            }
            else
            {
                EditorWindow.GetWindow <UIDrawCallViewer>(false, "Draw Call Tool", true);
            }
        }
    }
Example #23
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f);

        if (alpha != mPanel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel);
            mPanel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = mPanel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (mPanel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", mPanel);
                mPanel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }

                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0, imax = UIPanel.list.Count; i < imax; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && mPanel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping);

        if (mPanel.clipping != clipping)
        {
            mPanel.clipping = clipping;
            EditorUtility.SetDirty(mPanel);
        }

        // Contributed by Benzino07: http://www.tasharen.com/forum/index.php?topic=6956.15
        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Sorting Layer");

            // Get the names of the Sorting layers
            System.Type  internalEditorUtilityType = typeof(InternalEditorUtility);
            PropertyInfo sortingLayersProperty     = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
            string[]     names = (string[])sortingLayersProperty.GetValue(null, new object[0]);

            int index = 0;
            if (!string.IsNullOrEmpty(mPanel.sortingLayerName))
            {
                for (int i = 0; i < names.Length; i++)
                {
                    if (mPanel.sortingLayerName == names[i])
                    {
                        index = i;
                        break;
                    }
                }
            }

            // Get the selected index and update the panel sorting layer if it has changed
            int selectedIndex = EditorGUILayout.Popup(index, names);

            if (index != selectedIndex)
            {
                mPanel.sortingLayerName = names[selectedIndex];
                EditorUtility.SetDirty(mPanel);
            }
        }
        GUILayout.EndHorizontal();

        if (mPanel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = mPanel.baseClipRegion;

            // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable
            //EditorGUI.BeginDisabledGroup(mPanel.GetComponent<UIScrollView>() != null);
            GUI.changed = false;
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset, GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.clipOffset = off;
                EditorUtility.SetDirty(mPanel);
            }
            //EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y), GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w), GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (mPanel.baseClipRegion != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.baseClipRegion = range;
                EditorUtility.SetDirty(mPanel);
            }

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness, GUILayout.MinWidth(20f));
                GUILayout.EndHorizontal();

                if (soft.x < 0f)
                {
                    soft.x = 0f;
                }
                if (soft.y < 0f)
                {
                    soft.y = 0f;
                }

                if (mPanel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipSoftness = soft;
                    EditorUtility.SetDirty(mPanel);
                }
            }
            else if (mPanel.clipping == UIDrawCall.Clipping.TextureMask)
            {
                NGUIEditorTools.SetLabelWidth(0f);
                GUILayout.Space(-90f);
                Texture2D tex = (Texture2D)EditorGUILayout.ObjectField(mPanel.clipTexture,
                                                                       typeof(Texture2D), false, GUILayout.Width(70f), GUILayout.Height(70f));
                GUILayout.Space(20f);

                if (mPanel.clipTexture != tex)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipTexture = tex;
                    EditorUtility.SetDirty(mPanel);
                }
                NGUIEditorTools.SetLabelWidth(80f);
            }
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(mPanel.gameObject);
            }
        }

        if (NGUIEditorTools.DrawHeader("Advanced Options"))
        {
            NGUIEditorTools.BeginContents();

            GUILayout.BeginHorizontal();
            UIPanel.RenderQueue rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue);

            if (mPanel.renderQueue != rq)
            {
                mPanel.renderQueue = rq;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }

            if (rq != UIPanel.RenderQueue.Automatic)
            {
                int sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f));

                if (mPanel.startingRenderQueue != sq)
                {
                    mPanel.startingRenderQueue = sq;
                    mPanel.RebuildAllDrawCalls();
                    EditorUtility.SetDirty(mPanel);
                    if (UIDrawCallViewer.instance != null)
                    {
                        UIDrawCallViewer.instance.Repaint();
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUI.changed = false;
            // --==GAM==--
            //int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f));
            //if (GUI.changed) mPanel.sortingOrder = so;
            if (Application.isPlaying)
            {
                int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f));
                if (GUI.changed)
                {
                    mPanel.sortingOrder = so;
                }
            }
            else
            {
                SortingOrder soEnum = (SortingOrder)EditorGUILayout.EnumPopup("Sort Order", (SortingOrder)mPanel.sortingOrder);
                if (GUI.changed)
                {
                    mPanel.sortingOrder = (int)soEnum;
                }
            }
            // --==GAM==--

            GUILayout.BeginHorizontal();
            bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f));
            GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.generateNormals != norms)
            {
                mPanel.generateNormals = norms;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f));
            GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.cullWhileDragging != cull)
            {
                mPanel.cullWhileDragging = cull;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.alwaysOnScreen != alw)
            {
                mPanel.alwaysOnScreen = alw;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            NGUIEditorTools.DrawProperty("Padding", serializedObject, "softBorderPadding", GUILayout.Width(100f));
            GUILayout.Label("Soft border pads content", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(mPanel.GetComponent <UIRoot>() != null);
            bool off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset && mPanel.GetComponent <UIRoot>() == null, GUILayout.Width(100f));
            GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f));
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            if (mPanel.anchorOffset != off)
            {
                mPanel.anchorOffset = off;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.widgetsAreStatic != stat)
            {
                mPanel.widgetsAreStatic = stat;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            if (stat)
            {
                EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
            }

            GUILayout.BeginHorizontal();
            bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f));
            GUILayout.Label("Show in panel tool");
            GUILayout.EndHorizontal();

            if (mPanel.showInPanelTool != tool)
            {
                mPanel.showInPanelTool = !mPanel.showInPanelTool;
                EditorUtility.SetDirty(mPanel);
                EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
            }
            NGUIEditorTools.EndContents();
        }
        return(true);
    }
Example #24
0
    /// <summary>
    /// Draw the UI for this tool.
    /// </summary>

    void OnGUI()
    {
        Object fnt    = NGUISettings.ambigiousFont;
        UIFont uiFont = (fnt as UIFont);

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

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

        GUILayout.BeginHorizontal();
        mType = (FontType)EditorGUILayout.EnumPopup("Type", mType, GUILayout.MinWidth(200f));
        GUILayout.Space(18f);
        GUILayout.EndHorizontal();
        Create create = Create.None;

        if (mType == FontType.ImportedBitmap)
        {
            NGUISettings.fontData    = EditorGUILayout.ObjectField("Font Data", NGUISettings.fontData, typeof(TextAsset), false) as TextAsset;
            NGUISettings.fontTexture = EditorGUILayout.ObjectField("Texture", NGUISettings.fontTexture, typeof(Texture2D), false, GUILayout.Width(140f)) as Texture2D;
            NGUIEditorTools.EndContents();

            // Draw the atlas selection only if we have the font data and texture specified, just to make it easier
            EditorGUI.BeginDisabledGroup(NGUISettings.fontData == null || NGUISettings.fontTexture == null);
            {
                NGUIEditorTools.DrawHeader("Output", true);
                NGUIEditorTools.BeginContents();
                ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false);
                NGUIEditorTools.EndContents();
            }
            EditorGUI.EndDisabledGroup();

            if (NGUISettings.fontData == null)
            {
                EditorGUILayout.HelpBox("To create a font from a previously exported FNT file, you need to 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 FNT, 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.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info);
            }

            EditorGUI.BeginDisabledGroup(NGUISettings.fontData == null || NGUISettings.fontTexture == null);
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(20f);
                if (GUILayout.Button("Create the Font"))
                {
                    create = Create.Import;
                }
                GUILayout.Space(20f);
                GUILayout.EndHorizontal();
            }
            EditorGUI.EndDisabledGroup();
        }
        else
        {
            GUILayout.BeginHorizontal();
            if (NGUIEditorTools.DrawPrefixButton("Source"))
            {
                ComponentSelector.Show <Font>(OnUnityFont, new string[] { ".ttf", ".otf" });
            }

            Font ttf = EditorGUILayout.ObjectField(NGUISettings.ambigiousFont as Font, typeof(Font), false) as Font;
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                NGUISettings.fontSize = EditorGUILayout.IntField("Size", NGUISettings.fontSize, GUILayout.Width(120f));

                if (mType == FontType.Dynamic)
                {
                    NGUISettings.fontStyle = (FontStyle)EditorGUILayout.EnumPopup(NGUISettings.fontStyle);
                    GUILayout.Space(18f);
                }
            }
            GUILayout.EndHorizontal();

            // Choose the font style if there are multiple faces present
            if (mType == FontType.GeneratedBitmap)
            {
                if (!FreeType.isPresent)
                {
                    string filename = (Application.platform == RuntimePlatform.WindowsEditor) ? "FreeType.dll" : "FreeType.dylib";

                    EditorGUILayout.HelpBox("Assets/NGUI/Editor/" + filename + " is missing", MessageType.Error);

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

                    if (GUILayout.Button("Find " + filename))
                    {
                        string path = EditorUtility.OpenFilePanel("Find " + filename, "Assets",
                                                                  (Application.platform == RuntimePlatform.WindowsEditor) ? "dll" : "dylib");

                        if (!string.IsNullOrEmpty(path))
                        {
                            if (System.IO.Path.GetFileName(path) == filename)
                            {
                                NGUISettings.pathToFreeType = path;
                            }
                            else
                            {
                                LogSystem.LogWarning("The library must be named '", filename, "'");
                            }
                        }
                    }
                    GUILayout.Space(20f);
                    GUILayout.EndHorizontal();
                }
                else if (ttf != null)
                {
                    string[] faces = FreeType.GetFaces(ttf);

                    if (faces != null)
                    {
                        if (mFaceIndex >= faces.Length)
                        {
                            mFaceIndex = 0;
                        }

                        if (faces.Length > 1)
                        {
                            GUILayout.Label("Style", EditorStyles.boldLabel);
                            for (int i = 0; i < faces.Length; ++i)
                            {
                                GUILayout.BeginHorizontal();
                                GUILayout.Space(10f);
                                if (DrawOption(i == mFaceIndex, " " + faces[i]))
                                {
                                    mFaceIndex = i;
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                    }

                    GUILayout.Label("Characters", EditorStyles.boldLabel);

                    CharacterMap cm = characterMap;

                    GUILayout.BeginHorizontal(GUILayout.Width(100f));
                    GUILayout.BeginVertical();
                    GUI.changed = false;
                    if (DrawOption(cm == CharacterMap.Numeric, " Numeric"))
                    {
                        cm = CharacterMap.Numeric;
                    }
                    if (DrawOption(cm == CharacterMap.Ascii, " ASCII"))
                    {
                        cm = CharacterMap.Ascii;
                    }
                    if (DrawOption(cm == CharacterMap.Latin, " Latin"))
                    {
                        cm = CharacterMap.Latin;
                    }
                    if (DrawOption(cm == CharacterMap.Custom, " Custom"))
                    {
                        cm = CharacterMap.Custom;
                    }
                    if (GUI.changed)
                    {
                        characterMap = cm;
                    }
                    GUILayout.EndVertical();

                    EditorGUI.BeginDisabledGroup(cm != CharacterMap.Custom);
                    {
                        if (cm != CharacterMap.Custom)
                        {
                            string chars = string.Empty;

                            if (cm == CharacterMap.Ascii)
                            {
                                for (int i = 33; i < 127; ++i)
                                {
                                    chars += System.Convert.ToChar(i);
                                }
                            }
                            else if (cm == CharacterMap.Numeric)
                            {
                                chars = "01234567890";
                            }
                            else if (cm == CharacterMap.Latin)
                            {
                                for (int i = 33; i < 127; ++i)
                                {
                                    chars += System.Convert.ToChar(i);
                                }

                                for (int i = 161; i < 256; ++i)
                                {
                                    chars += System.Convert.ToChar(i);
                                }
                            }

                            NGUISettings.charsToInclude = chars;
                        }

                        GUI.changed = false;

                        string text = NGUISettings.charsToInclude;

                        if (cm == CharacterMap.Custom)
                        {
                            text = EditorGUILayout.TextArea(text, GUI.skin.textArea,
                                                            GUILayout.Height(80f), GUILayout.Width(ResolutionConstrain.Instance.width - 100f));
                        }
                        else
                        {
                            GUILayout.Label(text, GUI.skin.textArea,
                                            GUILayout.Height(80f), GUILayout.Width(ResolutionConstrain.Instance.width - 100f));
                        }

                        if (GUI.changed)
                        {
                            string final = string.Empty;

                            for (int i = 0; i < text.Length; ++i)
                            {
                                char c = text[i];
                                if (c < 33)
                                {
                                    continue;
                                }
                                string s = c.ToString();
                                if (!final.Contains(s))
                                {
                                    final += s;
                                }
                            }

                            if (final.Length > 0)
                            {
                                char[] chars = final.ToCharArray();
                                System.Array.Sort(chars);
                                final = new string(chars);
                            }
                            else
                            {
                                final = string.Empty;
                            }

                            NGUISettings.charsToInclude = final;
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                    GUILayout.EndHorizontal();
                }
            }
            NGUIEditorTools.EndContents();

            if (mType == FontType.Dynamic)
            {
                EditorGUI.BeginDisabledGroup(ttf == null);
                GUILayout.BeginHorizontal();
                GUILayout.Space(20f);
                if (GUILayout.Button("Create the Font"))
                {
                    create = Create.Dynamic;
                }
                GUILayout.Space(20f);
                GUILayout.EndHorizontal();
                EditorGUI.EndDisabledGroup();
#if UNITY_3_5
                EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
                // Helpful info
                if (ttf == null)
                {
                    EditorGUILayout.HelpBox("You don't have to create a UIFont to use dynamic fonts. You can just reference the Unity Font directly on the label.", 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
            {
                bool isBuiltIn = (ttf != null) && string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(ttf));

                // Draw the atlas selection only if we have the font data and texture specified, just to make it easier
                EditorGUI.BeginDisabledGroup(ttf == null || isBuiltIn || !FreeType.isPresent);
                {
                    NGUIEditorTools.DrawHeader("Output", true);
                    NGUIEditorTools.BeginContents();
                    ComponentSelector.Draw <UIAtlas>(NGUISettings.atlas, OnSelectAtlas, false);
                    NGUIEditorTools.EndContents();

                    if (ttf == null)
                    {
                        EditorGUILayout.HelpBox("You can create a bitmap font by specifying a dynamic font to use as the source.", MessageType.Info);
                    }
                    else if (isBuiltIn)
                    {
                        EditorGUILayout.HelpBox("You chose an embedded font. You can't create a bitmap font from an embedded resource.", MessageType.Warning);
                    }
                    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.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info);
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20f);
                    if (GUILayout.Button("Create the Font"))
                    {
                        create = Create.Bitmap;
                    }
                    GUILayout.Space(20f);
                    GUILayout.EndHorizontal();
                }
                EditorGUI.EndDisabledGroup();
            }
        }

        if (create == Create.None)
        {
            return;
        }

        // Open the "Save As" file dialog
        string prefabPath = EditorUtility.SaveFilePanelInProject("Save As", "New Font.prefab", "prefab", "Save font as...");
        if (string.IsNullOrEmpty(prefabPath))
        {
            return;
        }

        // Load the font's prefab
        GameObject go     = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
        Object     prefab = null;
        string     fontName;

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

            fontName = prefabPath.Replace(".prefab", string.Empty);
            fontName = fontName.Substring(prefabPath.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Create a new game object for the font
            go     = new GameObject(fontName);
            uiFont = go.AddComponent <UIFont>();
        }
        else
        {
            uiFont   = go.GetComponent <UIFont>();
            fontName = go.name;
        }

        if (create == Create.Dynamic)
        {
            uiFont.atlas            = null;
            uiFont.dynamicFont      = NGUISettings.dynamicFont;
            uiFont.dynamicFontStyle = NGUISettings.fontStyle;
            uiFont.defaultSize      = NGUISettings.fontSize;
        }
        else if (create == Create.Import)
        {
            Material mat = null;

            if (NGUISettings.atlas != null)
            {
                // Add the font's texture to the atlas
                UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, NGUISettings.fontTexture);
            }
            else
            {
                // Create a material for the font
                string matPath = prefabPath.Replace(".prefab", ".mat");
                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(ImportAssetOptions.ForceSynchronousImport);

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

                mat.mainTexture = NGUISettings.fontTexture;
            }

            uiFont.dynamicFont = null;
            BMFontReader.Load(uiFont.bmFont, NGUITools.GetHierarchy(uiFont.gameObject), NGUISettings.fontData.bytes);

            if (NGUISettings.atlas == null)
            {
                uiFont.atlas    = null;
                uiFont.material = mat;
            }
            else
            {
                uiFont.spriteName = NGUISettings.fontTexture.name;
                uiFont.atlas      = NGUISettings.atlas;
            }
            NGUISettings.fontSize = uiFont.defaultSize;
        }
        else if (create == Create.Bitmap)
        {
            // Create the bitmap font
            BMFont    bmFont;
            Texture2D tex;

            if (FreeType.CreateFont(
                    NGUISettings.dynamicFont,
                    NGUISettings.fontSize, mFaceIndex,
                    NGUISettings.charsToInclude, out bmFont, out tex))
            {
                uiFont.bmFont = bmFont;
                tex.name      = fontName;

                if (NGUISettings.atlas != null)
                {
                    // Add this texture to the atlas and destroy it
                    UIAtlasMaker.AddOrUpdate(NGUISettings.atlas, tex);
                    NGUITools.DestroyImmediate(tex);
                    NGUISettings.fontTexture = null;
                    tex = null;

                    uiFont.atlas      = NGUISettings.atlas;
                    uiFont.spriteName = fontName;
                }
                else
                {
                    string texPath = prefabPath.Replace(".prefab", ".png");
                    string matPath = prefabPath.Replace(".prefab", ".mat");

                    byte[]     png = tex.EncodeToPNG();
                    FileStream fs  = File.OpenWrite(texPath);
                    fs.Write(png, 0, png.Length);
                    fs.Close();

                    // See if the material already exists
                    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(ImportAssetOptions.ForceSynchronousImport);

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

                    // Re-load the texture
                    tex = AssetDatabase.LoadAssetAtPath(texPath, typeof(Texture2D)) as Texture2D;

                    // Assign the texture
                    mat.mainTexture          = tex;
                    NGUISettings.fontTexture = tex;

                    uiFont.atlas    = null;
                    uiFont.material = mat;
                }
            }
            else
            {
                return;
            }
        }

        if (prefab != null)
        {
            // Update the prefab
            PrefabUtility.ReplacePrefab(go, prefab);
            DestroyImmediate(go);
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

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

        if (uiFont != null)
        {
            NGUISettings.ambigiousFont = uiFont;
        }
        MarkAsChanged();
        Selection.activeGameObject = go;
    }
Example #25
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        BetterList <UIDrawCall> dcs = UIDrawCall.activeList;

        dcs.Sort(delegate(UIDrawCall a, UIDrawCall b)
        {
            return(a.finalRenderQueue.CompareTo(b.finalRenderQueue));
        });

        if (dcs.size == 0)
        {
            EditorGUILayout.HelpBox("No NGUI draw calls present in the scene", MessageType.Info);
            return;
        }

        UIPanel selectedPanel = NGUITools.FindInParents <UIPanel>(Selection.activeGameObject);

        GUILayout.Space(12f);

        NGUIEditorTools.SetLabelWidth(100f);
        ShowFilter show = (NGUISettings.showAllDCs ? ShowFilter.AllPanels : ShowFilter.SelectedPanel);

        if ((ShowFilter)EditorGUILayout.EnumPopup("Draw Call Filter", show) != show)
        {
            NGUISettings.showAllDCs = !NGUISettings.showAllDCs;
        }

        GUILayout.Space(6f);

        if (selectedPanel == null && !NGUISettings.showAllDCs)
        {
            EditorGUILayout.HelpBox("No panel selected", MessageType.Info);
            return;
        }

        NGUIEditorTools.SetLabelWidth(80f);
        mScroll = GUILayout.BeginScrollView(mScroll);

        int dcCount = 0;

        for (int i = 0; i < dcs.size; ++i)
        {
            UIDrawCall dc        = dcs[i];
            string     key       = "Draw Call " + (i + 1);
            bool       highlight = (selectedPanel == null || selectedPanel == dc.manager);

            if (!highlight)
            {
                if (!NGUISettings.showAllDCs)
                {
                    continue;
                }

                if (UnityEditor.EditorPrefs.GetBool(key, true))
                {
                    GUI.color = new Color(0.85f, 0.85f, 0.85f);
                }
                else
                {
                    GUI.contentColor = new Color(0.85f, 0.85f, 0.85f);
                }
            }
            else
            {
                GUI.contentColor = Color.white;
            }

            ++dcCount;
            string name = key + " of " + dcs.size;
            if (!dc.isActive)
            {
                name = name + " (HIDDEN)";
            }
            else if (!highlight)
            {
                name = name + " (" + dc.manager.name + ")";
            }

            if (NGUIEditorTools.DrawHeader(name, key))
            {
                GUI.color = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);

                NGUIEditorTools.BeginContents();
                EditorGUILayout.ObjectField("Material", dc.dynamicMaterial, typeof(Material), false);

                int count = 0;

                for (int a = 0; a < UIPanel.list.Count; ++a)
                {
                    UIPanel p = UIPanel.list[a];

                    for (int b = 0; b < p.widgets.Count; ++b)
                    {
                        UIWidget w = p.widgets[b];
                        if (w.drawCall == dc)
                        {
                            ++count;
                        }
                    }
                }

                string   myPath = NGUITools.GetHierarchy(dc.manager.cachedGameObject);
                string   remove = myPath + "\\";
                string[] list   = new string[count + 1];
                list[0] = count.ToString();
                count   = 0;

                for (int a = 0; a < UIPanel.list.Count; ++a)
                {
                    UIPanel p = UIPanel.list[a];

                    for (int b = 0; b < p.widgets.Count; ++b)
                    {
                        UIWidget w = p.widgets[b];

                        if (w.drawCall == dc)
                        {
                            string path = NGUITools.GetHierarchy(w.cachedGameObject);
                            list[++count] = count + ". " + (string.Equals(path, myPath) ? w.name : path.Replace(remove, ""));
                        }
                    }
                }

                GUILayout.BeginHorizontal();
                int sel = EditorGUILayout.Popup("Widgets", 0, list);
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();

                if (sel != 0)
                {
                    count = 0;

                    for (int a = 0; a < UIPanel.list.Count; ++a)
                    {
                        UIPanel p = UIPanel.list[a];

                        for (int b = 0; b < p.widgets.Count; ++b)
                        {
                            UIWidget w = p.widgets[b];

                            if (w.drawCall == dc && ++count == sel)
                            {
                                Selection.activeGameObject = w.gameObject;
                                break;
                            }
                        }
                    }
                }

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Render Q", dc.finalRenderQueue.ToString(), GUILayout.Width(120f));
                bool draw = (Visibility)EditorGUILayout.EnumPopup(dc.isActive ? Visibility.Visible : Visibility.Hidden) == Visibility.Visible;
                NGUIEditorTools.DrawPadding();
                GUILayout.EndHorizontal();

                if (dc.isActive != draw)
                {
                    dc.isActive = draw;
                    NGUITools.SetDirty(dc.manager);
                }

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Triangles", dc.triangles.ToString(), GUILayout.Width(120f));

                if (dc.manager != selectedPanel)
                {
                    if (GUILayout.Button("Select the Panel"))
                    {
                        Selection.activeGameObject = dc.manager.gameObject;
                    }
                    NGUIEditorTools.DrawPadding();
                }
                GUILayout.EndHorizontal();

                if (dc.manager.clipping != UIDrawCall.Clipping.None && !dc.isClipped)
                {
                    EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.",
                                            MessageType.Warning);
                }

                NGUIEditorTools.EndContents();
                GUI.color = Color.white;
            }
        }

        if (dcCount == 0)
        {
            EditorGUILayout.HelpBox("No draw calls found", MessageType.Info);
        }
        GUILayout.EndScrollView();
    }
Example #26
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        GUILayout.Space(6f);
        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.BeginHorizontal();
        // Key not found in the localization file -- draw it as a text field
        SerializedProperty sp = NGUIEditorTools.DrawProperty("Key", serializedObject, "key");

        string myKey     = sp.stringValue;
        bool   isPresent = (mKeys != null) && mKeys.Contains(myKey);

        GUI.color = isPresent ? Color.green : Color.red;
        GUILayout.BeginVertical(GUILayout.Width(22f));
        GUILayout.Space(2f);
        GUILayout.Label(isPresent? "\u2714" : "\u2718", "TL SelectionButtonNew", GUILayout.Height(20f));
        GUILayout.EndVertical();
        GUI.color = Color.white;
        GUILayout.EndHorizontal();

        if (isPresent)
        {
            if (NGUIEditorTools.DrawHeader("Preview"))
            {
                NGUIEditorTools.BeginContents();

                string[] keys = Localization.knownLanguages;
                string[] values;

                if (Localization.dictionary.TryGetValue(myKey, out values))
                {
                    if (keys.Length != values.Length)
                    {
                        EditorGUILayout.HelpBox("Number of keys doesn't match the number of values! Did you modify the dictionaries by hand at some point?", MessageType.Error);
                    }
                    else
                    {
                        for (int i = 0; i < keys.Length; ++i)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Label(keys[i], GUILayout.Width(66f));

                            if (GUILayout.Button(values[i], "AS TextArea", GUILayout.MinWidth(80f), GUILayout.MaxWidth(Screen.width - 110f)))
                            {
                                (target as UILocalize).value = values[i];
                                GUIUtility.hotControl        = 0;
                                GUIUtility.keyboardControl   = 0;
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                }
                else
                {
                    GUILayout.Label("No preview available");
                }

                NGUIEditorTools.EndContents();
            }
        }
        else if (mKeys != null && !string.IsNullOrEmpty(myKey))
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            GUILayout.BeginVertical();
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f);

            int matches = 0;

            for (int i = 0, imax = mKeys.Count; i < imax; ++i)
            {
                if (mKeys[i].StartsWith(myKey, System.StringComparison.OrdinalIgnoreCase) || mKeys[i].Contains(myKey))
                {
                    if (GUILayout.Button(mKeys[i] + " \u25B2", "CN CountBadge"))
                    {
                        sp.stringValue             = mKeys[i];
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                    }

                    if (++matches == 8)
                    {
                        GUILayout.Label("...and more");
                        break;
                    }
                }
            }
            GUI.backgroundColor = Color.white;
            GUILayout.EndVertical();
            GUILayout.Space(22f);
            GUILayout.EndHorizontal();
        }

        serializedObject.ApplyModifiedProperties();
    }
Example #27
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    protected override bool ShouldDrawProperties()
    {
        float alpha = EditorGUILayout.Slider("Alpha", mPanel.alpha, 0f, 1f);

        if (alpha != mPanel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", mPanel);
            mPanel.alpha = alpha;
        }

        GUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Depth");

            int depth = mPanel.depth;
            if (GUILayout.Button("Back", GUILayout.Width(60f)))
            {
                --depth;
            }
            depth = EditorGUILayout.IntField(depth, GUILayout.MinWidth(20f));
            if (GUILayout.Button("Forward", GUILayout.Width(68f)))
            {
                ++depth;
            }

            if (mPanel.depth != depth)
            {
                NGUIEditorTools.RegisterUndo("Panel Depth", mPanel);
                mPanel.depth = depth;

                if (UIPanelTool.instance != null)
                {
                    UIPanelTool.instance.Repaint();
                }

                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }
        }
        GUILayout.EndHorizontal();

        int matchingDepths = 0;

        for (int i = 0; i < UIPanel.list.size; ++i)
        {
            UIPanel p = UIPanel.list[i];
            if (p != null && mPanel.depth == p.depth)
            {
                ++matchingDepths;
            }
        }

        if (matchingDepths > 1)
        {
            EditorGUILayout.HelpBox(matchingDepths + " panels are sharing the depth value of " + mPanel.depth, MessageType.Warning);
        }

        UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", mPanel.clipping);

        if (mPanel.clipping != clipping)
        {
            mPanel.clipping = clipping;
            EditorUtility.SetDirty(mPanel);
        }

        if (mPanel.clipping != UIDrawCall.Clipping.None)
        {
            Vector4 range = mPanel.baseClipRegion;

            // Scroll view is anchored, meaning it adjusts the offset itself, so we don't want it to be modifiable
            //EditorGUI.BeginDisabledGroup(mPanel.GetComponent<UIScrollView>() != null);
            GUI.changed = false;
            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector3 off = EditorGUILayout.Vector2Field("Offset", mPanel.clipOffset);
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.clipOffset = off;
                EditorUtility.SetDirty(mPanel);
            }
            //EditorGUI.EndDisabledGroup();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 vTemp2 = Vector2.zero;
            vTemp2.x = range.x;
            vTemp2.y = range.y;
            Vector2 pos = EditorGUILayout.Vector2Field("Center", vTemp2);
            GUILayout.EndHorizontal();

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

            vTemp2.x = range.z;
            vTemp2.y = range.w;
            Vector2 size = EditorGUILayout.Vector2Field("Size", vTemp2);
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (mPanel.baseClipRegion != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                mPanel.baseClipRegion = range;
                EditorUtility.SetDirty(mPanel);
            }

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", mPanel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (mPanel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", mPanel);
                    mPanel.clipSoftness = soft;
                    EditorUtility.SetDirty(mPanel);
                }
            }
        }

        if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(mPanel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(mPanel.gameObject);
            }
        }

        if (NGUIEditorTools.DrawHeader("Advanced Options"))
        {
            NGUIEditorTools.BeginContents();

            GUILayout.BeginHorizontal();
            UIPanel.RenderQueue rq = (UIPanel.RenderQueue)EditorGUILayout.EnumPopup("Render Q", mPanel.renderQueue);

            if (mPanel.renderQueue != rq)
            {
                mPanel.renderQueue = rq;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
                if (UIDrawCallViewer.instance != null)
                {
                    UIDrawCallViewer.instance.Repaint();
                }
            }

            if (rq != UIPanel.RenderQueue.Automatic)
            {
                int sq = EditorGUILayout.IntField(mPanel.startingRenderQueue, GUILayout.Width(40f));

                if (mPanel.startingRenderQueue != sq)
                {
                    mPanel.startingRenderQueue = sq;
                    mPanel.RebuildAllDrawCalls();
                    EditorUtility.SetDirty(mPanel);
                    if (UIDrawCallViewer.instance != null)
                    {
                        UIDrawCallViewer.instance.Repaint();
                    }
                }
            }
            GUILayout.EndHorizontal();

#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
            if (rq == UIPanel.RenderQueue.Explicit)
            {
                GUI.changed = false;
                int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f));
                if (GUI.changed)
                {
                    mPanel.sortingOrder = so;
                }
            }
#endif

            GUILayout.BeginHorizontal();
            bool norms = EditorGUILayout.Toggle("Normals", mPanel.generateNormals, GUILayout.Width(100f));
            GUILayout.Label("Needed for lit shaders", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.generateNormals != norms)
            {
                mPanel.generateNormals = norms;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool cull = EditorGUILayout.Toggle("Cull", mPanel.cullWhileDragging, GUILayout.Width(100f));
            GUILayout.Label("Cull widgets while dragging them", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.cullWhileDragging != cull)
            {
                mPanel.cullWhileDragging = cull;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool alw = EditorGUILayout.Toggle("Visible", mPanel.alwaysOnScreen, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets never go off-screen", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.alwaysOnScreen != alw)
            {
                mPanel.alwaysOnScreen = alw;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool off = EditorGUILayout.Toggle("Offset", mPanel.anchorOffset, GUILayout.Width(100f));
            GUILayout.Label("Offset anchors by position", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.anchorOffset != off)
            {
                mPanel.anchorOffset = off;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            GUILayout.BeginHorizontal();
            bool stat = EditorGUILayout.Toggle("Static", mPanel.widgetsAreStatic, GUILayout.Width(100f));
            GUILayout.Label("Check if widgets won't move", GUILayout.MinWidth(20f));
            GUILayout.EndHorizontal();

            if (mPanel.widgetsAreStatic != stat)
            {
                mPanel.widgetsAreStatic = stat;
                mPanel.RebuildAllDrawCalls();
                EditorUtility.SetDirty(mPanel);
            }

            if (stat)
            {
                EditorGUILayout.HelpBox("Only mark the panel as 'static' if you know FOR CERTAIN that the widgets underneath will not move, rotate, or scale. Doing this improves performance, but moving widgets around will have no effect.", MessageType.Warning);
            }

            GUILayout.BeginHorizontal();
            bool tool = EditorGUILayout.Toggle("Panel Tool", mPanel.showInPanelTool, GUILayout.Width(100f));
            GUILayout.Label("Show in panel tool");
            GUILayout.EndHorizontal();

            if (mPanel.showInPanelTool != tool)
            {
                mPanel.showInPanelTool = !mPanel.showInPanelTool;
                EditorUtility.SetDirty(mPanel);
                EditorWindow.FocusWindowIfItsOpen <UIPanelTool>();
            }
            NGUIEditorTools.EndContents();
        }
        return(true);
    }
Example #28
0
    public override void OnInspectorGUI()
    {
        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);
        NGUIEditorTools.DrawPadding();
        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(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 as Object);
                mFont.replacement = mReplacement;
                NGUITools.SetDirty(mFont as Object);
            }
            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 as Object);
                mFont.dynamicFont = fnt;
            }

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

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

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

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

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

            if (mFont.atlas != null)
            {
                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.DrawAdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
            }
            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 as Object);
                    mFont.material = mat;
                }
            }

            if (!mFont.isDynamic)
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.IntField("Default Size", mFont.defaultSize, GUILayout.Width(120f));
                EditorGUI.EndDisabledGroup();
            }

            EditorGUILayout.Space();

            // 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 as Object);
                    BMFontReader.Load(mFont.bmFont, (mFont as Object).name, data.bytes);
                    mFont.MarkAsChanged();
                    resetWidthHeight = true;
                    Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters");
                }
            }

            if (mFont is UIFont && mFont.bmFont.isValid)
            {
                EditorGUILayout.HelpBox("Legacy font type should be upgraded in order to maintain compatibility with Unity 2018 and newer.", MessageType.Warning, true);

                if (GUILayout.Button("Upgrade"))
                {
                    var path = EditorUtility.SaveFilePanelInProject("Save As", (mFont as Object).name + ".asset", "asset", "Save atlas as...", NGUISettings.currentPath);

                    if (!string.IsNullOrEmpty(path))
                    {
                        NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path);
                        var asset = ScriptableObject.CreateInstance <NGUIFont>();
                        asset.bmFont      = mFont.bmFont;
                        asset.symbols     = mFont.symbols;
                        asset.atlas       = mFont.atlas;
                        asset.spriteName  = mFont.spriteName;
                        asset.uvRect      = mFont.uvRect;
                        asset.defaultSize = mFont.defaultSize;

                        var fontName = path.Replace(".asset", "");
                        fontName   = fontName.Substring(path.LastIndexOfAny(new char[] { '/', '\\' }) + 1);
                        asset.name = fontName;

                        AssetDatabase.CreateAsset(asset, path);
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

                        asset = AssetDatabase.LoadAssetAtPath <NGUIFont>(path);
                        NGUISettings.ambigiousFont = asset;
                        Selection.activeObject     = asset;

                        if (asset != null)
                        {
                            mFont.replacement = asset;
                            mFont.MarkAsChanged();
                        }
                    }
                }
            }

            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 as Object);
                        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 as Object);
                            }
                        }

                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("X", GUILayout.Width(22f)))
                        {
                            NGUIEditorTools.RegisterUndo("Remove symbol", mFont as Object);
                            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 as Object);
                        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();
        }
    }
    void DrawFont()
    {
        if (NGUIEditorTools.DrawHeader("Font"))
        {
            NGUIEditorTools.BeginContents();

            SerializedProperty ttf = null;

            GUILayout.BeginHorizontal();
            {
                if (NGUIEditorTools.DrawPrefixButton("Font"))
                {
                    if (mType == FontType.Bitmap)
                    {
                        ComponentSelector.Show <UIFont>(OnBitmapFont);
                    }
                    else
                    {
                        ComponentSelector.Show <Font>(OnDynamicFont, new string[] { ".ttf", ".otf" });
                    }
                }

#if DYNAMIC_FONT
                GUI.changed = false;
                mType       = (FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f));

                if (GUI.changed)
                {
                    GUI.changed = false;

                    if (mType == FontType.Bitmap)
                    {
                        serializedObject.FindProperty("trueTypeFont").objectReferenceValue = null;
                    }
                    else
                    {
                        serializedObject.FindProperty("bitmapFont").objectReferenceValue = null;
                    }
                }
#else
                mType = FontType.Bitmap;
#endif

                if (mType == FontType.Bitmap)
                {
                    NGUIEditorTools.DrawProperty("", serializedObject, "bitmapFont", GUILayout.MinWidth(40f));
                }
                else
                {
                    ttf = NGUIEditorTools.DrawProperty("", serializedObject, "trueTypeFont", GUILayout.MinWidth(40f));
                }
            }
            GUILayout.EndHorizontal();

            if (ttf != null && ttf.objectReferenceValue != null)
            {
                GUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup(ttf.hasMultipleDifferentValues);
                    NGUIEditorTools.DrawProperty("Font Size", serializedObject, "fontSize", GUILayout.Width(142f));
                    NGUIEditorTools.DrawProperty("", serializedObject, "fontStyle", GUILayout.MinWidth(40f));
                    NGUIEditorTools.DrawPadding();
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                NGUIEditorTools.DrawProperty("Font Size", serializedObject, "fontSize", GUILayout.Width(142f));
            }

            NGUIEditorTools.DrawProperty("Text Color", serializedObject, "textColor");

            GUILayout.BeginHorizontal();
            NGUIEditorTools.SetLabelWidth(66f);
            EditorGUILayout.PrefixLabel("Padding");
            NGUIEditorTools.SetLabelWidth(14f);
            NGUIEditorTools.DrawProperty("X", serializedObject, "padding.x", GUILayout.MinWidth(30f));
            NGUIEditorTools.DrawProperty("Y", serializedObject, "padding.y", GUILayout.MinWidth(30f));
            NGUIEditorTools.DrawPadding();
            NGUIEditorTools.SetLabelWidth(80f);
            GUILayout.EndHorizontal();

            NGUIEditorTools.EndContents();
        }
    }
Example #30
0
    void DrawLinkedPartitionList()
    {
        CharacterPartitionLink link = target as CharacterPartitionLink;

        if (NGUIEditorTools.DrawHeader(string.Format("Linked Partition List ({0})", link.LinkedPartitions.Count), "CharacterPartitionLink_Partitions"))
        {
            NGUIEditorTools.BeginContents();
            {
                bool delete = false;
                for (int i = 0; i < link.LinkedPartitions.Count; i++)
                {
                    if (i > 0)
                    {
                        GUILayout.Space(5);
                    }


                    NGUIEditorTools.BeginContents();
                    {
                        DrawPartition(i, ref delete);
                    }
                    NGUIEditorTools.EndContents();

                    if (delete)
                    {
                        link.LinkedPartitions.RemoveAt(i);
                        break;
                    }
                }

                if (GUILayout.Button("Add New Partition"))
                {
                    PartitionInfo newPartition = new PartitionInfo();
                    int           count        = 1;
                    string        name         = string.Format("Partition_{0}", count);
                    while (true)
                    {
                        bool nameExisted = false;
                        foreach (PartitionInfo partition in link.LinkedPartitions)
                        {
                            if (partition.Name == name)
                            {
                                nameExisted = true;
                                break;
                            }
                        }
                        if (nameExisted)
                        {
                            count++;
                            name = string.Format("Partition_{0}", count);
                        }
                        else
                        {
                            break;
                        }
                    }

                    newPartition.Name = name;
                    link.LinkedPartitions.Add(newPartition);
                }
            }
            NGUIEditorTools.EndContents();
        }
    }