Browse Source

Continue button is now displayed separately to the Page text box.

- 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 property
master
chrisgregan 11 years ago
parent
commit
30a7a54253
  1. BIN
      Assets/Fungus/Prefabs/ContinueStyle.prefab
  2. 4
      Assets/Fungus/Prefabs/ContinueStyle.prefab.meta
  3. BIN
      Assets/Fungus/Prefabs/Game.prefab
  4. BIN
      Assets/Fungus/Prefabs/PageStyle1.prefab
  5. BIN
      Assets/Fungus/Prefabs/PageStyle2.prefab
  6. 62
      Assets/Fungus/Scripts/ContinueStyle.cs
  7. 8
      Assets/Fungus/Scripts/ContinueStyle.cs.meta
  8. 13
      Assets/Fungus/Scripts/Game.cs
  9. 30
      Assets/Fungus/Scripts/Page.cs
  10. 19
      Assets/Fungus/Scripts/PageStyle.cs
  11. BIN
      Assets/FungusExample/Scenes/Example.unity

BIN
Assets/Fungus/Prefabs/ContinueStyle.prefab

Binary file not shown.

4
Assets/Fungus/Prefabs/ContinueStyle.prefab.meta

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: dcca71ea1c47741ce882a7c9dea90719
NativeFormatImporter:
userData:

BIN
Assets/Fungus/Prefabs/Game.prefab

Binary file not shown.

BIN
Assets/Fungus/Prefabs/PageStyle1.prefab

Binary file not shown.

BIN
Assets/Fungus/Prefabs/PageStyle2.prefab

Binary file not shown.

62
Assets/Fungus/Scripts/ContinueStyle.cs

@ -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);
}
}

8
Assets/Fungus/Scripts/ContinueStyle.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b5c35620ec53b405a8d00dcb285cd260
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

13
Assets/Fungus/Scripts/Game.cs

@ -28,11 +28,6 @@ namespace Fungus
*/
public bool showLinks = true;
/**
* Text to use on 'Continue' buttons.
*/
public string continueText = "Continue";
/**
* Writing speed for page text.
*/
@ -63,8 +58,16 @@ namespace Fungus
*/
public AudioClip buttonClickClip;
/**
* Time which must elapse before buttons will automatically hide.
*/
public float autoHideButtonDuration = 5f;
/**
* References to a style object which controls the appearance & behavior of the continue button.
*/
public ContinueStyle continueStyle;
float autoHideButtonTimer;
/**

30
Assets/Fungus/Scripts/Page.cs

@ -198,7 +198,6 @@ namespace Fungus
GUIStyle sayStyle = pageStyle.GetScaledSayStyle();
GUIStyle optionStyle = pageStyle.GetScaledOptionStyle();
GUIStyle optionAlternateStyle = pageStyle.GetScaledOptionAlternateStyle();
GUIStyle continueStyle = pageStyle.GetScaledContinueStyle();
Rect pageRect = GetScreenRect();
Rect outerRect = FitRectToScreen(pageRect);
@ -270,8 +269,12 @@ namespace Fungus
if (mode == Mode.Say)
{
Rect continueRect = CalcContinueRect(outerRect);
GUI.Button(continueRect, new GUIContent(Game.GetInstance().continueText), continueStyle);
ContinueStyle continueStyle = Game.GetInstance().continueStyle;
if (continueStyle != null)
{
Rect continueRect = continueStyle.CalcContinueRect();
GUI.Label(continueRect, new GUIContent(continueStyle.continueText), continueStyle.style);
}
// Player can continue by clicking anywhere
if (quickContinueTimer == 0 &&
@ -469,27 +472,6 @@ namespace Fungus
return innerRect;
}
Rect CalcContinueRect(Rect outerRect)
{
PageStyle pageStyle = Game.GetInstance().activePageStyle;
if (pageStyle == null)
{
return new Rect();
}
GUIStyle continueStyle = pageStyle.GetScaledContinueStyle();
GUIContent content = new GUIContent(Game.GetInstance().continueText);
float width = continueStyle.CalcSize(content).x;
float height = continueStyle.lineHeight;
float x = outerRect.xMin + (outerRect.width) - (width) - pageStyle.boxStyle.padding.right;
float y = outerRect.yMax - height / 2f;
return new Rect(x, y, width, height);
}
/**
* Returns the page rect in screen space coords
*/

19
Assets/Fungus/Scripts/PageStyle.cs

@ -21,9 +21,6 @@ namespace Fungus
/// Header font size as a fraction of screen height.
public float footerFontScale = 1f / 20f;
/// Continue font size as a fraction of screen height.
public float continueFontScale = 1f / 30f;
/// Option font size as a fraction of screen height.
public float optionFontScale = 1f / 25f;
@ -36,9 +33,6 @@ namespace Fungus
/// Style for say text
public GUIStyle sayStyle;
/// Style for continue button
public GUIStyle continueStyle;
/// Style for option text
public GUIStyle optionStyle;
@ -110,18 +104,5 @@ namespace Fungus
style.fontSize = Mathf.RoundToInt((float)Screen.height * optionFontScale);
return style;
}
/**
* 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 style;
style = new GUIStyle(continueStyle);
style.fontSize = Mathf.RoundToInt((float)Screen.height * continueFontScale);
return style;
}
}
}

BIN
Assets/FungusExample/Scenes/Example.unity

Binary file not shown.
Loading…
Cancel
Save