public override void InteractWith(Interactor interactor) { Containable containable = this.GetComponent <Containable>(); Container container = interactor.GetComponent <Container>(); containable.TryBeContained(container); }
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; }
void SendReleasedMessage(Containable released) { foreach (IOnContainerRelease onContainerRelease in this.GetComponents <IOnContainerRelease>()) { onContainerRelease.OnRelease(released); } }
public override bool GetInteractable(Interactor interactor) { Containable containable = this.GetComponent <Containable>(); Container container = interactor.GetComponent <Container>(); return(base.GetInteractable(interactor) && container && container.CanContain(containable)); }
public void OnRelease(Containable released) { if (this.state == HandState.closed) { UpdateState(HandState.fist); } }
public void Release(Containable containable) { if (contained.Contains(containable)) { containable.BeReleased(this); SendReleasedMessage(containable); contained.Remove(containable); } }
public bool TryContain(Containable containable) { if (!CanContain(containable)) { return(false); } containable.TryBeContained(this); return(contained.Contains(containable)); }
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); } }
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); } }
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); }
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); }
public bool CanContain(Containable containable) { return(containable && (contained.Count < maxObjects) && !contained.Contains(containable) && containable.CanBeContained(this)); }
// This should never be called directly public void Contain(Containable containable) { containable.BeContained(this); contained.Add(containable); }