forked from allenai/ai2thor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiscretePointClickAgentController.cs
153 lines (134 loc) · 6.54 KB
/
DiscretePointClickAgentController.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace UnityStandardAssets.Characters.FirstPerson
{
public class DiscretePointClickAgentController : MonoBehaviour
{
[SerializeField] private float HandMoveMagnitude = 0.1f;
public PhysicsRemoteFPSAgentController PhysicsController = null;
private GameObject InputMode_Text = null;
private ObjectHighlightController highlightController = null;
private GameObject throwForceBar = null;
private bool handMode = false;
void Start()
{
var Debug_Canvas = GameObject.Find("DebugCanvasPhysics");
PhysicsController = gameObject.GetComponent<PhysicsRemoteFPSAgentController>();
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
Debug_Canvas.GetComponent<Canvas>().enabled = true;
highlightController = new ObjectHighlightController(PhysicsController, PhysicsController.maxVisibleDistance, true, false);
}
public void OnEnable() {
InputMode_Text = GameObject.Find("DebugCanvasPhysics/InputModeText");
throwForceBar = GameObject.Find("DebugCanvasPhysics/ThrowForceBar");
if (InputMode_Text) {
InputMode_Text.GetComponent<Text>().text = "Point and Click Mode";
}
if (throwForceBar) {
throwForceBar.SetActive(false);
}
// InputFieldObj = GameObject.Find("DebugCanvasPhysics/InputField");
// TODO: move debug input field script from, Input Field and disable here
}
public void OnDisable() {
if (throwForceBar) {
throwForceBar.SetActive(true);
}
// TODO: move debug input field script from, Input Field and enable here
}
private void executeAction(string actionName, float moveMagnitude) {
Dictionary<string, object> action = new Dictionary<string, object>();
action["action"] = actionName;
action["moveMagnitude"] = moveMagnitude;
PhysicsController.ProcessControlCommand(action);
}
private void executeAction(string actionName) {
Dictionary<string, object> action = new Dictionary<string, object>();
action["action"] = actionName;
PhysicsController.ProcessControlCommand(action);
}
void Update()
{
highlightController.UpdateHighlightedObject(Input.mousePosition);
highlightController.MouseControls();
if (PhysicsController.ReadyForCommand) {
float WalkMagnitude = 0.25f;
if (!handMode) {
if(Input.GetKeyDown(KeyCode.W))
{
executeAction("MoveAhead", WalkMagnitude);
}
if(Input.GetKeyDown(KeyCode.S))
{
executeAction("MoveBack", WalkMagnitude);
}
if(Input.GetKeyDown(KeyCode.A))
{
executeAction("MoveLeft", WalkMagnitude);
}
if(Input.GetKeyDown(KeyCode.D))
{
executeAction("MoveRight", WalkMagnitude);
}
if(Input.GetKeyDown(KeyCode.UpArrow))
{
executeAction("LookUp");
}
if(Input.GetKeyDown(KeyCode.DownArrow))
{
executeAction("LookDown");
}
if(Input.GetKeyDown(KeyCode.LeftArrow) )//|| Input.GetKeyDown(KeyCode.J))
{
executeAction("RotateLeft");
}
if(Input.GetKeyDown(KeyCode.RightArrow) )//|| Input.GetKeyDown(KeyCode.L))
{
executeAction("RotateRight");
}
}
if (Input.GetKeyDown(KeyCode.LeftShift)) {
handMode = true;
}
else if (Input.GetKeyUp(KeyCode.LeftShift)){
handMode = false;
}
if (this.PhysicsController.WhatAmIHolding() != null && handMode)
{
var actionName = "MoveHandForce";
var localPos = new Vector3(0, 0, 0);
// Debug.Log(" Key down shift ? " + Input.GetKey(KeyCode.LeftAlt) + " up " + Input.GetKeyDown(KeyCode.UpArrow));
if (Input.GetKeyDown(KeyCode.W)) {
localPos.z += HandMoveMagnitude;
}
else if (Input.GetKeyDown(KeyCode.S)) {
localPos.z -= HandMoveMagnitude;
}
else if (Input.GetKeyDown(KeyCode.UpArrow)) {
localPos.y += HandMoveMagnitude;
}
else if (Input.GetKeyDown(KeyCode.DownArrow)) {
localPos.y -= HandMoveMagnitude;
}
else if (Input.GetKeyDown(KeyCode.LeftArrow)) {
localPos.x -= HandMoveMagnitude;
}
else if (Input.GetKeyDown(KeyCode.RightArrow)) {
localPos.x += HandMoveMagnitude;
}
if (actionName != "") {
Dictionary<string, object> action = new Dictionary<string, object>();
action["action"] = actionName;
action["x"] = localPos.x;
action["y"] = localPos.y;
action["z"] = localPos.z;
this.PhysicsController.ProcessControlCommand(action);
}
}
}
}
}
}