예제 #1
0
    void Update()
    {
        calculateGlobalSliderPosition();
        if (m_railGroupGlobalHandle != null && m_IsGlobalHandleGlobal)
        {
            m_railGroupGlobalHandle.transform.position = getWorldPositionAtGlobalSliderPosition(sliderPosition);
        }

        if (prevPos != sliderPosition)
        {
            if (onSliderPositionUpdate != null)
            {
                onSliderPositionUpdate.Invoke(this);
                if (oneshotSound != null)
                {
                    Valve.VR.InteractionSystem.Interactable interactable = children[m_currentRail].slider.child.GetComponent <Valve.VR.InteractionSystem.Interactable>();
                    if (interactable != null)
                    {
                        if (interactable.attachedToHand != null)
                        {
                            oneshotSound.thisAudioSource = interactable.attachedToHand.GetComponent <AudioSource>();
                            oneshotSound.Play((int)AudioClipGroup.SoundTypes_hoverClickSounds.hover);
                        }
                        else if (interactable.hoveringHand != null)
                        {
                            oneshotSound.thisAudioSource = interactable.hoveringHand.GetComponent <AudioSource>();
                            oneshotSound.Play((int)AudioClipGroup.SoundTypes_hoverClickSounds.hover);
                        }
                    }
                }
            }

            if (sliderPosition >= .25f && prevPos < .25f && onSliderOn_25Percent != null)
            {
                onSliderOn_25Percent.Invoke();
            }
            if (sliderPosition >= .75f && prevPos < .75f && onSliderOn_75Percent != null)
            {
                onSliderOn_75Percent.Invoke();
            }

            if (onSliderBinaryOn != null && sliderPosition > m_minMechanicalSliderValue && prevPos <= m_minMechanicalSliderValue)
            {
                onSliderBinaryOn.Invoke();
            }
            else if (onSliderOnMax != null && sliderPosition > m_maxMechanicalSliderValue && prevPos <= m_maxMechanicalSliderValue)
            {
                onSliderOnMax.Invoke();
                sliderPosition = 1;
            }
            else if (onSliderBinaryOff != null && sliderPosition <= m_minMechanicalSliderValue && prevPos > m_minMechanicalSliderValue)
            {
                onSliderBinaryOff.Invoke();
                sliderPosition = 0;
            }
        }
        prevPos = sliderPosition;
    }
 public void Hovered()
 {
     if (m_coroutine != null)
     {
         StopCoroutine(m_coroutine);
     }
     gizmoGroupThicknessRelative = m_gizmoGroupThicknessRelative_orig * gizmoHoverSize * m_GLHandlesDrawer.gizmoHoverSize;
     if (interactableLinkedTo != null && interactableLinkedTo.hoveringHand != null)
     {
         oneshotSound.thisAudioSource = interactableLinkedTo.hoveringHand.GetComponent <AudioSource>();
         oneshotSound.Play((int)SoundTypes.hover);
     }
 }
예제 #3
0
        //-------------------------------------------------
        public void ArrowInPosition()
        {
            DoHandednessCheck();

            if (nockSound != null)
            {
                nockSound.Play();
            }
        }
예제 #4
0
        //-------------------------------------------------
        public void ArrowReleased()
        {
            nocked = false;
            hand.HoverUnlock(GetComponent <Interactable>());
            hand.otherHand.HoverUnlock(arrowHand.GetComponent <Interactable>());

            if (releaseSound != null)
            {
                releaseSound.Play();
            }

            this.StartCoroutine(this.ResetDrawAnim());
        }
예제 #5
0
        //-------------------------------------------------
        public void StartNock(ArrowHand currentArrowHand)
        {
            arrowHand = currentArrowHand;
            hand.HoverLock(GetComponent <Interactable>());
            nocked                = true;
            nockLerpStartTime     = Time.time;
            nockLerpStartRotation = pivotTransform.rotation;

            // Sound of arrow sliding on nock as it's being pulled back
            arrowSlideSound.Play();

            // Decide which hand we're drawing with and lerp to the correct side
            DoHandednessCheck();
        }
예제 #6
0
        //-------------------------------------------------
        public void ArrowReleased()
        {
            nocked = false;
            hand.HoverUnlock(GetComponent <Interactable>());
            hand.otherHand.HoverUnlock(arrowHand.GetComponent <Interactable>());

            if (releaseSound != null)
            {
                releaseSound.Play();
            }

            TestControllerArchery.instance.onArrowShoot();

            this.StartCoroutine(this.ResetDrawAnim());
        }
예제 #7
0
        //-------------------------------------------------
        public GameObject SpawnBalloon(Balloon.BalloonColor color = Balloon.BalloonColor.Red)
        {
            if (balloonPrefab == null)
            {
                return(null);
            }
            GameObject balloon = Instantiate(balloonPrefab, transform.position, transform.rotation) as GameObject;

            balloon.SetActive(true);
            balloon.transform.localScale = new Vector3(scale, scale, scale);
            if (attachBalloon)
            {
                balloon.transform.parent = transform;
            }

            if (sendSpawnMessageToParent)
            {
                if (transform.parent != null)
                {
                    transform.parent.SendMessage("OnBalloonSpawned", balloon, SendMessageOptions.DontRequireReceiver);
                }
            }

            if (playSounds)
            {
                if (inflateSound != null)
                {
                    inflateSound.Play();
                }
                if (stretchSound != null)
                {
                    stretchSound.Play();
                }
            }
            balloon.GetComponentInChildren <Balloon>().SetColor(color);
            if (spawnDirectionTransform != null)
            {
                balloon.GetComponentInChildren <Rigidbody>().AddForce(spawnDirectionTransform.forward * spawnForce);
            }

            return(balloon);
        }
예제 #8
0
        //-------------------------------------------------
        public void ArrowReleased(float inputVelocity)
        {
            inFlight = true;
            released = true;

            airReleaseSound.Play();

            if (OnArrowReleased != null)
            {
                OnArrowReleased(this, "", null);
            }

            if (glintParticle != null)
            {
                glintParticle.Play();
            }

            if (gameObject.GetComponentInChildren <FireSource>().isBurning)
            {
                fireReleaseSound.Play();
            }

            // Check if arrow is shot inside or too close to an object
            RaycastHit[] hits = Physics.SphereCastAll(transform.position, 0.01f, transform.forward, 0.80f, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore);
            foreach (RaycastHit hit in hits)
            {
                if (hit.collider.gameObject != gameObject && hit.collider.gameObject != arrowHeadRB.gameObject && hit.collider != Player.instance.headCollider)
                {
                    Destroy(gameObject);
                    return;
                }
            }

            travelledFrames  = 0;
            prevPosition     = transform.position;
            prevRotation     = transform.rotation;
            prevHeadPosition = arrowHeadRB.transform.position;
            prevVelocity     = GetComponent <Rigidbody>().velocity;

            Destroy(gameObject, 30);
        }
예제 #9
0
 // Token: 0x0600219D RID: 8605 RVA: 0x000A63A4 File Offset: 0x000A45A4
 private void SpawnParticles(GameObject particlePrefab, SoundPlayOneshot sound)
 {
     if (this.bParticlesSpawned)
     {
         return;
     }
     this.bParticlesSpawned = true;
     if (particlePrefab != null)
     {
         GameObject gameObject = Object.Instantiate <GameObject>(particlePrefab, base.transform.position, base.transform.rotation);
         gameObject.GetComponent <ParticleSystem>().Play();
         Object.Destroy(gameObject, 2f);
     }
     if (sound != null)
     {
         if (Time.time - Balloon.s_flLastDeathSound < 0.1f)
         {
             sound.volMax *= 0.25f;
             sound.volMin *= 0.25f;
         }
         sound.Play();
         Balloon.s_flLastDeathSound = Time.time;
     }
 }
