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(); if (componentInParent.playerActions == null) { if (creatorControl) { componentInParent.SwitchAction = (Action)Delegate.Combine(componentInParent.SwitchAction, new Action(Switch)); Switch(GetComponentInParent().currentControl); } else { MenuControllerHandler instance = MenuControllerHandler.instance; instance.switchControlAction = (Action)Delegate.Combine(instance.switchControlAction, new Action(Switch)); Switch(MenuControllerHandler.menuControl); } } } private void OnEnable() { CharacterCreator componentInParent = GetComponentInParent(); if (componentInParent.playerActions != null) { componentInParent.SwitchAction = (Action)Delegate.Combine(componentInParent.SwitchAction, new Action(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); } } } }