-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathActionInkChoice.cs
120 lines (97 loc) · 3.42 KB
/
ActionInkChoice.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
[System.Serializable]
public class ActionInkChoice : Action
{
public override ActionCategory Category { get { return ActionCategory.Custom; }}
public override string Title { get { return "Action Ink Choice"; }}
public override string Description { get { return "Displays a menu for an Ink choice"; }}
protected Canvas localCanvas = null;
protected List<string> choices;
protected bool choiceSelected = false;
public override float Run ()
{
if (!isRunning)
{
isRunning = true;
GameObject pe = GameObject.Find("PersistentEngine");
Canvas canvas = pe.GetComponent<ACInkIntegration>().inkChoiceMenu;
if (canvas)
{
localCanvas = (Canvas) Instantiate (canvas);
localCanvas.gameObject.name = canvas.name;
DontDestroyOnLoad (localCanvas.gameObject);
}
UnityEngine.UI.Button[] buttons = localCanvas.GetComponentsInChildren<UnityEngine.UI.Button>();
for(int i = 0 ; i < buttons.Length ; i++){
UnityEngine.UI.Button b = buttons[i];
if(i< choices.Count){
b.onClick.AddListener(HandleChoice);
UnityEngine.UI.Text t = b.transform.GetChild(0).GetComponent<UnityEngine.UI.Text>();
t.text = choices[i];
}
else {
b.gameObject.SetActive(false);
}
}
return defaultPauseTime;
}
else
{
if(choiceSelected){
isRunning = false;
return 0f;
}
return defaultPauseTime;;
}
}
protected void HandleChoice()
{
string buttonName = EventSystem.current.currentSelectedGameObject.name;
char choice = buttonName[buttonName.Length - 1];
ACInkIntegration.choiceID = int.Parse(choice.ToString()) - 1;
Debug.Log(ACInkIntegration.choiceID);
choiceSelected = true;
Destroy(localCanvas.gameObject);
}
public override void Skip ()
{
/*
* This function is called when the Action is skipped, as a
* result of the player invoking the "EndCutscene" input.
*
* It should perform the instructions of the Action instantly -
* regardless of whether or not the Action itself has been run
* normally yet. If this method is left blank, then skipping
* the Action will have no effect. If this method is removed,
* or if the Run() method call is left below, then skipping the
* Action will cause it to run itself as normal.
*/
Run ();
}
#if UNITY_EDITOR
public override void ShowGUI ()
{
// Action-specific Inspector GUI code here
}
public override string SetLabel ()
{
// (Optional) Return a string used to describe the specific action's job.
return string.Empty;
}
#endif
public static ActionInkChoice CreateNew (List<string> inkChoices)
{
ActionInkChoice newAction = CreateNew<ActionInkChoice> ();
newAction.choices = inkChoices;
return newAction;
}
}
}