Mercurial > hg > Members > kazuma > JungleforUnity
comparison 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 |
comparison
equal
deleted
inserted
replaced
7:ad4729c5eec4 | 8:599bd8ddb72b |
---|---|
1 using System.Collections; | |
2 using System.Collections.Generic; | |
3 using UnityEngine; | |
4 | |
5 public class ImageChanger : MonoBehaviour { | |
6 | |
7 private int max_height; | |
8 private int max_width; | |
9 | |
10 public Texture2D tex_1; | |
11 public Texture2D tex_2; | |
12 | |
13 private Texture2D change_tex; | |
14 private Color[] tex_colors; | |
15 | |
16 | |
17 public GameObject obj; | |
18 // Use this for initialization | |
19 void Start () { | |
20 change_tex = tex_1; | |
21 SetPixel (tex_2.width, tex_2.height); | |
22 StartCoroutine (SetColor ()); | |
23 } | |
24 | |
25 private void SetPixel (int x, int y) { | |
26 change_tex.SetPixels (tex_1.GetPixels ()); | |
27 change_tex.Apply (); | |
28 max_width = x; | |
29 max_height = y; | |
30 print ("(height, width) = (" + max_height + ", " + max_width + ")"); | |
31 } | |
32 | |
33 public IEnumerator SetColor () { | |
34 for (int x = 0; x < max_width; x++) { | |
35 for (int y = 0; y < max_height; y++) { | |
36 change_tex.SetPixel (x, y, tex_2.GetPixel(x, y)); | |
37 print ("(height, width) = (" + x + ", " + y + ")"); | |
38 } | |
39 yield return new WaitForSeconds (0.01f); | |
40 if(x % 5 == 0) TextureUpdate (); | |
41 } | |
42 } | |
43 | |
44 // Update called once per frame | |
45 void Update () { | |
46 | |
47 } | |
48 | |
49 void TextureUpdate () { | |
50 change_tex.Apply (); | |
51 obj.GetComponent<Renderer> ().material.mainTexture = change_tex; | |
52 } | |
53 } |