private void executeAction(string actionName, float moveMagnitude) { Dictionary <string, object> action = new Dictionary <string, object>(); action["action"] = actionName; action["moveMagnitude"] = moveMagnitude; PhysicsController.ProcessControlCommand(action); }
public void Step(string serverAction) { ServerAction controlCommand = new ServerAction(); JsonUtility.FromJsonOverwrite(serverAction, controlCommand); PhysicsController.ProcessControlCommand(controlCommand); }
public void MouseControls() { // Interact action for mouse left-click when nothing is picked up if (Input.GetKeyDown(KeyCode.Mouse0)) { if (this.PhysicsController.WhatAmIHolding() == null && this.PhysicsController.actionComplete) { var closestObj = this.highlightedObject; if (closestObj != null) { var actionName = ""; if (closestObj.PrimaryProperty == SimObjPrimaryProperty.CanPickup && (onlyPickableObjectId == null || onlyPickableObjectId == closestObj.objectID)) { pickupState = true; actionName = "PickupObject"; } else if (closestObj.GetComponent <CanOpen_Object>()) { actionName = closestObj.GetComponent <CanOpen_Object>().isOpen ? "CloseObject" : "OpenObject"; } else if (closestObj.GetComponent <CanToggleOnOff>()) { actionName = closestObj.GetComponent <CanToggleOnOff>().isOn ? "ToggleObjectOff" : "ToggleObjectOn"; } if (actionName != "") { ServerAction action = new ServerAction { action = actionName, objectId = closestObj.objectID }; this.PhysicsController.ProcessControlCommand(action); } } } else if (this.PhysicsController.actionComplete) { this.mouseDownThrow = true; this.timerAtPress = Time.time; } if (highlightWhileHolding && this.highlightedObject != null && this.PhysicsController.WhatAmIHolding() != this.highlightedObject.gameObject && this.PhysicsController.actionComplete) { var closestObj = this.highlightedObject; if (closestObj != null) { var actionName = ""; if (closestObj.GetComponent <CanOpen_Object>()) { actionName = closestObj.GetComponent <CanOpen_Object>().isOpen ? "CloseObject" : "OpenObject"; } if (actionName != "") { ServerAction action = new ServerAction { action = actionName, objectId = closestObj.objectID }; this.PhysicsController.ProcessControlCommand(action); } } // else if (highlightWhileHolding && this.PhysicsController.WhatAmIHolding() == this.highlightedObject) { // } } } //simulate TouchThenApply for in-editor debugging stuff #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Mouse1) && !Input.GetKey(KeyCode.LeftShift)) { ServerAction dothis = new ServerAction(); dothis.action = "TouchThenApplyForce"; dothis.x = 0.5f; dothis.y = 0.5f; dothis.handDistance = 5.0f; dothis.direction = new Vector3(0, 0.1f, 1); dothis.moveMagnitude = 2000f; // dothis.action = "SliceObject"; // dothis.objectId = PhysicsController.GetComponent<PhysicsRemoteFPSAgentController>().ObjectIdOfClosestVisibleObject(); PhysicsController.ProcessControlCommand(dothis); } if (Input.GetKeyDown(KeyCode.Mouse1) && Input.GetKey(KeyCode.LeftShift)) { ServerAction dothis = new ServerAction(); dothis.action = "TouchThenApplyForce"; dothis.x = 0.5f; dothis.y = 0.5f; dothis.handDistance = 5.0f; dothis.direction = new Vector3(0, 0.1f, 1); dothis.moveMagnitude = 15000f; // dothis.action = "PutObject"; // dothis.receptacleObjectId = PhysicsController.ObjectIdOfClosestReceptacleObject(); PhysicsController.ProcessControlCommand(dothis); } #endif // Sets throw bar value if (ThrowEnabled && ThrowForceBarSlider != null) { if (this.mouseDownThrow) { var diff = Time.time - this.timerAtPress; var clampedForceTime = Mathf.Min(diff * diff, MaxChargeThrowSeconds); ThrowForceBarSlider.value = clampedForceTime / MaxChargeThrowSeconds; } else { ThrowForceBarSlider.value -= ThrowForceBarSlider.value > 0.0f ? Time.deltaTime / MaxChargeThrowSeconds : 0.0f; } } // Throw action on left click release if (Input.GetKeyUp(KeyCode.Mouse0)) { if (!pickupState) { if (this.PhysicsController.WhatAmIHolding() != null) { var diff = Time.time - this.timerAtPress; var clampedForceTime = Mathf.Min(diff * diff, MaxChargeThrowSeconds); var force = clampedForceTime * MaxThrowForce / MaxChargeThrowSeconds; if (this.PhysicsController.actionComplete && (!this.highlightWhileHolding || (highlightedObject != null && this.PhysicsController.WhatAmIHolding() == highlightedObject.gameObject))) { ServerAction action; if (ThrowEnabled) { action = new ServerAction { action = "ThrowObject", moveMagnitude = force, forceAction = true }; } else { action = new ServerAction { action = "DropHandObject", forceAction = true }; } this.PhysicsController.ProcessControlCommand(action); this.mouseDownThrow = false; } } } else { pickupState = false; } } }
public void SpawnObjectToHide(string objectMeta) { var objectData = new ObjectSpanwMetadata(); Debug.Log(objectMeta); JsonUtility.FromJsonOverwrite(objectMeta, objectData); ServerAction action = new ServerAction() { action = "CreateObject", objectType = objectData.objectType, objectVariation = objectData.objectVariation }; PhysicsController.ProcessControlCommand(action); onlyPickableObjectId = objectData.objectType + "|" + objectData.objectVariation; this.highlightController.SetOnlyPickableId(onlyPickableObjectId); // DisableObjectCollisionWithAgent(onlyPickableObjectId); }
private void DebugKeyboardControls() { //swap between text input and not if (Input.GetKeyDown(KeyCode.BackQuote) || Input.GetKeyDown(KeyCode.Escape)) { //Switch to Text Mode if (TextInputMode == false) { InputMode_Text.GetComponent <Text>().text = "Text Input Mode"; TextInputMode = true; Cursor.visible = true; Cursor.lockState = CursorLockMode.None; return; } //Switch to Mouse and Keyboard Mode if (TextInputMode == true) { InputMode_Text.GetComponent <Text>().text = "Free Mode"; TextInputMode = false; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; return; } } // Interact action for mouse left-click if (Input.GetKeyDown(KeyCode.Mouse0)) { if (TextInputMode == false) { if (this.PhysicsController.WhatAmIHolding() == null && this.PhysicsController.actionComplete) { var closestObj = this.highlightedObject; if (closestObj != null) { var actionName = ""; if (closestObj.PrimaryProperty == SimObjPrimaryProperty.CanPickup) { pickupState = true; actionName = "PickupObject"; } else if (closestObj.GetComponent <CanOpen_Object>()) { actionName = closestObj.GetComponent <CanOpen_Object>().isOpen ? "CloseObject" : "OpenObject"; } else if (closestObj.GetComponent <CanToggleOnOff>()) { actionName = closestObj.GetComponent <CanToggleOnOff>().isOn ? "ToggleObjectOff" : "ToggleObjectOn"; } if (actionName != "") { ServerAction action = new ServerAction { action = actionName, objectId = closestObj.uniqueID }; this.PhysicsController.ProcessControlCommand(action); } } } else if (this.PhysicsController.actionComplete) { this.mouseDownThrow = true; this.timerAtPress = Time.time; } } } // 1D Scroll for hand movement if (!scroll2DEnabled && this.PhysicsController.WhatAmIHolding() != null) { var scrollAmount = Input.GetAxis("Mouse ScrollWheel"); var eps = 1e-6; if (Mathf.Abs(scrollAmount) > eps) { ServerAction action = new ServerAction { action = "MoveHandAhead", moveMagnitude = scrollAmount }; this.PhysicsController.ProcessControlCommand(action); } } // Sets throw bar value if (this.mouseDownThrow) { var diff = Time.time - this.timerAtPress; var clampedForceTime = Mathf.Min(diff * diff, MaxChargeThrowSeconds); ThrowForceBarSlider.value = clampedForceTime / MaxChargeThrowSeconds; } else { ThrowForceBarSlider.value -= ThrowForceBarSlider.value > 0.0f ? Time.deltaTime / MaxChargeThrowSeconds : 0.0f; } if (Input.GetKeyDown(KeyCode.R)) { var action = new ServerAction { action = "InitialRandomSpawn", randomSeed = 0, forceVisible = false, maxNumRepeats = 5, placeStationary = true }; PhysicsController.ProcessControlCommand(action); } // Throw action on left clock release if (Input.GetKeyUp(KeyCode.Mouse0)) { // Debug.Log("Pickup state " + pickupState + " obj " + this.PhysicsController.WhatAmIHolding()); if (!pickupState) { if (this.PhysicsController.WhatAmIHolding() != null) { var diff = Time.time - this.timerAtPress; var clampedForceTime = Mathf.Min(diff * diff, MaxChargeThrowSeconds); var force = clampedForceTime * MaxThrowForce / MaxChargeThrowSeconds; if (this.PhysicsController.actionComplete) { ServerAction action = new ServerAction { action = "ThrowObject", moveMagnitude = force, forceAction = true }; this.PhysicsController.ProcessControlCommand(action); this.mouseDownThrow = false; //ThrowForceBar.GetComponent<Slider>().value = 0.0f; } } } else { pickupState = false; } } // allow actions only via text input if (TextInputMode == true) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; //if we press enter, select the input field if (Input.GetKeyDown(KeyCode.Return)) { UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(InputFieldObj); } } // no text input, we are in fps mode if (TextInputMode == false) { if (Input.GetKey(KeyCode.Space)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } if (Input.GetKeyUp(KeyCode.Space)) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } } }
void Update() { highlightController.UpdateHighlightedObject(Input.mousePosition); highlightController.MouseControls(); if (PhysicsController.ReadyForCommand) { 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); } } } }
void Update() { //use these for the Breakable Window demo video // if(Input.GetKeyDown(KeyCode.P)) // { // // print("pickup"); // ServerAction action = new ServerAction(); // action.action = "PickupObject"; // action.objectId = Agent.GetComponent<PhysicsRemoteFPSAgentController>().ObjectIdOfClosestVisibleObject(); // PhysicsController.ProcessControlCommand(action); // } // if(Input.GetKeyDown(KeyCode.T)) // { // ServerAction action = new ServerAction(); // action.action = "ThrowObject"; // action.moveMagnitude = 600f; // PhysicsController.ProcessControlCommand(action); // } // if(Input.GetKeyDown(KeyCode.U)) // { // ServerAction action = new ServerAction(); // action.action = "MoveHandMagnitude"; // action.moveMagnitude = 0.1f; // action.x = 0f; // action.y = 1f; // action.z = 0f; // PhysicsController.ProcessControlCommand(action); // } //if we press enter, select the input field if (PhysicsController.ReadyForCommand) { if (Input.GetKeyDown(KeyCode.Return)) { UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(InputFieldObj); } if (!inputField.isFocused) { // float FlyMagnitude = 1.0f; float WalkMagnitude = 0.25f; if (Input.GetKeyDown(KeyCode.W)) { ServerAction action = new ServerAction(); // if(PhysicsController.FlightMode) // { // action.action = "FlyAhead"; // action.moveMagnitude = FlyMagnitude; // PhysicsController.ProcessControlCommand(action); // } // else // { action.action = "MoveAhead"; action.moveMagnitude = WalkMagnitude; PhysicsController.ProcessControlCommand(action); // } } if (Input.GetKeyDown(KeyCode.S)) { ServerAction action = new ServerAction(); // if(PhysicsController.FlightMode) // { // action.action = "FlyBack"; // action.moveMagnitude = FlyMagnitude; // PhysicsController.ProcessControlCommand(action); // } // else // { action.action = "MoveBack"; action.moveMagnitude = WalkMagnitude; PhysicsController.ProcessControlCommand(action); // } } if (Input.GetKeyDown(KeyCode.A)) { ServerAction action = new ServerAction(); // if(PhysicsController.FlightMode) // { // action.action = "FlyLeft"; // action.moveMagnitude = FlyMagnitude; // PhysicsController.ProcessControlCommand(action); // } // else // { action.action = "MoveLeft"; action.moveMagnitude = WalkMagnitude; PhysicsController.ProcessControlCommand(action); // } } if (Input.GetKeyDown(KeyCode.D)) { ServerAction action = new ServerAction(); // if(PhysicsController.FlightMode) // { // action.action = "FlyRight"; // action.moveMagnitude = FlyMagnitude; // PhysicsController.ProcessControlCommand(action); // } // else // { action.action = "MoveRight"; action.moveMagnitude = WalkMagnitude; PhysicsController.ProcessControlCommand(action); // } } // if(Input.GetKeyDown(KeyCode.I)) // { // if(PhysicsController.FlightMode) // { // ServerAction action = new ServerAction(); // action.action = "FlyUp"; // action.moveMagnitude = FlyMagnitude; // PhysicsController.ProcessControlCommand(action); // } // } // if(Input.GetKeyDown(KeyCode.K)) // { // if(PhysicsController.FlightMode) // { // ServerAction action = new ServerAction(); // action.action = "FlyDown"; // action.moveMagnitude = FlyMagnitude; // 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.Space)) // { // if(PhysicsController.FlightMode) // { // ServerAction action = new ServerAction(); // action.action = "LaunchDroneObject"; // action.moveMagnitude = 200f; // //action. = new Vector3(0, 1, -1); // action.x = 0; // action.y = 1; // action.z = -1; // PhysicsController.ProcessControlCommand(action); // } // } // if(Input.GetKeyDown(KeyCode.O)) // { // if(PhysicsController.FlightMode) // { // ServerAction action = new ServerAction(); // action.action = "CheckDroneCaught"; // PhysicsController.ProcessControlCommand(action); // } // } } } }
public void Step(string jsonAction) { PhysicsController.ProcessControlCommand(new DynamicServerAction(jsonAction)); }
private void DebugKeyboardControls() { if (InputFieldObj != null) { InputField inField = InputFieldObj.GetComponentInChildren <InputField>(); if (inField != null) { if (inField.isFocused) { highlightController.ThrowEnabled = false; return; } else { highlightController.ThrowEnabled = true; } } } //swap between text input and not if (Input.GetKeyDown(KeyCode.BackQuote) || Input.GetKeyDown(KeyCode.Escape)) { //Switch to Text Mode if (FPSEnabled) { if (InputMode_Text) { InputMode_Text.GetComponent <Text>().text = "FPS Mode"; } FPSEnabled = false; Cursor.visible = true; Cursor.lockState = CursorLockMode.None; return; } else { if (InputMode_Text) { InputMode_Text.GetComponent <Text>().text = "FPS Mode (mouse free)"; } FPSEnabled = true; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; return; } } // 1D Scroll for hand movement if (!scroll2DEnabled && this.PhysicsController.WhatAmIHolding() != null) { var scrollAmount = Input.GetAxis("Mouse ScrollWheel"); var eps = 1e-6; if (Mathf.Abs(scrollAmount) > eps) { ServerAction action = new ServerAction { action = "MoveHandAhead", moveMagnitude = scrollAmount }; this.PhysicsController.ProcessControlCommand(action); } } if (Input.GetKeyDown(KeyCode.R)) { var action = new ServerAction { action = "InitialRandomSpawn", randomSeed = 0, forceVisible = false, numPlacementAttempts = 5, placeStationary = true }; PhysicsController.ProcessControlCommand(action); } if (Input.GetKey(KeyCode.Space)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } if (Input.GetKeyUp(KeyCode.Space)) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } }