private void OnRotationGesture(RotationGestureInfo info)
        {
            VR_Controller controller = grabbable.GrabController;

            float angle = Vector2.Angle(controller.transform.up, Vector2.up);

            //no enought rotation
            if (angle < reloadAngle)
            {
                return;
            }

            float dir = (controller.ControllerType == VR_ControllerType.Right ? 1.0f : -1.0f);

            angle = Vector3.Angle(controller.transform.right * dir, Vector3.up);

            //is the weapon facing the wrong direction?
            if (angle > 40.0f)
            {
                return;
            }

            barrelScript.Reload(dir, delegate
            {
                UpdateUI();
            });
        }
示例#2
0
        public void UpdatePositionAndRotation(VR_Controller controller, AimRaycastInfo info)
        {
            if (!marker.activeInHierarchy)
            {
                marker.SetActive(true);
            }

            marker.transform.position = info.hitPoint;
            marker.transform.up       = info.normal;


            Vector2 controllerInput     = controller.Input.GetJoystickInput().normalized;
            Vector3 controllerDirection = new Vector3(controllerInput.x, 0.0f, controllerInput.y);

            //get controller pointing direction in world space
            controllerDirection = controller.transform.TransformDirection(controllerDirection);

            //get marker forward in local space
            Vector3 forward = marker.transform.InverseTransformDirection(marker.transform.forward);

            //find the angle diference betwen the controller pointing direction and marker current forward
            float angle = Vector2.SignedAngle(new Vector2(controllerDirection.x, controllerDirection.z), new Vector2(forward.x, forward.z));

            //rotate marker in local space to match controller pointing direction
            marker.transform.Rotate(Vector3.up, angle, Space.Self);
        }
示例#3
0
 // Start is called before the first frame update
 void Awake()
 {
     vrCon    = GameObject.Find(Constants.VR_Tag).GetComponent <VR_Controller>();
     inVRMode = vrCon.IsVRMode();
     hand     = GameObject.FindGameObjectWithTag(Constants.HandTag);
     Debug.Assert(hand != null);
 }
示例#4
0
        private void Awake()
        {
            thisGrabbable = GetComponent <VR_Grabbable>();
            player        = GameObject.FindGameObjectWithTag("Player").transform;

            if (stringController == null)
            {
                stringController = transform.GetComponentInChildren <BowStringController>();
            }

            bowStringController.Grabbable.OnGrabStateChange.AddListener(OnStringGrabStateChange);
            thisGrabbable.OnGrabStateChange.AddListener(OnThisGrabStateChange);

            leftController  = VR_Manager.instance.LeftController;
            rightController = VR_Manager.instance.RightController;

            //try to get the grabzone
            if (arrowGrabZone == null && bowControlMode == BowControlMode.Realistic)
            {
                arrowGrabZone = FindArrowGrabbableZone();

                if (arrowGrabZone == null)
                {
                    Debug.LogError("Realistic bow needs a arrow grabzone in order to work!");
                }
            }

            if (arrowGrabZone != null)
            {
                arrowGrabZone.enabled = false;
            }
        }
示例#5
0
    void Start()
    {
        placement         = GetComponent <Placement>();
        placementRenderer = GetComponent <Renderer>();

        others          = new List <VRPlacementSelector>();
        otherPlacements = new List <Placement>();

        FindPlacements();

        selected = false;
        GameObject canvasGO = transform.GetChild(0).gameObject;

        VR_Controller vrCon = GameObject.Find(Constants.VR_Tag).GetComponent <VR_Controller>();

        if (vrCon.IsVRMode())
        {
            inVRMode = true;
            Canvas can = canvasGO.GetComponent <Canvas>();
            can.worldCamera = GameObject.Find(Constants.VR_PointerTag).GetComponent <Camera>();
            return;
        }

        inVRMode = false;
        enabled  = false;
        canvasGO.SetActive(false);
    }
示例#6
0
 private void SetControlPositionMode(VR_Controller controller, MotionControlMode mode)
 {
     if (controller.ControlPositionMode != mode)
     {
         controller.SetPositionControlMode(mode);
         controller.SetRotationControlMode(mode);
     }
 }
