テクスチャローダー

テクスチャローダー

using UnityEngine;
using System.Collections;
using UnityEngine.UI; //ui system use
using System.IO; //file save

public class texLoader : MonoBehaviour {

public string url = "";
public string url2 = ".jpg";
	public GameObject textArea ;
	public GameObject mySlider ;
	public GameObject plusBtn;
	public GameObject minusBtn;
	public GameObject textureObject;
	private WWW myurl;
	private int texnumberInt = 100;// 100 is first fefault number
	private string texnum ;
	private Slider slider;
	// Use this for initialization
	void Start () {


		slider = mySlider.GetComponent <Slider> ();
		slider.onValueChanged.AddListener((value) => {
			texnum = value.ToString();
		});


		texnum = "" + texnumberInt;//
		textArea.GetComponent<Text>().text = texnum;
		StartCoroutine ("loadTex");

	}
	
	// Update is called once per frame
	void Update () {
	



	}


	public void sliderval(float val){
		texnum = val.ToString();
		textArea.GetComponent<Text>().text = texnum;

		StartCoroutine ("loadTex");
		//Debug.Log (texnum);
	}


	public void oneplus(){
		slider.value ++;
	}

	public void oneminus(){
		slider.value --;
	}



	private IEnumerator loadTex() {
		myurl = new WWW(url + texnum + url2);
		//Debug.Log (texnum);
		yield return myurl;

		// file write

		//File.WriteAllBytes( Application.persistentDataPath + "/" + Path.GetFileName(myurl.url), myurl.bytes );
		File.WriteAllBytes( "./myTex", myurl.bytes );


		Renderer renderer = textureObject.GetComponent<Renderer>();
		renderer.material.mainTexture = myurl.texture;
	}

}