// notify the container that a bubble is required public void StartUsingChatBubble(ChatBubbleType type, ref GameObject refChatBubble, ref UILabel refChatBubbleLabel, ref UISprite refChatBubbleSprite) { // go over all the bubbles looking for one not being used currently for (int chatBubbleIndex = 0; chatBubbleIndex < _allChatBubbles.Count; ++chatBubbleIndex) { if (!_allChatBubbles[chatBubbleIndex].isInUseCurrently && type == _allChatBubbles[chatBubbleIndex].type) { _allChatBubbles[chatBubbleIndex].isInUseCurrently = true; refChatBubble = _allChatBubbles[chatBubbleIndex].bubble; refChatBubbleLabel = _allChatBubbles[chatBubbleIndex].bubbleLabel; refChatBubbleSprite = _allChatBubbles[chatBubbleIndex].bubbleSprite; return; } } // all our chat bubbles are being used, so we need to create a new one if (CreateSingleChatBubble(type)) { // the new one just created will be on the end of the list _allChatBubbles[_allChatBubbles.Count - 1].isInUseCurrently = true; refChatBubble = _allChatBubbles[_allChatBubbles.Count - 1].bubble; refChatBubbleLabel = _allChatBubbles[_allChatBubbles.Count - 1].bubbleLabel; refChatBubbleSprite = _allChatBubbles[_allChatBubbles.Count - 1].bubbleSprite; } }
// create a chat bubble private bool CreateSingleChatBubble(ChatBubbleType type) { //TODO: 弃用,后续厚超将弃用的聊天相关代码文件删除。 // GameObject newChatBubbleObject = null; // switch(type) // { // case ChatBubbleType.left: // const string ChatBubblePrefabLeft = "UI/UI_ChatBubble"; // newChatBubbleObject = UIHierarchyHelper.Instance.LoadAndPlace(ChatBubblePrefabLeft, UIHierarchyHelper.eUIType.HUD_Dynamic, null); // UIHierarchyHelper is only used on the MainHudUI // break; // case ChatBubbleType.right: // const string ChatBubblePrefabRight = "UI/UI_ChatBubble_Pixie"; // newChatBubbleObject = UIHierarchyHelper.Instance.LoadAndPlace(ChatBubblePrefabRight, UIHierarchyHelper.eUIType.HUD_Dynamic, null); // UIHierarchyHelper is only used on the MainHudUI // break; // default: // EB.Debug.LogError("ChatBubbleContainer.CreateSingleChatBubble() : Unsupported chat bubble type"); // break; // } // if (null != newChatBubbleObject) // { // _allChatBubbles.Add(new ChatBubble(newChatBubbleObject, type)); // NGUITools.SetActive(newChatBubbleObject, false); // return true; // } return(false); }
public ChatBubble(GameObject bubble, ChatBubbleType bubbleType) { this.bubble = bubble; type = bubbleType; const string ChatBubblePanelName = "ChatBubblePanel"; Transform chatBubblePanel = this.bubble.transform.Find(ChatBubblePanelName); if (chatBubblePanel) { const string SubSpriteName = "Sprite"; Transform spriteTransform = chatBubblePanel.Find(SubSpriteName); if (spriteTransform) { bubbleSprite = spriteTransform.gameObject.GetComponent <UISprite>(); } const string SubLabelName = "Label"; Transform labelTransform = chatBubblePanel.Find(SubLabelName); if (labelTransform) { bubbleLabel = labelTransform.gameObject.GetComponent <UILabel>(); } } }
// how many of the specified type of chat bubble exist private int CalculateNumChatBubblesOfType(ChatBubbleType type) { int count = 0; for (int chatBubbleIndex = 0; chatBubbleIndex < _allChatBubbles.Count; ++chatBubbleIndex) { if (type == _allChatBubbles[chatBubbleIndex].type) { ++count; } } return(count); }