|
楼主 |
发表于 2012-6-15 13:18
|
显示全部楼层
版本5. DrawTexture渐入渐出- using UnityEngine;
- using System.Collections;
- public class New: MonoBehaviour {
- private Texture2D txr;
- private Rect rct;
- void Start () {
- txr = new Texture2D(10,10);
- rct = new Rect(0, 0, Screen.width, Screen.height);
- Color[] clr = new Color[100];
- for (int i = 0; i < clr.Length; i++)
- {
- clr[i] = new Color(0, 0, 0, 1);
- }
- txr.SetPixels(clr);
- txr.Apply();
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- void OnGUI()
- {
- GUI.DrawTexture(rct, txr);
- if (GUI.Button(new Rect(10, 10, 100, 50), "show"))
- {
- StartCoroutine(showScene());
- }
- if (GUI.Button(new Rect(10, 70, 100, 50), "hide"))
- {
- StartCoroutine(hideScene());
- }
- }
- IEnumerator showScene()
- {
- Color[] clr = txr.GetPixels();
- while (txr.GetPixel(0, 0).a > 0)
- {
- for (int i = 0; i < clr.Length; i++)
- {
- clr[i].a -= Time.deltaTime;
- }
- txr.SetPixels(clr);
- txr.Apply();
- yield return new WaitForEndOfFrame();
- }
- }
- IEnumerator hideScene()
- {
- Color[] clr = txr.GetPixels();
- while (txr.GetPixel(0, 0).a < 1)
- {
- for (int i = 0; i < clr.Length; i++)
- {
- clr[i].a += Time.deltaTime;
- }
- txr.SetPixels(clr);
- txr.Apply();
- yield return new WaitForEndOfFrame();
- }
- }
- }
复制代码 |
|