Example #1
0
 public GrabObject()
 {
     this.enabledThrow        = true;
     this.grabInputKey        = OVRInput.Button.PrimaryIndexTrigger;
     this.isToFarAction       = () => MyOVRInput.GetSwipe(KeyCode.UpArrow);
     this.isToNearAction      = () => MyOVRInput.GetSwipe(KeyCode.DownArrow);
     this.distanceChangeSpeed = 0.1f;
 }
Example #2
0
        // update
        void Update()
        {
            // ヒットしているオブジェクトを取得
            RaycastHit hitInfo;
            GameObject hitObj;

            MyOVRRayHelper.GetRayHit(out hitInfo, out hitObj);

            // 掴むのを開始
            if (MyOVRInput.GetDown(this.grabInputKey) && IsGrabable(hitObj))
            {
                _grabObject   = hitObj;
                _grabDistance = hitInfo.distance;
                _grabOffset   = _grabObject.transform.position - hitInfo.point;       // ヒットした場所からオブジェクト中心までの距離
                _gravOldPos   = _grabObject.transform.position;
            }

            // 掴んだオブジェクトを移動
            if (_grabObject != null)
            {
                // 距離変更
                if (this.isToFarAction())
                {
                    _grabDistance += this.distanceChangeSpeed;
                }
                if (this.isToNearAction())
                {
                    _grabDistance -= this.distanceChangeSpeed;
                }
                if (_grabDistance < 0.1)
                {
                    _grabDistance = 0.1f;
                }

                // 移動
                _gravOldPos = _grabObject.transform.position;

                Transform controller     = MyOVRRayHelper.GetController();
                Vector3   rayDistancePos = controller.position;
                rayDistancePos += controller.rotation * (Vector3.forward * _grabDistance);         // コントローラから_grabDistanceほど進んだ位置
                _grabObject.transform.position = rayDistancePos + _grabOffset;

                // 重力を無効にするために速度をゼロに戻しておく
                Rigidbody rigidbody = _grabObject.GetComponent <Rigidbody>();
                if (rigidbody != null)
                {
                    rigidbody.velocity = Vector3.zero;
                }
            }

            // 掴んだオブジェクトを離す
            if (MyOVRInput.GetUp(this.grabInputKey))
            {
                this.RelaseGrab();
            }
        }
Example #3
0
        void Update()
        {
            if (MyOVRInput.GetDown(this.warpInputKey))
            {
                // ヒットしているオブジェクト名を取得
                RaycastHit hitInfo;
                GameObject hitObj;
                MyOVRRayHelper.GetRayHit(out hitInfo, out hitObj);

                if (hitObj != null)
                {
                    Vector3 newPos = hitInfo.point;
                    newPos += new Vector3(0, this.baseHeight, 0);
                    _moveTarget.position = newPos;
                }
            }
        }
Example #4
0
 void Update()
 {
     if (MyOVRInput.Get(OVRInput.Touch.PrimaryTouchpad))
     {
         Vector2 axis = MyOVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);
         if (MyOVRInput.Get(OVRInput.Button.PrimaryIndexTrigger))
         {
             // トリガーを押しているときは上下
             _moveTarget.position += Vector3.up * (axis.y * _maxSpeed * Time.deltaTime);
         }
         else
         {
             // それ以外は前後左右
             Transform camera = Camera.main.transform;
             _moveTarget.position += NormalizedLandscape(camera.rotation * Vector3.right) * (axis.x * _maxSpeed * Time.deltaTime);
             _moveTarget.position += NormalizedLandscape(camera.rotation * Vector3.forward) * (axis.y * _maxSpeed * Time.deltaTime);
         }
     }
 }
Example #5
0
        void Update()
        {
            if (MyOVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger))
            {
                Transform controller = MyOVRRayHelper.GetController();
                _basePos = controller.rotation * Vector3.forward;
            }
            if (MyOVRInput.Get(OVRInput.Button.PrimaryIndexTrigger))
            {
                Transform controller = MyOVRRayHelper.GetController();
                Vector3   currPos    = controller.rotation * Vector3.forward;
                Vector3   diffVec    = currPos - _basePos;

                float normalizedMagnitute = Mathf.InverseLerp(0f, SQRT2, diffVec.magnitude);

                if (normalizedMagnitute > 0.05f)
                {
                    _moveTarget.position += NormalizedLandscape(diffVec) * (normalizedMagnitute * _maxSpeed * Time.deltaTime);
                }
            }
        }