-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIQuickMenuPlacement.cs
More file actions
71 lines (55 loc) · 1.81 KB
/
UIQuickMenuPlacement.cs
File metadata and controls
71 lines (55 loc) · 1.81 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIQuickMenuPlacement : UIQuickMenuPage
{
[SerializeField]
private UIIconButton centerButton;
[SerializeField]
private UIIconButton iconButtonPrefab;
[SerializeField]
private Transform iconButtonParent;
private Dictionary<UISelectable, Character> buttonMap;
private int characterCount;
void Update()
{
if (PlacementController.charactersToPlace.Count != characterCount)
{
characterCount = PlacementController.charactersToPlace.Count;
if (characterCount == 0)
{
menu.Close();
}
else
{
updatePage();
}
}
}
private void updatePage()
{
List<UIIconButton> buttons = new List<UIIconButton>();
buttons.Add(centerButton);
buttonMap = new Dictionary<UISelectable, Character>();
foreach (Character character in PlacementController.charactersToPlace)
{
Character c = character;
UIIconButton iconButton = Instantiate(iconButtonPrefab);
iconButton.SetIconSprite(character.identity.icon);
iconButton.transform.SetParent(iconButtonParent);
iconButton.onClick.AddListener(() => click(c));
buttons.Add(iconButton);
}
for(int i = 0; i < buttons.Count; i++)
{
buttons[i].neighborLeft = buttons[NeverdawnUtility.RepeatIndex(i - 1, buttons.Count)];
buttons[i].neighborRight = buttons[NeverdawnUtility.RepeatIndex(i + 1, buttons.Count)];
}
buttons[0].Select();
}
private void click(Character character)
{
menu.Close();
avatarController.PlaceCharacter(character);
}
}