-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuHandler.cs
More file actions
84 lines (68 loc) · 1.76 KB
/
Copy pathMenuHandler.cs
File metadata and controls
84 lines (68 loc) · 1.76 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
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
public class MenuHandler : MonoBehaviour
{
[SerializeField]
private RectTransform selector;
[SerializeField]
private List<MenuButton> buttons;
private int indexNow;
public MenuButton buttonAdd
{
set
{
buttons.Add(value);
buttons[buttons.Count - 1].Set(buttons.Count - 1, this);
}
}
private void Awake()
{
for (int i = 0; i < buttons.Count; ++i)
{
buttons[i].Set(i, this);
}
indexNow = 0;
CheckButtonSelected(indexNow);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void ClickButton(int index)
{
if (CheckButtonSelected(index))
{
buttons[index].events.Invoke();
}
}
private bool CheckButtonSelected(int index)
{
if (!gameObject.activeSelf || !enabled || buttons.Count < 1)
return false;
if (indexNow == index)
return true;
indexNow = index;
if (indexNow < 0)
indexNow = buttons.Count - 1;
if (indexNow >= buttons.Count)
indexNow = 0;
selector.SetParent(buttons[index].rectTransform);
selector.anchorMin = new Vector2(0, 0);
selector.anchorMax = new Vector2(1, 1);
selector.offsetMin = new Vector2(0, 0);
selector.offsetMax = new Vector2(1, 1);
return false;
}
public void SelectMenu()
{
if (gameObject.activeSelf && enabled)
buttons[indexNow].events.Invoke();
}
}