예제 #10
0
        //-------------------------------------------------
        private void StickInTarget(Collision collision, bool bSkipRayCast)
        {
            Vector3 prevForward = prevRotation * Vector3.forward;

            // Only stick in target if the collider is front of the arrow head
            if (!bSkipRayCast)
            {
                RaycastHit[] hitInfo;
                hitInfo = Physics.RaycastAll(prevHeadPosition - prevVelocity * Time.deltaTime, prevForward, prevVelocity.magnitude * Time.deltaTime * 2.0f);
                bool properHit = false;
                for (int i = 0; i < hitInfo.Length; ++i)
                {
                    RaycastHit hit = hitInfo[i];

                    if (hit.collider == collision.collider)
                    {
                        properHit = true;
                        break;
                    }
                }

                if (!properHit)
                {
                    return;
                }
            }

            Destroy(glintParticle);

            inFlight = false;

            SetCollisionMode(CollisionDetectionMode.Discrete, true);

            shaftRB.velocity        = Vector3.zero;
            shaftRB.angularVelocity = Vector3.zero;
            shaftRB.isKinematic     = true;
            shaftRB.useGravity      = false;
            shaftRB.transform.GetComponent <BoxCollider>().enabled = false;

            arrowHeadRB.velocity        = Vector3.zero;
            arrowHeadRB.angularVelocity = Vector3.zero;
            arrowHeadRB.isKinematic     = true;
            arrowHeadRB.useGravity      = false;
            arrowHeadRB.transform.GetComponent <BoxCollider>().enabled = false;

            hitTargetSound.Play();


            // If the hit item has a parent, dock an empty object to that
            // this fixes an issue with scaling hierarchy. I suspect this is not sustainable for a large object / scaling hierarchy.
            scaleParentObject = new GameObject("Arrow Scale Parent");
            Transform parentTransform = collision.collider.transform;

            // Don't do this for weebles because of how it has a fixed joint
            ExplosionWobble wobble = collision.collider.gameObject.GetComponent <ExplosionWobble>();

            if (!wobble)
            {
                if (parentTransform.parent)
                {
                    parentTransform = parentTransform.parent;
                }
            }

            scaleParentObject.transform.parent = parentTransform;

            // Move the arrow to the place on the target collider we were expecting to hit prior to the impact itself knocking it around
            transform.parent   = scaleParentObject.transform;
            transform.rotation = prevRotation;
            transform.position = prevPosition;
            transform.position = collision.contacts[0].point - transform.forward * (0.75f - (Util.RemapNumberClamped(prevVelocity.magnitude, 0f, 10f, 0.0f, 0.1f) + Random.Range(0.0f, 0.05f)));
        }
