// Update is called once per frame void Update() { // process engine messages (TODO: put in some other place) agora_gaming_rtc.IRtcEngine engine = agora_gaming_rtc.IRtcEngine.QueryEngine(); if (engine == null) { return; } while (engine.GetMessageCount() > 0) { engine.Poll(); } // render video Renderer rend = GetComponent <Renderer> (); Debug.Log(" VideoSurface render = " + rend); #if UNITY_IOS || UNITY_ANDROID uint uid = mUid; if (mEnable) { // create texture if not existent if (rend.material.mainTexture == null) { //Debug.Log("rend.material.mainTexture"); System.IntPtr texPtr = (System.IntPtr)engine.GenerateNativeTexture(); Texture2D nativeTexture = Texture2D.CreateExternalTexture(640, 360, TextureFormat.ARGB32, false, false, texPtr); // FIXME! texture size is subject to change rend.material.mainTexture = nativeTexture; } // update texture if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D) { //Debug.Log("rend.material.mainTexture is Texture2D"); //Debug.Log("rend.material.mainTexture is Texture2D ThreadID : -->"+System.Threading.Thread.CurrentThread.ManagedThreadId); Texture2D tex = rend.material.mainTexture as Texture2D; int texId = (int)tex.GetNativeTexturePtr(); // update texture (possible size changing) uint texWidth = 0; uint texHeight = 0; if (engine.UpdateTexture(texId, uid, ref texWidth, ref texHeight) == 0) { // TODO: process texture then render } } } else { if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D) { Texture2D tex = rend.material.mainTexture as Texture2D; int texId = (int)tex.GetNativeTexturePtr(); engine.DeleteTexture(texId); rend.material.mainTexture = null; } } #endif // add your extra effects if (mAdjustTransfrom != null) { Transform trans = rend.transform; mAdjustTransfrom(mUid, gameObject.name, ref trans); } }
// Update is called once per frame void Update() { // process engine messages (TODO: put in some other place) agora_gaming_rtc.IRtcEngine engine = agora_gaming_rtc.IRtcEngine.QueryEngine(); if (engine == null) { return; } while (engine.GetMessageCount() > 0) { engine.Poll(); } // render video Image image = GetComponent <Image>(); #if UNITY_IOS || UNITY_ANDROID uint uid = mUid; if (mEnable) { // create texture if not existent if (testTexture == null) { System.IntPtr texPtr = (System.IntPtr)engine.GenerateNativeTexture(); Texture2D nativeTexture = Texture2D.CreateExternalTexture(640, 360, TextureFormat.ARGB32, false, false, texPtr); // FIXME! texture size is subject to change testTexture = nativeTexture; Sprite m_sprite = Sprite.Create(testTexture, new Rect(0, 0, testTexture.width, testTexture.height), new Vector2(0, 0)); image.sprite = m_sprite; } // update texture if (image.sprite != null && testTexture is Texture2D) { Texture2D tex = testTexture; int texId = (int)tex.GetNativeTexturePtr(); // update texture (possible size changing) uint texWidth = 0; uint texHeight = 0; if (engine.UpdateTexture(texId, uid, ref texWidth, ref texHeight) == 0) { // TODO: process texture then render } } } else { if (image.sprite != null && testTexture is Texture2D) { Texture2D tex = testTexture as Texture2D; int texId = (int)tex.GetNativeTexturePtr(); engine.DeleteTexture(texId); testTexture = null; } } #endif // add your extra effects //if (mAdjustTransfrom != null) //{ // Transform trans = image.transform; // mAdjustTransfrom(mUid, gameObject.name, ref trans); //} }