forked from allenai/ai2thor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscretePointClickAgentController.cs
164 lines (145 loc) · 7.51 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
154
155
156
157
158
159
160
161
162
163
164
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
}
void Update()
{
highlightController.UpdateHighlightedObject(Input.mousePosition);
highlightController.MouseControls();
if (PhysicsController.actionComplete) {
float WalkMagnitude = 0.25f;
if (!handMode) {
if(Input.GetKeyDown(KeyCode.W))
{
ServerAction action = new ServerAction();
action.action = "MoveAhead";
action.moveMagnitude = WalkMagnitude;
PhysicsController.ProcessControlCommand(action);
}
if(Input.GetKeyDown(KeyCode.S))
{
ServerAction action = new ServerAction();
action.action = "MoveBack";
action.moveMagnitude = WalkMagnitude;
PhysicsController.ProcessControlCommand(action);
}
if(Input.GetKeyDown(KeyCode.A))
{
ServerAction action = new ServerAction();
action.action = "MoveLeft";
action.moveMagnitude = WalkMagnitude;
PhysicsController.ProcessControlCommand(action);
}
if(Input.GetKeyDown(KeyCode.D))
{
ServerAction action = new ServerAction();
action.action = "MoveRight";
action.moveMagnitude = WalkMagnitude;
PhysicsController.ProcessControlCommand(action);
}
if(Input.GetKeyDown(KeyCode.UpArrow))
{
ServerAction action = new ServerAction();
action.action = "LookUp";
PhysicsController.ProcessControlCommand(action);
}
if(Input.GetKeyDown(KeyCode.DownArrow))
{
ServerAction action = new ServerAction();
action.action = "LookDown";
PhysicsController.ProcessControlCommand(action);
}
if(Input.GetKeyDown(KeyCode.LeftArrow) )//|| Input.GetKeyDown(KeyCode.J))
{
ServerAction action = new ServerAction();
action.action = "RotateLeft";
PhysicsController.ProcessControlCommand(action);
}
if(Input.GetKeyDown(KeyCode.RightArrow) )//|| Input.GetKeyDown(KeyCode.L))
{
ServerAction action = new ServerAction();
action.action = "RotateRight";
PhysicsController.ProcessControlCommand(action);
}
}
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 != "") {
ServerAction action = new ServerAction
{
action = "MoveHandForce",
x = localPos.x,
y = localPos.y,
z = localPos.z
};
this.PhysicsController.ProcessControlCommand(action);
}
}
}
}
}
}