Exemplo n.º 1
0
    private void FindAndHighlightClosestObject()
    {
        m_closestObject = null;
        if (m_gadgetSelectorOpen)
        {
            m_gadgetSelector.Highlight(transform.position, SteamVR_Controller.Input((int)trackedObj.index).GetAxis());
        }
        else if (m_inventory != null && !m_inventory.isEmpty)
        {
            m_inventory.Highlight(transform.position);
        }
        else if (m_itemsInRange.Count == 0)
        {
            return;
        }
        else if (m_itemsInRange.Count == 1)
        {
            ItemProperties itemProperties = m_itemsInRange[0].GetComponent <ItemProperties>();
            if (itemProperties.isInUse)
            {
                itemProperties.Highlight(false);
            }
            else
            {
                itemProperties.Highlight(true);
                m_closestObject = m_itemsInRange[0];
            }
        }
        else
        {
            float          minMagnitude   = float.MaxValue;
            GameObject     closestObject  = null;
            ItemProperties itemProperties = null;
            foreach (GameObject item in m_itemsInRange)
            {
                itemProperties = item.GetComponent <ItemProperties>();
                itemProperties.Highlight(false);
                if (itemProperties.isInUse)
                {
                    continue;
                }

                float dist = (item.transform.position - transform.position).magnitude;
                if (dist < minMagnitude)
                {
                    minMagnitude  = dist;
                    closestObject = item;
                }
            }
            if (closestObject != null)
            {
                m_closestObject = closestObject;
                m_closestObject.GetComponent <ItemProperties>().Highlight(true);
            }
        }
    }
Exemplo n.º 2
0
    private void PickupItem(GameObject item)
    {
        handObject = item;
        handObject.transform.position = transform.position;
        handObject.transform.rotation = transform.rotation;
        handObject.GetComponent <Collider>().enabled      = false;
        handObject.GetComponent <Rigidbody>().isKinematic = true;
        handObject.transform.parent = transform;
        m_isHandBusy = true;

        ItemProperties itemProperties = handObject.GetComponent <ItemProperties>();

        itemProperties.isInUse = true;
        itemProperties.Highlight(false);

        m_otherDevicePickupSystem.RemoveItemFromRange(item);
    }
Exemplo n.º 3
0
    void Update()
    {
        var device = SteamVR_Controller.Input((int)trackedObj.index);

        if (handObject == null)
        {
            if (!m_isHandBusy)
            {
                FindAndHighlightClosestObject();
            }

            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis0) && !m_interactiveInRange && m_gadgetSelector != null)
            {
                OpenGadgetSelector();
            }
            else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Axis0) && m_gadgetSelector != null)
            {
                CloseGadgetSelector(device.GetAxis());
            }
            else if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu) && m_inventory != null)
            {
                EnableInventory();
            }
            else if (device.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu) && m_inventoryOpen && m_inventory != null)
            {
                DisableInventory();
            }
        }
        else if (handObject != null && device.GetPressUp(SteamVR_Controller.ButtonMask.Axis0) && handObject.tag == "Item")
        {
            ItemProperties itemProperties = handObject.GetComponent <ItemProperties>();

            // If possible, store the item in the inventory
            if (m_inventory != null && itemProperties.storable && !m_inventory.isFull)
            {
                m_inventory.StoreItem(handObject);
            }
            // If possible, toss the item
            else if (itemProperties.tossable)
            {
                Rigidbody handObjectRigidbody = handObject.GetComponent <Rigidbody>();
                Rigidbody playerRigidbody     = transform.parent.GetComponent <Rigidbody>();
                handObjectRigidbody.isKinematic = false;

                var origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent;
                if (origin != null)
                {
                    handObjectRigidbody.velocity        = playerRigidbody.velocity + origin.TransformVector(device.velocity);
                    handObjectRigidbody.angularVelocity = playerRigidbody.angularVelocity + origin.TransformVector(device.angularVelocity);
                }
                else
                {
                    handObjectRigidbody.velocity        = playerRigidbody.velocity + device.velocity;
                    handObjectRigidbody.angularVelocity = playerRigidbody.angularVelocity + device.angularVelocity;
                }

                handObjectRigidbody.maxAngularVelocity = handObjectRigidbody.angularVelocity.magnitude;
            }

            // Release object
            if (handObject.transform.parent == transform)
            {
                handObject.transform.parent = null;
            }

            itemProperties.isInUse = false;
            itemProperties.Highlight(false);
            handObject.GetComponent <Collider>().enabled = true;
            handObject      = null;
            m_isHandBusy    = false;
            m_closestObject = null;
            m_itemsInRange.Clear();
            FindAndHighlightClosestObject();
        }
    }