GL.IssuePluginEvent 發布插件事件


Description 描述

Send a user-defined event to a native code plugin.

發送一個用戶定義的事件到一個本地代碼插件。

Rendering in Unity can be multithreaded if the platform and number of available CPUs will allow for it. When multithreaded rendering is used, the rendering APIcommands happen on a thread which is completely separate from the one that runs the scripts. Consequently, it is not possible for your plugin to start rendering immediately, since it might interfere with what the render thread is doing at the time.

如果該平台可用的GPU允許Unity可以多線程渲染。當使用多線程時,渲染API命令一個線程從其中一個運行的腳本上完全獨立。所以,你的插件可能不會立即渲染,因此它可能會影響什么渲染線程正在做的時間。 In order to do any rendering from the plugin, you should call GL.IssuePluginEvent from your script, which will cause your native plugin to be called from the render thread. For example, if you call GL.IssuePluginEvent from the camera's OnPostRender function, you'll get a plugin callback immediately after the camera has finished rendering.

為了從插件做任何渲染,應該從腳本調用GL.IssuePluginEvent,這將使您的本地插件可以被渲染線程調用。如果你從相機的OnPostRender函數調用GL.IssuePluginEvent,你將會在相機渲染完成后立即得到一個插件回調。

 

C#

protected IEnumerator CallPluginAtEndOfFrames()
{
    while (true)
    {
        // Wait until all frame rendering is done
        yield return new WaitForEndOfFrame();
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR
        GL.IssuePluginEvent(1);
#elif UNITY_IPHONE || UNITY_ANDROID
        UnityRenderEvent(1);
#endif
    }
}

 

Example 例子

An example of a low-level rendering plugin can be downloaded here. This simply draws a rotating triangle from C++ code after all regular rendering is done. The project works with Windows (Visual Studio 2008) and Mac OS X (Xcode 3.2) and uses Direct3D 9 on Windows and OpenGL on both platforms.The Direct3D 9 project also demonstrates how to handle "lost" devices.

這里下載一個底層渲染的插件的例子。這只是一個在所有規則的渲染完成之后利用C++代碼畫出一個旋轉的三角形的簡單例子。該項目可以工作與Windows(Visual Sutdio 2008)和Mac OS X(Xcode 3.2),在Windows中使用了Direct3D 9,同時兩個平台使用了OpenGL。使用Direct3D 9的項目同時還演示了如果處理設備丟失。

 

摘抄自

  底層本地插件接口 Low-level Native Plugin Interface

  GL.IssuePluginEvent 發布插件事件


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM