Ejemplo n.º 1
0
    /// <summary>
    /// 是否还须扩展,满足2的n次方不需要
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static bool GetWrapEnable(string path)
    {
        Texture2D texture = AssetDatabase.LoadAssetAtPath <Texture2D>(path);

        if (texture != null)
        {
            Vec2Int wrapSize = GetWrapSize(texture.width, texture.height);
            return(wrapSize.Equals(new Vec2Int(texture.width, texture.height)));
        }
        return(true);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 扩充png
    /// </summary>
    /// <param name="texture"></param>
    /// <param name="anchor"></param>
    /// <returns></returns>
    public static Texture2D Expand(Texture2D texture, TextAnchor anchor = TextAnchor.MiddleCenter)
    {
        Vec2Int wrapSize = GetWrapSize(texture.width, texture.height);

        if (wrapSize.Equals(new Vec2Int(texture.width, texture.height)))
        {
            return(null);
        }

        bool      alphaEnable = GetAlphaEnable(texture);
        Texture2D newTex      = new Texture2D(wrapSize.x, wrapSize.y, TextureFormat.ARGB32, false);

        ResetTex(newTex, alphaEnable);

        Vec2Int start = GetStartPos(wrapSize, texture.width, texture.height, anchor);

        Color[] colors = texture.GetPixels();
        newTex.SetPixels(start.x, start.y, texture.width, texture.height, colors);
        return(newTex);
    }