summaryrefslogtreecommitdiff
path: root/GameCode/MenuControllerToggler.cs
blob: 465cf16220476f35cf99ab40128ee8b52abc7f00 (plain)
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
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);
			}
		}
	}
}