/// <summary> /// Adds a controller to the priority que. /// </summary> public void Add(MusicController controller) { // If there weren't any controllers, the new one becomes active. if (m_Controllers.Count == 0) { m_Controllers.Add(controller); controller.Activate(); return; } // If the controller is already in the que, do not add it. else if (m_Controllers.Contains(controller)) { return; } // Insert the controller into the priority que for (int i = 0; i < m_Controllers.Count; ++i) { if (controller.importance > m_Controllers[i].importance) { // If this is the highest priority controller, give it control. if (i == 0) { if (m_Controllers[0]) { m_Controllers[0].Deactivate(); } m_Controllers.Insert(i, controller); controller.Activate(); return; } // Otherwise just insert it into the que. m_Controllers.Insert(i, controller); return; } } // If this is the lowest priority que, just add it to the end. m_Controllers.Add(controller); }