using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Debug = UnityEngine.Debug;
public class MainScriptfull : MonoBehaviour
{
public Rect screenPosition;
[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, uint uFlags);
[DllImport(“kernel32”, CharSet = CharSet.Auto)]
public static extern int GetPrivateProfileInt(string section, string key, int def, string filePath);
[DllImport(“user32.dll”)]
static extern IntPtr GetActiveWindow();
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
private int i = 0;
void Awake()
{
if (ReadScreenWidth() == 0 || ReadScreenHeight() == 0)
{
int width = Screen.currentResolution.width;
int height = Screen.currentResolution.height;
Debug.Log(width);
Debug.Log(height);
//写入配置文件
ToolReadInConfig.WriteIniContent(“version”, “UnityWindowWidth”, width.ToString());
ToolReadInConfig.WriteIniContent(“version”, “UnityWindowHeight”, height.ToString());
screenPosition.width = width;
screenPosition.height = height;
}
else
{
screenPosition.width = ReadScreenWidth();
screenPosition.height = ReadScreenHeight();
}
Screen.SetResolution(Screen.width, Screen.height, false);
}
// 初始化串口
void Start()
{
SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER);
SetWindowPos(GetActiveWindow(), -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);
}
// Update is called once per frame
void Update()
{
i++;
if (i < 5)
{
SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER);
SetWindowPos(GetActiveWindow(), -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);
}
}
public static int ReadScreenWidth()
{
int ret = GetPrivateProfileInt("version", "UnityWindowWidth", 0, Application.streamingAssetsPath + "/config.ini");
return ret;
}
public static int ReadScreenHeight()
{
int ret = GetPrivateProfileInt("version", "UnityWindowHeight", 0, Application.streamingAssetsPath + "/config.ini");
return ret;
}
}