예제 #11
0
        //-------------------------------------------------
        private void HandAttachedUpdate(Hand hand)
        {
            if (bow == null)
            {
                FindBow();
            }

            if (bow == null)
            {
                return;
            }

            if (allowArrowSpawn && (currentArrow == null))                 // If we're allowed to have an active arrow in hand but don't yet, spawn one
            {
                currentArrow = InstantiateArrow();
                arrowSpawnSound.Play();
            }

            var distanceToNockPosition = Vector3.Distance(transform.parent.position, bow.nockTransform.position);

            // If there's an arrow spawned in the hand and it's not nocked yet
            if (!nocked)
            {
                // If we're close enough to nock position that we want to start arrow rotation lerp, do so
                if (distanceToNockPosition < rotationLerpThreshold)
                {
                    var lerp = Util.RemapNumber(distanceToNockPosition, rotationLerpThreshold, lerpCompleteDistance, 0, 1);

                    arrowNockTransform.rotation = Quaternion.Lerp(arrowNockTransform.parent.rotation, bow.nockRestTransform.rotation, lerp);
                }
                else                 // Not close enough for rotation lerp, reset rotation
                {
                    arrowNockTransform.localRotation = Quaternion.identity;
                }

                // If we're close enough to the nock position that we want to start arrow position lerp, do so
                if (distanceToNockPosition < positionLerpThreshold)
                {
                    var posLerp = Util.RemapNumber(distanceToNockPosition, positionLerpThreshold, lerpCompleteDistance, 0, 1);

                    posLerp = Mathf.Clamp(posLerp, 0f, 1f);

                    arrowNockTransform.position = Vector3.Lerp(arrowNockTransform.parent.position, bow.nockRestTransform.position, posLerp);
                }
                else                 // Not close enough for position lerp, reset position
                {
                    arrowNockTransform.position = arrowNockTransform.parent.position;
                }


                // Give a haptic tick when lerp is visually complete
                if (distanceToNockPosition < lerpCompleteDistance)
                {
                    if (!arrowLerpComplete)
                    {
                        arrowLerpComplete = true;
                        hand.controller.TriggerHapticPulse(500);
                    }
                }
                else
                {
                    if (arrowLerpComplete)
                    {
                        arrowLerpComplete = false;
                    }
                }

                // Allow nocking the arrow when controller is close enough
                if (distanceToNockPosition < nockDistance)
                {
                    if (!inNockRange)
                    {
                        inNockRange = true;
                        bow.ArrowInPosition();
                    }
                }
                else
                {
                    if (inNockRange)
                    {
                        inNockRange = false;
                    }
                }

                // If arrow is close enough to the nock position and we're pressing the trigger, and we're not nocked yet, Nock
                if ((distanceToNockPosition < nockDistance) && hand.controller.GetPress(SteamVR_Controller.ButtonMask.Trigger) && !nocked)
                {
                    if (currentArrow == null)
                    {
                        currentArrow = InstantiateArrow();
                    }

                    nocked = true;
                    bow.StartNock(this);
                    hand.HoverLock(GetComponent <Interactable>());
                    allowTeleport.teleportAllowed = false;
                    currentArrow.transform.parent = bow.nockTransform;
                    Util.ResetTransform(currentArrow.transform);
                    Util.ResetTransform(arrowNockTransform);
                }
            }


            // If arrow is nocked, and we release the trigger
            if (nocked && (!hand.controller.GetPress(SteamVR_Controller.ButtonMask.Trigger) || hand.controller.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)))
            {
                if (bow.pulled)                   // If bow is pulled back far enough, fire arrow, otherwise reset arrow in arrowhand
                {
                    FireArrow();
                }
                else
                {
                    arrowNockTransform.rotation   = currentArrow.transform.rotation;
                    currentArrow.transform.parent = arrowNockTransform;
                    Util.ResetTransform(currentArrow.transform);
                    nocked = false;
                    bow.ReleaseNock();
                    hand.HoverUnlock(GetComponent <Interactable>());
                    allowTeleport.teleportAllowed = true;
                }

                bow.StartRotationLerp();                 // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation
            }
        }
