Beispiel #1
0
    private void SetupControllerInputDevice()
    {
        GvrControllerInputDevice newDevice = GvrControllerInput.GetDevice(controllerHand);

        if (controllerInputDevice == newDevice)
        {
            return;
        }
        if (controllerInputDevice != null)
        {
            controllerInputDevice.OnStateChanged -= OnControllerStateChanged;
            controllerInputDevice = null;
        }

        controllerInputDevice = newDevice;
        if (controllerInputDevice != null)
        {
            controllerInputDevice.OnStateChanged += OnControllerStateChanged;
            OnControllerStateChanged(controllerInputDevice.State, controllerInputDevice.State);
        }
        else
        {
            OnControllerStateChanged(GvrConnectionState.Disconnected, GvrConnectionState.Disconnected);
        }
        PropagateControllerInputDevice();
    }
Beispiel #2
0
 // Start is called before the first frame update
 void Start()
 {
     controller = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
     hudVideo.SetActive(true);
     followVideo.SetActive(false);
     podium.SetActive(false);
 }
Beispiel #3
0
        // Runtime switching enabled only in-editor.
        private void Update()
        {
            UpdateStatusMessage();

            // Scan all devices' buttons for button down, and switch the singleton pointer
            // to the controller the user last clicked.
            int newPointer = activeControllerPointer;

            if (controllerPointers.Length > 1 && controllerPointers[1] != null)
            {
                GvrTrackedController trackedController1 =
                    controllerPointers[1].GetComponent <GvrTrackedController>();
                foreach (var hand in ALL_HANDS)
                {
                    GvrControllerInputDevice device = GvrControllerInput.GetDevice(hand);
                    if (device.GetButtonDown(POINTER_BUTTON_MASK))
                    {
                        // Match the button to our own controllerPointers list.
                        if (device == trackedController1.ControllerInputDevice)
                        {
                            newPointer = 1;
                        }
                        else
                        {
                            newPointer = 0;
                        }
                        break;
                    }
                }
            }

            if (newPointer != activeControllerPointer)
            {
                activeControllerPointer = newPointer;
                SetVRInputMechanism();
            }

#if !RUNNING_ON_ANDROID_DEVICE
            UpdateEmulatedPlatformIfPlayerSettingsChanged();
            if ((isDaydream && gvrEmulatedPlatformType == EmulatedPlatformType.Daydream) ||
                (!isDaydream && gvrEmulatedPlatformType == EmulatedPlatformType.Cardboard))
            {
                return;
            }

            isDaydream = (gvrEmulatedPlatformType == EmulatedPlatformType.Daydream);
            SetVRInputMechanism();
#else
            // Running on an Android device.
            // Viewer type switched at runtime.
            if (!IsDeviceDaydreamReady() || viewerPlatform == GvrSettings.ViewerPlatform)
            {
                return;
            }

            isDaydream     = GvrSettings.ViewerPlatform == GvrSettings.ViewerPlatformType.Daydream;
            viewerPlatform = GvrSettings.ViewerPlatform;
            SetVRInputMechanism();
#endif  // !RUNNING_ON_ANDROID_DEVICE
        }
Beispiel #4
0
    void Awake()
    {
        if (instances.Length > 0)
        {
            Debug.LogError("More than one active GvrControllerInput instance was found in your scene. "
                           + "Ensure that there is only one GvrControllerInput.");
            this.enabled = false;
            return;
        }
        if (controllerProvider == null)
        {
            controllerProvider = ControllerProviderFactory.CreateControllerProvider(this);
        }

        handedness = GvrSettings.Handedness;
        int controllerCount = 2;

        instances = new GvrControllerInputDevice[controllerCount];
        for (int i = 0; i < controllerCount; i++)
        {
            instances[i] = new GvrControllerInputDevice(controllerProvider, i);
        }
        if (onDevicesChangedInternal != null)
        {
            onDevicesChangedInternal();
        }

        // Keep screen on here, since GvrControllerInput must be in any GVR scene in order to enable
        // controller capabilities.
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
    }
Beispiel #5
0
        protected override void OnUpdatePoses()
        {
            switch (_node)
            {
            case XRNode.LeftHand:
                _controller = GvrControllerInput.GetDevice(GvrControllerHand.Left);
                break;

            case XRNode.RightHand:
                _controller = GvrControllerInput.GetDevice(GvrControllerHand.Right);
                break;
            }

            if (_controller != null)
            {
                nodePosition = _controller.Position;
                nodeRotation = _controller.Orientation;
            }

            if (!_overridePosition)
            {
                transform.localPosition = nodePosition;
            }
            else
            {
                transform.position = _positionTarget.position;
            }

            transform.localRotation = nodeRotation;
        }
        public void UpdateData()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            // Running on Android device.
            // Update controller state.
            GvrBasePointer pointer            = GvrPointerInputModule.Pointer;
            bool           isPointerAvailable = pointer != null && pointer.IsAvailable;
            if (isPointerAvailable)
            {
                GvrControllerInputDevice controllerInputDevice = pointer.ControllerInputDevice;
                if (controllerInputDevice != null && controllerInputDevice.State == GvrConnectionState.Connected)
                {
                    bool pressed = controllerInputDevice.GetButton(GvrControllerButton.TouchPadButton);
                    gvr_keyboard_update_button_state(keyboard_context, kGvrControllerButtonClick, pressed);

                    // Update touch state
                    Vector2 touch_pos = controllerInputDevice.TouchPos;
                    IntPtr  touch_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(touch_pos));
                    Marshal.StructureToPtr(touch_pos, touch_ptr, true);
                    bool isTouching = controllerInputDevice.GetButton(GvrControllerButton.TouchPadTouch);
                    gvr_keyboard_update_controller_touch(keyboard_context, isTouching, touch_ptr);

                    GvrBasePointer.PointerRay pointerRay = pointer.GetRayForDistance(currentDistance);

                    Vector3 startPoint = pointerRay.ray.origin;
                    // Need to flip Z for native library
                    startPoint.z *= -1;
                    IntPtr start_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(startPoint));
                    Marshal.StructureToPtr(startPoint, start_ptr, true);

                    Vector3 endPoint = pointerRay.ray.GetPoint(pointerRay.distance);
                    // Need to flip Z for native library
                    endPoint.z *= -1;
                    IntPtr end_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(endPoint));
                    Marshal.StructureToPtr(endPoint, end_ptr, true);

                    Vector3 hit     = Vector3.one;
                    IntPtr  hit_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(Vector3.zero));
                    Marshal.StructureToPtr(Vector3.zero, hit_ptr, true);

                    gvr_keyboard_update_controller_ray(keyboard_context, start_ptr, end_ptr, hit_ptr);
                    hit    = (Vector3)Marshal.PtrToStructure(hit_ptr, typeof(Vector3));
                    hit.z *= -1;

                    Marshal.FreeHGlobal(touch_ptr);
                    Marshal.FreeHGlobal(hit_ptr);
                    Marshal.FreeHGlobal(end_ptr);
                    Marshal.FreeHGlobal(start_ptr);
                }
            }
#endif  // UNITY_ANDROID && !UNITY_EDITOR

            // Get time stamp.
            gvr_clock_time_point time = gvr_get_time_point_now();
            time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;

            // Update frame data.
            GvrKeyboardSetFrameData(keyboard_context, time);
            GL.IssuePluginEvent(renderEventFunction, advanceID);
        }
Beispiel #7
0
 private void Start()
 {
     controller = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
     if (!anchored)
     {
         AttachToCamera();
     }
 }
Beispiel #8
0
    public int siteLayer   = 10; // This should match the layer number sites are in

    // Use this for initialization
    void Start()
    {
        _dominantController = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
        //_previousOrientation = _dominantController.Orientation * Vector3.forward;
        _previousTouch = _dominantController.TouchPos;
        _translate     = new Vector3();
        _initTransform = this.transform.position;
    }
Beispiel #9
0
 // Start is called before the first frame update
 void Start()
 {
     controller = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
     menu.SetActive(false);
     countdownBox.SetActive(true);
     timer          = 0.0f;
     actionComplete = false;
     menuActive     = false;
 }
Beispiel #10
0
 void OnDestroy()
 {
     GvrControllerInput.OnDevicesChanged -= SetupControllerInputDevice;
     if (controllerInputDevice != null)
     {
         controllerInputDevice.OnStateChanged -= OnControllerStateChanged;
         controllerInputDevice = null;
         PropagateControllerInputDevice();
     }
 }
