Browse Source

Better follow the project's coding standards.

master
Gerardo Marset 9 years ago
parent
commit
f67cbf0705
  1. 26
      Assets/Fungus/Narrative/Scripts/MenuDialog.cs
  2. 27
      Assets/Fungus/UI/Scripts/SelectOnEnable.cs

26
Assets/Fungus/Narrative/Scripts/MenuDialog.cs

@ -20,14 +20,14 @@ namespace Fungus
// Currently active Menu Dialog used to display Menu options // Currently active Menu Dialog used to display Menu options
public static MenuDialog activeMenuDialog; public static MenuDialog activeMenuDialog;
[Tooltip("Automatically select the first interactable button when the menu is shown.")] [Tooltip("Automatically select the first interactable button when the menu is shown.")]
public bool autoSelectFirstButton = false; public bool autoSelectFirstButton = false;
[NonSerialized] [NonSerialized]
public Button[] cachedButtons; public Button[] cachedButtons;
[NonSerialized] [NonSerialized]
public Slider cachedSlider; public Slider cachedSlider;
public static MenuDialog GetMenuDialog() public static MenuDialog GetMenuDialog()
{ {
@ -73,10 +73,10 @@ namespace Fungus
} }
public virtual void OnEnable() public virtual void OnEnable()
{ {
// The canvas may fail to update if the menu dialog is enabled in the first game frame. // The canvas may fail to update if the menu dialog is enabled in the first game frame.
// To fix this we just need to force a canvas update when the object is enabled. // To fix this we just need to force a canvas update when the object is enabled.
Canvas.ForceUpdateCanvases(); Canvas.ForceUpdateCanvases();
} }
public virtual void Clear() public virtual void Clear()
@ -115,10 +115,10 @@ namespace Fungus
button.interactable = interactable; button.interactable = interactable;
if (interactable && autoSelectFirstButton && !cachedButtons.Select((x) => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject)) if (interactable && autoSelectFirstButton && !cachedButtons.Select((x) => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
{ {
EventSystem.current.SetSelectedGameObject(button.gameObject); EventSystem.current.SetSelectedGameObject(button.gameObject);
} }
Text textComponent = button.GetComponentInChildren<Text>(); Text textComponent = button.GetComponentInChildren<Text>();
if (textComponent != null) if (textComponent != null)
@ -130,7 +130,7 @@ namespace Fungus
button.onClick.AddListener(delegate { button.onClick.AddListener(delegate {
EventSystem.current.SetSelectedGameObject(null); EventSystem.current.SetSelectedGameObject(null);
StopAllCoroutines(); // Stop timeout StopAllCoroutines(); // Stop timeout
Clear(); Clear();
@ -173,7 +173,7 @@ namespace Fungus
if (cachedSlider != null) if (cachedSlider != null)
{ {
cachedSlider.gameObject.SetActive(true); cachedSlider.gameObject.SetActive(true);
gameObject.SetActive(true); gameObject.SetActive(true);
StopAllCoroutines(); StopAllCoroutines();
StartCoroutine(WaitForTimeout(duration, targetBlock)); StartCoroutine(WaitForTimeout(duration, targetBlock));
} }

27
Assets/Fungus/UI/Scripts/SelectOnEnable.cs

@ -1,22 +1,21 @@
using System; using UnityEngine;
using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
namespace Fungus namespace Fungus
{ {
[RequireComponent(typeof(Selectable))] [RequireComponent(typeof(Selectable))]
public class SelectOnEnable : MonoBehaviour public class SelectOnEnable : MonoBehaviour
{ {
private Selectable selectable; private Selectable selectable;
private void Awake() private void Awake()
{ {
selectable = GetComponent<Selectable>(); selectable = GetComponent<Selectable>();
} }
private void OnEnable() private void OnEnable()
{ {
selectable.Select(); selectable.Select();
} }
} }
} }
Loading…
Cancel
Save