Files

22 lines
636 B
C#
Raw Permalink Normal View History

2024-01-27 08:49:55 +08:00
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class LoadImageFromStreamingAssets : MonoBehaviour
{
public Image LoadToObject;
public string ImagePathFromStreamingAssets;
void Start()
{
Texture2D texture = new(2,2);
texture.LoadImage(File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, ImagePathFromStreamingAssets)));
Debug.Log("Loaded texture " + texture.name);
if (LoadToObject)
{
LoadToObject.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
}
}
}