标签:unity c++匿名函数 c#匿名函数 委托 回调函数
using UnityEngine;
using System.Collections;
public class AClass{
public delegate void onComplete(Sprite sprite);
public IEnumerator GetTexture(onComplete callback)
{
//save
Texture2D t=new Texture2D(Screen.width,(int)(Screen.width*aspect));
t.ReadPixels(new Rect(0,0,Screen.width,(int)(Screen.width*aspect)),0,0,false);
t.Apply();
byte[] byt = t.EncodeToPNG();
m_photoName = Time.time+".png";
m_photoPath = Globe.persistentDataUrl+m_photoName;
Debug.Log("System.IO++++++++Start WritePng");
System.IO.File.WriteAllBytes(m_photoPath.Replace("file://",""),byt);
Debug.Log("m_photoPath="+m_photoPath);
//load image
WWW www = new WWW(m_photoPath);
yield return www;
//回调
callback(sprite);
}
}using UnityEngine;
using System.Collections;
public class BClass{
public void ExecuteCallBack(){
StartCoroutine(m_webCamera.GetTexture(delegate(Sprite sp)
{
watermark.gameObject.SetActive(false);
photoImg.sprite=sp;
}));
}
}using UnityEngine;
using System.Collections;
public class BClass{
public void ExecuteCallBack(){
//StartCoroutine();
m_webCamera.GetTexture(delegate(Sprite sp)
{
watermark.gameObject.SetActive(false);
photoImg.sprite=sp;
});
}
} public void ExecuteCallBack(){
//StartCoroutine();
m_webCamera.GetTexture(delegate(Sprite sp);
m_webCamera.GetTexture(delegate(Sprite sp)
{
watermark.gameObject.SetActive(false);
photoImg.sprite=sp;
});
}using UnityEngine;
using System.Collections;
public class AClass{
public delegate void onComplete(Sprite sprite);
public void GetTexture(onComplete callback){
StartCoroutine(ScreenCapture(callback));
}
public IEnumerator ScreenCapture(onComplete callback)
{
//save
Texture2D t=new Texture2D(Screen.width,(int)(Screen.width*aspect));
t.ReadPixels(new Rect(0,0,Screen.width,(int)(Screen.width*aspect)),0,0,false);
t.Apply();
byte[] byt = t.EncodeToPNG();
m_photoName = Time.time+".png";
m_photoPath = Globe.persistentDataUrl+m_photoName;
Debug.Log("System.IO++++++++Start WritePng");
System.IO.File.WriteAllBytes(m_photoPath.Replace("file://",""),byt);
Debug.Log("m_photoPath="+m_photoPath);
//load image
WWW www = new WWW(m_photoPath);
yield return www;
//回调
callback(sprite);
}
}版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:unity c++匿名函数 c#匿名函数 委托 回调函数
原文地址:http://blog.csdn.net/yupu56/article/details/47080759