Beispiel #11
0
 void Update()
 {
     if (VRDevice.OculusGo)         //On OculusGo, use the controller's trigger to recalibrate
     {
         OVRInput.Update();
         if (OVRInput.Get(oculusGoRecenterButton))
         {
             Recenter();
         }
         if (OVRInput.Get(oculusGoQuitButton))
         {
             Application.Quit();
         }
     }
     else if (VRDevice.MirageSolo)           //On Mirage Solo, use the controller's click button
     {
         bool overrideTouch = false;
         bool overrideQuit  = false;
         GvrControllerInputDevice device = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
         if (device == null)
         {
             device = GvrControllerInput.GetDevice(GvrControllerHand.NonDominant);
             if (device == null)
             {
                 Haze.Logger.LogError("Daydream Input API Status: " + GvrControllerInput.ApiStatus);
                 Haze.Logger.LogError("ErrorDetails: " + GvrControllerInput.ErrorDetails);
             }
         }
         if ((device != null && device.GetButton(mirageRecenterButton)) || overrideTouch)
         {
             Recenter();
         }
         if ((device != null && device.GetButton(mirageQuitButton)) || overrideQuit)
         {
             Application.Quit();
         }
     }
     else if (VRDevice.GearVR)         //On GearVR, double-tap to recalibrate
     {
         if (firstTap > 0)             //we've tapped a first time!
         {
             if (Input.GetMouseButtonDown(0))
             {
                 //that's it, double-tapped.
                 Recenter();
                 firstTap = 0;
             }
             firstTap -= Time.deltaTime;
         }
         else if (Input.GetMouseButtonUp(0))
         {
             firstTap = 0.3f;                //you have .3 seconds to tap once more for double tap!
         }
     }
 }
Beispiel #12
0
        /// Returns true the frame after the user stops pressing down any of buttons specified
        /// in `buttons` on any controller.
        public static bool AnyButtonUp(GvrControllerButton buttons)
        {
            bool ret = false;

            foreach (var hand in AllHands)
            {
                GvrControllerInputDevice device = GvrControllerInput.GetDevice(hand);
                ret |= device.GetButtonUp(buttons);
            }
            return(ret);
        }
 private void Update()
 {
     foreach (var hand in Gvr.Internal.ControllerUtils.AllHands)
     {
         GvrControllerInputDevice device = GvrControllerInput.GetDevice(hand);
         if (device.GetButtonUp(GvrControllerButton.App))
         {
             CycleSeeThroughModes();
         }
     }
 }
Beispiel #14
0
    public override void OnEnterState(GameController gameController)
    {
        throwController = gameController.GetThrowController();
        controller      = gameController.GetController();
        throwController.StartThrow(controller);
        gameController.GetArrow().SetActive(true);
        Disc disc = gameController.GetDisc();

        disc.SetColliderEnabled(false);
        //TransparencyUtil.MakeObjectOpaque(disc.gameObject);
    }
Beispiel #15
0
 // Start is called before the first frame update
 void Start()
 {
     videoPlay  = true;
     audioPlay  = false;
     currAudio  = Resources.Load <AudioClip>("Audio/Section1/" + audioFiles[0]);
     controller = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
     Reset();
     overlay.SetActive(false);
     visionBlocker.SetActive(false);
     playVideo.videoPlayer.enabled = false;
     playVideo.videoCanvas.SetActive(false);
 }
Beispiel #16
0
    public override void OnEnterState(GameController gameController)
    {
        controller = gameController.GetController();
        gameController.SetPopupActive(true);
        Popup popup = gameController.GetPopup();

        popup.SetLargeText("Out of Bounds");
        popup.SetExtraLargeText(null);
        int strokes = gameController.GetStrokes();
        int diff    = strokes - gameController.GetPar();

        popup.SetBottomText("Stroke " + strokes + "(" + (diff > 0 ? "+" : "") + diff + ")");
    }
Beispiel #17
0
    private void Teleport(GvrControllerInputDevice device)
    {
        if (device.GetButtonUp(GvrControllerButton.TouchPadButton) &&
            GvrLaserPointer.CurrentRaycastResult.gameObject != null &&
            (GvrLaserPointer.CurrentRaycastResult.gameObject.tag == TELEPORT_CAPABLE_TAG ||
             (GvrLaserPointer.CurrentRaycastResult.gameObject.tag == SWIM_LANE_TAG &&
              !BoardManager.AnyCardsSelected())))
        {
            transform.position = GvrLaserPointer.CurrentRaycastResult.worldPosition + new Vector3(0, 1.5f, 0);

            networkManager.RaiseEvent(NetworkManager.EventCode.PlayerPositionChanged, transform.position);
        }
    }
