summaryrefslogtreecommitdiff
path: root/GameCode/MenuControllerToggler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'GameCode/MenuControllerToggler.cs')
-rw-r--r--GameCode/MenuControllerToggler.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/GameCode/MenuControllerToggler.cs b/GameCode/MenuControllerToggler.cs
new file mode 100644
index 0000000..465cf16
--- /dev/null
+++ b/GameCode/MenuControllerToggler.cs
@@ -0,0 +1,75 @@
+using System;
+using UnityEngine;
+
+public class MenuControllerToggler : MonoBehaviour
+{
+ public bool creatorControl;
+
+ public GameObject controllerObject;
+
+ public GameObject keyboardObject;
+
+ private CharacterCreator creator;
+
+ private void Awake()
+ {
+ CharacterCreator componentInParent = GetComponentInParent<CharacterCreator>();
+ if (componentInParent.playerActions == null)
+ {
+ if (creatorControl)
+ {
+ componentInParent.SwitchAction = (Action<MenuControllerHandler.MenuControl>)Delegate.Combine(componentInParent.SwitchAction, new Action<MenuControllerHandler.MenuControl>(Switch));
+ Switch(GetComponentInParent<CharacterCreator>().currentControl);
+ }
+ else
+ {
+ MenuControllerHandler instance = MenuControllerHandler.instance;
+ instance.switchControlAction = (Action<MenuControllerHandler.MenuControl>)Delegate.Combine(instance.switchControlAction, new Action<MenuControllerHandler.MenuControl>(Switch));
+ Switch(MenuControllerHandler.menuControl);
+ }
+ }
+ }
+
+ private void OnEnable()
+ {
+ CharacterCreator componentInParent = GetComponentInParent<CharacterCreator>();
+ if (componentInParent.playerActions != null)
+ {
+ componentInParent.SwitchAction = (Action<MenuControllerHandler.MenuControl>)Delegate.Combine(componentInParent.SwitchAction, new Action<MenuControllerHandler.MenuControl>(Switch));
+ if (componentInParent.inputType == GeneralInput.InputType.Controller)
+ {
+ Switch(MenuControllerHandler.MenuControl.Controller);
+ }
+ if (componentInParent.inputType == GeneralInput.InputType.Keyboard)
+ {
+ Switch(MenuControllerHandler.MenuControl.Mouse);
+ }
+ }
+ }
+
+ private void Switch(MenuControllerHandler.MenuControl control)
+ {
+ if (control == MenuControllerHandler.MenuControl.Controller)
+ {
+ if ((bool)controllerObject)
+ {
+ controllerObject.SetActive(value: true);
+ }
+ if ((bool)keyboardObject)
+ {
+ keyboardObject.SetActive(value: false);
+ }
+ }
+ else
+ {
+ if ((bool)controllerObject)
+ {
+ controllerObject.SetActive(value: false);
+ }
+ if ((bool)keyboardObject)
+ {
+ keyboardObject.SetActive(value: true);
+ }
+ }
+ }
+}