Exemple #1
0
        /// <summary>
        /// Update the dictionary that keeps rigidbodies and their picking information. This should
        /// be called whenever a pickable object is picked up or released.
        /// </summary>
        /// <param name="pickableRb">Rigidbody of the pickable object.</param>
        /// <param name="isPicked">Whether this rigidbody is picked up.</param>
        /// <param name="picker">The picker of the rigidbody.</param>
        public static void UpdatePickableMapping(Rigidbody pickableRb, bool isPicked, IPicker picker)
        {
            if (picker == null)
            {
                throw new ArgumentNullException("picker");
            }
            RigidbodyPickingInfo pickingInfo;

            if (!_pickableRbToPickingInfoDict.TryGetValue(pickableRb, out pickingInfo))
            {
                // If the rigidbody is not in the dictionary, create new picking info for this one.
                pickingInfo = new RigidbodyPickingInfo();
                _pickableRbToPickingInfoDict.Add(pickableRb, pickingInfo);
            }
            if (isPicked)
            {
                // The picker picks up this object
                pickingInfo.Picker   = picker;
                pickingInfo.IsPicked = true;
            }
            else
            {
                if (picker == pickingInfo.Picker)
                {
                    // Current picker is releasing this pickable object
                    pickingInfo.IsPicked = false;
                    pickingInfo.Picker   = null;
                }
                else
                {
                    // This should never happen
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Return the picker if the rigidbody is picked up.
        /// </summary>
        /// <param name="rb">Rigidbody to check.</param>
        /// <returns>Picker of the rigidbody if any. Null if the rigidbody
        /// is not picked up.</returns>
        public static IPicker GetAssociatedPicker(Rigidbody rb)
        {
            RigidbodyPickingInfo pickerInfo = GetPickingInfo(rb);

            if (pickerInfo == null)
            {
                return(null);
            }
            else
            {
                return(pickerInfo.Picker);
            }
        }
Exemple #3
0
        /// <summary>
        /// Check if the rigidbody is currently being held by any picker.
        /// </summary>
        /// <param name="rb">The rigidbody to check.</param>
        /// <returns>True if the rigidbody is picked up.</returns>
        public static bool CheckIsPicked(Rigidbody rb)
        {
            RigidbodyPickingInfo pickerInfo = GetPickingInfo(rb);

            if (pickerInfo == null)
            {
                return(false);
            }
            else
            {
                return(pickerInfo.IsPicked);
            }
        }