LoginSignup
0

More than 5 years have passed since last update.

Unity : AssetDatabase.LoadMainAssetAtPathでSpriteを取得する

Last updated at Posted at 2018-08-19

AssetDatabase.LoadMainAssetAtPath("Assets/textures/hoge.png");
で取得できるのはどうやらTextureで、直接Spriteとしては使用できないみたい。
(Resources.Loadでは直接Spriteとして使えるのに...)
なので、Spriteに変換する処理を入れる。

Texture2D texture = (Texture2D)AssetDatabase.LoadMainAssetAtPath("Assets/textures/hoge.png");
Sprite sprite = Sprite.Create(texture, new Rect(0,0,texture.width,texture.height), Vector2.zero);

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0