public void Recenter()
    {
        Transform playArea = VRTK_DeviceFinder.PlayAreaTransform();

        if (playArea != null)
        {
            Debug.Log("PlayArea position: " + playArea.position + " rotation " + playArea.rotation);
            playArea.position = Vector3.zero;
            playArea.rotation = Quaternion.identity;
        }
    }
Example #2
0
 protected virtual void OnEnable()
 {
     AvatarTop           = AvatarTop != null ? AvatarTop : NetUtils.Find(gameObject, "Top");
     AvatarHead          = AvatarHead != null ? AvatarHead : NetUtils.Find(gameObject, "Head");
     LeftHand            = LeftHand != null ? LeftHand : NetUtils.Find(gameObject, "Left Hand");
     RightHand           = RightHand != null ? RightHand : NetUtils.Find(gameObject, "Right Hand");
     headsetTransform    = VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.Headset).gameObject.transform;
     leftHandTransform   = VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.LeftController).gameObject.transform;
     rightHandTransform  = VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.RightController).gameObject.transform;
     playAreaTransform   = VRTK_DeviceFinder.PlayAreaTransform();
     Camera.onPreRender += OnCamPreRender;
 }
 private void OnEnable()
 {
     m_playArea = VRTK_DeviceFinder.PlayAreaTransform();
     if (m_playArea != null)
     {
         var container = new GameObject("[Autogenerated][VR_PlayAreaBoxCollider]");
         container.transform.SetParent(m_playArea, false);
         m_boxCollider      = container.AddComponent <BoxCollider>();
         m_boxCollider.size = new Vector3(2.5f, 2, 2.5f);
         m_boxCollider.transform.localPosition = new Vector3(0, 1, 0);
         m_boxCollider.isTrigger = true;
     }
 }
Example #4
0
    // Use this for initialization
    protected virtual void OnEnable()
    {
        Transform playArea = VRTK_DeviceFinder.PlayAreaTransform();

        if (playArea && SpawnPoint)
        {
            playArea.position = SpawnPoint.transform.position;
        }
        else
        {
            Debug.LogError("Play Area or Spawn Point undefined. Could not spawn at object.");
        }
    }
Example #5
0
 // Update is called once per frame
 void Update()
 {
     if (playArea == null)
     {
         playArea = VRTK_DeviceFinder.PlayAreaTransform();
         headset  = VRTK_DeviceFinder.HeadsetTransform();
     }
     else if (playArea != null && headset != null)
     {
         transform.position = new Vector3(headset.position.x, playArea.position.y, headset.position.z);
         transform.rotation = Quaternion.Euler(0, headset.eulerAngles.y, 0);
     }
 }
 protected virtual void SetupPlayArea()
 {
     playArea = VRTK_DeviceFinder.PlayAreaTransform();
     if (playArea != null)
     {
         lastPlayAreaPosition = playArea.position;
         collisionTracker     = playArea.GetComponent <VRTK_CollisionTracker>();
         if (collisionTracker == null)
         {
             collisionTracker = playArea.gameObject.AddComponent <VRTK_CollisionTracker>();
         }
         ManageCollisionListeners(true);
     }
 }
