コード例 #1
0
ファイル: PistolExample.cs プロジェクト: srcnalt/InteraktVR
 void Start()
 {
     _audioSource = GetComponent <AudioSource>();
     _item        = GetComponent <VRInteractableItem>();
     if (_item == null)
     {
         Debug.LogError("This script requires an VRInteracableItem script on the same object", gameObject);
         return;
     }
 }
コード例 #2
0
    void OnTriggerStay(Collider collider)
    {
        //If collider has a rigid body to report to
        if (collider.attachedRigidbody != null)
        {
            //If rigidbody's object has interactable item scripts, iterate through them
            VRInteractableItem[] interactables = collider.attachedRigidbody.GetComponents <VRInteractableItem>();
            for (int i = 0; i < interactables.Length; i++)
            {
                VRInteractableItem interactable = interactables[i];
                for (int b = 0; b < buttonsTracked.Count; b++)
                {
                    //If a tracked button is pressed
                    EVRButtonId button = buttonsTracked[b];
                    if (device.GetPressDown(button))
                    {
                        //If we haven't already sent the button press message to this interactable
                        //Safeguard against objects that have multiple colliders for one interactable script
                        if (!pressDownObjects.ContainsKey(button) || !pressDownObjects[button].Contains(interactable))
                        {
                            //Send button press through to interactable script
                            interactable.ButtonPressDown(button, this);

                            //Add interactable script to a dictionary flagging it to recieve notice
                            //when that same button is released
                            if (!pressDownObjects.ContainsKey(button))
                            {
                                pressDownObjects.Add(button, new List <VRInteractableItem>());
                            }

                            pressDownObjects[button].Add(interactable);
                        }
                    }
                }
            }
        }
    }
コード例 #3
0
        public virtual void Teleport()
        {
            if (_interactor != null && hideWhenHoldingItem && _interactor.heldItem != null)
            {
                return;
            }
            if (_hoverItem != null)
            {
                if (_interactor == null)
                {
                    Debug.LogError("Need VRInteractor attached to same object as teleporter to pickup items", gameObject);
                    return;
                }
                if (_interactor.hoverItem != null)
                {
                    _interactor.hoverItem.DisableHover(_interactor);
                }
                _interactor.hoverItem = _hoverItem;
                _interactor.TryPickup();
                _hoverItem = null;
                if (teleportHighlight != null && pickupHighlight != null)
                {
                    if (_alternativeHighlightInstance == null)
                    {
                        _alternativeHighlightInstance = Instantiate <GameObject>(teleportHighlight);
                    }
                    GameObject tempHighlight = _teleportHighlightInstance;
                    _teleportHighlightInstance    = _alternativeHighlightInstance;
                    _alternativeHighlightInstance = tempHighlight;
                    _alternativeHighlightInstance.SetActive(false);
                    _teleportHighlightInstance.SetActive(true);
                }
                return;
            }

            if (transitioning || (Time.time - lastTeleportTime) < teleportCooldown || !enabled)
            {
                return;
            }
            if (canTeleport)
            {
                _roomRotation = _roomShapeInstance.transform.rotation;
                _roomPosition = _roomShapeInstance.transform.position;
            }
            if (onMoveSound != null)
            {
                AudioSource.PlayClipAtPoint(onMoveSound, transform.position);
            }
            switch (firingMode)
            {
            case FiringMode.ARC:
                if (teleportActive && canTeleport)
                {
                    switch (transition)
                    {
                    case Transition.INSTANT:
                        MoveToTarget();
                        lastTeleportTime = Time.time;
                        break;

                    case Transition.FADE:
                        if (fadeQuad == null)
                        {
                            CreateFadeQuad();
                            StartCoroutine(fadeTransition());
                            lastTeleportTime = Time.time;
                        }
                        break;

                    case Transition.DASH:
                        StartCoroutine(dashTransition());
                        lastTeleportTime = Time.time;
                        break;
                    }
                }
                break;

            case FiringMode.PROJECTILE:
                if (projectileInstance != null)
                {
                    switch (transition)
                    {
                    case Transition.INSTANT:
                        if (canTeleport)
                        {
                            MoveToTarget();
                            lastTeleportTime = Time.time;
                        }
                        break;

                    case Transition.FADE:
                        if (canTeleport && fadeQuad == null)
                        {
                            CreateFadeQuad();
                            StartCoroutine(fadeTransition());
                            lastTeleportTime = Time.time;
                        }
                        break;

                    case Transition.DASH:
                        StartCoroutine(dashTransition());
                        lastTeleportTime = Time.time;
                        break;
                    }
                }
                break;
            }
        }
コード例 #4
0
        //	Overide and change to expand on what is a good landing spot
        virtual protected bool IsGoodSpot(RaycastHit hit)
        {
            if (hit.transform == null)
            {
                return(false);
            }

            if (canPickupItems)
            {
                VRInteractableItem item = hit.collider.GetComponent <VRInteractableItem>();
                if (item == null)
                {
                    VRItemCollider itemCollider = hit.collider.GetComponent <VRItemCollider>();
                    if (itemCollider != null)
                    {
                        item = itemCollider.item;
                    }
                }
                if (item != null && _hoverItem == null)
                {
                    _hoverItem = item;
                    if (teleportHighlight != null && pickupHighlight != null)
                    {
                        if (_alternativeHighlightInstance == null)
                        {
                            _alternativeHighlightInstance = Instantiate <GameObject>(pickupHighlight);
                        }
                        GameObject tempHighlight = _teleportHighlightInstance;
                        _teleportHighlightInstance    = _alternativeHighlightInstance;
                        _alternativeHighlightInstance = tempHighlight;
                        _alternativeHighlightInstance.SetActive(false);
                        _teleportHighlightInstance.SetActive(true);
                    }
                }
                else if (item == null && _hoverItem != null)
                {
                    _hoverItem = null;
                    if (teleportHighlight != null && pickupHighlight != null)
                    {
                        if (_alternativeHighlightInstance == null)
                        {
                            _alternativeHighlightInstance = Instantiate <GameObject>(teleportHighlight);
                        }
                        GameObject tempHighlight = _teleportHighlightInstance;
                        _teleportHighlightInstance    = _alternativeHighlightInstance;
                        _alternativeHighlightInstance = tempHighlight;
                        _alternativeHighlightInstance.SetActive(false);
                        _teleportHighlightInstance.SetActive(true);
                    }
                }
            }

            if (onlyLandOnFlat)
            {
                float angle = Vector3.Angle(Vector3.up, hit.normal);
                if (angle > slopeLimit)
                {
                    return(false);
                }
            }
            if (onlyLandOnTag)
            {
                bool foundSpot = false;
                foreach (string tag in tags)
                {
                    if (hit.transform.tag == tag)
                    {
                        foundSpot = true;
                    }
                }
                if (!foundSpot)
                {
                    return(false);
                }
            }
            _lastGoodSpot = true;
            return(true);
        }