IEnumerator OnRender() { int instanceId = this.gameObject.GetInstanceID(); for (;;) { yield return(new WaitForEndOfFrame()); GL.IssuePluginEvent(PluginUtil.GetRenderEventFunc(), instanceId); } }
internal bool SetTexture(GameObject go, int index, bool isBlocking, bool isAlreadySet) { var sID = go.GetInstanceID(); StReadResult tResult = new StReadResult(); string filename = LoadRequest(index, isBlocking, out tResult); if (!isAlreadySet && tResult.readStatus == 2) { Texture2D tex = null; #if UNITY_STANDALONE_OSX var textureFormat = TextureFormat.RGBA32; #elif UNITY_STANDALONE_WIN var textureFormat = TextureFormat.BGRA32; #endif tex = new Texture2D(tResult.width, tResult.height, textureFormat, false, false); tex.LoadRawTextureData(tResult.buffer, tResult.width * tResult.height * 4); tex.filterMode = FilterMode.Bilinear; tex.Apply(); var renderer = go.GetComponent <Renderer>(); Image image = null; SpriteRenderer spriteRenderer = null; IntPtr ptr = IntPtr.Zero; if ((spriteRenderer = go.GetComponent <SpriteRenderer>()) != null) { spriteRenderer.sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f, 2, SpriteMeshType.FullRect); ptr = spriteRenderer.sprite.texture.GetNativeTexturePtr(); Assert.IsTrue(ptr != IntPtr.Zero); } else if (renderer != null) { var mat = go.GetComponent <Renderer>().sharedMaterial; mat.mainTexture = tex; // ptr = mat.mainTexture.GetNativeTexturePtr(); Assert.IsTrue(ptr != IntPtr.Zero); } else if ((image = go.GetComponent <Image>()) != null) { image.sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f, 1, SpriteMeshType.FullRect); ptr = image.mainTexture.GetNativeTexturePtr(); Assert.IsTrue(ptr != IntPtr.Zero); var material = image.material; #if UNITY_STANDALONE_WIN #if UNITY_2017_2_OR_NEWER #else if (material != null) { var id = Shader.PropertyToID("_GammaCorrection"); if (id > 0) { material.SetInt(id, 1); } } #endif #endif } PluginUtil.SetNativeTexturePtr(ptr, (uint)tResult.width, (uint)tResult.height, sID); isAlreadySet = true; } bool textureIsSet = false; if (tResult.readStatus == 2 && m_sLastIndex != index) { PluginUtil.SetLoadedTexture(filename, sID); textureIsSet = true; } if (textureIsSet && !UpdateManager.useCoroutine) { GL.IssuePluginEvent(PluginUtil.GetRenderEventFunc(), sID); } m_sLastIndex = index; return(isAlreadySet); }