public static ChatEmotion CreateChatEmotion(GameObject parent, Vector3 localPos, string strText, float scale) { Object prefab = PrefabLoader.loadFromPack("ZQ/ChatEmotion"); if (prefab != null) { GameObject obj = Instantiate(prefab) as GameObject; RED.AddChild(obj, parent); obj.transform.localPosition = localPos; ChatEmotion emotion = obj.GetComponent <ChatEmotion>(); emotion.InitEmotionText(strText, scale); return(emotion); } return(null); }
/// <summary> /// Trys to get the packet number for the provided chat emotion. /// </summary> /// <param name="e">Chat Emotion</param> /// <returns></returns> private static int GetEmoticonPacketNum(ChatEmotion e) { switch (e) { case ChatEmotion.Smile: return 1; case ChatEmotion.Angry: return 2; case ChatEmotion.Shocked: return 3; case ChatEmotion.Sad: return 4; default: return 0; } }
/// <summary> /// Trys to get the packet number for the provided chat emotion. /// </summary> /// <param name="e">Chat Emotion</param> /// <returns></returns> private static int GetEmoticonPacketNum(ChatEmotion e) { switch (e) { case ChatEmotion.Smile: return(1); case ChatEmotion.Angry: return(2); case ChatEmotion.Shocked: return(3); case ChatEmotion.Sad: return(4); default: return(0); } }
void ProcessEmotionText() { string strText = m_txtContent; if (string.IsNullOrEmpty(m_txtContent)) { m_labContent.text = m_txtContent; SwapText(); return; } if (!strText.Contains("<") || !strText.Contains(">")) { m_labContent.text = m_txtContent; SwapText(); return; } m_labContent.text = " "; float spaceWidth = m_labContent.width; int spaceCnt = (int)(m_nEmotionSize / spaceWidth) + 1; List <int> list = new List <int>(); int m_Index = 0; foreach (char c in strText) { if (c == '>') { list.Add(m_Index); } m_Index++; } m_labContent.text = ""; string[] strArry = strText.Split('>'); for (int i = 0; i < strArry.Length; i++) { int startIndex = strArry [i].IndexOf('<'); if (startIndex < 0) { m_labContent.text += strArry[i]; continue; } string strEmotion = strArry[i].Substring(startIndex, strArry[i].Length - startIndex); strArry [i] = strArry [i].Replace(strEmotion, ""); m_labContent.text += strArry[i]; strEmotion = strEmotion.Replace("<", ""); int lineCount = m_labContent.width / m_lineWidth; Vector3 pos = Vector3.zero; if (lineCount > 0) { pos.x = m_labContent.width % m_lineWidth; pos.y = m_labContent.width / m_lineWidth * (m_labContent.fontSize + m_labContent.spacingY) * -1; pos.y -= m_labContent.fontSize - m_nEmotionSize; pos.y -= m_offset.y; } else { pos.x = m_labContent.width; pos.y -= m_labContent.fontSize - m_nEmotionSize; pos.y -= m_offset.y; } if (!CheckEmotion(strEmotion)) { m_labContent.text += "<" + strEmotion + ">"; } else { ChatEmotion emotion = ChatEmotion.CreateChatEmotion(this.gameObject, pos, strEmotion, m_nEmotionSize); m_listEmotionl.Add(emotion); for (int n = 0; n < spaceCnt; n++) { m_labContent.text += " "; } } } SwapText(); }