diff --git a/Assets/Fungus/Prefabs/ContinueStyle.prefab b/Assets/Fungus/Prefabs/ContinueStyle.prefab new file mode 100644 index 00000000..13f3d451 Binary files /dev/null and b/Assets/Fungus/Prefabs/ContinueStyle.prefab differ diff --git a/Assets/Fungus/Prefabs/ContinueStyle.prefab.meta b/Assets/Fungus/Prefabs/ContinueStyle.prefab.meta new file mode 100644 index 00000000..b94aeb25 --- /dev/null +++ b/Assets/Fungus/Prefabs/ContinueStyle.prefab.meta @@ -0,0 +1,4 @@ +fileFormatVersion: 2 +guid: dcca71ea1c47741ce882a7c9dea90719 +NativeFormatImporter: + userData: diff --git a/Assets/Fungus/Prefabs/Game.prefab b/Assets/Fungus/Prefabs/Game.prefab index 0749709b..1cb8dd81 100644 Binary files a/Assets/Fungus/Prefabs/Game.prefab and b/Assets/Fungus/Prefabs/Game.prefab differ diff --git a/Assets/Fungus/Prefabs/PageStyle1.prefab b/Assets/Fungus/Prefabs/PageStyle1.prefab index 58d9dbe3..eaee2b8e 100644 Binary files a/Assets/Fungus/Prefabs/PageStyle1.prefab and b/Assets/Fungus/Prefabs/PageStyle1.prefab differ diff --git a/Assets/Fungus/Prefabs/PageStyle2.prefab b/Assets/Fungus/Prefabs/PageStyle2.prefab index 57fc1381..876499cd 100644 Binary files a/Assets/Fungus/Prefabs/PageStyle2.prefab and b/Assets/Fungus/Prefabs/PageStyle2.prefab differ diff --git a/Assets/Fungus/Scripts/ContinueStyle.cs b/Assets/Fungus/Scripts/ContinueStyle.cs new file mode 100644 index 00000000..1bb84632 --- /dev/null +++ b/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); + } +} diff --git a/Assets/Fungus/Scripts/ContinueStyle.cs.meta b/Assets/Fungus/Scripts/ContinueStyle.cs.meta new file mode 100644 index 00000000..1f401643 --- /dev/null +++ b/Assets/Fungus/Scripts/ContinueStyle.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b5c35620ec53b405a8d00dcb285cd260 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/Scripts/Game.cs b/Assets/Fungus/Scripts/Game.cs index a26b8321..5b88e1f4 100644 --- a/Assets/Fungus/Scripts/Game.cs +++ b/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; /** diff --git a/Assets/Fungus/Scripts/Page.cs b/Assets/Fungus/Scripts/Page.cs index a51fd805..277727a3 100644 --- a/Assets/Fungus/Scripts/Page.cs +++ b/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 */ diff --git a/Assets/Fungus/Scripts/PageStyle.cs b/Assets/Fungus/Scripts/PageStyle.cs index 3ff077c9..cc7c5ec5 100644 --- a/Assets/Fungus/Scripts/PageStyle.cs +++ b/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; - } } } \ No newline at end of file diff --git a/Assets/FungusExample/Scenes/Example.unity b/Assets/FungusExample/Scenes/Example.unity index 8fcb3576..7f5bf656 100644 Binary files a/Assets/FungusExample/Scenes/Example.unity and b/Assets/FungusExample/Scenes/Example.unity differ