コード例 #1
0
ファイル: VREmulator.cs プロジェクト: marcosav/MinecraftVR
    private void Awake()
    {
        controls = new MinecraftVR();

        if (Instance == null)
        {
            instance = this;
        }
        else if (Instance != this)
        {
            Debug.LogError("More than one active GvrEditorEmulator instance was found in your " +
                           "scene.  Ensure that there is only one active GvrEditorEmulator.");
            this.enabled = false;
            return;
        }
    }
コード例 #2
0
        private void UpdatePreview()
        {
            if (Application.isPlaying)
            {
                DestroyPreview();
                return;
            }

            if (mEmulator == null)
            {
                mEmulator = FindObjectOfType <VREmulator>();
            }

            if (mEmulator == null)
            {
                return;
            }

            // Do we need to create a new preview?
            // Only if th device has changed, or there is currently no preview visible
            if (mEmulator.EmulatorDevice == mPreviewDevice && mPreviewVisual != null)
            {
                return;
            }

            DestroyPreview();

            mPreviewDevice = mEmulator.EmulatorDevice;
            mPreviewVisual = CreateEditorPreivew(mPreviewDevice);

            if (mPreviewVisual != null)
            {
                mPreviewVisual.transform.SetParentAndIdentity(transform);
                mPreviewVisual.gameObject.hideFlags = HideFlags.HideAndDontSave | HideFlags.NotEditable;
                mPreviewVisual.gameObject.SetActive(true);

                // Hide any pointer visuals, because they can be annoying!
                foreach (var ptrVis in mPreviewVisual.GetComponentsInChildren <LaserPointerVisual>(true))
                {
                    ptrVis.gameObject.SetActive(false);
                }
            }
        }
コード例 #3
0
    void Update()
    {
        if (transform.position.y < -20)
        {
            transform.position = new Vector3(transform.position.x, 2, transform.position.z);
            return;
        }

        Vector2 input = controls.Player.Move.ReadValue <Vector2>();
        float   x     = input.x;
        float   z     = input.y;

        bool sprint = controls.Player.Sprint.ReadValue <float>() == 1;
        bool jump   = controls.Player.Jump.ReadValue <float>() == 1;

        bool flashLight = controls.Player.ToggleFlashLight.ReadValue <float>() == 1;

        var     c   = VREmulator.GetRotation();
        Vector3 dir = c * Vector3.right * x + c * Vector3.forward * z;

        bool grounded = IsOnGround();

        if (!grounded)
        {
            dir *= .7f;
        }

        float actualSpeed = speed;

        if (sprint)
        {
            actualSpeed *= sprintMultiplier;
        }

        dir *= actualSpeed;

        if (jump && grounded)
        {
            directionY = jumpSpeed;
        }

        if (flashLight)
        {
            if (on)
            {
                fComponent.enabled = true;
                on = !on;
            }
            else if (!on)
            {
                fComponent.enabled = false;
                on = !on;
            }
        }

        if (!grounded)
        {
            directionY -= g * 1.4f * Time.deltaTime;
        }

        else if (directionY < 0)
        {
            directionY = -g / 2;
        }

        dir.y = directionY;

        cntrl.Move(dir * Time.deltaTime);

        moved += new Vector2(dir.x, dir.z).magnitude *Time.deltaTime;

        if (moved > 2.5f)
        {
            moved = 0;
            PlaySound();
        }
    }