Original address: https://alastaira.wordpress.com/2015/06/15/creating-windowless-unity-applications/
Bull Address: http://www.manew.com/thread-43230-1-1.html
This effect is only for Windows platforms. This effect is implemented in conjunction with the camera's Onrenderimage event and some Windows underlying API calls.
First, a transparent shader is needed, and I use the system directly.
Then create a C # script Transparentwindow
1 usingUnityengine;2 usingSystem.Collections;3 usingSystem.Runtime.InteropServices;4 usingSystem;5 6 Public classTransparentwindow:monobehaviour7 {8 [Serializefield]9 PrivateMaterial m_material;Ten Private structMARGINS One { A Public intCxleftwidth; - Public intCxrightwidth; - Public intCytopheight; the Public intCybottomheight; - } - //Define function signatures to import from Windows APIs -[DllImport ("user32.dll")] + Private Static externIntPtr GetActiveWindow (); -[DllImport ("user32.dll")] + Private Static extern intSetWindowLong (IntPtr hWnd,intNIndex,UINTDwnewlong); A[DllImport ("Dwmapi.dll")] at Private Static extern UINTDwmExtendFrameIntoClientArea (IntPtr hWnd,refMARGINS MARGINS); - //Definitions of window styles - Const intGwl_style =- -; - Const UINTWs_popup =0x80000000; - Const UINTWs_visible =0x10000000; - voidStart () in { - #if! Unity_editor to varmargins =NewMARGINS () {cxleftwidth =-1 }; + //Get A handle to the window - varhwnd =GetActiveWindow (); the //Set Properties of the window * //See :https://msdn.microsoft.com/en-us/library/windows/desktop/ms633591%28v=vs.85%29.aspx $SetWindowLong (hwnd, Gwl_style, Ws_popup |ws_visible);Panax Notoginseng //Extend the window into the client area - //See :https://msdn.microsoft.com/en-us/library/windows/desktop/aa969512%28v=vs.85%29.aspx theDwmExtendFrameIntoClientArea (hwnd,refmargins); + #endif A } the //Pass the output of the camera to the custom material + //For chroma Replacement - voidOnrenderimage (rendertexture from, rendertexture to) $ { $Graphics.blit ( from, to, m_material); - } - the}
The code above uses the InteropServices namespace to invoke some of the windows underlying APIs to change the window properties of the Unity app at run time. Then use the Onrenderimage event to apply the camera's output to the rendertexture. Assign the material using shader to the M_material field in the script so that we can start keying the graph.
Then, the point is: Change the camera's background color to the same as the _transparentcolourkey property in the transparent material.
You can set the color casually, but both sides must be the same.
The end result is build and run. Because of the use of rendertexture, if the use of unity4.x must be pro version, and 5.x any version can be.
Effect:
Creation of Unity Transparent forms