Newer
Older
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class ToolModeSelector : MonoBehaviour
{
private Button[] Buttons;
private HideUI_mobile UIManager2;
private Canvas UIManager_Canvas;
private bool Showing = true;
private bool initUpdate = false;
// Start is called before the first frame update
void Start()
{
if (UIconfig.ToolModeSelector_HandlerMode == 1)
{
if (UIconfig.FrameITUIversion == 1)
{
activeGadgetScaleFactor = 1.5f;
}
if (UIconfig.FrameITUIversion == 2)
{
activeGadgetScaleFactor = 2.1f;
}
myStart();
}
if (UIconfig.ToolModeSelector_HandlerMode == 2)
{
initUpdate = false;
myStart();
}
}
public void myStart()
{
//Requires buttons to be in the same order as the toolmode enum
//We could fully generate the buttons instead if we have icons with file names matching the enums
var buttons = GetComponentsInChildren<Button>();
Buttons = buttons.OrderBy(x => x.transform.position.x).ToArray();
ParentCanvas = GetComponentInParent<Canvas>();
for (int i = 0; i < Buttons.Length; ++i)
{
int copiedIndex = i; //this is important
var button = Buttons[i];
button.onClick.AddListener(() => Select(copiedIndex));
Buttons[GadgetManager.activeGadget.id].transform.localScale *= activeGadgetScaleFactor;
if (UIconfig.FrameITUIversion == 1)
{
UIManager = GetComponentInParent<HideUI>();
//UIManager_Canvas = GetComponentInParent<HideUI>().UICanvas;
activeGadgetScaleFactor = 1.5f;
}
if (UIconfig.FrameITUIversion == 2)
{
UIManager_Canvas = GetComponentInParent<HideUI_mobile>().UICanvas;
UIManager2 = GetComponentInParent<HideUI_mobile>();
activeGadgetScaleFactor = 2.1f;
}
initUpdate = true;
}
public void Select(int id)
{
Buttons[GadgetManager.activeGadget.id].transform.localScale /= activeGadgetScaleFactor;
CommunicationEvents.ToolModeChangedEvent.Invoke(id);
Buttons[GadgetManager.activeGadget.id].transform.localScale *= activeGadgetScaleFactor;
StartCoroutine(HideRoutine());
}
IEnumerator HideRoutine()
{
ParentCanvas.enabled = false;
}
}
// Update is called once per frame
void Update()
//Used for reactivating of the Hitboxes for the pointer Gadget
if(GadgetFirstUse == 0)
{
int id1 = 1;
Select(id1);
GadgetFirstUse++;
}
if (GadgetFirstUse == 1)
{
int id0 = 0;
Select(id0);
GadgetFirstUse++;
}
if (initUpdate == true) {
Update2();
}
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
159
160
161
162
163
164
165
166
void Update2()
{
if (CommunicationEvents.takeNewToolID)
{
CheckToolModeSelection_set1();
}
else
{
if (UIconfig.FrameITUIversion == 1)
{
//Check if the ToolMode was switched
if (!UIManager.UICanvas.enabled)
//if (!UIManager_Canvas.enabled)
{
CheckToolModeSelection();
}
}
if (UIconfig.FrameITUIversion == 2)
{
//Check if the ToolMode was switched
if (!UIManager_Canvas.enabled)
//if (!UIManager2.enabled) //funktioniert nicht
{
CheckToolModeSelection();
}
}
}
CommunicationEvents.ToolID_selected = GadgetManager.activeGadget.id;
}
//Checks if the ToolMode was switched by User, and handle it
void CheckToolModeSelection()
{
if (Input.GetButtonDown("ToolMode"))
{
Gadget tempActiveGadget = GadgetManager.activeGadget;
int id = (tempActiveGadget.id + 1) % GadgetManager.gadgets.Length;
else if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
Gadget tempActiveGadget = GadgetManager.activeGadget;
int move = (int)Mathf.Sign(Input.GetAxis("Mouse ScrollWheel"));
move = tempActiveGadget.id + move;
CheckToolModeSelection_subF1(move);
void CheckToolModeSelection_set1()
{
int move = (int)CommunicationEvents.ToolID_new;
CheckToolModeSelection_subF1(move);
CommunicationEvents.takeNewToolID = false;
}
void CheckToolModeSelection_subF1(int move)
{
int id = (move) % Buttons.Length;// GadgetManager.gadgets.Length;
if (id < 0) id = Buttons.Length - 1;// GadgetManager.gadgets.Length-1;
Select(id);
//print("subF1 select " + id);
}