Example #7
0
 // Update is called once per frame
 void Update()
 {
     if (playArea == null)
     {
         playArea = VRTK_DeviceFinder.PlayAreaTransform();
     }
     else
     {
         if (playArea.position.y <= -1.0f)
         {
             playArea.position = new Vector3(5f, -0.441f, 3f);
         }
     }
 }
        protected override void OnEnable()
        {
            trackedObjects = new List <Transform>();
            movementList   = new Dictionary <Transform, List <float> >();
            //base.previousYPositions = new Dictionary<Transform, float>();
            previousTriggerAxisPositions = new Dictionary <Transform, float>();
            initalGaze        = Vector3.zero;
            direction         = Vector3.zero;
            previousDirection = Vector3.zero;
            averagePeriod     = 60;
            currentSpeed      = 0f;
            active            = false;

            activeMovement       = false;
            previousEngageButton = engageButton;

            bodyPhysics         = (bodyPhysics != null ? bodyPhysics : GetComponentInChildren <VRTK_BodyPhysics>());
            controllerLeftHand  = VRTK_DeviceFinder.GetControllerLeftHand();
            controllerRightHand = VRTK_DeviceFinder.GetControllerRightHand();

            SetControllerListeners(controllerLeftHand, leftController, ref leftSubscribed);
            SetControllerListeners(controllerRightHand, rightController, ref rightSubscribed);

            headset = VRTK_DeviceFinder.HeadsetTransform();

            SetControlOptions(myControlOptions);

            playArea = VRTK_DeviceFinder.PlayAreaTransform();

            for (int i = 0; i < trackedObjects.Count; i++)
            {
                Transform trackedObj = trackedObjects[i];
                movementList.Add(trackedObj, new List <float>());
                if (isAxisYTheTriggerAxis)
                {
                    previousTriggerAxisPositions.Add(trackedObj, trackedObj.transform.localPosition.y);
                }
                else
                {
                    previousTriggerAxisPositions.Add(trackedObj, trackedObj.transform.localPosition.z);
                }
            }
            if (playArea == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SDK_OBJECT_NOT_FOUND, "PlayArea", "Boundaries SDK"));
            }

            userUpVector = trackerPelvis.transform.up;
        }
Example #9
0
 /**
  * A normal member allowing to choose a Soldier during the gameplay
  * @param sender object.
  * @param e InteractableObjectEventArgs.
  */
 private void ObjectChoosenToPlay(object sender, InteractableObjectEventArgs e)
 {
     if (GameManager.Instance.gamemode == GameManager.GameMode.PLAYER_TURN && canBeChosenToPlay)
     {
         Debug.Log("Player turn");
         GameManager.Instance.SetRolePlayMode();
         sceneObjects.localScale *= 2.5f / PlayAreaRealSize.GetFactor();
         VRTK_DeviceFinder.PlayAreaTransform().position = transform.position; //teleport to soldier place
         soldierModel.SetActive(false);
         soldierCollider.SetActive(false);
         UsableItem.GetComponent <VRTK_InteractableObject>().isGrabbable = true;
         weaponController.setPosition(transform.position.x, transform.position.z);
         weaponController.collider.enabled = true; // collider control
     }
 }
Example #10
0
        protected virtual void Move()
        {
            Transform playArea = VRTK_DeviceFinder.PlayAreaTransform();
            Transform headset  = VRTK_DeviceFinder.HeadsetTransform();

            if (playArea != null && headset != null)
            {
                transform.position = new Vector3(headset.position.x, playArea.position.y, headset.position.z);
                controlObject.transform.localPosition = headset.forward * 0.5f;
                controlObject.transform.localPosition = new Vector3(controlObject.transform.localPosition.x, 0f, controlObject.transform.localPosition.z);
                Vector3 targetPosition = headset.position;
                targetPosition.y = playArea.transform.position.y;
                controlObject.transform.LookAt(targetPosition);
                controlObject.transform.localEulerAngles = new Vector3(0f, controlObject.transform.localEulerAngles.y, 0f);
            }
        }
Example #11
0
    void CheckDistance()
    {
        Transform playTransform      = VRTK_DeviceFinder.PlayAreaTransform();
        float     distanceToPlayArea = Vector3.Distance(transform.position, playTransform.position);

        if (distanceToPlayArea > ActivateDistance)
        {
            DoDestroy();
            return;
        }

        float relativeScale = baseScale * (distanceToPlayArea / ActivateDistance);

        relativeScale        = (relativeScale < 0 ? 0 : relativeScale);
        transform.localScale = Vector3.one * relativeScale;
    }
Example #12
0
    void Update()
    {
        Transform          t = transform;
        DestructibleObject d = GetComponent <DestructibleObject>();

        if (d != null)
        {
            t = d.GetCurrentActiveObject().transform;
        }

        Transform playAreaTransform = VRTK_DeviceFinder.PlayAreaTransform();

        if (playAreaTransform != null)
        {
            playAreaTransform.position = t.position;
            playAreaTransform.rotation = t.rotation;
        }
    }
