Skip to content

Commit ff4bcc8

Browse files
committed
added the option to add new refrencevalues when picking one
1 parent 938f80d commit ff4bcc8

14 files changed

+89
-24
lines changed

Assets/EntryWindowPrefabs.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ MonoBehaviour:
1818
NumField: {fileID: 5657202803026543527, guid: 24a40e65e8de26541ba75250d8c07924, type: 3}
1919
StringField: {fileID: 4731904965347522395, guid: 4e0d229237b9f3b45ac0b53c707f98dc, type: 3}
2020
SwitchToValueParamButton: {fileID: 1540659989233520010, guid: 88e114d13fb498b449edd5378f31f6ba, type: 3}
21-
ValuePicker: {fileID: 0}
21+
ValuePicker: {fileID: 8501436416858665696, guid: 8fd569e2768397b47b15f54db3402d75, type: 3}

Assets/Prefabs/HUD/RefrenceValuePicker.prefab

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ MonoBehaviour:
555555
m_CaptionImage: {fileID: 0}
556556
m_ItemText: {fileID: 7385228575122100960}
557557
m_ItemImage: {fileID: 0}
558-
m_Value: 0
558+
m_Value: -9
559559
m_Options:
560560
m_Options: []
561561
m_OnValueChanged:

Assets/Prefabs/HUD/ValueEntry.prefab

+2-2
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ RectTransform:
498498
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
499499
m_AnchorMin: {x: 1, y: 1}
500500
m_AnchorMax: {x: 1, y: 1}
501-
m_AnchoredPosition: {x: -27.224304, y: -21.002563}
502-
m_SizeDelta: {x: 38.090202, y: 38.090202}
501+
m_AnchoredPosition: {x: -22.3, y: -21.6}
502+
m_SizeDelta: {x: 50.78205, y: 50.78205}
503503
m_Pivot: {x: 0.5, y: 0.5}
504504
--- !u!222 &5585254916595062987
505505
CanvasRenderer:

Assets/Scripts/HUD/Entry.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
public abstract class Entry
22
{
3-
public int Type;
3+
public ParameterType Type;
44

55
public Entry ParentEntry = null;
66
public float Time = 0f;

Assets/Scripts/HUD/EntryCollectionHud.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private IEnumerable<EntryType> GetChildren(EntryType entry)
9191
return _entries.Where(e => e.ParentEntry == entry);
9292
}
9393

