Newer
Older
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PiUIManager : MonoBehaviour
{
[SerializeField] UnityStandardAssets.Characters.FirstPerson.FirstPersonController FPSC;
public NameMenuPair[] nameMenu;
private Dictionary<string, PiUI> dict = new Dictionary<string, PiUI>( );
private void Awake()
{
foreach(NameMenuPair pair in nameMenu)
{
dict.Add(pair.name, pair.menu);
}
transform.localScale = new Vector3(1f / Screen.width, 1f / Screen.height);
transform.position = Vector2.zero;
}
/// <summary>
/// Will open/close the menu name passed at the position passed.
/// </summary>
/// <param name="menuName">Menu to open or close.</param>
/// <param name="pos">Position to open menu.</param>
public void ChangeMenuState(string menuName, Vector2 pos = default(Vector2))
{
FPSC.enabled = !FPSC.enabled;
PiUI currentPi = GetPiUIOf(menuName);
if (currentPi.openedMenu)
{
currentPi.CloseMenu( );
}else
{
currentPi.OpenMenu(pos);
}
}
/// <summary>
/// Gets if the passed in piUi is currently opened
/// </summary>
/// <param name="piName"></param>
/// <returns></returns>
public bool PiOpened(string menuName)
{
return GetPiUIOf(menuName).openedMenu;
}
/// <summary>
/// Returns the PiUi for the given menu allowing you to change it as you wish
/// </summary>
public PiUI GetPiUIOf(string menuName)
{
if (dict.ContainsKey(menuName))
{
return dict[menuName];
}
else{
NoMenuOfThatName( );
return null;
}
}
/// <summary>
/// After changing the PiUI.sliceCount value and piData data,call this function with the menu name to recreate the menu, at a given position
/// </summary>
public void RegeneratePiMenu(string menuName,Vector2 newPos = default(Vector2))
{
GetPiUIOf(menuName).GeneratePi(newPos);
}
/// <summary>
/// After changing the PiUI.PiData call this function to update the slices, if sliceCount is changed call RegeneratePiMenu
/// </summary>
public void UpdatePiMenu(string menuName)
{
GetPiUIOf(menuName).UpdatePiUI( );
}
public bool OverAMenu()
{
foreach(KeyValuePair<string,PiUI> pi in dict)
{
if (pi.Value.overMenu)
{
return true;
}
}
return false;
}
private void NoMenuOfThatName()
{
Debug.LogError("No pi menu with that name, please check the name of which you're calling");
}
[System.Serializable]
public class NameMenuPair
{
public string name;
public PiUI menu;
}
//Mods start here
void Update()
{
if (Input.GetKeyDown(KeyCode.Tab)){
ChangeMenuState("Normal Menu", new Vector2(Screen.width / 2f, Screen.height / 2f));
}
if (Input.GetMouseButtonDown(0) && GetPiUIOf("Normal Menu").openedMenu)
{
ChangeMenuState("Normal Menu", new Vector2(Screen.width / 2f, Screen.height / 2f));
}
}
void Start()
{
var normalMenu = GetComponentInChildren<PiUI>();
foreach (PiUI.PiData data in normalMenu.piData)
{
//Changes slice label
//Creates a new unity event and adds the testfunction to it
data.onSlicePressed = new PiUI.SliceEvent();
data.onSlicePressed.AddListener(TestFunction);
}
UpdatePiMenu("Normal Menu");
//Open or close the menu depending on it's current state at the center of the screne
}
private void TestFunction(ToolMode toolMode)
{
Debug.Log(toolMode);
CommunicationEvents.ToolModeChangedEvent.Invoke(toolMode);
}
}