Beispiel #18
0
    public override void OnEnterState(GameController gameController)
    {
        controller    = gameController.GetController();
        discRigidbody = gameController.GetDisc().GetComponent <Rigidbody>();
        gameController.SetPopupActive(true);
        Popup popup   = gameController.GetPopup();
        int   strokes = gameController.GetStrokes();
        int   diff    = strokes - gameController.GetPar();

        popup.SetExtraLargeText(strokes + "(" + (diff >= 0 ? "+" : "") + diff + ")");
        popup.SetLargeText(null);
        popup.SetBottomText(GetBottomTextString(diff));
        discRigidbody.isKinematic = true;
    }
Beispiel #19
0
    void Update()
    {
        bool connected = false;

        foreach (var hand in Gvr.Internal.ControllerUtils.AllHands)
        {
            GvrControllerInputDevice device = GvrControllerInput.GetDevice(hand);
            if (device.State == GvrConnectionState.Connected)
            {
                connected = true;
                break;
            }
        }

        if (!connected)
        {
            return;
        }

// Daydream is loaded only on deivce, not in editor.
#if UNITY_ANDROID && !UNITY_EDITOR
        if (XRSettings.loadedDeviceName != GvrSettings.VR_SDK_DAYDREAM)
        {
            return;
        }
#endif

        if (GvrControllerInput.Recentered)
        {
            ApplyYawCorrection();
            return;
        }

#if UNITY_EDITOR
        // Compatibility for Instant Preview.
        if (Gvr.Internal.InstantPreview.Instance != null &&
            Gvr.Internal.InstantPreview.Instance.enabled &&
            Gvr.Internal.ControllerUtils.AnyButton(GvrControllerButton.System))
        {
            return;
        }
#else  // !UNITY_EDITOR
        if (Gvr.Internal.ControllerUtils.AnyButton(GvrControllerButton.System))
        {
            return;
        }
#endif  // UNITY_EDITOR

        yawCorrection = GetYawCorrection();
    }
Beispiel #20
0
        public override void OnActivated()
        {
            EnsureDeviceStateLength(3);

            if (Object.FindObjectOfType <GvrHeadset>() == null)
            {
                VRModule.Instance.gameObject.AddComponent <GvrHeadset>();
            }

            if (Object.FindObjectOfType <GvrControllerInput>() == null)
            {
                VRModule.Instance.gameObject.AddComponent <GvrControllerInput>();
            }

            m_rightDevice = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
            m_leftDevice  = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);

            var armModels = VRModule.Instance.GetComponents <GvrArmModel>();

            if (armModels != null && armModels.Length >= 1)
            {
                m_rightArm = armModels[0];
            }
            else
            {
                m_rightArm = VRModule.Instance.GetComponent <GvrArmModel>();

                if (m_rightArm == null)
                {
                    m_rightArm = VRModule.Instance.gameObject.AddComponent <GvrArmModel>();
                }
            }
            m_rightArm.ControllerInputDevice = m_rightDevice;

            if (armModels != null && armModels.Length >= 2)
            {
                m_leftArm = armModels[1];
            }
            else
            {
                m_leftArm = VRModule.Instance.GetComponent <GvrArmModel>();

                if (m_leftArm == null)
                {
                    m_leftArm = VRModule.Instance.gameObject.AddComponent <GvrArmModel>();
                }
            }
            m_leftArm.ControllerInputDevice = m_leftDevice;
        }
Beispiel #21
0
 // Start is called before the first frame update
 void Start()
 {
     narratorAudio = GetComponent <AudioSource>();
     currAudio     = Resources.Load <AudioClip>("Audio/Section1/Intro");
     controller    = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
     if (hideObjects)
     {
         Reset();
     }
     else
     {
         placed = true;
         ChangeActive(true);
     }
 }
