Skip to content

Instantly share code, notes, and snippets.

@dskjal
Last active September 22, 2016 21:05
Show Gist options
  • Save dskjal/ef2a115c0791ca8d58a4f29bf201df96 to your computer and use it in GitHub Desktop.
Save dskjal/ef2a115c0791ca8d58a4f29bf201df96 to your computer and use it in GitHub Desktop.
Unity で Mod をサポートする(外部リソースをロードする)
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2016 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
public class DynamicTextureLoad : MonoBehaviour {
private Image img;
void Start () {
img = GetComponent<Image>();
StartCoroutine(LoadTexture());
}
IEnumerator LoadTexture() {
// C ドライブのみ利用可能
var www = new WWW("file://C:/mods/external_tex.jpg");
yield return www;
if (img && string.IsNullOrEmpty(www.error)) {
var tex = www.texture;
img.sprite = Sprite.Create(tex, new Rect(0f,0f, tex.width, tex.height), new Vector2());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment