Example #1
0
 /// <summary>
 /// This funcion is called when snapper exits the snapping region.
 /// It calls snappable object's OnSnappedExit if any.
 /// </summary>
 protected virtual void OnSnappedExit()
 {
     if (SnappedObject != null && !SnappedObject.Equals(null))
     {
         SnappedObject.OnSnappedExit(this);
     }
 }
Example #2
0
        /// <summary>
        /// This function is called for every FixedUpdate cycle. It checks if
        /// snapper is now in any snapping region and if so, snaps itself to
        /// any snappable object.
        /// </summary>
        public virtual void SnapUpdate()
        {
            // Test if the snapped object is still there (i.e. not destroyed)
            if (SnappedObject != null && SnappedObject.Equals(null))
            {
                IsSnapped     = false;
                SnappedObject = null;
                return;
            }
            bool       isSnappedToTheSameObject;
            ISnappable firstSnappedObject;

            IsSnapped = GetSnappingStatus(out isSnappedToTheSameObject,
                                          out firstSnappedObject);
            if (LastSnappingStatus)
            {
                if (IsSnapped)
                {
                    if (isSnappedToTheSameObject)
                    {
                        // All is good. Don't need to do anything.
                    }
                    else
                    {
                        // Snapped to the different object. Do some finish up.
                        // OnSnappedExit for the current snapped object.
                        OnSnappedExit();
                        SnappedObject = firstSnappedObject;
                        // OnSnappedEnter for the new snapped object.
                        OnSnappedEnter();
                    }
                }
                else
                {
                    // Not snapped to the object any more.
                    OnSnappedExit();
                    SnappedObject = null;
                }
            }
            else
            {
                if (IsSnapped)
                {
                    // Start to snap to the object.
                    SnappedObject = firstSnappedObject;
                    OnSnappedEnter();
                }
                else
                {
                    // Still not snap to anything. Do nothing here.
                }
            }

            if (IsSnapped)
            {
                OnSnappedStay();
            }
            LastSnappingStatus = IsSnapped;
        }