這裏介紹兩種全屏顯示的方法。第一種是寫代碼實現的可以外部載入數據並且修改分辨率。
using RenderHeads.Media.AVProVideo;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Xml;
using System.Text;
using System;
using System.Runtime.InteropServices;
public class GameControl : MonoBehaviour {
[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("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll", EntryPoint = "GetSystemMetrics")]
public static extern IntPtr GetSystemMetrics(int nIndex);
const int SM_CXSCREEN = 0x00000000;
const int SM_CYSCREEN = 0x00000001;
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
const int WS_POPUP = 0x800000;
//float x = mycamera.WorldToScreenPoint(kongjian.transform.position).x;
//float y = mycamera.WorldToScreenPoint(kongjian.transform.position).y;
//x,y即爲控件在屏幕的座標camera.WorldToScreenPoint()方法返回的是一個position類型 是vector3類型,camera爲要轉化到的目標攝像機,傳入的參數爲控件的世界座標
void Start()
{
//bool result = SetWindowPos(GetForegroundWindow(), 0, winPosX, winPosY, winWidth, winHeight, SWP_SHOWWINDOW);
//測試發現左下角座標爲(0,1),修改如下
string a = ReadALine(FileName, 1);//讀取第一行
string b = ReadALine(FileName, 2);//讀取第二行
//string c = ReadALine(FileName, 3);//讀取第三行
//string d = ReadALine(FileName, 4);//讀取第四行
string e = ReadALine(FileName, 3);//讀取第四行
string f = ReadALine(FileName, 4);//讀取第四行
//轉換成Int值
VideoOnePosX = int.Parse(a);
VideoOnePosY = int.Parse(b);
//VideoTowPosX = int.Parse(c);
//VideoTowPosY = int.Parse(d);
Weight= int.Parse(e);
Height = int.Parse(f);
VideoOnePos.anchoredPosition = new Vector3(VideoOnePosX, VideoOnePosY, 0);//設置屏幕位置
//VideoTowPos.anchoredPosition = new Vector3(VideoTowPosX, VideoTowPosY, 0);//設置屏幕位置
//Debug.Log(VideoOnePos.anchoredPosition);
//Debug.Log(VideoTowPos.anchoredPosition);
//SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_POPUP);
//測試發現左下角座標爲(0,1),修改如下
//bool result = SetWindowPos(GetForegroundWindow(), 0, 0, 0, Weight, Height, SWP_SHOWWINDOW);
}
//讀取文本某一行字符串
string ReadALine(string FileName, int linenumber) // 參數1:打開的文件(路徑+文件命),參數2:讀取的行數
{
string[] strs = File.ReadAllLines(FileName);
if (linenumber == 0)
{
return "0";
}
else
{
return strs[linenumber - 1];
}
}
// Update is called once per frame
void Update () {
//Screen.SetResolution(Weight, Height, true);//這是設置屏幕分辨率的方法,後面的false表示非全屏
//SetWindowPos(GetForegroundWindow(), 0, PosX, PosY,100, 100, 0x001);
}
}
}
但是這種方式有一個問題就是打包出來屏幕周邊會有一些白邊。下面是一種外部通過創建快捷鍵來設置屏幕全屏的方式:
創建exe快捷方式後點擊快捷鍵屬性 複製下面代碼到 exe 後面空格也要複製進去
-screen-width 2590 -screen-height 768 -popupwindow
這種方式簡單方便,當然Unity中的也有設置全屏的,但是適用於單屏,分辨率改變的額話會有一些問題。
file->buildSetting->playersetting將打鉤就OK了。
順便簡單介紹一些打包設置吧
首先取消Unity的分辨率選擇框
在平臺設定中,可以設置遊戲的一些平臺屬性,比如遊戲圖標,logo和遊戲名稱。
設置的方式爲首先點擊Edit->project Setting ->player調出設置面板,設置面板中有4大設定,如圖:
這裏寫圖片描述
如上圖:首先是company name 和product name,即公司名字和產品名字,然後是default icon,就是生成的文件圖標。
對於1部分:
Resolution and presentation展開後爲:
這裏寫圖片描述
對於以上設置,分別爲:1,是否默認全屏。2:默認屏幕大小。3,4,5,6:默認即可。7:界面是否可以縮放,如果不選則最終的遊戲窗口不能拖動縮放,並且全屏時沒有關閉按鈕。9:是否全屏轉換,跟7合用,控制全屏顯示。
這裏寫圖片描述
對於Icon的設置,這裏的顯示的圖片由最上方默認圖標選擇的圖片,不用設置。
這裏寫圖片描述
對於splash image設置項,標紅處用來設置你的遊戲運行時是否播放Unity官方的開始動畫,即含Unity圖標的動畫,默認爲勾選,即播放官方開始動畫,我們可以取消勾選。
這裏寫圖片描述
最後就是其他的一些設置,我們都選擇默認即可。