protected Color AssignBalloonColor(ChatUI.BalloonTypes type) { Color temp = Color.magenta; //nonsense initialization for error-checking switch (type) { case ChatUI.BalloonTypes.Player: ColorUtility.TryParseHtmlString(PLAYER_BALLOON_COLOR_HEX, out temp); break; case ChatUI.BalloonTypes.Opponent: ColorUtility.TryParseHtmlString(OPPONENT_BALLOON_COLOR_HEX, out temp); break; case ChatUI.BalloonTypes.Object: ColorUtility.TryParseHtmlString(OBJECT_BALLOON_COLOR_HEX, out temp); break; default: Debug.Log("Invalid balloon type: " + type.ToString()); break; } Debug.Assert(temp != Color.magenta, "Failed to parse color string."); return(temp); }
/// <summary> /// Choose the appropriate speech balloon, based on who (or what) is speaking. /// /// Right now everyone uses the same image. If that changes, this function allows for that. /// </summary> /// <returns>The balloon image.</returns> /// <param name="type">The type of speech balloon.</param> protected Sprite AssignBalloonImage(ChatUI.BalloonTypes type) { Sprite temp; switch (type) { case ChatUI.BalloonTypes.Player: case ChatUI.BalloonTypes.Opponent: case ChatUI.BalloonTypes.Object: temp = Resources.Load <Sprite>(PLAYER_BALLOON_IMG); break; default: Debug.Log("Invalid balloon type: " + type.ToString()); temp = Resources.Load <Sprite>(PLAYER_BALLOON_IMG); break; } return(temp); }
///////////////////////////////////////////// /// Functions ///////////////////////////////////////////// //constructor public MoveBalloonTask(Vector3 position, float xSize, float ySize, string message, GrowOrShrink change, ChatUI.BalloonTypes balloonType) { RectTransform balloon = MonoBehaviour.Instantiate <GameObject>(Resources.Load <GameObject>(BALLOON_OBJ), GameObject.Find(CHAT_UI_ORGANIZER).transform).GetComponent <RectTransform>(); this.balloonType = balloonType; balloon.Find(IMAGE_OBJ).GetComponent <Image>().sprite = AssignBalloonImage(this.balloonType); balloon.Find(IMAGE_OBJ).GetComponent <Image>().color = AssignBalloonColor(this.balloonType); balloon.transform.position = position; this.balloon = balloon; this.xSize = xSize; this.ySize = ySize; this.message = message; balloon.transform.Find(TEXT_OBJ).GetComponent <TextMeshProUGUI>().text = ""; this.change = change; //if this is a message that's growing to the size of the chat window, don't let it be bigger than //the chat window if (change == GrowOrShrink.Grow) { this.xSize = CHAT_WINDOW_WIDTH; } //change the sizeDeltas of the speech balloon and its children, the background image and the text balloon.sizeDelta = new Vector2(xSize, ySize); foreach (Transform child in balloon.transform) { child.GetComponent <RectTransform>().sizeDelta = new Vector2(xSize, ySize); } }