示例#1
1
    protected int _timeToDie = 0;  // Timer after _timeToLive goes negative before deactivation.

    public override void Init(IInteractionBehaviour interactionBehaviour, ActivityManager manager) {
      _interactionBehaviour = interactionBehaviour;
      _manager = manager;
      Revive();

      _rigidbody = GetComponent<Rigidbody>();
    }
        protected override bool checkShouldGraspAtemporal(IInteractionBehaviour intObj)
        {
            var sphere = singleContactBone.collider as SphereCollider;

            return(intObj.GetHoverDistance(sphere.transform.TransformPoint(sphere.center))
                   < sphere.transform.TransformVector(Vector3.right).magnitude *sphere.radius);
        }
        /// <summary>
        /// Unregisters an InteractionObject from this manager.  This removes it from the internal
        /// scene and prevents any further interaction.
        ///
        /// Trying to unregister a behaviour that is not registered is safe and is a no-op.
        /// </summary>
        public void UnregisterInteractionBehaviour(IInteractionBehaviour interactionBehaviour)
        {
            if (_graspedBehaviours.Remove(interactionBehaviour))
            {
                for (var it = _idToInteractionHand.GetEnumerator(); it.MoveNext();)
                {
                    var interactionHand = it.Current.Value;
                    if (interactionHand.graspedObject == interactionBehaviour)
                    {
                        try {
                            if (interactionHand.isUntracked)
                            {
                                interactionHand.MarkTimeout();
                            }
                            else
                            {
                                interactionHand.ReleaseObject();
                            }
                        } catch (Exception e) {
                            //Only log to console
                            //We want to continue so we can destroy the shape and dispatch OnUnregister
                            Debug.LogException(e);
                        }
                        break;
                    }
                }
            }

            _activityManager.Unregister(interactionBehaviour);
            _grabClassifier.UnregisterInteractionBehaviour(interactionBehaviour);
        }
        /// <summary>
        /// Forces the given object to be released by any hands currently holding it.  Will return true
        /// only if there was at least one hand holding the object.
        /// </summary>
        public bool ReleaseObject(IInteractionBehaviour graspedObject)
        {
            if (!_graspedBehaviours.Remove(graspedObject))
            {
                return(false);
            }

            for (var it = _idToInteractionHand.GetEnumerator(); it.MoveNext();)
            {
                var interactionHand = it.Current.Value;
                if (interactionHand.graspedObject == graspedObject)
                {
                    if (interactionHand.isUntracked)
                    {
                        interactionHand.MarkTimeout();
                    }
                    else
                    {
                        if (_graspingEnabled)
                        {
                        }
                        interactionHand.ReleaseObject();

                        InteractionBrushHand ibHand;
                        if ((ibHand = _handPool.GetHandModel <InteractionBrushHand>(interactionHand.hand.Id)) != null)
                        {
                            ibHand.enableSoftContact();
                        }
                    }
                }
            }

            return(true);
        }
        protected override bool checkShouldGrasp(out IInteractionBehaviour objectToGrasp)
        {
            var toGrasp = OverlapSphereGetClosest(singleContactBone.collider as SphereCollider,
                                                  manager.GetInteractionLayerMask());

            if (toGrasp == null)
            {
                objectToGrasp = null;
                return(false);
            }

            var intObj = toGrasp.attachedRigidbody.GetComponent <InteractionBehaviour>();

            if (intObj != null && !intObj.ignoreGrasping
                &&
                enableKeyboardControl && Input.GetKey(graspKey))
            {
                objectToGrasp = intObj;
                return(true);
            }
            else
            {
                objectToGrasp = null;
                return(false);
            }
        }
        protected virtual void dispatchOnHandsHolding(List <Hand> hands, IInteractionBehaviour interactionBehaviour, bool isPhysics)
        {
            for (int j = 0; j < hands.Count; j++)
            {
                var             hand = hands[j];
                InteractionHand interactionHand;
                if (_idToInteractionHand.TryGetValue(hand.Id, out interactionHand))
                {
                    if (interactionHand.graspedObject == interactionBehaviour)
                    {
                        _holdingHands.Add(hand);
                    }
                }
            }

            try {
                if (isPhysics)
                {
                    interactionBehaviour.NotifyHandsHoldPhysics(_holdingHands);
                }
                else
                {
                    interactionBehaviour.NotifyHandsHoldGraphics(_holdingHands);
                }
            } catch (Exception e) {
                _activityManager.NotifyMisbehaving(interactionBehaviour);
                Debug.LogException(e);
            }

            _holdingHands.Clear();
        }
        /// <summary>
        /// Forces a hand to grasp the given interaction behaviour.  The grasp will only be terminated when
        /// the hand either times out or the user calls ReleaseHand.
        /// </summary>
        /// <param name="hand"></param>
        public void GraspWithHand(Hand hand, IInteractionBehaviour interactionBehaviour)
        {
            if (!_activityManager.IsRegistered(interactionBehaviour))
            {
                throw new InvalidOperationException("Cannot grasp " + interactionBehaviour + " because it is not registered with this manager.");
            }

            InteractionHand interactionHand;

            if (!_idToInteractionHand.TryGetValue(hand.Id, out interactionHand))
            {
                throw new InvalidOperationException("Hand with id " + hand.Id + " is not registered with this manager.");
            }

            if (interactionHand.graspedObject != null)
            {
                throw new InvalidOperationException("Cannot grasp with hand " + hand.Id + " because that hand is already grasping " + interactionHand.graspedObject);
            }

            //Ensure behaviour is active already
            _activityManager.Activate(interactionBehaviour);

            if (!interactionBehaviour.IsBeingGrasped)
            {
                _graspedBehaviours.Add(interactionBehaviour);
            }

            interactionHand.GraspObject(interactionBehaviour, isUserGrasp: true);
        }
