Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Last active August 29, 2015 14:24
Show Gist options
  • Save grimmdev/cafde455f7f23b602953 to your computer and use it in GitHub Desktop.
Save grimmdev/cafde455f7f23b602953 to your computer and use it in GitHub Desktop.
I modified the default PowerUI Manager to accept a design resolution, so you can design for one resolution that better fits all.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using PowerUI;
/// <summary>
/// This is the default PowerUIManager with a much needed design resolution.
/// </summary>
public class GUIManager : MonoBehaviour {
/// <summary>A File containing the html/css/nitro of your UI.</summary>
public TextAsset HtmlFile;
/// We like 200,600 though!
public Vector2 DesignResolution = new Vector2 (800, 480);
// OnEnable is called when the game starts, or when the manager script component is enabled.
void OnEnable () {
int DPI = Mathf.RoundToInt (Screen.dpi);
int X = Mathf.RoundToInt (DesignResolution.x);
int Y = Mathf.RoundToInt (DesignResolution.y);
// Optional. This allows PowerUI to easily work with screens of varying resolution.
UI.Resolution=new ResolutionInfo(new DesignSize(X,Y,DPI));
// Load the UI from the above HtmlFile. Note that UI's don't have to be loaded like this! You
// can also just set a string of text if needed.
if(HtmlFile==null){
Debug.Log("Please provide a HTML file for your UI.");
}else{
// Write the html:
UI.Html=HtmlFile.text;
}
}
// OnDisable is called when the manager script component is disabled. You don't need this.
void OnDisable () {
UI.Destroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment