Unity根据图片路径获得精灵Sprite

     /// <summary>
    /// 创建精灵
    /// </summary>
    /// <param name="url">路径</param>
    /// <returns></returns>
    public static Sprite CreateSprite (string url) {
        Texture2D texture = AssetSystem.Load (url) as Texture2D;
        if (texture == null) return null;
        Sprite sp = Sprite.Create (
            texture,
            new Rect (0, 0, texture.width, texture.height),
            new Vector2 (0.5f, 0.5f));
 
        return sp;
    }

使用方式:

sp.sprite = 类名.CreateSprite ("图片路径");
—— 完 ——
相关推荐
评论

立 为 非 似

中 谁 昨 此

宵 风 夜 星

。 露 , 辰

文章点击榜

细 无 轻 自

如 边 似 在

愁 丝 梦 飞

。 雨 , 花