示例#8
0
        public void Deactivate(IInteractionBehaviour interactionBehaviour)
        {
            IActivityMonitor monitor;

            if (_registeredBehaviours.TryGetValue(interactionBehaviour, out monitor))
            {
                if (monitor != null)
                {
                    //The monitor that is last in the array of monitors
                    IInteractionBehaviour lastBehaviour = _activeBehaviours[_activeBehaviours.Count - 1];
                    IActivityMonitor      lastMonitor   = _registeredBehaviours[lastBehaviour];

                    //Replace the monitor we are going to destroy with the last monitor
                    _activeBehaviours[monitor.arrayIndex] = lastBehaviour;
                    //Make sure to update the index of the moved monitor!
                    lastMonitor.arrayIndex = monitor.arrayIndex;
                    //Remove the empty space at the end
                    _activeBehaviours.RemoveAt(_activeBehaviours.Count - 1);

                    _registeredBehaviours[interactionBehaviour] = null;
                    UnityEngine.Object.Destroy(monitor);

                    if (OnDeactivate != null)
                    {
                        OnDeactivate(interactionBehaviour);
                    }
                }
            }
        }
示例#9
0
        public IActivityMonitor Activate(IInteractionBehaviour interactionBehaviour)
        {
            IActivityMonitor monitor;

            if (_registeredBehaviours.TryGetValue(interactionBehaviour, out monitor))
            {
                if (monitor == null)
                {
                    if (_maxDepth == 1)
                    {
                        monitor = interactionBehaviour.gameObject.AddComponent <ActivityMonitorLite>();
                    }
                    else
                    {
                        monitor = interactionBehaviour.gameObject.AddComponent <ActivityMonitor>();
                    }

                    monitor.Init(interactionBehaviour, this);

                    _registeredBehaviours[interactionBehaviour] = monitor;

                    monitor.arrayIndex = _activeBehaviours.Count;
                    _activeBehaviours.Add(interactionBehaviour);

                    if (OnActivate != null)
                    {
                        OnActivate(interactionBehaviour);
                    }
                }
            }
            return(monitor);
        }
示例#10
0
        public void UpdateBehaviour(IInteractionBehaviour behaviour, Hand _hand)
        {
            using (new ProfilerSample("Update Individual Classifier", behaviour.gameObject)) {
                GrabClassifierHeuristics.GrabClassifier classifier;
                Dictionary <IInteractionBehaviour, GrabClassifierHeuristics.GrabClassifier> classifiers = (_hand.IsLeft ? leftGrabClassifiers : rightGrabClassifiers);
                if (!classifiers.TryGetValue(behaviour, out classifier))
                {
                    classifier = new GrabClassifierHeuristics.GrabClassifier(behaviour.gameObject);
                    classifiers.Add(behaviour, classifier);
                }

                //Do the actual grab classification logic
                fillClassifier(_hand, ref classifier);
                GrabClassifierHeuristics.UpdateClassifier(classifier, collidingCandidates, numberOfColliders, scaledGrabParams);

                if (classifier.isGrabbing != classifier.prevGrabbing)
                {
                    if (classifier.isGrabbing)
                    {
                        if (!_manager.TwoHandedGrasping)
                        {
                            _manager.ReleaseObject(behaviour);
                        }
                        _manager.GraspWithHand(_hand, behaviour);
                    }
                    else if (behaviour.IsBeingGraspedByHand(_hand.Id))
                    {
                        _manager.ReleaseHand(_hand.Id);
                        classifier.coolDownProgress = 0f;
                    }
                }
                classifier.prevGrabbing = classifier.isGrabbing;
            }
        }
示例#11
0
 public void EnsureActive(IInteractionBehaviour interactionBehaviour)
 {
     if (!_activityManager.IsActive(interactionBehaviour))
     {
         _activityManager.Activate(interactionBehaviour);
     }
 }
示例#12
0
        /// <summary>
        /// Unregisters an InteractionObject from this manager.  This removes it from the internal
        /// scene and prevents any further interaction.
        ///
        /// Trying to unregister a behaviour that is not registered is safe and is a no-op.
        /// </summary>
        public void UnregisterInteractionBehaviour(IInteractionBehaviour interactionBehaviour)
        {
            if (_graspedBehaviours.Remove(interactionBehaviour))
            {
                foreach (var interactionHand in _idToInteractionHand.Values)
                {
                    if (interactionHand.graspedObject == interactionBehaviour)
                    {
                        try {
                            if (interactionHand.isUntracked)
                            {
                                interactionHand.MarkTimeout();
                            }
                            else
                            {
                                interactionHand.ReleaseObject();
                            }
                        } catch (Exception e) {
                            //Only log to console
                            //We want to continue so we can destroy the shape and dispatch OnUnregister
                            Debug.LogException(e);
                        }
                        break;
                    }
                }
            }

            _activityManager.Unregister(interactionBehaviour);
        }
示例#13
0
        /// <summary>
        /// Forces the given object to be released by any hands currently holding it.  Will return true
        /// only if there was at least one hand holding the object.
        /// </summary>
        public bool ReleaseObject(IInteractionBehaviour graspedObject)
        {
            if (!_graspedBehaviours.Remove(graspedObject))
            {
                return(false);
            }

            foreach (var interactionHand in _idToInteractionHand.Values)
            {
                if (interactionHand.graspedObject == graspedObject)
                {
                    if (interactionHand.isUntracked)
                    {
                        interactionHand.MarkTimeout();
                    }
                    else
                    {
                        if (_graspingEnabled)
                        {
                            INTERACTION_HAND_RESULT result = new INTERACTION_HAND_RESULT();
                            result.classification = ManipulatorMode.Contact;
                            result.handFlags      = HandResultFlags.ManipulatorMode;
                            result.instanceHandle = new INTERACTION_SHAPE_INSTANCE_HANDLE();
                            InteractionC.OverrideHandResult(ref _scene, (uint)interactionHand.hand.Id, ref result);
                        }
                        interactionHand.ReleaseObject();
                    }
                }
            }

            return(true);
        }
示例#14
0
        public override void SwapGrasp(IInteractionBehaviour replacement)
        {
            var original = graspedObject;

            base.SwapGrasp(replacement);

            grabClassifier.SwapClassifierState(original, replacement);
        }
