/// <summary> /// Add the unit in a group and assign a role /// </summary> /// <param name="name">name of the group</param> /// <param name="role">role in the group</param> /// <returns>Return true if success and false otherwise</returns> public bool EnterGroup(string name, string role) { int teamID = this.GetTeamID(); if (teamID == 0) { return(false); } Group group = GroupController.FindGroup(teamID, name); if (group == null) { GroupController.AddGroup(teamID, new Group(name)); group = GroupController.FindGroup(teamID, name); } if (this.groups.Contains(group)) { return(false); } groups.Add(group); group.Add(this.gameObject, role); return(true); }
/// <summary> /// Remove the unit of a group /// </summary> /// <param name="name">name of the group</param> /// <returns>Return true if success and false otherwise</returns> public bool LeaveGroup(string name) { foreach (Group g in groups) { if (g.Name == name) { g.Remove(this.gameObject); if (g.Members.Length == 0) { GroupController.RemoveGroup(this.GetTeamID(), g); } return(true); } } return(false); }