-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoadSprite.cs
More file actions
36 lines (28 loc) · 895 Bytes
/
LoadSprite.cs
File metadata and controls
36 lines (28 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.IO;
using UnityEngine;
namespace LoadSprite
{
internal static class LoadSprite
{
internal static Sprite LoadSpriteFromDisk(this string path)
{
if (string.IsNullOrEmpty(path))
{
return null;
}
byte[] data = File.ReadAllBytes(path);
if (data == null || data.Length <= 0)
{
return null;
}
Texture2D tex = new Texture2D(512, 512);
if (!Il2CppImageConversionManager.LoadImage(tex, data))
{
return null;
}
Sprite sprite = Sprite.CreateSprite(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f, 0, 0, new Vector4(), false);
sprite.hideFlags |= HideFlags.DontUnloadUnusedAsset;
return sprite;
}
}
}