예제 #1
0
    protected override void DrawIconSpriteUI(NJGMapBase.MapItemType mapItem)
    {
        if (m.atlas != null)
        {
            string spr = mapItem.sprite;

            IconField("Icon Sprite", spr, delegate(string sp)
            {
                mapItem.sprite = sp;
                Save(true);
            }, GUILayout.Width(120f));

            float extraSpace = 0;

            // Draw sprite preview.
            if (mMat == null)
            {
                mMat = m.atlas.spriteMaterial;
            }

            if (mMat != null)
            {
                Texture2D tex = mMat.mainTexture as Texture2D;

                if (tex != null)
                {
                    NJGAtlas.Sprite sprite = m.atlas.GetSprite(spr);

                    if (sprite != null)
                    {
                        int size = mapItem.useCustomSize ? mapItem.size : m.iconSize;
                        GUILayout.Space(4f);
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Space((Screen.width - 100) - size);
                            GUI.color = mMat.color = mapItem.color;

                            DrawSprite(tex, sprite.uvs, null, false, size, new Vector2(0, 18));
                            GUI.color = Color.white;
                        }
                        GUILayout.EndHorizontal();

                        extraSpace = size * (float)sprite.height / sprite.width;
                    }
                }
                extraSpace = Mathf.Max(0f, extraSpace - 24f);
                GUILayout.Space(extraSpace);
            }
        }
    }
예제 #2
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
#if UNITY_4_3
        EditorGUIUtility.LookLikeControls(80f);
#else
        EditorGUIUtility.labelWidth = 80f;
#endif

        bool close = false;
        GUILayout.Label("Icons", "LODLevelNotifyText");
        NJGEditorTools.DrawSeparator();

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

        string before = mSearch;
        string after  = EditorGUILayout.TextField("", before, "SearchTextField");
        mSearch = after;

        if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
        {
            mSearch = "";
            GUIUtility.keyboardControl = 0;
        }
        GUILayout.Space(84f);
        GUILayout.EndHorizontal();

        Texture2D tex = mAtlas.texture as Texture2D;

        if (tex == null)
        {
            GUILayout.Label("The atlas doesn't have a texture to work with");
            return;
        }

        List <string> sprites = mAtlas.GetListOfSprites(mSearch);

        float size    = 80f;
        float padded  = size + 10f;
        int   columns = Mathf.FloorToInt(Screen.width / padded);
        if (columns < 1)
        {
            columns = 1;
        }

        int  offset = 0;
        Rect rect   = new Rect(10f, 0, size, size);

        GUILayout.Space(10f);
        mPos = GUILayout.BeginScrollView(mPos);

        while (offset < sprites.Count)
        {
            GUILayout.BeginHorizontal();
            {
                int col = 0;
                rect.x = 10f;

                for (; offset < sprites.Count; ++offset)
                {
                    NJGAtlas.Sprite sprite = mAtlas.GetSprite(sprites[offset]);
                    if (sprite == null)
                    {
                        continue;
                    }

                    // Button comes first
                    if (GUI.Button(rect, ""))
                    {
                        float delta = Time.realtimeSinceStartup - mClickTime;
                        mClickTime = Time.realtimeSinceStartup;

                        if (mSprite != sprite.name)
                        {
                            mSprite = sprite.name;
                            if (mCallback != null)
                            {
                                mCallback(mSprite);
                            }
                        }
                        else if (delta < 0.5f)
                        {
                            close = true;
                        }
                    }

                    if (Event.current.type == EventType.Repaint)
                    {
                        // On top of the button we have a checkboard grid
                        NJGEditorTools.DrawTiledTexture(rect, NJGEditorTools.backdropTexture);

                        // Calculate the texture's scale that's needed to display the sprite in the clipped area
                        float scaleX = rect.width / sprite.width;
                        float scaleY = rect.height / sprite.height;

                        // Stretch the sprite so that it will appear proper
                        float aspect   = (scaleY / scaleX) / ((float)sprite.height / sprite.width);
                        Rect  clipRect = rect;

                        if (aspect != 1f)
                        {
                            if (aspect < 1f)
                            {
                                // The sprite is taller than it is wider
                                float padding = size * (1f - aspect) * 0.5f;
                                clipRect.xMin += padding;
                                clipRect.xMax -= padding;
                            }
                            else
                            {
                                // The sprite is wider than it is taller
                                float padding = size * (1f - 1f / aspect) * 0.5f;
                                clipRect.yMin += padding;
                                clipRect.yMax -= padding;
                            }
                        }

                        GUI.DrawTextureWithTexCoords(clipRect, tex, sprite.uvs);

                        // Draw the selection
                        if (mSprite == sprite.name)
                        {
                            NJGEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
                        }
                    }

                    if (++col >= columns)
                    {
                        ++offset;
                        break;
                    }
                    rect.x += padded;
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(padded);
            rect.y += padded;
        }
        GUILayout.EndScrollView();
        if (close)
        {
            Close();
        }
    }
예제 #3
0
    protected override void DrawArrowSpriteUI(NJGMapBase.MapItemType mapItem)
    {
        if (m.atlas != null && mapItem.haveArrow)
        {
            GUILayout.BeginVertical("Box");

            //if (string.IsNullOrEmpty(mSpriteName)) mSpriteName = m.atlas.spriteList[0].name;
            //string spr = string.IsNullOrEmpty(mapItem.arrowSprite) ? mSpriteName : mapItem.arrowSprite;
            string spr = mapItem.arrowSprite;

            mapItem.arrowOffset = EditorGUILayout.IntField("Arrow Offset", mapItem.arrowOffset);
            mapItem.arrowRotate = EditorGUILayout.Toggle("Arrow Rotate", mapItem.arrowRotate);

            IconField("Arrow Sprite", spr, delegate(string sp)
            {
                mapItem.arrowSprite = sp;
                Save(true);
            }, GUILayout.Width(120f));

            float extraSpace = 0;

            // Draw sprite preview.
            if (mMat == null)
            {
                mMat = m.atlas.spriteMaterial;
            }

            if (mMat != null)
            {
                Texture2D tex = mMat.mainTexture as Texture2D;

                if (tex != null)
                {
                    NJGAtlas.Sprite sprite = m.atlas.GetSprite(spr);

                    if (sprite != null)
                    {
                        GUILayout.Space(4f);
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Space((Screen.width - 100) - m.arrowSize);
                            GUI.color = mMat.color = mapItem.color;
                            DrawSprite(tex, sprite.uvs, null, false, m.arrowSize, new Vector2(0, 18));
                            GUI.color = Color.white;
                        }
                        GUILayout.EndHorizontal();

                        extraSpace = m.arrowSize * (float)tex.height / tex.width;
                    }
                }
                extraSpace = Mathf.Max(0f, extraSpace - 20f);
                GUILayout.Space(extraSpace);
            }

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

                int depth = mapItem.arrowDepth;
                if (GUILayout.Button("Back", GUILayout.Width(60f)))
                {
                    --depth;
                }
                depth = EditorGUILayout.IntField(depth);
                if (GUILayout.Button("Forward", GUILayout.Width(60f)))
                {
                    ++depth;
                }

                if (mapItem.arrowDepth != depth)
                {
                    mapItem.arrowDepth = depth;
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
    }