Beispiel #1
0
    public override void InteractWith(Interactor interactor)
    {
        Containable containable = this.GetComponent <Containable>();
        Container   container   = interactor.GetComponent <Container>();

        containable.TryBeContained(container);
    }
Beispiel #2
0
    IEnumerator RunHighlight(Interactor interactor)
    {
        MeshRenderer    mr   = this.GetComponent <MeshRenderer>();
        List <Material> mats = new List <Material>(mr.materials);

        mats.Add(highlightMaterial);
        mr.materials = mats.ToArray();

        Controller interactorController = interactor.GetComponent <Controller>();

        if (!interactorController)
        {
            Containable interactorContainable = interactor.GetComponent <Containable>();
            if (interactorContainable && interactorContainable.GetContainer())
            {
                interactorController = interactorContainable.GetContainer().GetComponent <Controller>();
            }
        }
        if (interactorController)
        {
            interactorController.Get.TriggerHapticPulse(2000);
        }
        while (hoverBuffer >= 0)
        {
            yield return(null);
        }
        mats.RemoveAt(mats.Count - 1);
        mr.materials = mats.ToArray();
        coroutine    = null;
    }
Beispiel #3
0
 void SendReleasedMessage(Containable released)
 {
     foreach (IOnContainerRelease onContainerRelease in this.GetComponents <IOnContainerRelease>())
     {
         onContainerRelease.OnRelease(released);
     }
 }
Beispiel #4
0
    public override bool GetInteractable(Interactor interactor)
    {
        Containable containable = this.GetComponent <Containable>();
        Container   container   = interactor.GetComponent <Container>();

        return(base.GetInteractable(interactor) && container && container.CanContain(containable));
    }
Beispiel #5
0
 public void OnRelease(Containable released)
 {
     if (this.state == HandState.closed)
     {
         UpdateState(HandState.fist);
     }
 }
Beispiel #6
0
 public void Release(Containable containable)
 {
     if (contained.Contains(containable))
     {
         containable.BeReleased(this);
         SendReleasedMessage(containable);
         contained.Remove(containable);
     }
 }
Beispiel #7
0
 public bool TryContain(Containable containable)
 {
     if (!CanContain(containable))
     {
         return(false);
     }
     containable.TryBeContained(this);
     return(contained.Contains(containable));
 }
Beispiel #8
0
        private void ContainableAdded(Containable component, long entityIdentifier)
        {
            if (component.ContainingEntityId.HasValue)
            {
                if (!_containedEntityiesMap.ContainsKey(component.ContainingEntityId.Value))
                {
                    _containedEntityiesMap.Add(component.ContainingEntityId.Value, new HashSet <long>());
                }

                _containedEntityiesMap[component.ContainingEntityId.Value].Add(entityIdentifier);
            }
        }
Beispiel #9
0
    void Update()
    {
        Controller controller = this.GetComponent <Controller>();

        if ((state == HandState.open || state == HandState.point) &&
            controller.Get.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)
            )
        {
            if (hoverObject)
            {
                hoverObject.InteractWith(this);
            }
            if (hoverObject && hoverObject.GetComponent <Containable>() && hoverObject.GetComponent <Containable>().GetContainer() == this.GetComponent <Container>())
            {
                UpdateState(HandState.closed);
            }
            else
            {
                UpdateState(HandState.fist);
            }
        }
        else if ((state == HandState.closed || state == HandState.fist) &&
                 controller.Get.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            List <Containable> contained = this.GetComponent <Container>().GetContained();
            if (contained.Count > 0)
            {
                Containable toDrop = contained[0];
                this.GetComponent <HandContainer>().Release(toDrop);
                foreach (IOnLetGo letGo in toDrop.GetComponentsInChildren <IOnLetGo>())
                {
                    letGo.OnLetGo(this.GetComponent <HandContainer>());
                }
            }
            this.GetComponent <HandContainer>().ReleaseAll();
            if (controller.Get.GetPress(SteamVR_Controller.ButtonMask.Grip))
            {
                UpdateState(HandState.point);
            }
            else
            {
                UpdateState(HandState.open);
            }
        }
        else if (state == HandState.open && controller.Get.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
        {
            UpdateState(HandState.point);
        }
        else if (state == HandState.point && controller.Get.GetPressUp(SteamVR_Controller.ButtonMask.Grip))
        {
            UpdateState(HandState.open);
        }
    }
Beispiel #10
0
        private void ContainableUpdated(Containable oldComponent, Containable newComponent, long entityIdentifier)
        {
            if (oldComponent.ContainingEntityId.HasValue)
            {
                _containedEntityiesMap[oldComponent.ContainingEntityId.Value].Remove(entityIdentifier);

                if (_containedEntityiesMap[oldComponent.ContainingEntityId.Value].Count == 0)
                {
                    _containedEntityiesMap.Remove(oldComponent.ContainingEntityId.Value);
                }
            }

            ContainableAdded(newComponent, entityIdentifier);
        }
Beispiel #11
0
    public override bool CanInteractWith(Interactable interactable)
    {
        if (!base.CanInteractWith(interactable))
        {
            return(false);
        }
        if (this.state != HandState.open)
        {
            return(false);
        }
        if (interactable.GetComponent <OpenHandInteractable>() == null)
        {
            return(false);
        }
        Containable containable = interactable.GetComponent <Containable>();

        if (containable)
        {
            return(this.GetComponent <HandContainer>().CanContain(interactable.GetComponent <Containable>()));
        }
        return(true);
    }
Beispiel #12
0
 public bool CanContain(Containable containable)
 {
     return(containable && (contained.Count < maxObjects) && !contained.Contains(containable) && containable.CanBeContained(this));
 }
Beispiel #13
0
 // This should never be called directly
 public void Contain(Containable containable)
 {
     containable.BeContained(this);
     contained.Add(containable);
 }