示例#7
0
    // Use this for initialization
    void Start()
    {
        simulator                  = new GameObject().AddComponent <Rigidbody>();
        simulator.name             = "simulator";
        simulator.transform.parent = transform.parent;

        controller = GetComponent <VR_Controller>();
    }
示例#8
0
        private void PostTeleportUpdate()
        {
            teleportMarker.Hide();
            lastActiveController = null;
            lastRaycastInfo      = null;

            currentTeleportState = TeleporState.WaitingInput;
        }
    // Start is called before the first frame update
    void Start()
    {
        placements = new List <VRPlacementSelector>();
        cards      = new List <Card.VRCardSelector>();
        vrCon      = GameObject.Find(Constants.VR_Tag).GetComponent <VR_Controller>();
        inVRMode   = vrCon.IsVRMode();

        FindPlacements();
        FindCards();
    }
示例#10
0
 private void CheckIfCanUseGrabbeArrow()
 {
     if (bowControlMode == BowControlMode.Realistic && currentArrow == null && CanUseArrow())
     {
         VR_Controller controller = thisGrabbable.GrabController == rightController ? leftController : rightController;
         GameObject    go         = controller.CurrentGrab.gameObject;
         controller.CurrentGrab.ForceDrop();
         controller.ForceGrab(bowStringController.Grabbable);
         UseArrow(go.GetComponent <Arrow>());
     }
 }
示例#11
0
        void Start()
        {
            InitMercenary();

            VR_Controller vrCon = GameObject.Find(Constants.VR_Tag).GetComponent <VR_Controller>();

            if (vrCon.IsVRMode())
            {
                inVRMode = true;
                return;
            }

            dragScript = GetComponent <DragCard>();
            canGroup   = GetComponent <CanvasGroup>();
            hand       = GameObject.FindGameObjectWithTag(Constants.HandTag);
            cam        = GameObject.FindWithTag(Constants.CameraTag).GetComponent <Camera>();
        }
示例#12
0
        void Start()
        {
            selected            = false;
            selectionBackground = transform.Find("Selected").gameObject;
            selectionBackground.SetActive(false);

            VR_Controller vrCon = GameObject.Find(Constants.VR_Tag).GetComponent <VR_Controller>();

            if (vrCon.IsVRMode())
            {
                inVRMode = true;
                return;
            }

            inVRMode = false;
            enabled  = false;
        }
示例#13
0
        private void EnterPreviewMode(VR_Controller controller)
        {
            targetScript = (HandVisualizerTool)target;

            grabbable = targetScript.GetComponent <VR_Grabbable>();
            grabbable.gameObject.AddComponent <GameObjectMarker>();
            EditorSceneManager.MarkAllScenesDirty();
            EditorSceneManager.SaveOpenScenes();

            grabbableClone   = Instantiate(grabbable, grabbable.transform.position, grabbable.transform.rotation);
            activeController = Instantiate(controller, grabbable.RightInteractPoint.position, Quaternion.identity);

            grabbableClone.SetEditorGrabPositionAndRotation(activeController);



            HandPreviewManager.EnterPreviewMode(grabbableClone.transform.root.gameObject);
        }
示例#14
0
        void Start()
        {
            VR_Controller vrCon = GameObject.Find(Constants.VR_Tag).GetComponent <VR_Controller>();

            if (vrCon.IsVRMode())
            {
                //enabled = false;
                inVRMode = true;
                return;
            }

            inVRMode = false;

            canGroup = GetComponent <CanvasGroup>();

            cardSize = GameObject.FindGameObjectWithTag(Constants.DeckManager).GetComponent <Deck>().GetCardSize();
            hand     = GameObject.FindGameObjectWithTag(Constants.HandTag);
        }
示例#15
0
    // Start is called before the first frame update
    void Start()
    {
        VR_Controller vrCon = GameObject.Find(Constants.VR_Tag).GetComponent <VR_Controller>();

        if (vrCon.IsVRMode())
        {
            inVRMode = true;
        }
        else
        {
            inVRMode = false;
        }

        pose          = GetComponent <SteamVR_Behaviour_Pose>();
        hasPosition   = false;
        isTeleporting = false;
        fadeTime      = 0.5f;
    }
