螢幕快照 2015-01-28 下午9.55.54  

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

    public Texture2D t;
        
    public Color drawColor = new Color32(240190170255);
    public Color defaultColor = new Color32(0000);

    Color minValveColor = new Color32(245237210255);
    Color maxValveColor = new Color32(255248230255);

    float minR = 0;
    float minG = 0;
    float minB = 0;

    float maxR = 0;
    float maxG = 0;
    float maxB = 0;

    Texture2D tt;
    
    void Start () {
        minR = minValveColor.r ;

        minG = minValveColor.g ;
        minB = minValveColor.b ;
        
        maxR = maxValveColor.r ;
        maxG = maxValveColor.g ;
        maxB = maxValveColor.b ;

        transform.localScale = new Vector3 ((float)t.width/(float)t.height1);
        InvokeRepeating ("MyUpdate"01);
    }

    string z = "";

    void MyUpdate () {
        if(tt != null){
            Destroy(tt);
        }
        tt = new Texture2D (t.widtht.height);
        for(int y = 0y < t.heighty++){
            for(int x = 0x < t.widthx++){
                Color c = t.GetPixel(xy);
                float r = c.r ;
                float g = c.g ;
                float b = c.b ;

                if(r >= minR && r <= maxR && g >= minG && g <= maxG && b >= minB && b <= maxB){
                    tt.SetPixel(xydrawColor);
                }else{
                    tt.SetPixel(xydefaultColor);
                }
            }
        }
        tt.Apply ();
        renderer.material.mainTexture = tt;
    }

}


arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(0) 人氣()