Example #13
0
 bool Find()
 {
     if (findReady)
     {
         return(true);
     }
     playAreaTransform = VRTK_DeviceFinder.PlayAreaTransform();
     headsetTransform  = VRTK_DeviceFinder.HeadsetTransform();
     leftController    = VRTK_DeviceFinder.GetControllerLeftHand();
     rightController   = VRTK_DeviceFinder.GetControllerRightHand();
     findReady         = playAreaTransform && headsetTransform && leftController &&
                         rightController;
     if (findReady)
     {
         OnFindReady();
     }
     return(findReady);
 }
Example #14
0
    private void DoTouchpadTouchStart(object sender, ControllerInteractionEventArgs e)
    {
        Debug.Log(e.touchpadAxis.y);
        playArea = VRTK_DeviceFinder.PlayAreaTransform();
        playArea.GetComponent <Rigidbody>().isKinematic = false;
        playArea.GetComponent <Rigidbody>().useGravity  = false;
        playArea.GetComponent <Rigidbody>().mass        = 0.1f;

        /*
         * if (e.touchpadAxis.y < 0 && playArea.position.y <= 0) return;
         * playArea.Translate(0, e.touchpadAxis.y, 0);
         * startPos = new Vector3(playArea.position.x, playArea.position.y, playArea.position.z);
         * endPos = new Vector3(playArea.position.x + e.touchpadAxis.x, playArea.position.y + e.touchpadAxis.y, playArea.position.z);
         * distance = Vector3.Distance(startPos, endPos);
         * startTime = Time.time;
         * isMoving = true;*/
        _xForce = e.touchpadAxis.x;
        _yForce = e.touchpadAxis.y;
    }
Example #15
0
    /**
     * A normal member to be called after the user is done with playing in the role of the chosen Soldier.
     */
    public void AfterFinishedAction()
    {
        sceneObjects.localScale /= 2.5f / PlayAreaRealSize.GetFactor();
        VRTK_DeviceFinder.PlayAreaTransform().position = Vector3.zero;
        soldierModel.SetActive(true);
        soldierCollider.SetActive(true);
        UsableItem.GetComponent <VRTK_InteractableObject>().isGrabbable = false;
        UsableItem.transform.position = originalItemPosition;
        UsableItem.transform.rotation = originalItemRotation;

        UsableItem.GetComponent <Shooter>()?.ResetWeapon();
        weaponController.collider.enabled = false; // disabling collider to avoid disabling a weapon when collider is moving around the playground

        // if gamemode is MENU (= level ended), enemy turn cannot be executed
        if (GameManager.Instance.gamemode != GameManager.GameMode.MENU)
        {
            GetComponent <Enemy>().EnemyController();
        }
    }
Example #16
0
    void UnloadMenu()
    {
        if (stashedRoots.Count == 0 || storedPosition == null || storedRotation == null)
        {
            return;
        }

        SceneManager.UnloadSceneAsync(sceneName);

        Transform playArea = VRTK_DeviceFinder.PlayAreaTransform();

        playArea.position = storedPosition;
        playArea.rotation = storedRotation;

        foreach (GameObject obj in stashedRoots)
        {
            obj.SetActive(true);
        }
        stashedRoots.Clear();
    }
Example #17
0
    private void Start()
    {
        VRTK_HeadsetFade fade = VRTKScripts.instance.GetComponentInChildren <VRTK_HeadsetFade>();

        if (fade != null)
        {
            fade.Fade(Color.black, 0);
        }

        Transform playArea = VRTK_DeviceFinder.PlayAreaTransform();

        playArea.position = this.transform.position;
        playArea.rotation = this.transform.rotation;

        OnStart();

        if (fade != null)
        {
            fade.Unfade(0.5f);
        }
    }
    private void OnEnable()
    {
        switch (target)
        {
        case ObjectType.Headset:
            SetParent(VRTK_DeviceFinder.HeadsetTransform());
            break;

        case ObjectType.LeftController:
            SetParent(VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.LeftController));
            break;

        case ObjectType.RightController:
            SetParent(VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.RightController));
            break;

        case ObjectType.PlayArea:
            SetParent(VRTK_DeviceFinder.PlayAreaTransform());
            break;
        }
    }