示例#16
0
        private bool CanUseArrow()
        {
            VR_Controller targetController = thisGrabbable.GrabController == rightController ? leftController : rightController;

            if (targetController.CurrentGrab == null)
            {
                return(false);
            }

            if (GetDistanceToController() > stringGrabDistance)
            {
                return(false);
            }

            Arrow arrow = targetController.CurrentGrab.GetComponent <Arrow>();

            return(arrow != null);
        }
示例#17
0
    private void Awake()
    {
        VR_Controller vrCon = GameObject.Find(Constants.VR_Tag).GetComponent <VR_Controller>();

        if (vrCon.IsVRMode())
        {
            inVRMode = true;
        }
        else
        {
            inVRMode = false;
        }

        Camera         = GetComponent <Camera>();
        Camera.enabled = false;

        lineRenderer = GetComponent <LineRenderer>();

        pointerRay = new Ray(transform.position, transform.forward);
    }
示例#18
0
        public static void EnterPreviewMode(GameObject clone)
        {
            Scene originalScene = EditorSceneManager.GetActiveScene();

            originalScenePath = EditorApplication.currentScene;

            Scene previewScene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Additive);

            EditorSceneManager.MoveGameObjectToScene(clone, previewScene);

            EditorSceneManager.UnloadSceneAsync(originalScene);
            previewModeEnable  = true;
            inspectedGrabbable = GameObject.FindObjectOfType <VR_Grabbable>();
            activeController   = GameObject.FindObjectOfType <VR_Controller>();

            OverrideGrabAnimation();

            activeController.Animator.SetBool("IsGrabbing", true);

            EditorApplication.update += Update;
        }
示例#19
0
    // Start is called before the first frame update
    void Start()
    {
        hitAgent        = new RaycastHit();
        initialPosition = Constants.NullVector3;
        zeroXRotation   = new Vector3(0, 0, 0);

        GameObject vrconGO = GameObject.Find(Constants.VR_Tag);

        if (vrconGO == null)
        {
            cam = gameObject.GetComponent <Camera>();
        }
        else
        {
            vrcon = vrconGO.GetComponent <VR_Controller>();
            if (vrcon.IsVRMode() == false)
            {
                cam = gameObject.GetComponent <Camera>();
            }
        }
    }
示例#20
0
    void Awake()
    {
        if (vrInstance != null)
        {
            Destroy(gameObject);
            return;
        }

        vrInstance = this;
        DontDestroyOnLoad(gameObject);

        if (XRDevice.isPresent)
        {
            vrModeActive = true;
        }
        else
        {
            vrModeActive = false;
        }

        vrPointer = GameObject.Find(Constants.VR_PointerTag);
    }
示例#21
0
        private void OnStringGrabStateChange(GrabState state)
        {
            if (state == GrabState.Grab && currentArrow == null)
            {
                if (bowControlMode == BowControlMode.Unrealistic)
                {
                    CreateArrow();
                    SetArrowRotation();
                }

                arrowController = bowStringController.Grabbable.GrabController;
            }
            else if (state == GrabState.Drop)
            {
                if (currentArrow == null)
                {
                    SetControlPositionMode(arrowController, MotionControlMode.Engine);
                }
                else
                {
                    shootIntent = true;
                }
            }
        }
示例#22
0
 public void Start()
 {
     input = GetComponent <VR_Controller>();
 }
示例#23
0
 private void Start()
 {
     rightController = VR_Manager.instance.RightController;
     leftController  = VR_Manager.instance.LeftController;
 }
示例#24
0
 //set the controller that makes the teleport intent
 private void UpdateActiveController()
 {
     activeController     = GetActiveController();
     lastActiveController = activeController;
 }
示例#25
0
        private float GetDistanceToController()
        {
            VR_Controller targetController = thisGrabbable.GrabController == rightController ? leftController : rightController;

            return(Vector3.Distance(bowStringController.Middle.position, targetController.GrabPoint.position));
        }