-
Notifications
You must be signed in to change notification settings - Fork 1
/
StandAloneCharacterPointSystem.cs
158 lines (144 loc) · 5.66 KB
/
StandAloneCharacterPointSystem.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
namespace Fungus
{
/// <summary>
/// Loads a saved value and stores it in a Boolean, Integer, Float or String variable. If the key is not found then the variable is not modified.
/// </summary>
[CommandInfo("Variable",
"Standalone Character's Point System",
"Point/affinity system like in HP, MP or point systems for characters in visual novel. IMPORTANT: Use On-Update only when this command works as a standalone/in disconnected block ")]
[AddComponentMenu("")]
public class StandAloneCharacterPointSystem : Command
{
[HideInInspector] protected string key = "";
[Tooltip("Variable to store the value in.")]
[VariableProperty(typeof(IntegerVariable),
typeof(FloatVariable))]
[SerializeField] protected Variable variable;
[SerializeField] protected float maxValueOf;
[SerializeField] protected Slider slider;
[SerializeField] protected bool useTextUI = false;
[Tooltip("If Text component is used, Slider component will be ignored")]
[SerializeField] protected Text textComponent;
[Header("Realtime Update. MUST be standalone/disconnected block")]
[Tooltip("Use this only when this command works as a standalone(separate block/disconnected block)")]
[SerializeField] protected bool onUpdate = true;
//Slight delay
float time = 0.1f;
void Update()
{
if(onUpdate)
{
if (time >= 0)
{
time -= Time.deltaTime;
return;
}
else
{
GetCharacterPoint();
}
}
}
public void GetCharacterPoint()
{
if(variable != null)
{
key = variable.name;
if (key == "" ||
variable == null)
{
Continue();
return;
}
var flowchart = GetFlowchart();
// Prepend the current save profile (if any)
string prefsKey = SetSaveProfile.SaveProfile + "_" + flowchart.SubstituteVariables(key);
System.Type variableType = variable.GetType();
if (variableType == typeof(IntegerVariable))
{
IntegerVariable integerVariable = variable as IntegerVariable;
if(textComponent != null && useTextUI == true)
{
textComponent.text = integerVariable.Value.ToString();
}
if(slider != null && useTextUI == false)
{
slider.maxValue = maxValueOf;
slider.wholeNumbers = true;
//slider.value = (float)integerVariable.Value;
//Debug.Log(integerVariable.Value);
var tmpfinttofloat = slider.GetComponent<Slider>().value;
//Debug.Log(tmpfinttofloat);
//float animfloat =
slider.value = (float)integerVariable.Value;
}
}
else if (variableType == typeof(FloatVariable))
{
FloatVariable floatVariable = variable as FloatVariable;
if(textComponent != null && useTextUI == true)
{
textComponent.text = floatVariable.Value.ToString();
}
if(slider != null && useTextUI == false)
{
slider.maxValue = maxValueOf;
slider.wholeNumbers = true;
var tmpfinttofloat = slider.GetComponent<Slider>().value;
slider.value = floatVariable.Value;
}
}
}
}
#region Public members
public override void OnEnter()
{
if(!onUpdate)
{
GetCharacterPoint();
}
Continue();
}
public override string GetSummary()
{
if (variable == null)
{
return "Error: No variable selected";
}
if(textComponent == null && textComponent == true)
{
return "Error: No Text component available";
}
if(slider == null && textComponent == false)
{
return "Error: No Slider component available";
}
return variable.Key;
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
public override bool HasReference(Variable in_variable)
{
return this.variable == in_variable ||
base.HasReference(in_variable);
}
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(key, referencedVariables);
}
#endif
#endregion Editor caches
}
}