private void Update()
        {
            highlightController.UpdateHighlightedObject(new Vector3(Screen.width / 2, Screen.height / 2));
            highlightController.MouseControls();

            DebugKeyboardControls();

            ///////////////////////////////////////////////////////////////////////////
            // we are not in focus mode, so use WASD and mouse to move around
            if (FPSEnabled)
            {
                FPSInput();
                if (Cursor.visible == false)
                {
                    // accept input to update view based on mouse input
                    MouseRotateView();
                }
            }
        }
Esempio n. 2
0
        // public void TeleportAgent(string actionStr) {
        //     var command = new ServerAction();
        //     JsonUtility.FromJsonOverwrite(actionStr, command);
        //     PhysicsController.ProcessControlCommand(command);
        // }

        void Update()
        {
            highlightController.UpdateHighlightedObject(Input.mousePosition);
            highlightController.MouseControls();

            if (PhysicsController.ReadyForCommand)
            {
                handMode = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                float WalkMagnitude = 0.25f;
                if (!handMode && !hidingPhase)
                {
                    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.LeftArrow))//|| Input.GetKeyDown(KeyCode.J))
                    {
                        ServerAction action = new ServerAction();
                        // action.action = "RotateLeft";
                        action.action   = "RotateLeftSmooth";
                        action.timeStep = 0.4f;
                        PhysicsController.ProcessControlCommand(action);
                    }

                    if (Input.GetKeyDown(KeyCode.RightArrow))//|| Input.GetKeyDown(KeyCode.L))
                    {
                        ServerAction action = new ServerAction();
                        // action.action = "RotateRight";
                        action.action   = "RotateRightSmooth";
                        action.timeStep = 0.4f;
                        PhysicsController.ProcessControlCommand(action);
                    }
                }



                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.y += HandMoveMagnitude;
                    }
                    else if (Input.GetKeyDown(KeyCode.S))
                    {
                        localPos.y -= HandMoveMagnitude;
                    }
                    else if (Input.GetKeyDown(KeyCode.UpArrow))
                    {
                        localPos.z += HandMoveMagnitude;
                    }
                    else if (Input.GetKeyDown(KeyCode.DownArrow))
                    {
                        localPos.z -= HandMoveMagnitude;
                    }
                    else if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
                    {
                        localPos.x -= HandMoveMagnitude;
                    }
                    else if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
                    {
                        localPos.x += HandMoveMagnitude;
                    }
                    if (actionName != "" && localPos.sqrMagnitude > 0)
                    {
                        ServerAction action = new ServerAction {
                            action = "MoveHandForce",
                            x      = localPos.x,
                            y      = localPos.y,
                            z      = localPos.z
                        };
                        this.PhysicsController.ProcessControlCommand(action);
                    }

                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        SetObjectVisible(true);
                        var action = new ServerAction {
                            action      = "DropHandObject",
                            forceAction = true
                        };
                        this.PhysicsController.ProcessControlCommand(action);
                    }
                }
                else if (handMode)
                {
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        var withinReach = PhysicsController.FindObjectInVisibleSimObjPhysics(onlyPickableObjectId) != null;
                        if (withinReach)
                        {
                            ServerAction action = new ServerAction();
                            action.objectId = onlyPickableObjectId;
                            action.action   = "PickupObject";
                            PhysicsController.ProcessControlCommand(action);
                        }
                    }
                }
                if ((Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.C) || Input.GetKeyDown(KeyCode.RightControl)) && PhysicsController.ReadyForCommand)
                {
                    ServerAction action = new ServerAction();
                    if (this.PhysicsController.isStanding())
                    {
                        action.action = "Crouch";
                        PhysicsController.ProcessControlCommand(action);
                    }
                    else
                    {
                        action.action = "Stand";
                        PhysicsController.ProcessControlCommand(action);
                    }
                }

                if (PhysicsController.WhatAmIHolding() != null)
                {
                    if (Input.GetKeyDown(KeyCode.Space) && !hidingPhase && !handMode)
                    {
                        SetObjectVisible(!visibleObject);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
Esempio n. 4
0
        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);
                    }
                }
            }
        }