94-
public void AddNewEntryAtCursor(int entryType)
94+
public virtual void AddEntryAtCursor(ParameterType entryType)
9595
{
9696
var entry = new EntryType()
9797
{

Assets/Scripts/HUD/MainTimeLineBehaviour.cs

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public void Rename(string prevName, string newName)
3636
_hudTimeLine.Rename(prevName, newName);
3737
}
3838

39+
public void Redraw()
40+
{
41+
_hudTimeLine.Redraw();
42+
}
43+
3944
private void LoadMechanic(string name)
4045
{
4146
_title.text = _titlePrefix + name;

Assets/Scripts/HUD/SubElementBehaviour.cs

+26-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
public class SubElementBehaviour : MonoBehaviour
1111
{
12+
public enum SpecialWindows
13+
{
14+
ValueEditor,
15+
}
16+
1217
[SerializeField]
1318
private GameObject _tabPrefab;
1419

@@ -36,7 +41,10 @@ public class SubElementBehaviour : MonoBehaviour
3641
private GameObject _windowGameObject;
3742
private List<GameObject> _dropDownGameObject = new List<GameObject>();
3843

39-
private readonly List<string> _specialWindows = new List<string>() { "[ValueEditor]" };
44+
//private readonly List<string> _specialWindows = new List<string>() { "[ValueEditor]" };
45+
private readonly Dictionary<SpecialWindows, string> _specialWindows = new Dictionary<SpecialWindows, string>() {
46+
{SpecialWindows.ValueEditor, "[ValueEditor]"}
47+
};
4048

4149
private void Start()
4250
{
@@ -53,7 +61,7 @@ private void ShowAddDropDown()
5361
from option in _mainTimeLine.CustomMechanics
5462
where !_tabs.Contains(option.Key)
5563
select option.Key).ToList();
56-
options.AddRange(_specialWindows.Except(_tabs));
64+
options.AddRange(_specialWindows.Values.Except(_tabs));
5765
if (options.Count() == 0)
5866
{
5967
Destroy(dropDown.gameObject);
@@ -88,6 +96,7 @@ public void Rename(string name, string newName)
8896
{
8997
_tabs[_tabs.IndexOf(name)] = newName;
9098
RedrawTabbar();
99+
_mainTimeLine.Redraw();
91100
}
92101

93102
private void Update()
@@ -135,14 +144,27 @@ private void SetActiveTab(int i)
135144
RedrawContent();
136145
}
137146

147+
public void SetActiveWindow(SpecialWindows specialWindows)
148+
{
149+
var windowName = _specialWindows[specialWindows];
150+
if (!_tabs.Contains(windowName))
151+
{
152+
AddWindow(windowName);
153+
}
154+
else
155+
{
156+
SetActiveWindow(windowName);
157+
}
158+
}
159+
138160
private void RedrawContent()
139161
{
140162
Destroy(_windowGameObject);
141163
if (_activeTabIndex < 0)
142164
return;
143165
string mechanicName = _tabs[_activeTabIndex];
144166

145-
if (_specialWindows.Contains(mechanicName))
167+
if (_specialWindows.Values.Contains(mechanicName))
146168
{
147169
// todo use a dictionary for this, put it in the inspector somehow
148170
if (mechanicName == "[ValueEditor]")
@@ -177,5 +199,6 @@ public void SetActiveWindow(string mechanic)
177199
_activeTabIndex = index;
178200
}
179201
RedrawTabbar();
202+
RedrawContent();
180203
}
181204
}

Assets/Scripts/HUD/TimeLineBehaviour.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override void DisplayDropDownMenu(Dropdown dropDown)
3232
dropDown.AddOptions(Enum.GetNames(typeof(TimeLineEntryType)).ToList());
3333
dropDown.onValueChanged.AddListener((i) =>
3434
{
35-
AddNewEntryAtCursor(i);
35+
AddEntryAtCursor((ParameterType)i);
3636
UnlockCursorLine();
3737
Destroy(dropDown.gameObject);
3838
});

Assets/Scripts/HUD/TimeLineEntryHud.cs

+25-3
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,45 @@ private GameObject InstantiateRefrenceValuePicker(ParameterData parameter, Param
237237
{
238238
List<string> options = (
239239
from val in _mainTimeLine.RefrenceValues
240-
where val.Type == (int)type
240+
where val.Type == type
241241
select val.Label).ToList();
242242

243243
var valuePicker = Instantiate(_timeLine.EntryHudScriptableObject.ValuePicker, transform);
244244
var dropDown = valuePicker.GetComponentInChildren<Dropdown>();
245+
dropDown.SetValueWithoutNotify(-1);
246+
options.Insert(0, "[New Value]");
245247
dropDown.AddOptions(options);
246-
247248
if (parameter.RefrenceValue != null)
248249
dropDown.SetValueWithoutNotify(options.IndexOf(parameter.RefrenceValue.Label ?? ""));
249250
dropDown.onValueChanged.AddListener(
250251
(optionIndex) =>
251252
{
252-
parameter.RefrenceValue = _mainTimeLine.RefrenceValues.FirstOrDefault((value) => value.Label == options[optionIndex]);
253+
if (optionIndex == 0)
254+
{
255+
parameter.RefrenceValue = CreateNewValue(type);
256+
_mainTimeLine.Redraw();
257+
}
258+
else
259+
parameter.RefrenceValue = _mainTimeLine.RefrenceValues.FirstOrDefault((value) => value.Label == options[optionIndex - 1]);
253260
});
254261
return valuePicker;
255262
}
256263

264+
private ValueEntry CreateNewValue(ParameterType type)
265+
{
266+
var newVal = new ValueEntry()
267+
{
268+
Label = $"New {type} Value",
269+
Time = 0,
270+
ParentEntry = null,
271+
Type = type,
272+
Value = null
273+
};
274+
_mainTimeLine.RefrenceValues.Add(newVal);
275+
_subElementBehaviour.SetActiveWindow(SubElementBehaviour.SpecialWindows.ValueEditor);
276+
return newVal;
277+
}
278+
257279
private GameObject EntryWindowNum(ParameterData parameter)
258280
{
259281
if (parameter.IsRefrenceValue)

Assets/Scripts/HUD/ValueEditorBehaviour.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@ public class ValueEditorBehaviour : EntryCollectionHud<ValueEntry>
1212
[SerializeField]
1313
private GameObject _prefabChildValue;
1414

15+
private MainTimeLineBehaviour _mainTimeline;
16+
1517
protected override GameObject CreateEntry(List<ValueEntry> sortedEntries, int i)
1618
{
1719
ValueEntry entry = sortedEntries[i];
1820
var entryName = entry.Label.Clone();
1921
var hasParent = entry.ParentEntry != null;
2022
var go = Instantiate(hasParent ? _prefabChildValue : _prefabEmptyValue, _contentTransform.transform);
21-
go.GetComponentInChildren<Button>().onClick.AddListener(() => RemoveEntry(entry));
23+
go.GetComponentInChildren<Button>().onClick.AddListener(() =>
24+
{
25+
RemoveEntry(entry);
26+
_mainTimeline.Redraw();
27+
});
2228
var input = go.GetComponentInChildren<InputField>();
2329
if (input != null)
2430
{
2531
input.SetTextWithoutNotify(entry.Label);
2632
input.onEndEdit.AddListener((s) => Rename(entry, s));
2733
}
28-
var type = (ParameterType)(entry.Type % ((int)ParameterType.POS + 1));
34+
var type = (ParameterType)((int)entry.Type % ((int)ParameterType.POS + 1));
2935
GameObject field = null;
3036
switch (type)
3137
{
@@ -50,6 +56,12 @@ protected override GameObject CreateEntry(List<ValueEntry> sortedEntries, int i)
5056
return go;
5157
}
5258

59+
public override void AddEntryAtCursor(ParameterType entryType)
60+
{
61+
base.AddEntryAtCursor(entryType);
62+
_mainTimeline.Redraw();
63+
}
64+
5365
private GameObject NewVec2Field(ValueEntry entry, GameObject go)
5466
{
5567
GameObject field = Instantiate(EntryHudScriptableObject.Vec2Field, go.transform);
@@ -115,6 +127,7 @@ private GameObject NewNumField(ValueEntry entry, GameObject go)
115127
private void Rename(ValueEntry entry, string s)
116128
{
117129
entry.Label = s;
130+
_mainTimeline.Redraw();
118131
Redraw();
119132
}
120133

@@ -123,14 +136,15 @@ protected override void DisplayDropDownMenu(Dropdown dropDown)
123136
dropDown.AddOptions(Enum.GetNames(typeof(ParameterType)).ToList());
124137
dropDown.onValueChanged.AddListener((i) =>
125138
{
126-
AddNewEntryAtCursor(i);
139+
AddEntryAtCursor((ParameterType)i);
127140
UnlockCursorLine();
128141
Destroy(dropDown.gameObject);
129142
});
130143
}
131144

132145
internal override void SetEntries(List<ValueEntry> timeLineEntries)
133146
{
147+
_mainTimeline = FindObjectOfType<MainTimeLineBehaviour>();
134148
_entryPrefabs = new GameObject[] {
135149
_prefabEmptyValue,
136150
_prefabChildValue,

Assets/Scripts/HUD/ValueEntry.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public class ValueEntry : Entry
1515

1616
public override bool IsParentingType()
1717
{
18-
return Type > (int)ParameterType.POS;
18+
return Type > ParameterType.POS;
1919
}
2020
}

Packages/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"com.unity.ide.rider": "2.0.5",
44
"com.unity.ide.visualstudio": "2.0.2",
55
"com.unity.ide.vscode": "1.2.1",
6-
"com.unity.test-framework": "1.1.14",
7-
"com.unity.textmeshpro": "3.0.0-preview.1",
6+
"com.unity.test-framework": "1.1.16",
7+
"com.unity.textmeshpro": "3.0.1",
88
"com.unity.timeline": "1.4.0-preview.5",
99
"com.unity.ugui": "1.0.0",
1010
"com.unity.vectorgraphics": "2.0.0-preview.12",

Packages/packages-lock.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"url": "https://packages.unity.com"
3838
},
3939
"com.unity.test-framework": {
40-
"version": "1.1.14",
40+
"version": "1.1.16",
4141
"depth": 0,
4242
"source": "registry",
4343
"dependencies": {
@@ -48,7 +48,7 @@
4848
"url": "https://packages.unity.com"
4949
},
5050
"com.unity.textmeshpro": {
51-
"version": "3.0.0-preview.1",
51+
"version": "3.0.1",
5252
"depth": 0,
5353
"source": "registry",
5454
"dependencies": {
@@ -68,7 +68,8 @@
6868
"depth": 0,
6969
"source": "builtin",
7070
"dependencies": {
71-
"com.unity.modules.ui": "1.0.0"
71+
"com.unity.modules.ui": "1.0.0",
72+
"com.unity.modules.imgui": "1.0.0"
7273
}
7374
},
7475
"com.unity.vectorgraphics": {

ProjectSettings/ProjectVersion.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
m_EditorVersion: 2020.1.0f1
2-
m_EditorVersionWithRevision: 2020.1.0f1 (2ab9c4179772)
1+
m_EditorVersion: 2020.1.2f1
2+
m_EditorVersionWithRevision: 2020.1.2f1 (7b32bc54ba47)

0 commit comments

Comments
 (0)