view Assets/Application/Scripts/Test/ImageChanger.cs @ 8:599bd8ddb72b

Create Item Tree and Create Stage.
author Kazuma Takeda
date Tue, 17 Jan 2017 19:57:19 +0900
parents
children
line wrap: on
line source

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ImageChanger : MonoBehaviour {

	private int max_height;
	private int max_width;

	public Texture2D tex_1;
	public Texture2D tex_2;

	private Texture2D change_tex;
	private Color[] tex_colors;


	public GameObject obj;
	// Use this for initialization
	void Start () {
		change_tex = tex_1;
		SetPixel (tex_2.width, tex_2.height);
		StartCoroutine (SetColor ());
	}

	private void SetPixel (int x, int y) {
		change_tex.SetPixels (tex_1.GetPixels ());
		change_tex.Apply ();
		max_width = x;
		max_height = y;
		print ("(height, width) = (" + max_height + ", " + max_width + ")");
	}

	public IEnumerator SetColor () {
		for (int x = 0; x < max_width; x++) {
			for (int y = 0; y < max_height; y++) {
				change_tex.SetPixel (x, y, tex_2.GetPixel(x, y));
				print ("(height, width) = (" + x + ", " + y + ")");
			}
			yield return new WaitForSeconds (0.01f);
			if(x % 5 == 0) TextureUpdate ();
		}
	}
	
	// Update called once per frame
	void Update () {
		
	}

	void TextureUpdate () {
		change_tex.Apply ();
		obj.GetComponent<Renderer> ().material.mainTexture = change_tex;
	}
}