Last active
December 20, 2015 15:49
-
-
Save tsubaki/6156645 to your computer and use it in GitHub Desktop.
テクスチャを保持したまま(変換せず)使うサンプル。エディタ上から確認も出来る。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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