2017-09-11 1 views
1

J'ai créé le menu d'options de l'interface utilisateur pour les graphiques et l'écran. Le fait est que j'ai pu ajouter obly une valeur booléenne pour le mode fullScreen. J'ai besoin d'ajouter une liste déroulante avec 3 modes: plein écran, fenêtré et fenêtré sans cadre (étiré à la taille de l'écran entier). Comment puis-je obtenir le troisième mode?Ajouter des modes d'écran dans les paramètres

Répondre

1

Découvrez this sample code. Cependant, il utilise la bibliothèque user32.dll, vous devrez donc probablement le référencer dans votre projet.

using System; 
using System.Collections; 
using System.Runtime.InteropServices; 
using System.Diagnostics; 
using UnityEngine; 

public class WindowMod : 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("user32.dll")] 
static extern IntPtr GetForegroundWindow(); 

// not used rigth now 
//const uint SWP_NOMOVE = 0x2; 
//const uint SWP_NOSIZE = 1; 
//const uint SWP_NOZORDER = 0x4; 
//const uint SWP_HIDEWINDOW = 0x0080; 

const uint SWP_SHOWWINDOW = 0x0040; 
const int GWL_STYLE = -16; 
const int WS_BORDER = 1; 

void Start() 
{ 
    SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_BORDER); 
    bool result = SetWindowPos (GetForegroundWindow(), 0,(int)screenPosition.x,(int)screenPosition.y, (int)screenPosition.width,(int) screenPosition.height, SWP_SHOWWINDOW); 
} 

Avec cette méthode, votre meilleur pari serait de:

  1. Créer un ENUM pour toutes les options, par exemple public enum WindowMode { FullScreen, Borderless, Window }
  2. Créer une classe de gestionnaire avec une méthode qui prend l'ENUM comme argument : public void SetWindowMode(WindowMode wm // or int) {...}
  3. fil vers le haut de sorte que la méthode est appelée chaque fois qu'un élément est sélectionné dans la liste déroulante dans le menu options avec EventSystem thingy du IUU
  4. C'est à peu près tout.