Beispiel #22
0
    private void Rotate(GvrControllerInputDevice device)
    {
        if (device.GetButton(GvrControllerButton.TouchPadTouch) && !device.GetButton(GvrControllerButton.TouchPadButton))
        {
            if (prevTouchPos == Vector2.zero)
            {
                prevTouchPos = device.TouchPos;
            }
            else
            {
                swipeDelta   = device.TouchPos - prevTouchPos;
                prevTouchPos = device.TouchPos;

                if (!hasSwiped && swipeDelta.magnitude >= SwipeThreshold)
                {
                    targetRotation += RotationAmount * swipeDelta.x / Mathf.Abs(swipeDelta.x);

                    if (targetRotation > 360)
                    {
                        targetRotation -= 360;
                    }
                    else if (targetRotation < 0)
                    {
                        targetRotation += 360;
                    }

                    var quat = transform.rotation;
                    var temp = quat.eulerAngles;
                    temp.y           = targetRotation;
                    quat.eulerAngles = temp;

                    networkManager.RaiseEvent(NetworkManager.EventCode.PlayerRotationChanged, quat);

                    hasSwiped = true;
                }
            }
        }
        else
        {
            prevTouchPos = Vector2.zero;
            hasSwiped    = false;
        }

        var eulerAngles = transform.eulerAngles;

        eulerAngles.y         = Mathf.Lerp(eulerAngles.y, targetRotation, Time.deltaTime * 5);
        transform.eulerAngles = eulerAngles;
    }
 void Start()
 {
     player     = GameObject.FindGameObjectWithTag("Player");
     controller = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
     boundsHandler.OutOfBoundsListener += OutOfBounds;
     InitStates();
     SetScoreboardPars();
     SetupHoleSigns();
     SetRaycastingEnabled(false);
     MovePlayerToCurrentHoleStart();
     SetState(statePreThrow);
     disc.gameObject.SetActive(false);
     scoreboardController.gameObject.SetActive(false);
     pauseMenu.SetActive(false);
     popup.gameObject.SetActive(false);
 }
    void Start()
    {
        /* Character Controller Boilerplate */
        cc = GetComponent <CharacterController>();

        /* Latch the GVRControllerInputDevice */
        //TODO: If this fails, is there feedback to the user, and
        // is there a retry?  Is there a onConnected callback somewhere?
        device = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
        if (device == null)
        {
            Debug.LogError($"{logtag} GvrControllerInputDevice is null");
        }
        else
        {
            Debug.LogError($"{logtag} Latched GvrControllerInputDevice.");
        }
    }
Beispiel #25
0
    public void UpdateDiscVelocity(GvrControllerInputDevice controller)
    {
        float newAccelMag = Math.Abs(controller.Accel.magnitude - 9.8f);

        //debugText.text = "accel = " + newAccelMag;
        UpdateValues(accelMag, newAccelMag);

        Vector3    pos = disc.transform.position;
        Quaternion rot = disc.transform.rotation;

        Vector3 frameVelocity = (pos - lastDiscPosition) / Time.deltaTime;

        discVelocity = Vector3.Lerp(frameVelocity, discVelocity, velocitySmoothingFactor);

        rotationDifference = Quaternion.Inverse(lastDiscRotation) * rot;

        lastDiscPosition = pos;
        lastDiscRotation = rot;
    }
Beispiel #26
0
    public override void OnUpdate(GameController gameController)
    {
        GvrControllerInputDevice controller = gameController.GetController();

        //Vector3 lookDirection = Camera.main.transform.forward;
        //lookDirection.y = 0;
        //lookDirection.Normalize();

        //if(Vector3.Dot(direction, lookDirection) < 0.95f)
        //{
        //direction = Vector3.Slerp(direction, lookDirection, Time.deltaTime);
        //SetArrowTransform(gameController);
        //}


        if (controller.GetButtonDown(GvrControllerButton.TouchPadButton))
        {
            gameController.GetThrowController().SetDirection(direction);
            gameController.SetState(State.THROWING);
        }
    }
    public override void OnEnterState(GameController gameController)
    {
        controller    = gameController.GetController();
        discRigidbody = gameController.GetDisc().GetComponent <Rigidbody>();
        gameController.SetScoreboardActive(true);
        ScoreboardController scoreboard = gameController.GetScoreboardController();
        int finalScore = scoreboard.GetFinalScore();
        int finalDiff  = scoreboard.GetFinalDifference();

        discRigidbody.isKinematic = true;

        string sceneName = SceneManager.GetActiveScene().name;
        string keyScore  = "bestScore_" + sceneName;
        string keyDiff   = "bestDiff_" + sceneName;
        int    bestScore = PlayerPrefs.GetInt(keyScore, -1);

        if (bestScore == -1 || finalScore < bestScore)
        {
            PlayerPrefs.SetInt(keyScore, finalScore);
            PlayerPrefs.SetInt(keyDiff, finalDiff);
        }
    }
