|
|
@ -1,5 +1,6 @@ |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.UI; |
|
|
|
using UnityEngine.UI; |
|
|
|
|
|
|
|
using UnityEngine.Events; |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
@ -14,13 +15,11 @@ namespace Fungus.Script |
|
|
|
public class Option |
|
|
|
public class Option |
|
|
|
{ |
|
|
|
{ |
|
|
|
public string text; |
|
|
|
public string text; |
|
|
|
public Action onSelect; |
|
|
|
public UnityAction onSelect; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<UnityEngine.UI.Button> optionButtons = new List<UnityEngine.UI.Button>(); |
|
|
|
public List<UnityEngine.UI.Button> optionButtons = new List<UnityEngine.UI.Button>(); |
|
|
|
|
|
|
|
|
|
|
|
List<Action> optionActions = new List<Action>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Choose(string text, List<Option> options, float timeoutDuration, Action onTimeout) |
|
|
|
public void Choose(string text, List<Option> options, float timeoutDuration, Action onTimeout) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Clear(); |
|
|
|
Clear(); |
|
|
@ -76,7 +75,10 @@ namespace Fungus.Script |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
optionActions.Clear(); |
|
|
|
foreach (UnityEngine.UI.Button button in optionButtons) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
button.onClick.RemoveAllListeners(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (UnityEngine.UI.Button button in optionButtons) |
|
|
|
foreach (UnityEngine.UI.Button button in optionButtons) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -87,7 +89,7 @@ namespace Fungus.Script |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool AddOption(string text, Action action) |
|
|
|
bool AddOption(string text, UnityAction action) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (optionButtons == null) |
|
|
|
if (optionButtons == null) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -107,7 +109,16 @@ namespace Fungus.Script |
|
|
|
textComponent.text = text; |
|
|
|
textComponent.text = text; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
optionActions.Add(action); |
|
|
|
UnityAction buttonAction = action; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button.onClick.AddListener(delegate { |
|
|
|
|
|
|
|
StopAllCoroutines(); // Stop timeout |
|
|
|
|
|
|
|
Clear(); |
|
|
|
|
|
|
|
if (buttonAction != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
buttonAction(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
addedOption = true; |
|
|
|
addedOption = true; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -116,20 +127,6 @@ namespace Fungus.Script |
|
|
|
|
|
|
|
|
|
|
|
return addedOption; |
|
|
|
return addedOption; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void SelectOption(int index) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (index < optionActions.Count) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Action optionAction = optionActions[index]; |
|
|
|
|
|
|
|
if (optionAction != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StopCoroutine("WaitForTimeout"); |
|
|
|
|
|
|
|
Clear(); |
|
|
|
|
|
|
|
optionAction(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|