I can make the entire window transparent, but not a specific color.
In the scene, I created a ball in front of camera and set camera’s background color to black.
By the way, how do I convert RGB color to int?
using System.Collections;
using System.Runtime.InteropServices;
public class WindowMod : MonoBehaviour
{
public Rect screenPosition;
[DllImport("user32.dll")]
static extern int GetWindowLong (IntPtr hwnd, int _nIndex);
[DllImport("user32.dll")]
static extern IntPtr SetWindowLong (IntPtr hwnd, int _nIndex ,int dwNewLong);
[DllImport("user32.dll")]
static extern bool SetWindowPos (IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow ();
[DllImport("user32.dll")]
static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, int dwFlags);
const int SWP_SHOWWINDOW = 0x0040;
const int GWL_EXSTYLE = -20;
const int GWL_STYLE = -16;
const int WS_CAPTION = 0x00C00000;
const int WS_BORDER = 0x00800000;
const int WS_EX_LAYERED = 0x80000;
public const int LWA_ALPHA = 0x2;
public const int LWA_COLORKEY = 0x1;
private IntPtr handle;
void Start ()
{
handle = GetForegroundWindow ();
SetWindowLong(handle, GWL_EXSTYLE, WS_EX_LAYERED);
SetWindowLong(handle, GWL_STYLE, GetWindowLong(handle, GWL_STYLE) ~WS_BORDER ~WS_CAPTION);
SetWindowPos (handle, -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);
//this does not work
SetLayeredWindowAttributes(handle, 0, 100, LWA_COLORKEY);
//this works
SetLayeredWindowAttributes(handle, 0, 100, LWA_ALPHA);
}
void Update () {
}
}