private void RefreshMounters_Menu()
        {
            // Design note: This process is designed to support mounters that have been linked
            // from other game objects.

            m_Mounters.PurgeDestroyed();

            var seen = new System.Collections.Generic.List <IAccessoryMounter>();

            // TODO: Remove this once the GUI properly prevents duplicates.
            for (int i = m_Mounters.Count - 1; i >= 0; i--)
            {
                if (seen.Contains(m_Mounters[i]))
                {
                    m_Mounters.Remove(m_Mounters[i]);
                }
                else
                {
                    seen.Add(m_Mounters[i]);
                }
            }

            var refreshItems = GetComponents <IAccessoryMounter>();

            if (refreshItems.Length == 0)
            {
                return;  // Leave existing alone.
            }
            var items = new System.Collections.Generic.List <IAccessoryMounter>(refreshItems.Length);

            for (int i = 0; i < m_Mounters.Count; i++)
            {
                if (m_Mounters[i] != null)
                {
                    items.Add(m_Mounters[i]);
                }
            }

            // Add new items to end.
            foreach (var refreshItem in refreshItems)
            {
                if (!items.Contains(refreshItem))
                {
                    items.Add(refreshItem);
                }
            }

            AccessoryMounterGroup.UnsafeReplaceItems(this, m_Mounters, items.ToArray());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Replace the items in the buffer.
 /// </summary>
 /// <remarks>
 /// <para>
 /// To use this method safely, either set <paramref name="asReference"/> to false, or
 /// discard all external references to the <paramref name="items"/> array.
 /// </para>
 /// </remarks>
 /// <param name="mounters">The object to udpate. (Required)</param>
 /// <param name="asReference">
 /// If true, the inernal buffer will be replaced by a referecne to <paramref name="items"/>.
 /// Otherwise <paramref name="items"/> will be copied.
 /// </param>
 /// <param name="items">The items to put into the buffer.</param>
 public static void UnsafeReplaceItems(
     Object refObj, AccessoryMounterGroup mounters, params IAccessoryMounter[] items)
 {
     mounters.AddItems(refObj, items);
 }
 /// <summary>
 /// Replaces all current mounters with the provided mounters.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Behavior is undefined if this method if used after accessory initialization.
 /// </para>
 /// <para>
 /// If <paramref name="asReference"/> is true, then all external references to the
 /// mounters array must be discared or behavior will be undefined.
 /// </para>
 /// </remarks>
 /// <param name="accessory">The accessory. (Required)</param>
 /// <param name="asReference">If true the accessory will use the reference to the array.
 /// Otherwise the array will be copied.</param>
 /// <param name="mountPoints">The mounters, or null to clear all mounters.</param>
 public static bool UnsafeReplaceMounters(StandardAccessory accessory, params IAccessoryMounter[] mounters)
 {
     AccessoryMounterGroup.UnsafeReplaceItems(accessory, accessory.m_Mounters, mounters);
     return(true);
 }