t1 / TFDContents / Assets / VLC for Unity / Misc / BackgroundKey.cs @ 11
이력 | 보기 | 이력해설 | 다운로드 (1.87 KB)
1 |
using System; |
---|---|
2 |
using System.Runtime.InteropServices; |
3 |
using UnityEngine; |
4 |
|
5 |
public class BackgroundKey : MonoBehaviour |
6 |
{ |
7 |
|
8 |
#region dll |
9 |
[DllImport("Dwmapi.dll")]static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins margins); |
10 |
[DllImport("user32.dll")]static extern int SetWindowLong(IntPtr hWnd, int nIndex, long dwNewLong); |
11 |
[DllImport("user32.dll")]public static extern long GetWindowLong(IntPtr hWnd, int nIndex); |
12 |
|
13 |
private struct Margins{ |
14 |
public int Left; |
15 |
public int Right; |
16 |
public int Top; |
17 |
public int Bottom; |
18 |
} |
19 |
#endregion dll |
20 |
|
21 |
#region Private |
22 |
|
23 |
private long style; |
24 |
private IntPtr thisHwnd; |
25 |
private bool active = true; |
26 |
[SerializeField]private Material _keyMaterial; |
27 |
|
28 |
#endregion Private |
29 |
|
30 |
void Start() { |
31 |
transform.SetAsFirstSibling(); |
32 |
|
33 |
} |
34 |
|
35 |
public void ActivateTransparency(IntPtr hWnd) { |
36 |
|
37 |
thisHwnd = hWnd; |
38 |
|
39 |
active = true; |
40 |
Color32 c =GetComponent<Camera>().backgroundColor; |
41 |
GetComponent<Camera>().backgroundColor=new Color32(c.r,c.g,c.b,5); |
42 |
#if !UNITY_EDITOR |
43 |
style = GetWindowLong(thisHwnd, -16); |
44 |
|
45 |
var m = new Margins() { Left = -1 }; |
46 |
SetWindowLong(hWnd, -16, 0x80000000 | 0x10000000); |
47 |
DwmExtendFrameIntoClientArea(hWnd, ref m); |
48 |
#endif |
49 |
} |
50 |
|
51 |
public void DisableTransparency() { |
52 |
active = false; |
53 |
Color32 c = GetComponent<Camera>().backgroundColor; |
54 |
GetComponent<Camera>().backgroundColor = new Color32(c.r, c.g, c.b, 255); |
55 |
#if !UNITY_EDITOR |
56 |
SetWindowLong(thisHwnd, -16, style); |
57 |
|
58 |
#endif |
59 |
|
60 |
} |
61 |
|
62 |
void OnRenderImage(RenderTexture a, RenderTexture n) |
63 |
{ |
64 |
if (active) { |
65 |
Graphics.Blit(a, n, _keyMaterial); |
66 |
} |
67 |
else { |
68 |
Graphics.Blit(a, n); |
69 |
} |
70 |
|
71 |
|
72 |
|
73 |
} |
74 |
} |