summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Input/InputManager.cs
blob: c1a26327f804d28558dafb5e19c5ac76e3468d33 (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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InputManager : Singleton<InputManager>
{
	private List<Command> m_CommandRecord;
	private Command m_CurrentCommand;

	public void Init()
	{
		m_CommandRecord = new List<Command>();
		m_CurrentCommand = new Command(CommandCode.Blank, 0);
	}

	public void Update()
	{
		CommandCode cmd = CommandCode.Blank;
		// 移动
		if (Input.GetKeyDown("w"))
			cmd = CommandCode.Up;
		if (Input.GetKeyDown("s"))
			cmd = CommandCode.Down;
		if (Input.GetKeyDown("a"))
			cmd = CommandCode.Left;
		if (Input.GetKeyDown("d"))
			cmd = CommandCode.Right;
		// 动作
		if (Input.GetKeyDown("j"))
			cmd = CommandCode.Circle;
		if (Input.GetKeyDown("k"))
			cmd = CommandCode.Triangle;
		if (Input.GetKeyDown("l"))
			cmd = CommandCode.Square;
		if(Input.GetKeyDown("u"))
			cmd = CommandCode.Cross;

		if(cmd != CommandCode.Blank)
		{
			float time = Time.time;
			Command command = new Command(cmd, time);
			Debug.Log(CommandToString(command));
			m_CurrentCommand = command;
			m_CommandRecord.Add(command);
		}
	}

	string CommandCodeToString(CommandCode cmd)
	{
		switch(cmd)
		{
			case CommandCode.Left: return "←";
			case CommandCode.Right: return "→";
			case CommandCode.Up: return "↑";
			case CommandCode.Down: return "↓";
			case CommandCode.Circle: return "○";
			case CommandCode.Triangle: return "△";
			case CommandCode.Square: return "□";
			case CommandCode.Cross: return "×";
			default: return "Unknown";
		}
	}

	string CommandToString(Command cmd)
	{
		string sign = CommandCodeToString(cmd.code);
		return sign + "      " + cmd.time + "s";
	}

}