예제 #12
0
        //-------------------------------------------------
        private void HandAttachedUpdate(Hand hand)
        {
            if (_bow == null)
            {
                FindBow();
            }

            if (_bow == null)
            {
                return;
            }

            if (allowArrowSpawn && (_currentArrow == null))                 // If we're allowed to have an active arrow in hand but don't yet, spawn one
            {
                InstantiateAndSetArrow();
                arrowSpawnSound.Play();
            }

            float distanceToNockPosition = Vector3.Distance(transform.parent.position, _bow.nockTransform.position);

            // If there's an arrow spawned in the hand and it's not nocked yet
            if (!nocked)
            {
                // If we're close enough to nock position that we want to start arrow rotation lerp, do so
                if (distanceToNockPosition < rotationLerpThreshold)
                {
                    float lerp = Util.RemapNumber(distanceToNockPosition, rotationLerpThreshold, lerpCompleteDistance, 0, 1);
                    ArrowNockTransform.rotation = Quaternion.Lerp(ArrowNockTransform.parent.rotation, _bow.nockRestTransform.rotation, lerp);
                }
                else                 // Not close enough for rotation lerp, reset rotation
                {
                    ArrowNockTransform.localRotation = Quaternion.identity;
                }
                // If we're close enough to the nock position that we want to start arrow position lerp, do so
                if (distanceToNockPosition < positionLerpThreshold)
                {
                    float posLerp = Util.RemapNumber(distanceToNockPosition, positionLerpThreshold, lerpCompleteDistance, 0, 1);

                    posLerp = Mathf.Clamp(posLerp, 0f, 1f);

                    ArrowNockTransform.position = Vector3.Lerp(ArrowNockTransform.parent.position, _bow.nockRestTransform.position, posLerp);
                }
                else                 // Not close enough for position lerp, reset position
                {
                    ArrowNockTransform.position = ArrowNockTransform.parent.position;
                }


                // Give a haptic tick when lerp is visually complete
                if (distanceToNockPosition < lerpCompleteDistance)
                {
                    if (!arrowLerpComplete)
                    {
                        arrowLerpComplete = true;
                        hand.TriggerHapticPulse(500);
                    }
                }
                else if (arrowLerpComplete)
                {
                    arrowLerpComplete = false;
                }

                // Allow nocking the arrow when controller is close enough
                if (distanceToNockPosition < nockDistance)
                {
                    if (!inNockRange)
                    {
                        inNockRange = true;
                        _bow.ArrowInPosition();
                    }
                }
                else if (inNockRange)
                {
                    inNockRange = false;
                }

                GrabTypes bestGrab = hand.GetBestGrabbingType(GrabTypes.Pinch, true);

                // If arrow is close enough to the nock position and we're pressing the trigger, and we're not nocked yet, Nock
                if ((distanceToNockPosition < nockDistance) && bestGrab != GrabTypes.None && !nocked)
                {
                    if (_currentArrow == null)
                    {
                        InstantiateAndSetArrow();
                    }

                    nocked         = true;
                    nockedWithType = bestGrab;
                    _bow.StartNock(this);
                    hand.HoverLock(GetComponent <Interactable>());
                    _currentArrow.transform.parent = _bow.nockTransform;
                    Util.ResetTransform(_currentArrow.transform);
                    Util.ResetTransform(ArrowNockTransform);
                }
            }
            if (_currentArrowCmpt != null)
            {
                _currentArrowCmpt.Charging = nocked && _bow.pulled;
            }

            // If arrow is nocked, and we release the trigger
            if (nocked)
            {
                if (hand.IsGrabbingWithType(nockedWithType) == false)
                {
                    if (_bow.pulled)                     // If bow is pulled back far enough, fire arrow, otherwise reset arrow in arrowhand
                    {
                        FireArrow();
                    }
                    else
                    {
                        ArrowNockTransform.rotation    = _currentArrow.transform.rotation;
                        _currentArrow.transform.parent = ArrowNockTransform;
                        Util.ResetTransform(_currentArrow.transform);
                        nocked         = false;
                        nockedWithType = GrabTypes.None;
                        _bow.ReleaseNock();
                        hand.HoverUnlock(GetComponent <Interactable>());
                    }
                    _bow.StartRotationLerp();                     // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation
                }
            }
        }
