[Unity] exe의 제목 표시줄을 숨깁니다.

9577 단어 UnityC#
제목 표시줄을 삭제하고 싶습니다.

① WindowController.cs


장면에서 좋아하는 대상에 부착하다.
using UnityEngine;
using System.Collections;

using System;
using System.Runtime.InteropServices;

namespace Utils {

    public class WindowController : MonoBehaviour {

        private string windowName = "windowname";
        private int x = 0;
        private int y = 0;
        private int width = 1920;
        private int height = 1080;
        private bool hideTitleBar = true;

        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        public static extern IntPtr FindWindow(System.String className, System.String windowName);

        // Sets window attributes
        [DllImport("user32.dll")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        // Gets window attributes
        [DllImport("user32.dll")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        // assorted constants needed
        public static int GWL_STYLE = -16;
        public static int WS_CHILD = 0x40000000; //child window
        public static int WS_BORDER = 0x00800000; //window with border
        public static int WS_DLGFRAME = 0x00400000; //window with double border but no title
        public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME; //window with a title bar

        void Awake () {
            var window = FindWindow(null, windowName);
            if(hideTitleBar) {
                int style = GetWindowLong(window, GWL_STYLE);
                SetWindowLong(window, GWL_STYLE, (style & ~WS_CAPTION));
            }
            SetWindowPos(window, 0, x, y, width, height, width * height == 0 ? 1 : 0);
        }
    }
}
private string windowName = "windowname";window의 제목
.창 왼쪽 상단 좌표 x
.창 왼쪽 상단 좌표 yprivate int x = 0; 창 너비private int y = 0; 창 높이private int width = 1920; 제목 표시줄 숨기기

② user32.dll


Assets/Plugins 아래에 직접 놓으십시오.
extern "C" __declspec(dllexport) int Add(int a, int b)
{
     return(a + b);
}
※ 코드 내용은 의미가 없습니다. 더 좋은 코드가 있다면 누구입니까?

③ Player Settings


Player Settings > Player > Resolution and Presentation > Resolution
· Fullscreen Mode를 Windows로 설정합니다.
・ Resizable Window 선택을 취소합니다.

코드 참조 소스


Is there a way to set the position of a standalone unity window?
Removing the Title bar of external application using c#

좋은 웹페이지 즐겨찾기