Example #19
0
    public void Focus()
    {
        Transform playTransform = VRTK_DeviceFinder.PlayAreaTransform();

        GameObject[] magicObjects     = GameObject.FindGameObjectsWithTag("MagicObject");
        MagicObject  selectedObject   = null;
        float        smallestDistance = float.PositiveInfinity;

        foreach (GameObject obj in magicObjects)
        {
            MagicObject script = obj.GetComponent <MagicObject>();
            if (script == null || !script.isOwned)
            {
                continue;
            }

            float distance = Vector3.Distance(playTransform.position, script.transform.position);
            if (distance > 4f || distance > smallestDistance)
            {
                continue;
            }

            selectedObject   = script;
            smallestDistance = distance;
        }

        if (selectedObject != null)
        {
            selectedSeal = selectedObject.DisplaySeal(true);
            leftSealControls.ResetSavedVectors();
            rightSealControls.ResetSavedVectors();
        }

        if (OnFocus != null)
        {
            OnFocus();
        }
    }
Example #20
0
    void LoadMenu()
    {
        Transform playArea = VRTK_DeviceFinder.PlayAreaTransform();

        storedPosition = playArea.position;
        storedRotation = playArea.rotation;

        for (int i = 0; i < SceneManager.sceneCount; i++)
        {
            Scene scene = SceneManager.GetSceneAt(i);
            if (scene.name != VRTKSceneName)
            {
                GameObject[] roots = scene.GetRootGameObjects();
                foreach (GameObject obj in roots)
                {
                    obj.SetActive(false);
                    stashedRoots.Add(obj);
                }
            }
        }

        AsyncOperation async = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
    }
Example #21
0
 public static void ShowFloatVR(string text)
 {
     HideFloatVR();
     if (!string.IsNullOrEmpty(text))
     {
         Transform eyesTransform = PlayerManager.PlayerCamera?.transform;
         if (eyesTransform == null)
         {
             return;
         }
         Vector3   position = eyesTransform.position + eyesTransform.forward * 1.5f;
         Transform parent;
         if (VRManager.IsVREnabled())
         {
             parent = VRTK_DeviceFinder.PlayAreaTransform();
         }
         else // Shouldn't be case for this mod.
         {
             parent = (PlayerManager.Car ? PlayerManager.Car.interior : (SingletonBehaviour <WorldMover> .Exists ? SingletonBehaviour <WorldMover> .Instance.originShiftParent : null));
         }
         floatieVR = (Object.Instantiate(Resources.Load("tutorial_floatie"), position, Quaternion.identity, parent) as GameObject);
         floatieVR.GetComponent <TutorialFloatie>().UpdateTextExternally(text);
     }
 }
Example #22
0
 // Find and save components for later use.
 private void CacheComponents()
 {
     playArea        = VRTK_DeviceFinder.PlayAreaTransform();
     headsetLocation = VRTK_DeviceFinder.HeadsetTransform();
 }
Example #23
0
 private void OnEnable()
 {
     m_controllerEvents = m_controllerEvents ? m_controllerEvents : GetComponent <VRTK_ControllerEvents>();
     m_headset          = VRTK_DeviceFinder.HeadsetTransform();
     m_playArea         = VRTK_DeviceFinder.PlayAreaTransform();
 }
    public void FlipPlayArea()
    {
        var playarea = VRTK_DeviceFinder.PlayAreaTransform();

        playarea.rotation = Quaternion.Euler(playarea.rotation.eulerAngles + new Vector3(0, 180, 0));
    }
Example #25
0
 // Use this for initialization
 void Awake()
 {
     playArea = VRTK_DeviceFinder.PlayAreaTransform();
     headset  = VRTK_DeviceFinder.HeadsetTransform();
 }
