Unity W7, Script c#, Siempre Encima, Transparencia, Sin Click, Sin icono en taskbar.

Les dejo aqui el script.
Busque en muchas fuentes por Internet, pero ninguna reunía todas las características. Ojala sea útil para alguien.

using System;
using System.Runtime.InteropServices;
using UnityEngine;

public class TransparentWindow : MonoBehaviour
{
[SerializeField]
private Material m_Material;

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, long dwNewLong);

[DllImport(“user32.dll”,SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport(“user32.dll”, EntryPoint=”FindWindow”, SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

[DllImport(“user32.dll”)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport(“Dwmapi.dll”)]
private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margins);

[DllImport(“user32.dll”)]
static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

[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(“user32.dll”)]
private static extern bool ShowWindow(IntPtr hWnd, uint uFlags);

const int GWL_HWNDPARENT = -8;
const int GWL_STYLE = -16;
const int GWL_EXSTYLE = -20;
const uint WS_POPUP = 0x80000000;
const uint WS_CHILD = 0x40000000;
const uint WS_CLIPCHILDREN = 0x02000000;
const uint WS_DLGFRAME = 0x00400000;
const uint WS_VISIBLE = 0x10000000;
const long WS_EX_TOOLWINDOW = 0x80;
const long WS_EX_APPWINDOW = 0x40000;
const long WS_CAPTION = 0x00C00000;
const long WS_EX_LAYERED = 0x80000;
const long WS_EX_TRANSPARENT = 0x20;
const int HWND_TOPMOST = -1;
const int WS_BORDER = 0X00800000;

void Start()
{

var resolutions = Screen.resolutions;
// Print the resolutions
var maxr = resolutions.Length – 1;

// Switch to the lowest supported fullscreen resolution
Screen.SetResolution (resolutions[maxr].width, resolutions[maxr].height, false);

#if !UNITY_EDITOR // You really don’t want to enable this in the editor..
var margins = new MARGINS() { cxLeftWidth = -1 };
var hwnd = GetActiveWindow();
//var Handle = FindWindowByCaption(IntPtr.Zero, “TransparentWindow”);

int fWidth = Screen.width;
int fHeight = Screen.height;

const int SW_HIDE = 0x00;
const int SW_SHOW = 0x05;

//HIDE TASKBAR
long style= GetWindowLong(hwnd, GWL_STYLE);
long exstyle= GetWindowLong(hwnd, GWL_EXSTYLE);

style &= ~(WS_CAPTION);
style &= ~(WS_BORDER);

exstyle &= ~(WS_EX_APPWINDOW);
exstyle |= WS_EX_TOOLWINDOW;
exstyle |= WS_EX_LAYERED;
exstyle |= WS_EX_TRANSPARENT;
// flags don’t work – windows remains in taskbar

ShowWindow(hwnd, SW_HIDE);
SetWindowLong(hwnd, GWL_STYLE, style);
SetWindowLong(hwnd, GWL_EXSTYLE, exstyle);
ShowWindow(hwnd, SW_SHOW);
//SetWindowLong(hwnd, GWL_STYLE, style);

//TRANSPARENTE ON TOP
SetWindowLong(hwnd, GWL_STYLE, WS_VISIBLE );
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, fWidth, fHeight, 32 | 64); //SWP_FRAMECHANGED = 0x0020 (32); //SWP_SHOWWINDOW = 0x0040 (64)
SetLayeredWindowAttributes(hwnd, 0, 255, 2);// Transparency=51=20%, LWA_ALPHA=2
DwmExtendFrameIntoClientArea(hwnd, ref margins);

//#endif
}

void Update()
{
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}

}

void OnRenderImage(RenderTexture from, RenderTexture to)
{
Graphics.Blit(from, to, m_Material);
}

}

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

*
= 3 + 6