/// <summary>
    /// Integer vector field.
    /// </summary>

    static public IntVector IntPair(string prefix, string leftCaption, string rightCaption, int x, int y)
    {
        GUILayout.BeginHorizontal();

        if (string.IsNullOrEmpty(prefix))
        {
            GUILayout.Space(82f);
        }
        else
        {
            GUILayout.Label(prefix, GUILayout.Width(74f));
        }

        CWALKEditorTools.SetLabelWidth(48f);
        IntVector vec2 = new IntVector();

        vec2.x = EditorGUILayout.IntField(leftCaption, x, GUILayout.MinWidth(30f));
        vec2.y = EditorGUILayout.IntField(rightCaption, y, GUILayout.MinWidth(30f));

        CWALKEditorTools.SetLabelWidth(80f);

        GUILayout.EndHorizontal();
        return(vec2);
    }
Exemple #2
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        CWALKEditorTools.SetLabelWidth(80f);

        if (CWALKSettingTools.S_MeshSpriteMaker == null)
        {
            GUILayout.Label("No config selected.", "LODLevelNotifyText");
        }
        else
        {
            bool close = false;
            CWALKEditorTools.DrawSeparator();

            List <Texture2D> texturelist = CWALKSettingTools.S_MeshSpriteMaker.textureList;

            if (texturelist == null)
            {
                return;
            }
            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);
            int rows = 1;

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

                    for (; offset < texturelist.Count; ++offset)
                    {
                        Texture tex = texturelist[offset];

                        if (tex == null)
                        {
                            continue;
                        }

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

                                if (CWALKSettingTools.S_SelectedSprite != tex.name)
                                {
                                    if (mSprite != null)
                                    {
                                        mSprite.mainTexture = tex;
                                        EditorUtility.SetDirty(mSprite.gameObject);
                                    }

                                    CWALKSettingTools.S_SelectedSprite = tex.name;
                                    if (mCallback != null)
                                    {
                                        mCallback(tex);
                                    }
                                }
                                else if (delta < 0.5f)
                                {
                                    close = true;
                                }
                            }
                            else
                            {
                            }
                        }

                        if (Event.current.type == EventType.Repaint)
                        {
                            // Calculate the texture's scale that's needed to display the sprite in the clipped area
                            float scaleX = rect.width / tex.width;
                            float scaleY = rect.height / tex.height;

                            // Stretch the sprite so that it will appear proper
                            float aspect   = (scaleY / scaleX) / ((float)tex.height / tex.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.DrawTexture(clipRect, tex);

                            // Draw the selection
                            if (CWALKSettingTools.S_SelectedSprite == tex.name)
                            {
                                CWALKEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
                            }
                        }

                        GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                        GUI.contentColor    = new Color(1f, 1f, 1f, 0.7f);
                        GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), tex.name, "ProgressBarBack");
                        GUI.contentColor    = Color.white;
                        GUI.backgroundColor = Color.white;

                        if (++col >= columns)
                        {
                            ++offset;
                            break;
                        }
                        rect.x += padded;
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(padded);
                rect.y += padded + 26;
                ++rows;
            }
            GUILayout.Space(rows * 26);
            GUILayout.EndScrollView();

            if (close)
            {
                Close();
            }
        }
    }