Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active December 20, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/6156645 to your computer and use it in GitHub Desktop.
Save tsubaki/6156645 to your computer and use it in GitHub Desktop.
テクスチャを保持したまま(変換せず)使うサンプル。エディタ上から確認も出来る。
using UnityEngine;
using System.Collections;
using System.IO;
[ExecuteInEditMode]
public class ImageLoader : MonoBehaviour
{
// テクスチャ(png/jpeg)の拡張子をbytesとしたもの
public TextAsset image;
void Start ()
{
if (image == null) {
return;
}
LoadImage();
}
void LoadImage ()
{
Texture2D tex2d = new Texture2D (1, 1);
tex2d.LoadImage (image.bytes);
tex2d.filterMode = FilterMode.Point;
renderer.sharedMaterial.mainTexture = tex2d;
#if UNITY_EDITOR
preAssetName = image.name;
#else
image = null;
#endif
}
#if UNITY_EDITOR
private string preAssetName = string.Empty;
void Update () {
if( preAssetName != image.name )
{
LoadImage();
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment