每日自动提交 2026-04-15 18:30
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Assets.MyGame.Scripts.Net;
|
||||
using Assets.MyGame.Scripts.Net.APIRequest.Objs;
|
||||
using Assets.MyGame.Scripts.Net.WebResponses;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
@@ -10,10 +13,60 @@ public class UIHome_BY_ServicePanel : SubUIBase
|
||||
public Toggle toggle_DefaultQuestion;
|
||||
public Toggle toggle_YouChangeIChange;
|
||||
public Toggle toggle_OnlineService;
|
||||
public TMP_InputField input_Text;
|
||||
|
||||
[Header("客服")]
|
||||
public TMP_InputField tMPInput_Text;
|
||||
public GameObject dialogGreenPrefab;
|
||||
public GameObject dialogOrangePrefab;
|
||||
public Transform dialogPrefabParent;
|
||||
public Button btn_SendText;
|
||||
public string conversationId;
|
||||
public void OnMessageReceived(CustomerMessageReceived customerMessageReceived)
|
||||
{
|
||||
if (customerMessageReceived.senderType==1)
|
||||
{
|
||||
if (dic_dialogItems.ContainsKey(customerMessageReceived.guid))
|
||||
{
|
||||
dic_dialogItems[customerMessageReceived.guid].waitMessage.SetActive(false);
|
||||
//失败没有写
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Instantiate(dialogOrangePrefab, dialogPrefabParent).GetComponent<DialogItem>().SetMessage(customerMessageReceived.content);
|
||||
ScrollToBottom();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public void OnConversationStarted(CustomerConversationStartedResult customerConversationStartedResult)
|
||||
{
|
||||
conversationId = customerConversationStartedResult.conversation.id;
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
WebSocketSendList.Customer_LeaveConversation(conversationId);
|
||||
WebSocketManager.Instance.Close(SocketType.customer);
|
||||
|
||||
}
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
btn_Close.onClick.AddListener(() =>
|
||||
{
|
||||
uIManager.Close(UIPanel.ServicePanel);
|
||||
});
|
||||
WebSocketManager.Instance.Connect(SocketType.customer, () =>
|
||||
{
|
||||
// 发起会话(服务端会回调 OnConversationStarted,自动 JoinConversation)
|
||||
WebSocketSendList.Customer_StartConversation(
|
||||
GameManager.Instance.user.id,
|
||||
GameManager.Instance.user.BaseInfo.userName
|
||||
);
|
||||
// 连接后加入接单队列,服务端有新会话会回调 OnNewConversation(自动 JoinConversation)
|
||||
WebSocketSendList.Customer_JoinCustomerQueue(conversationId);
|
||||
|
||||
|
||||
});
|
||||
toggle_DefaultQuestion.onValueChanged.AddListener((a) =>
|
||||
{
|
||||
if (a)
|
||||
@@ -21,11 +74,41 @@ public class UIHome_BY_ServicePanel : SubUIBase
|
||||
//APIRequestList.GetOnlineCustomers
|
||||
}
|
||||
});
|
||||
btn_SendText.onClick.AddListener(() =>
|
||||
{
|
||||
var var = Instantiate(dialogGreenPrefab, dialogPrefabParent).GetComponent<DialogItem>();
|
||||
var.SetMessage(tMPInput_Text.text);
|
||||
ScrollToBottom();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
WebSocketSendList.Customer_SendMessage(conversationId, 1, GameManager.Instance.user.id, GameManager.Instance.user.BaseInfo.userName, null, 1, tMPInput_Text.text, guid);
|
||||
dic_dialogItems.Add(guid, var);
|
||||
});
|
||||
}
|
||||
Dictionary<string, DialogItem> dic_dialogItems = new Dictionary<string, DialogItem>();
|
||||
|
||||
|
||||
public void ScrollToBottom()
|
||||
{
|
||||
StartCoroutine(ScrollBottomCoroutine());
|
||||
}
|
||||
|
||||
IEnumerator ScrollBottomCoroutine()
|
||||
{
|
||||
// 等待所有布局刷新
|
||||
yield return null;
|
||||
yield return null; // 两帧最稳
|
||||
yield return null; // 两帧最稳
|
||||
|
||||
dialogPrefabParent.parent.parent.GetComponent<ScrollRect>().verticalNormalizedPosition = 0;
|
||||
|
||||
// 再强制刷新一次,防止被覆盖
|
||||
Canvas.ForceUpdateCanvases();
|
||||
dialogPrefabParent.parent.parent.GetComponent<ScrollRect>().verticalNormalizedPosition = 0;
|
||||
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user