예제 #1
0
        /// <summary>
        /// Look for other AI that are potential members of this AIs group.
        /// If any are found invite them into the group.
        /// </summary>
        private void FormGroup()
        {
#if UNITY_EDITOR
            if (!IsLeader)
            {
                Debug.LogWarning("OPTIMIZATION: we shouldn't be calling FormGroup if the character is not the leader.");
                return;
            }
            if (IsFull)
            {
                Debug.LogWarning("OPTIMIZATION: we shouldn't be calling FormGroup if the group is already full.");
                return;
            }
#endif

            Collider[] colliders = Physics.OverlapSphere(transform.position, m_DetectionRadius, m_LayerMask);
            for (int i = 0; i < colliders.Length && !IsFull; i++)
            {
                if (colliders[i].gameObject == gameObject)
                {
                    continue;
                }

                AiGroupController other = colliders[i].GetComponentInParent <AiGroupController>();
                if (other == null || other.Count > Count)
                {
                    continue;
                }

                if (m_Members.Contains(other))
                {
                    continue;
                }

                other.LeaveGroup();

                m_Members.Add(other);
                other.Leader = this;
            }
        }
예제 #2
0
 /// <summary>
 /// Remove a member fromt the group this AI is a member of.
 /// </summary>
 /// <param name="member"></param>
 public void Remove(AiGroupController member)
 {
     m_Members.Remove(member);
 }