-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransparentWindow.cs
More file actions
65 lines (49 loc) · 1.84 KB
/
Copy pathTransparentWindow.cs
File metadata and controls
65 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public class TransparentWindow : MonoBehaviour
{
[DllImport("user32.dll")]
public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type);
[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
private struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
[DllImport("Dwmapi.dll")]
private static extern uint DwmExtendFrameIntoClientArea(IntPtr hHwnd, ref MARGINS margins);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
const int GWL_EXSTYLE = -20;
const uint WS_EX_LAYERED = 0x00080000;
const uint WS_EX_TRANSPARENT = 0x00000020;
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
IntPtr hWnd;
// Start is called before the first frame update
void Start()
{
#if !UNITY_EDITOR
//Uncomment this if you need it, for my case i don't need it.
//MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog",0);
hWnd = GetActiveWindow();
MARGINS margins = new MARGINS { cxLeftWidth = -1};
DwmExtendFrameIntoClientArea(hWnd, ref margins);
SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT);
SetWindowPos(hWnd, HWND_TOPMOST, 0,0,0,0,0);
#endif
Application.runInBackground = true;
}
// Update is called once per frame
void Update()
{
// SetClickThrough(Physics2D.OverlapPoint())
}
}