public void TrackPlayer(PlayerStatus playerStatus) { if (reserveTrackers.Count == 0) { Debug.LogError("No tracker available for this AvatarName"); return; } AvatarNamesTracker tracker = reserveTrackers.Dequeue(); tracker.SetPlayerStatus(playerStatus); tracker.SetVisibility(true); trackers.Add(playerStatus.id, tracker); }
public void Initialize(int maxAvatarNames) { //Return current trackers to reserve trackers.Keys.ToList().ForEach(UntrackPlayer); trackers.Clear(); //Remove exceeding trackers in the reserve while (reserveTrackers.Count > maxAvatarNames) { AvatarNamesTracker tracker = reserveTrackers.Dequeue(); tracker.DestroyUIElements(); } //Fill the reserve if not ready for (int i = reserveTrackers.Count; i < maxAvatarNames; i++) { RectTransform background = Instantiate(backgroundPrefab, backgroundsContainer).GetComponent <RectTransform>(); RectTransform nameTMP = Instantiate(namePrefab, namesContainer).GetComponent <RectTransform>(); RectTransform voiceChat = Instantiate(voiceChatPrefab, voiceChatContainer).GetComponent <RectTransform>(); AvatarNamesTracker tracker = new AvatarNamesTracker(canvasRect, background, nameTMP, voiceChat); tracker.SetVisibility(false); reserveTrackers.Enqueue(tracker); } }