123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class FriendChatInput : MonoBehaviour
- {
- public InputField inputField;
- public int targetId;
- void Start()
- {
- (inputField.placeholder as Text).text = Language.GetStr ("ChatPanel", "placeholder");
- inputField.onValidateInput = StringUtil.InputValidateHandler;
- }
- public void OnInputChanged()
- {
- inputField.text = StringUtil.LimitInput (inputField.text, Config.MAX_CHAT_LENGTH);
- }
- public void StartTap()
- {
- inputField.ActivateInputField ();
- }
- public void Send()
- {
- if (!StringUtil.Empty (inputField.text)) {
- DealSend (inputField.text);
- inputField.text = "";
- }
- }
- private void DealSend(string content)
- {
- ChatRequest.SendFollowMsg (targetId, content).ResultEvent.AddListener ((bool success, LitJson.JsonData data) => {
- if(success)
- {
- int id = JsonUtil.ToInt(data["id"]);
- int receiver = JsonUtil.ToInt(data["receiver"]);
- string time = data["time"].ToString();
- ChatManager.GetInstance().AddMyFollowMsg(id, receiver, content, time);
- }
- });
- }
- }
|