Example #1
0
    /// <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));
        }

        WeaponXIToolsEditor.SetLabelWidth(48f);

        IntVector retVal;

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

        WeaponXIToolsEditor.SetLabelWidth(80f);

        GUILayout.EndHorizontal();
        return(retVal);
    }
Example #2
0
    /// <summary>
    /// Integer vector field.
    /// </summary>

    static public Vector4 IntPadding(string prefix, Vector4 v)
    {
        int left   = Mathf.RoundToInt(v.x);
        int top    = Mathf.RoundToInt(v.y);
        int right  = Mathf.RoundToInt(v.z);
        int bottom = Mathf.RoundToInt(v.w);

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

        return(new Vector4(a.x, a.y, b.x, b.y));
    }
Example #3
0
    /// <summary>
    /// Integer rectangle field.
    /// </summary>

    static public Rect IntRect(string prefix, Rect rect)
    {
        int left   = Mathf.RoundToInt(rect.xMin);
        int top    = Mathf.RoundToInt(rect.yMin);
        int width  = Mathf.RoundToInt(rect.width);
        int height = Mathf.RoundToInt(rect.height);

        WeaponXIToolsEditor.IntVector a = WeaponXIToolsEditor.IntPair(prefix, "Left", "Top", left, top);
        WeaponXIToolsEditor.IntVector b = WeaponXIToolsEditor.IntPair(null, "Width", "Height", width, height);

        return(new Rect(a.x, a.y, b.x, b.y));
    }
Example #4
0
    /// <summary>
    /// Draw the specified sprite.
    /// </summary>

    public static void DrawTexture(Texture2D tex, Rect rect, Rect uv, Color color, Material mat)
    {
        int w = Mathf.RoundToInt(tex.width * uv.width);
        int h = Mathf.RoundToInt(tex.height * uv.height);

        // Create the texture rectangle that is centered inside rect.
        Rect outerRect = rect;

        outerRect.width  = w;
        outerRect.height = h;

        if (outerRect.width > 0f)
        {
            float f = rect.width / outerRect.width;
            outerRect.width  *= f;
            outerRect.height *= f;
        }

        if (rect.height > outerRect.height)
        {
            outerRect.y += (rect.height - outerRect.height) * 0.5f;
        }
        else if (outerRect.height > rect.height)
        {
            float f = rect.height / outerRect.height;
            outerRect.width  *= f;
            outerRect.height *= f;
        }

        if (rect.width > outerRect.width)
        {
            outerRect.x += (rect.width - outerRect.width) * 0.5f;
        }

        // Draw the background
        WeaponXIToolsEditor.DrawTiledTexture(outerRect, WeaponXIToolsEditor.backdropTexture);

        // Draw the sprite
        GUI.color = color;

        if (mat == null)
        {
            GUI.DrawTextureWithTexCoords(outerRect, tex, uv, true);
        }
        else
        {
            // NOTE: There is an issue in Unity that prevents it from clipping the drawn preview
            // using BeginGroup/EndGroup, and there is no way to specify a UV rect... le'suq.
            UnityEditor.EditorGUI.DrawPreviewTexture(outerRect, tex, mat);
        }
        GUI.color = Color.white;

        // Draw the lines around the sprite
        Handles.color = Color.black;
        Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMin), new Vector3(outerRect.xMin, outerRect.yMax));
        Handles.DrawLine(new Vector3(outerRect.xMax, outerRect.yMin), new Vector3(outerRect.xMax, outerRect.yMax));
        Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMin), new Vector3(outerRect.xMax, outerRect.yMin));
        Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMax), new Vector3(outerRect.xMax, outerRect.yMax));

        // Sprite size label
        string text = string.Format("Texture Size: {0}x{1}", w, h);

        EditorGUI.DropShadowLabel(GUILayoutUtility.GetRect(Screen.width, 18f), text);
    }