Example #26
0
 public void Start()
 {
     PlayArea = VRTK_DeviceFinder.PlayAreaTransform();
     Headset  = VRTK_DeviceFinder.DeviceTransform(VRTK_DeviceFinder.Devices.Headset);
 }
Example #27
0
 protected virtual void Start()
 {
     playArea = VRTK_DeviceFinder.PlayAreaTransform();
     SetRandomSpawnpoint();
     StartLevel();
 }
Example #28
0
        IEnumerator Start()
        {
            yield return(null);

            // VRTKのSDKオートロードはせずに手動セットアップ
            string vrSystem = ApplicationSetting.Instance.GetString("VRSystem");
            int    sdkIndex = (int)DEVICE_TYPE.OCULUS;

            if (vrSystem.ToLower() == "oculus")
            {
                Debug.Log("select VR System [ Oculus ]");
                sdkIndex = (int)DEVICE_TYPE.OCULUS;

                deviceType = DEVICE_TYPE.OCULUS;
            }
            else if (vrSystem.ToLower() == "vive")
            {
                Debug.Log("select VR System [ VIVE ]");
                sdkIndex = (int)DEVICE_TYPE.VIVE;

                deviceType = DEVICE_TYPE.VIVE;
            }

            try
            {
                VRTK_SDKManager.instance.TryLoadSDKSetup(sdkIndex, true, VRTK_SDKManager.instance.setups);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                yield break;
            }

            // デバイス初期化に時間がかかるため、各デバイスのエイリアスが取得できるまで確認ループ
            while (!AllDeviceIsReady())
            {
                yield return(null); // 初期化完了待機 1フレ後に以下取得を確認

                // リグRoot
                vrRig = VRTK_DeviceFinder.PlayAreaTransform();

                // ヘッドセット
                headset = VRTK_DeviceFinder.HeadsetCamera();

                // 初期化時 左コントローラー → 右コントローラー の認識順
                leftControllerReference = VRTK_DeviceFinder.GetControllerReferenceLeftHand();
                GameObject leftHand = VRTK_DeviceFinder.GetControllerLeftHand(false);
                if (leftHand != null)
                {
                    leftControllerEvents = leftHand.GetComponent <VRTK_ControllerEvents>();
                }
                if (leftControllerEvents != null)
                {
                    leftControllerRoot = leftControllerEvents.transform.parent.gameObject;

                    if (deviceType == DEVICE_TYPE.OCULUS)
                    {
                        leftControllerModel = leftControllerRoot.transform.Find("LeftControllerAnchor").gameObject;
                    }
                    else if (deviceType == DEVICE_TYPE.VIVE)
                    {
                        leftControllerModel = leftControllerRoot.transform.Find("Model").gameObject;
                    }
                }

                rightControllerReference = VRTK_DeviceFinder.GetControllerReferenceRightHand();
                GameObject rightHand = VRTK_DeviceFinder.GetControllerRightHand(false);
                if (rightHand != null)
                {
                    rightControllerEvents = rightHand.GetComponent <VRTK_ControllerEvents>();
                }
                if (rightControllerEvents != null)
                {
                    rightControllerRoot = rightControllerEvents.transform.parent.gameObject;

                    if (deviceType == DEVICE_TYPE.OCULUS)
                    {
                        rightControllerModel = rightControllerRoot.transform.Find("RightControllerAnchor").gameObject;
                    }
                    else if (deviceType == DEVICE_TYPE.VIVE)
                    {
                        rightControllerModel = rightControllerRoot.transform.Find("Model").gameObject;
                    }
                }
            }

            isReady = true;

            yield break;
        }
Example #29
0
 private void OnEnable()
 {
     playArea = VRTK_DeviceFinder.PlayAreaTransform();
 }
 public void OnEvent(Events.ResetPlayerEvent e)
 {
     VRTK_DeviceFinder.PlayAreaTransform().position = Vector3.zero;
 }