示例#15
0
        protected int _timeToDie  = 0; // Timer after _timeToLive goes negative before deactivation.

        public override void Init(IInteractionBehaviour interactionBehaviour, ActivityManager manager)
        {
            _interactionBehaviour = interactionBehaviour;
            _manager = manager;
            Revive();

            _rigidbody = GetComponent <Rigidbody>();
        }
 protected override void onObjectUnregistered(IInteractionBehaviour intObj)
 {
     if (graspedObject == intObj)
     {
         Debug.LogError("Object was unregistered while grasped by the "
                        + "InteractionTestController: " + intObj.name);
     }
 }
        IEnumerator graspWatcher()
        {
            bool graspingState = false;
            IInteractionBehaviour graspedObject;
            int handId = 0;

            while (true)
            {
                if (interactionManager != null)
                {
                    Leap.Hand hand = HandModel.GetLeapHand();
                    if (hand != null)
                    {
                        handId = hand.Id;
                    }
                    else
                    {
                        handId = 0;
                    }
                    interactionManager.TryGetGraspedObject(handId, out graspedObject);
                    graspingState = false;
                    if (graspedObject != null)
                    {
                        if ((AnyInteractionObject ||
                             (TagName != "" && graspedObject.gameObject.tag == TagName)))
                        {
                            graspingState = true;
                        }
                        else
                        {
                            for (int o = 0; o < TargetObjects.Length; o++)
                            {
                                if (TargetObjects[o] == graspedObject)
                                {
                                    graspingState = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (graspingState)
                    {
                        if (_currentObj != graspedObject)
                        {
                            _currentObj = graspedObject;
                            OnGrasp.Invoke(_currentObj);
                        }
                        Activate();
                    }
                    else
                    {
                        _currentObj = null;
                        Deactivate();
                    }
                }
                yield return(new WaitForSeconds(Period));
            }
        }
示例#18
0
        void IInternalInteractionManager.NotifyIntObjRemovedNoContactLayer(IInteractionBehaviour intObj, int layer, bool refreshImmediately)
        {
            _intObjNoContactLayers[layer].Remove(intObj);

            if (refreshImmediately)
            {
                refreshInteractionLayerMask();
            }
        }
 public static void NotifyIntObjHasNewNoContactLayer(this IInternalInteractionManager manager,
                                                     IInteractionBehaviour intObj,
                                                     int oldNoContactLayer,
                                                     int newNoContactLayer)
 {
     manager.NotifyIntObjRemovedNoContactLayer(intObj, oldNoContactLayer, false);
     manager.NotifyIntObjAddedNoContactLayer(intObj, newNoContactLayer, false);
     manager.RefreshLayersNow();
 }
示例#20
0
    public void Register(IInteractionBehaviour behaviour) {
      //Do nothing if already registered
      if (_registeredBehaviours.ContainsKey(behaviour)) {
        return;
      }

      _registeredBehaviours.Add(behaviour, null);

      behaviour.NotifyRegistered();
    }
示例#21
0
        public bool IsActive(IInteractionBehaviour interactionBehaviour)
        {
            IActivityMonitor monitor;

            if (_registeredBehaviours.TryGetValue(interactionBehaviour, out monitor))
            {
                return(monitor != null);
            }
            return(false); // Not even registered.
        }
    private void assertIsRegisteredWithThisManager(IInteractionBehaviour interactionObj) {
      Assert.IsTrue(interactionObj.IsRegisteredWithManager,
                    "Object must be registered with a manager.");

      Assert.AreEqual(interactionObj.Manager, this,
                      "Object must be registered with this manager.");

      Assert.IsTrue(interactionObj.isActiveAndEnabled,
                    "Object must be active and enabled.");
    }
示例#23
0
        protected virtual void destroyInteractionShape(IInteractionBehaviour interactionBehaviour)
        {
            INTERACTION_SHAPE_INSTANCE_HANDLE instanceHandle = interactionBehaviour.ShapeInstanceHandle;

            _instanceHandleToBehaviour.Remove(instanceHandle);

            InteractionC.DestroyShapeInstance(ref _scene, ref instanceHandle);

            interactionBehaviour.NotifyInteractionShapeDestroyed();
        }
示例#24
0
        private void assertIsRegisteredWithThisManager(IInteractionBehaviour interactionObj)
        {
            Assert.IsTrue(interactionObj.IsRegisteredWithManager,
                          "Object must be registered with a manager.");

            Assert.AreEqual(interactionObj.Manager, this,
                            "Object must be registered with this manager.");

            Assert.IsTrue(interactionObj.isActiveAndEnabled,
                          "Object must be active and enabled.");
        }
示例#25
0
        private void handleCollision(Collision collision)
        {
            IInteractionBehaviour otherBehaviour = null;
            ActivityMonitor       neighbor       = collision.gameObject.GetComponent <ActivityMonitor>();

            if (neighbor != null)
            {
                if (arrayIndex > neighbor.arrayIndex)
                {
                    return; // Only need to do this on one side of a pair.
                }

                otherBehaviour = neighbor._interactionBehaviour;
            }
            else
            {
                if (_timeToLive <= 1)
                {
                    return; // Do not activate neighbor.
                }

                otherBehaviour = collision.gameObject.GetComponent <IInteractionBehaviour>();
                if (otherBehaviour == null)
                {
                    return;
                }

                // Unregistered behaviours will fail to activate.
                neighbor = _manager.Activate(otherBehaviour) as ActivityMonitor;
                if (neighbor != null)
                {
                    neighbor._timeToLive = _timeToLive - 1;
                }
                return;
            }

            // Allow different managers.
            if (!_manager.IsRegistered(otherBehaviour))
            {
                return;
            }

            // propagate both ways
            int nextTime = ((_timeToLive > neighbor._timeToLive) ? _timeToLive : neighbor._timeToLive) - 1;

            if (_timeToLive < nextTime)
            {
                _timeToLive = nextTime;
            }
            else if (neighbor._timeToLive < nextTime)
            {
                neighbor._timeToLive = nextTime;
            }
        }
示例#26
0
        private void tryNotify(Collider other)
        {
            IInteractionBehaviour ib = other.GetComponentInParent <IInteractionBehaviour>();

            if (ib)
            {
                manager.EnsureActive(ib);
                _dislocatedCounter = 0;
                ib.NotifyBrushDislocated();
            }
        }
        protected override bool checkShouldRelease(out IInteractionBehaviour objectToRelease)
        {
            bool shouldRelease = _graspButtonUp && isGraspingObject;

            objectToRelease = null;
            if (shouldRelease)
            {
                objectToRelease = graspedObject;
            }

            return(shouldRelease);
        }
示例#28
0
        public void Register(IInteractionBehaviour behaviour)
        {
            //Do nothing if already registered
            if (_registeredBehaviours.ContainsKey(behaviour))
            {
                return;
            }

            _registeredBehaviours.Add(behaviour, null);

            behaviour.NotifyRegistered();
        }
 protected override bool checkShouldRelease(out IInteractionBehaviour objectToRelease)
 {
     if (enableKeyboardControl && Input.GetKeyDown(releaseKey))
     {
         objectToRelease = graspedObject;
         return(true);
     }
     else
     {
         objectToRelease = null;
         return(false);
     }
 }
示例#30
0
        protected int _timeToDie  = 0; // Timer after _timeToLive goes negative before deactivation.

        public override void Init(IInteractionBehaviour interactionBehaviour, ActivityManager manager)
        {
            _interactionBehaviour = interactionBehaviour;
            _manager = manager;
            Revive();

            _rigidbody = GetComponent <Rigidbody>();

            _prevPosition        = _rigidbody.position;
            _prevVelocity        = _rigidbody.velocity;
            _prevRotation        = _rigidbody.rotation;
            _prevAngularVelocity = _rigidbody.angularVelocity;
        }
示例#31
0
    public void Unregister(IInteractionBehaviour behaviour) {
      //Do nothing if not registered
      if (!_registeredBehaviours.ContainsKey(behaviour)) {
        return;
      }

      if (IsActive(behaviour)) {
        Deactivate(behaviour);
      }

      _registeredBehaviours.Remove(behaviour);

      behaviour.NotifyUnregistered();
    }
示例#32
0
        void IInternalInteractionManager.NotifyIntObjAddedNoContactLayer(IInteractionBehaviour intObj, int layer, bool refreshImmediately)
        {
            if (!_intObjNoContactLayers.ContainsKey(layer))
            {
                _intObjNoContactLayers[layer] = new HashSet <IInteractionBehaviour>();
            }

            _intObjNoContactLayers[layer].Add(intObj);

            if (refreshImmediately)
            {
                refreshInteractionLayerMask();
            }
        }
示例#33
0
        public static bool ShouldIgnoreHover(this IInteractionBehaviour intObj, InteractionController controller)
        {
            switch (intObj.ignoreHoverMode)
            {
            case IgnoreHoverMode.None: return(false);

            case IgnoreHoverMode.Left: return(!controller.isTracked || controller.isLeft);

            case IgnoreHoverMode.Right: return(!controller.isTracked || controller.isRight);

            case IgnoreHoverMode.Both:
            default: return(true);
            }
        }
        protected override bool checkShouldGrasp(out IInteractionBehaviour objectToGrasp)
        {
            bool shouldGrasp = !isGraspingObject &&
                               (_graspButtonDown || _graspButtonDownSlopTimer > 0F) &&
                               _closestGraspableObject != null;

            objectToGrasp = null;
            if (shouldGrasp)
            {
                objectToGrasp = _closestGraspableObject;
            }

            return(shouldGrasp);
        }
示例#35
0
    protected virtual void destroyInteractionShape(IInteractionBehaviour interactionBehaviour) {
      INTERACTION_SHAPE_INSTANCE_HANDLE instanceHandle = interactionBehaviour.ShapeInstanceHandle;

      _instanceHandleToBehaviour.Remove(instanceHandle);

      InteractionC.DestroyShapeInstance(ref _scene, ref instanceHandle);

      interactionBehaviour.NotifyInteractionShapeDestroyed();
    }
示例#36
0
 public void GraspObject(IInteractionBehaviour obj, bool isUserGrasp) {
   this.isUserGrasp = isUserGrasp;
   graspedObject = obj;
   graspedObject.NotifyHandGrasped(hand);
 }
示例#37
0
    /// <summary>
    /// Tries to find an InteractionObject that is currently being grasped by a Hand with
    /// the given ID.
    /// </summary>
    public bool TryGetGraspedObject(int handId, out IInteractionBehaviour graspedObject) {
      for (int i = 0; i < _graspedBehaviours.Count; i++) {
        var iObj = _graspedBehaviours[i];
        if (iObj.IsBeingGraspedByHand(handId)) {
          graspedObject = iObj;
          return true;
        }
      }

      graspedObject = null;
      return false;
    }
示例#38
0
    public override void Init(IInteractionBehaviour interactionBehaviour, ActivityManager manager) {
      base.Init(interactionBehaviour, manager);

      bool wasSleeping = _rigidbody.IsSleeping();

      //We need to do this in order to force Unity to reconsider collision callbacks for this object
      //Otherwise scripts added in the middle of a collision never recieve the Stay callbacks.
      Collider singleCollider = GetComponentInChildren<Collider>();
      if (singleCollider != null) {
        Physics.IgnoreCollision(singleCollider, singleCollider, true);
        Physics.IgnoreCollision(singleCollider, singleCollider, false);
      }

      if (wasSleeping) {
        _rigidbody.Sleep();
      }
    }
示例#39
0
    public static int hysteresisTimeout = 5;                       //In fixed frames

    public abstract void Init(IInteractionBehaviour interactionBehaviour, ActivityManager manager);
示例#40
0
    /// <summary>
    /// Forces the given object to be released by any hands currently holding it.  Will return true
    /// only if there was at least one hand holding the object.
    /// </summary>
    public bool ReleaseObject(IInteractionBehaviour graspedObject) {
      if (!_graspedBehaviours.Remove(graspedObject)) {
        return false;
      }

      foreach (var interactionHand in _idToInteractionHand.Values) {
        if (interactionHand.graspedObject == graspedObject) {
          if (interactionHand.isUntracked) {
            interactionHand.MarkTimeout();
          } else {
            if (_graspingEnabled) {
              INTERACTION_HAND_RESULT result = new INTERACTION_HAND_RESULT();
              result.classification = ManipulatorMode.Contact;
              result.handFlags = HandResultFlags.ManipulatorMode;
              result.instanceHandle = new INTERACTION_SHAPE_INSTANCE_HANDLE();
              InteractionC.OverrideHandResult(ref _scene, (uint)interactionHand.hand.Id, ref result);
            }
            interactionHand.ReleaseObject();
          }
        }
      }

      return true;
    }
示例#41
0
 public bool IsActive(IInteractionBehaviour interactionBehaviour) {
   IActivityMonitor monitor;
   if (_registeredBehaviours.TryGetValue(interactionBehaviour, out monitor)) {
     return monitor != null;
   }
   return false; // Not even registered.
 }
示例#42
0
 public void NotifyMisbehaving(IInteractionBehaviour behaviour) {
   _misbehavingBehaviours.Add(behaviour);
 }
示例#43
0
    /// <summary>
    /// Unregisters an InteractionObject from this manager.  This removes it from the internal
    /// scene and prevents any further interaction.
    ///
    /// Trying to unregister a behaviour that is not registered is safe and is a no-op.
    /// </summary>
    public void UnregisterInteractionBehaviour(IInteractionBehaviour interactionBehaviour) {
      if (_graspedBehaviours.Remove(interactionBehaviour)) {
        foreach (var interactionHand in _idToInteractionHand.Values) {
          if (interactionHand.graspedObject == interactionBehaviour) {
            try {
              if (interactionHand.isUntracked) {
                interactionHand.MarkTimeout();
              } else {
                interactionHand.ReleaseObject();
              }
            } catch (Exception e) {
              //Only log to console
              //We want to continue so we can destroy the shape and dispatch OnUnregister
              Debug.LogException(e);
            }
            break;
          }
        }
      }

      _activityManager.Unregister(interactionBehaviour);
    }
示例#44
0
 public void EnsureActive(IInteractionBehaviour interactionBehaviour) {
   if (!_activityManager.IsActive(interactionBehaviour)) {
     _activityManager.Activate(interactionBehaviour);
   }
 }
示例#45
0
    protected virtual void dispatchOnHandsHolding(List<Hand> hands, IInteractionBehaviour interactionBehaviour, bool isPhysics) {
      for (int j = 0; j < hands.Count; j++) {
        var hand = hands[j];
        InteractionHand interactionHand;
        if (_idToInteractionHand.TryGetValue(hand.Id, out interactionHand)) {
          if (interactionHand.graspedObject == interactionBehaviour) {
            _holdingHands.Add(hand);
          }
        }
      }

      try {
        if (isPhysics) {
          interactionBehaviour.NotifyHandsHoldPhysics(_holdingHands);
        } else {
          interactionBehaviour.NotifyHandsHoldGraphics(_holdingHands);
        }
      } catch (Exception e) {
        _activityManager.NotifyMisbehaving(interactionBehaviour);
        Debug.LogException(e);
      }

      _holdingHands.Clear();
    }
示例#46
0
 public bool IsRegistered(IInteractionBehaviour interactionBehaviour) {
   return _registeredBehaviours.ContainsKey(interactionBehaviour);
 }
示例#47
0
    /// <summary>
    /// Forces a hand to grasp the given interaction behaviour.  The grasp will only be terminated when
    /// the hand either times out or the user calls ReleaseHand.
    /// </summary>
    /// <param name="hand"></param>
    public void GraspWithHand(Hand hand, IInteractionBehaviour interactionBehaviour) {
      if (!_activityManager.IsRegistered(interactionBehaviour)) {
        throw new InvalidOperationException("Cannot grasp " + interactionBehaviour + " because it is not registered with this manager.");
      }

      InteractionHand interactionHand;
      if (!_idToInteractionHand.TryGetValue(hand.Id, out interactionHand)) {
        throw new InvalidOperationException("Hand with id " + hand.Id + " is not registered with this manager.");
      }

      if (interactionHand.graspedObject != null) {
        throw new InvalidOperationException("Cannot grasp with hand " + hand.Id + " because that hand is already grasping " + interactionHand.graspedObject);
      }

      //Ensure behaviour is active already
      _activityManager.Activate(interactionBehaviour);

      if (!interactionBehaviour.IsBeingGrasped) {
        _graspedBehaviours.Add(interactionBehaviour);
      }

      interactionHand.GraspObject(interactionBehaviour, isUserGrasp: true);
    }
示例#48
0
    protected virtual void createInteractionShape(IInteractionBehaviour interactionBehaviour) {
      INTERACTION_SHAPE_DESCRIPTION_HANDLE descriptionHandle = interactionBehaviour.ShapeDescriptionHandle;
      INTERACTION_SHAPE_INSTANCE_HANDLE instanceHandle = new INTERACTION_SHAPE_INSTANCE_HANDLE();

      INTERACTION_CREATE_SHAPE_INFO createInfo;
      INTERACTION_TRANSFORM createTransform;
      interactionBehaviour.GetInteractionShapeCreationInfo(out createInfo, out createTransform);

      InteractionC.CreateShapeInstance(ref _scene, ref descriptionHandle, ref createTransform, ref createInfo, out instanceHandle);

      _instanceHandleToBehaviour[instanceHandle] = interactionBehaviour;

      interactionBehaviour.NotifyInteractionShapeCreated(instanceHandle);
    }
示例#49
0
    public void Deactivate(IInteractionBehaviour interactionBehaviour) {
      IActivityMonitor monitor;
      if (_registeredBehaviours.TryGetValue(interactionBehaviour, out monitor)) {
        if (monitor != null) {
          //The monitor that is last in the array of monitors
          IInteractionBehaviour lastBehaviour = _activeBehaviours[_activeBehaviours.Count - 1];
          IActivityMonitor lastMonitor = _registeredBehaviours[lastBehaviour];

          //Replace the monitor we are going to destroy with the last monitor
          _activeBehaviours[monitor.arrayIndex] = lastBehaviour;
          //Make sure to update the index of the moved monitor!
          lastMonitor.arrayIndex = monitor.arrayIndex;
          //Remove the empty space at the end
          _activeBehaviours.RemoveAt(_activeBehaviours.Count - 1);

          _registeredBehaviours[interactionBehaviour] = null;
          UnityEngine.Object.Destroy(monitor);

          if (OnDeactivate != null) {
            OnDeactivate(interactionBehaviour);
          }
        }
      }
    }
示例#50
0
 /// <summary>
 /// Registers an InteractionObject with this manager, which automatically adds the objects
 /// representation into the internal interaction scene.  If the manager is disabled,
 /// the registration will still succeed and the object will be added to the internal scene
 /// when the manager is next enabled.
 ///
 /// Trying to register a behaviour that is already registered is safe and is a no-op.
 /// </summary>
 public void RegisterInteractionBehaviour(IInteractionBehaviour interactionBehaviour) {
   _activityManager.Register(interactionBehaviour);
 }
示例#51
0
    public IActivityMonitor Activate(IInteractionBehaviour interactionBehaviour) {
      IActivityMonitor monitor;
      if (_registeredBehaviours.TryGetValue(interactionBehaviour, out monitor)) {
        if (monitor == null) {
          if (_maxDepth == 1) {
            monitor = interactionBehaviour.gameObject.AddComponent<ActivityMonitorLite>();
          } else {
            monitor = interactionBehaviour.gameObject.AddComponent<ActivityMonitor>();
          }

          monitor.Init(interactionBehaviour, this);

          _registeredBehaviours[interactionBehaviour] = monitor;

          monitor.arrayIndex = _activeBehaviours.Count;
          _activeBehaviours.Add(interactionBehaviour);

          if (OnActivate != null) {
            OnActivate(interactionBehaviour);
          }
        }
      }
      return monitor;
    }