Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Djcmoon · Jun 10, 2010 at 10:46 AM · guibuttonresolutionfullscreen

full screen and resolution

Hey everyone,

I have a pause game script here that I really love

var skin:GUISkin;

private var gldepth = -0.5; private var startTime = 0.1;

var mat:Material;

private var tris = 0; private var verts = 0; private var savedTimeScale:float; private var pauseFilter;

private var showfps:boolean; private var showtris:boolean; private var showvtx:boolean; private var showfpsgraph:boolean;

var lowFPSColor = Color.red; var highFPSColor = Color.green;

var lowFPS = 30; var highFPS = 50;

var start:GameObject;

var url = "unity.html";

var statColor:Color = Color.yellow;

var credits:String[]=[ "A Moonlight Studios Production", "Programming by Moonlight Studios", "Moonlight Studios logo by Moonlight Studios Productions", "Copyright (c)"] ; var crediticons:Texture[];

enum Page { None,Main,Options,Credits }

private var currentPage:Page;

private var fpsarray:int[]; private var fps:float;

function Start() { fpsarray = new int[Screen.width]; Time.timeScale = 1.0; PauseGame(); }

function OnPostRender() { if (showfpsgraph && mat != null) { GL.PushMatrix (); GL.LoadPixelMatrix(); for (var i = 0; i < mat.passCount; ++i) { mat.SetPass(i); GL.Begin( GL.LINES ); for (var x=0; x<fpsarray.length; ++x) { GL.Vertex3(x,fpsarray[x],gldepth); } GL.End(); } GL.PopMatrix(); ScrollFPS(); } }

function ScrollFPS() { for (var x=1; x<fpsarray.length; ++x) { fpsarray[x-1]=fpsarray[x]; } if (fps < 1000) { fpsarray[fpsarray.length-1]=fps; } }

static function IsDashboard() { return Application.platform == RuntimePlatform.OSXDashboardPlayer; }

static function IsBrowser() { return (Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.OSXWebPlayer); }

function LateUpdate () { if (showfps || showfpsgraph) { FPSUpdate(); } if (Input.GetKeyDown("escape")) { switch (currentPage) { case Page.None: PauseGame(); break; case Page.Main: if (!IsBeginning()) UnPauseGame(); break; default: currentPage = Page.Main; } } }

function OnGUI () { if (skin != null) { GUI.skin = skin; } ShowStatNums(); ShowLegal(); if (IsGamePaused()) { GUI.color = statColor; switch (currentPage) { case Page.Main: PauseMenu(); break; case Page.Options: ShowToolbar(); break; case Page.Credits: ShowCredits(); break; } }
}

function ShowLegal() { if (!IsLegal()) { GUI.Label(Rect(Screen.width-100,Screen.height-20,90,20), "mlsproductions.com"); } }

function IsLegal() { return !IsBrowser() || Application.absoluteURL.StartsWith("http://www.mlsprductions.com/") || Application.absoluteURL.StartsWith("http://mlsproductions.com/"); }

private var toolbarInt:int=0; private var toolbarStrings: String[]= ["Audio","Graphics","FPS Rate","System"];

function ShowToolbar() { BeginPage((Screen.width)/2*1.5,(Screen.height)/2); toolbarInt = GUILayout.Toolbar (toolbarInt, toolbarStrings); switch (toolbarInt) { case 0: VolumeControl(); break; case 3: ShowDevice(); break; case 1: Qualities(); QualityControl(); break; case 2: StatControl(); break; } EndPage(); }

function ShowCredits() { BeginPage((Screen.width)/2,(Screen.height)/2); for (var credit in credits) { GUILayout.Label(credit); } for (var credit in crediticons) { GUILayout.Label(credit); } EndPage(); }

function ShowBackButton() { if (GUI.Button(Rect(20,Screen.height-50,100,35),"Back")) { currentPage = Page.Main; } }

function ShowDevice() { GUILayout.Label ("Unity player version "+Application.unityVersion); GUILayout.Label("Graphics: "+SystemInfo.graphicsDeviceName+" "+ SystemInfo.graphicsMemorySize+"MB\n"+ SystemInfo.graphicsDeviceVersion+"\n"+ SystemInfo.graphicsDeviceVendor); GUILayout.Label("Shadows: "+SystemInfo.supportsShadows); GUILayout.Label("Image Effects: "+SystemInfo.supportsImageEffects); GUILayout.Label("Render Textures: "+SystemInfo.supportsRenderTextures); }

function Qualities() { switch (QualitySettings.currentLevel) { case QualityLevel.Fastest: GUILayout.Label("Fastest"); break; case QualityLevel.Fast: GUILayout.Label("Fast"); break; case QualityLevel.Simple: GUILayout.Label("Simple"); break; case QualityLevel.Good: GUILayout.Label("Good"); break; case QualityLevel.Beautiful: GUILayout.Label("Beautiful"); break; case QualityLevel.Fantastic: GUILayout.Label("Fantastic"); break; } }