예제 #13
0
        //-------------------------------------------------
        private void HandAttachedUpdate(Hand hand)
        {
            //quiver.GetComponent<Quiver>().
            //Debug.Log("update");
            if (bow == null)
            {
                FindBow();
            }

            if (bow == null)
            {
                return;
            }

            float distanceToNockPosition = Vector3.Distance(transform.parent.position, bow.nockTransform.position);

            int quiverType = quiverSelection.GetComponent <Dropdown>().value + 1;

            switch (quiverType)
            {
            case 1:
                quiver = GameObject.Find("Quiver (Neck)");
                break;

            case 2:
                quiver = GameObject.Find("Quiver (Shoulder)");
                break;

            case 3:
                quiver = GameObject.Find("Quiver (Chest)");
                break;

            default:
                print("Oops");
                break;
            }

            noQuiver = quiverEnable.GetComponent <Toggle>().isOn;

            if (allowArrowSpawn && (currentArrow == null) && ((noQuiver || quiver.GetComponent <Interactable>().isHovering)))   // If we're allowed to have an active arrow in hand but don't yet, spawn one
            {
                currentArrow = InstantiateArrow();
                arrowSpawnSound.Play();
                hand.TriggerHapticPulse(5000);
            }



            // If there's an arrow spawned in the hand and it's not nocked yet
            else if ((currentArrow != null) && !nocked)
            {
                // If we're close enough to nock position that we want to start arrow rotation lerp, do so
                if (distanceToNockPosition < rotationLerpThreshold)
                {
                    float lerp = Util.RemapNumber(distanceToNockPosition, rotationLerpThreshold, lerpCompleteDistance, 0, 1);

                    arrowNockTransform.rotation = Quaternion.Lerp(arrowNockTransform.parent.rotation, bow.nockRestTransform.rotation, lerp);
                }
                else                 // Not close enough for rotation lerp, reset rotation
                {
                    arrowNockTransform.localRotation = Quaternion.identity;
                }

                // If we're close enough to the nock position that we want to start arrow position lerp, do so
                if (distanceToNockPosition < positionLerpThreshold)
                {
                    float posLerp = Util.RemapNumber(distanceToNockPosition, positionLerpThreshold, lerpCompleteDistance, 0, 1);

                    posLerp = Mathf.Clamp(posLerp, 0f, 1f);

                    arrowNockTransform.position = Vector3.Lerp(arrowNockTransform.parent.position, bow.nockRestTransform.position, posLerp);
                }
                else                 // Not close enough for position lerp, reset position
                {
                    arrowNockTransform.position = arrowNockTransform.parent.position;
                }


                // Give a haptic tick when lerp is visually complete
                if (distanceToNockPosition < lerpCompleteDistance)
                {
                    if (!arrowLerpComplete)
                    {
                        arrowLerpComplete = true;
                        hand.TriggerHapticPulse(500);
                    }
                }
                else
                {
                    if (arrowLerpComplete)
                    {
                        arrowLerpComplete = false;
                    }
                }

                // Allow nocking the arrow when controller is close enough
                if (distanceToNockPosition < nockDistance)
                {
                    if (!inNockRange)
                    {
                        inNockRange = true;
                        bow.ArrowInPosition();
                    }
                }
                else
                {
                    if (inNockRange)
                    {
                        inNockRange = false;
                    }
                }

                GrabTypes bestGrab = hand.GetBestGrabbingType(GrabTypes.Pinch, true);

                // If arrow is close enough to the nock position and we're pressing the trigger, and we're not nocked yet, Nock
                if ((distanceToNockPosition < nockDistance) && bestGrab != GrabTypes.None && !nocked)
                {
                    if (currentArrow == null)
                    {
                        currentArrow = InstantiateArrow();
                    }

                    nocked         = true;
                    nockedWithType = bestGrab;
                    bow.StartNock(this);
                    hand.HoverLock(GetComponent <Interactable>());
                    allowTeleport.teleportAllowed = false;
                    currentArrow.transform.parent = bow.nockTransform;
                    Util.ResetTransform(currentArrow.transform);
                    Util.ResetTransform(arrowNockTransform);
                }
            }


            // If arrow is nocked, and we release the trigger
            if (nocked && hand.IsGrabbingWithType(nockedWithType) == false)
            {
                if (bow.pulled)                   // If bow is pulled back far enough, fire arrow, otherwise reset arrow in arrowhand
                {
                    FireArrow();
                }
                else
                {
                    arrowNockTransform.rotation   = currentArrow.transform.rotation;
                    currentArrow.transform.parent = arrowNockTransform;
                    Util.ResetTransform(currentArrow.transform);
                    nocked         = false;
                    nockedWithType = GrabTypes.None;
                    bow.ReleaseNock();
                    hand.HoverUnlock(GetComponent <Interactable>());
                    allowTeleport.teleportAllowed = true;
                }

                bow.StartRotationLerp();                 // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation
            }
        }