Beispiel #28
0
    // Retrieve controller parameters from a Daydream controller.
    private void GetDaydreamControllerStatus(GameObject controllerObject, bool isLeft, out bool trigger, out Vector3 direction, out bool touchpad, out Vector2 touchposition, out bool backButton)
    {
        trigger       = false;
        direction     = new Vector3(0, 0, 0);
        touchpad      = false;
        touchposition = new Vector2(0, 0);
        backButton    = false;

        GvrTrackedController track = controllerObject.GetComponent <GvrTrackedController> ();

        if (track != null)
        {
            GvrControllerInputDevice inputDevice = track.ControllerInputDevice;
            if (inputDevice != null)
            {
                trigger       = inputDevice.GetButton(GvrControllerButton.TouchPadButton);
                backButton    = inputDevice.GetButton(GvrControllerButton.App);
                direction     = controllerObject.transform.forward;
                touchpad      = inputDevice.GetButton(GvrControllerButton.TouchPadTouch);
                touchposition = inputDevice.TouchPos;
            }
        }
    }
Beispiel #29
0
    private void Awake()
    {
        /*
         */
        WaniQ.Enqueue(new WaniProgress(WaniStatus.start, 2));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.eatyou, 3));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.wani1, 10));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.wani2, 10));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.wani3, 10));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.wani4, 10));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.wani5, 10));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.none, 1.5f));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.angry, 2));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.wani6, 10));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.finish, 7));
        WaniQ.Enqueue(new WaniProgress(WaniStatus.bye, 0));

        gvrController = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);

        //やっぱやめた

        /*
         * TextAsset textAsset = new TextAsset();
         * textAsset = Resources.Load("timing", typeof(TextAsset)) as TextAsset;
         * string text = textAsset.text;
         * string[] line = text.Split('\n');
         * for (int i = 0; i < line.Length; i++)
         * {
         *  string[] col = line[i].Split(',');
         *  timing.Add(int.Parse(col[0]), int.Parse(col[1]));
         * }
         */

        aud = GetComponent <AudioSource>();

        Menu.SetActive(false);
    }
Beispiel #30
0
    public bool ReleaseDisc(GvrControllerInputDevice controller)
    {
        float max = Max(accelMag);
        //debugText.text = "accel = " + max;

        float forceStrength = Mathf.Lerp(0, maxThrowVelocity, max / accelLimit);

        Debug.Log("controllerAccel = " + accelMag + ", velocity = " + forceStrength);

        float distanceToTarget = Vector3.Distance(targetPosition, disc.transform.position);

        Vector3 lookDirection = Vector3.Scale(Camera.main.transform.forward, new Vector3(1f, 0f, 1f)).normalized;

        Vector3 targetDirection        = (targetPosition - disc.transform.position).normalized;
        Vector3 targetDirectionInPlane = Vector3.Scale(targetDirection, new Vector3(1f, 0f, 1f)).normalized;

        float lookAngle = Vector3.Angle(targetDirectionInPlane, lookDirection);

        Vector3 forceDirection;

        float a;

        if (distanceToTarget < 20f)
        {
            a = distanceToTarget * 0.5f;
            forceDirection = lookAngle < 30f ? targetDirection : lookDirection;
            forceStrength  = Mathf.Min(forceStrength, maxThrowVelocity * velocityLimitingFactor);
        }
        else
        {
            if (distanceToTarget > 100f)
            {
                a = 20f;
            }
            else
            {
                a = 15f;
            }
            forceDirection = lookAngle < 30f ? targetDirectionInPlane : lookDirection;
        }

        forceDirection = Vector3.RotateTowards(forceDirection, Vector3.up, a * Mathf.Deg2Rad, 0f).normalized;


        if (forceStrength < minThrowVelocity)
        {
            return(false);
        }

        //Vector3 forward = direction;
        //float angle = Vector3.Angle(forceDirection, forward);
        //float radiansChanged = forwardWeight * angle * Mathf.Deg2Rad;
        //forceDirection = Vector3.RotateTowards(forceDirection, forward, radiansChanged, float.MaxValue);

        Rigidbody rb = disc.GetComponent <Rigidbody>();

        Vector3 aVel = new Vector3(0, Mathf.Sign(rotationDifference.eulerAngles.y), 0);

        disc.ReleaseThrow(forceDirection * forceStrength, ForceMode.VelocityChange, aVel * 2000f, ForceMode.Impulse);
        //disc.ReleaseThrow(forceDirection * max, ForceMode.Acceleration, aVel * 2000f, ForceMode.Impulse);

        return(true);
    }