function QualityControl() { GUILayout.BeginHorizontal(); if (GUILayout.Button("Decrease")) { QualitySettings.DecreaseLevel(); } if (GUILayout.Button("Increase")) { QualitySettings.IncreaseLevel(); } GUILayout.EndHorizontal(); }

function VolumeControl() { GUILayout.Label("Volume"); AudioListener.volume = GUILayout.HorizontalSlider(AudioListener.volume,0.0,1.0); }

function StatControl() { GUILayout.BeginHorizontal(); showfps = GUILayout.Toggle(showfps,"Show Frame Rate (Frames Per Second)"); GUILayout.EndHorizontal(); }

function FPSUpdate() { var delta = Time.smoothDeltaTime; if (!IsGamePaused() && delta !=0.0) { fps = 1 / delta; } }

function ShowStatNums() { GUILayout.BeginArea(Rect(Screen.width-100,10,100,200)); if (showfps) { var fpsString= fps.ToString ("#,##0 fps"); GUI.color = Color.Lerp(lowFPSColor, highFPSColor,(fps-lowFPS)/(highFPS-lowFPS)); GUILayout.Label (fpsString); }

 GUILayout.EndArea();

}

function BeginPage(width,height) { GUILayout.BeginArea(Rect((Screen.width-width)/2,(Screen.height-height)/2,width,height)); }

function EndPage() { GUILayout.EndArea(); if (currentPage != Page.Main) { ShowBackButton(); } }

function IsBeginning() { return Time.time < startTime; }

function PauseMenu() { BeginPage((Screen.width)/2,(Screen.height)/2); if (GUILayout.Button (IsBeginning() ? "Play" : "Continue")) { UnPauseGame();

 }
 if (GUILayout.Button ("Options")) {
     currentPage = Page.Options;
 }
 if (GUILayout.Button ("Credits")) {
     currentPage = Page.Credits;
 }
   if (GUILayout.Button ("Quit")) {
     Application.LoadLevel(0);
 }
 if (IsBrowser() &amp;&amp; !IsBeginning() &amp;&amp; GUILayout.Button ("Restart")) {
     Application.OpenURL(url);
 }
 EndPage();

}

function GetObjectStats() { verts = 0; tris = 0; var ob = FindObjectsOfType(GameObject); for (var obj in ob) { GetObjectStats(obj); } }

function GetObjectStats(object) { var filters : Component[]; filters = object.GetComponentsInChildren(MeshFilter); for( var f : MeshFilter in filters ) { tris += f.sharedMesh.triangles.Length/3; verts += f.sharedMesh.vertexCount; } }

function PauseGame() { Screen.lockCursor = false; savedTimeScale = Time.timeScale; Time.timeScale = 0; AudioListener.pause = true; if (pauseFilter) pauseFilter.enabled = true; currentPage = Page.Main; }

function UnPauseGame() { Screen.lockCursor = true; Time.timeScale = savedTimeScale; AudioListener.pause = false; if (pauseFilter) pauseFilter.enabled = false; currentPage = Page.None; if (IsBeginning() && start != null) { start.active = true; } }

function IsGamePaused() { return Time.timeScale==0; }

function OnApplicationPause(pause:boolean) { if (IsGamePaused()) { AudioListener.pause = true; } }

Like I said, I love this code but I would like to and resolution buttons and a fullscreen button under my options menu.

Is there any code that can do this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by newbrand · Jun 10, 2010 at 11:26 AM

Hi Djcmoon.

If you must double post your questions, please be so kind to provide a link to the forum-post and vice versa lest people waste their time on already solved issues.

To answer your question: Yes.

Check out Screen.fullScreen, Screen.resolutions and Screen.SetResolution. To toggle fullscreen you'll probably want to use a GUI.Toggle (a checkbox). To switch resolutions, you can for instance populate a GUI.SelectionGrid with the items of Screen.resolutions, although it is probably better to use GUILayout instead or scrollbars. Another possibility that is easier to implement is a Label with arrow-buttons to each side to go through the different resolutions plus another button to apply the changes.

If you want to know more about GUI scripting, check out this helpful guide: http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Djcmoon · Jun 10, 2010 at 09:02 PM 0
Share

Thank you very much.

I didn't even know that I did post this twice.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Button and resolution problem 1 Answer

Changing screen resolution with GUI Buttons 0 Answers

Problem in setting GUI Button for mobile device 1 Answer

GUI Buttons scaling with resolution - help 2 Answers

How to make button stay the same size on all screens? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges