Browse Source
- Added ContinueStyle component and prefab to control appearance of continue button - Can control continue button position on screen and padding from screen edge. - Added Game.continueStyle propertymaster
11 changed files with 88 additions and 48 deletions
Binary file not shown.
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2 |
||||
guid: dcca71ea1c47741ce882a7c9dea90719 |
||||
NativeFormatImporter: |
||||
userData: |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,62 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
|
||||
public class ContinueStyle : MonoBehaviour |
||||
{ |
||||
/** |
||||
* Text to use on 'Continue' buttons. |
||||
*/ |
||||
public string continueText = "Continue"; |
||||
|
||||
/// Continue font size as a fraction of screen height. |
||||
public float continueFontScale = 1f / 30f; |
||||
|
||||
/// Style for continue button |
||||
public GUIStyle style; |
||||
|
||||
/** |
||||
* Specifies continue button position in normalized screen coordinates. |
||||
* (0,0) is top left of screen. |
||||
* (1,1) is bottom right of screen |
||||
*/ |
||||
public Vector2 screenPosition = new Vector2(1,1); |
||||
|
||||
/** |
||||
* Padding distance between button and edge of the screen in pixels. |
||||
*/ |
||||
public Vector2 padding = new Vector2(4,4); |
||||
|
||||
/** |
||||
* Returns the style for the Continue button. |
||||
* Overrides the font size to compensate for varying device resolution. |
||||
* Font size is calculated as a fraction of the current screen height. |
||||
*/ |
||||
public GUIStyle GetScaledContinueStyle() |
||||
{ |
||||
GUIStyle guiStyle; |
||||
guiStyle = new GUIStyle(style); |
||||
guiStyle.fontSize = Mathf.RoundToInt((float)Screen.height * continueFontScale); |
||||
return guiStyle; |
||||
} |
||||
|
||||
public Rect CalcContinueRect() |
||||
{ |
||||
GUIStyle continueStyle = GetScaledContinueStyle(); |
||||
|
||||
GUIContent content = new GUIContent(continueText); |
||||
Vector2 size = continueStyle.CalcSize(content); |
||||
|
||||
float x = Screen.width * screenPosition.x; |
||||
float y = Screen.height * screenPosition.y; |
||||
float width = size.x; |
||||
float height = size.y; |
||||
|
||||
x = Mathf.Max(x, padding.x); |
||||
x = Mathf.Min(x, Screen.width - width - padding.x); |
||||
|
||||
y = Mathf.Max(y, padding.y); |
||||
y = Mathf.Min(y, Screen.height - height - padding.y); |
||||
|
||||
return new Rect(x, y, width, height); |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: b5c35620ec53b405a8d00dcb285cd260 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
Binary file not shown.
Loading…
Reference in new issue