Last active
March 18, 2022 05:42
Revisions
-
Thaina revised this gist
Mar 18, 2022 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // origin : Transparent Unity App! : Code Monkey : https://www.youtube.com/watch?v=RqgsGaMPZTw using UnityEngine; using UnityEditor.Build; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // origin : Transparent Unity App! : Code Monkey : https://www.youtube.com/watch?v=RqgsGaMPZTw using System; using System.Runtime.InteropServices; -
Thaina revised this gist
Mar 18, 2022 . 2 changed files with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // origin : https://www.youtube.com/watch?v=RqgsGaMPZTw using UnityEngine; using UnityEditor.Build; using UnityEditor.Build.Reporting; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // origin : https://www.youtube.com/watch?v=RqgsGaMPZTw using System; using System.Runtime.InteropServices; -
Thaina created this gist
Mar 18, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ using UnityEngine; using UnityEditor.Build; using UnityEditor.Build.Reporting; public class TransparentWindowSetting : IPreprocessBuildWithReport { public int callbackOrder => 0; public void OnPreprocessBuild(BuildReport report) { #if UNITY_STANDALONE_WIN UnityEditor.PlayerSettings.fullScreenMode = FullScreenMode.FullScreenWindow; UnityEditor.PlayerSettings.useFlipModelSwapchain = false; UnityEditor.PlayerSettings.runInBackground = true; #endif } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ using System; using System.Runtime.InteropServices; using UnityEngine; public static class TransparentWindow { #if UNITY_STANDALONE_WIN private struct MARGINS { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; } [DllImport("user32.dll")] private static extern IntPtr GetActiveWindow(); [DllImport("user32.dll")] private static extern int SetWindowLong(IntPtr hWnd,int nIndex,uint dwNewLong); [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")] private static extern int GetSystemMetrics(int nIndex); [DllImport("user32.dll",EntryPoint = "SetLayeredWindowAttributes")] static extern int SetLayeredWindowAttributes(IntPtr hwnd,int crKey,byte bAlpha,int dwFlags); [DllImport("user32.dll",EntryPoint = "SetWindowPos")] private static extern int SetWindowPos(IntPtr hwnd,int hwndInsertAfter,int x,int y,int cx,int cy,int uFlags); [DllImport("Dwmapi.dll")] private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd,ref MARGINS margins); const int GWL_STYLE = -16; const int GWL_EXSTYLE = -20; const uint WS_POPUP = 0x80000000; const uint WS_VISIBLE = 0x10000000; const uint WS_EX_LAYERED = 0x00080000; const int HWND_TOPMOST = -1; [RuntimeInitializeOnLoadMethod] public static void Init() { Camera.main.clearFlags = CameraClearFlags.SolidColor; Camera.main.backgroundColor = new Color(0,0,0,0); #if !UNITY_EDITOR // You really don't want to enable this in the editor.. SetWindowTransparent(); #endif } static void SetWindowTransparent() { int fWidth = Screen.width; int fHeight = Screen.height; var hwnd = GetActiveWindow(); // Transparent windows with click through var margins = new MARGINS() { cxLeftWidth = -1 }; DwmExtendFrameIntoClientArea(hwnd, ref margins); SetWindowLong(hwnd,GWL_EXSTYLE,WS_EX_LAYERED); SetLayeredWindowAttributes(hwnd, 0, 0, 1); SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,0); } #endif }