2025-09-08 14:51:28 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using ZXKFramework;
|
2025-09-24 19:24:19 +08:00
|
|
|
|
namespace DongWuYiXue.DaoNiaoShu
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
public static class UIBehaviourExtension
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
public static void OnEventButtonEvent(this GameObject self, EventTriggerType type, UnityAction<BaseEventData> action)
|
2025-09-24 19:24:19 +08:00
|
|
|
|
{
|
2025-09-08 14:51:28 +08:00
|
|
|
|
EventTrigger.Entry entry = new EventTrigger.Entry { eventID = type };
|
|
|
|
|
|
var eventTrigger = self.GetComponent<EventTrigger>() ?? self.gameObject.AddComponent<EventTrigger>();
|
|
|
|
|
|
entry.callback.AddListener(action);
|
|
|
|
|
|
eventTrigger.triggers.Add(entry);
|
2025-09-24 19:24:19 +08:00
|
|
|
|
}
|
2025-09-08 14:51:28 +08:00
|
|
|
|
}
|
2025-09-24 19:24:19 +08:00
|
|
|
|
|
2025-09-08 14:51:28 +08:00
|
|
|
|
public class SpeakPanel : UIBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public override string GroupName => "SpeakPanel";
|
|
|
|
|
|
public override string Name => "SpeakPanel";
|
|
|
|
|
|
|
|
|
|
|
|
Button tip;
|
|
|
|
|
|
Button Send;
|
2025-09-24 19:24:19 +08:00
|
|
|
|
Button Voice;
|
2025-09-08 14:51:28 +08:00
|
|
|
|
ItemInput userInput;
|
2025-09-24 19:24:19 +08:00
|
|
|
|
GameObject content;
|
2025-09-08 14:51:28 +08:00
|
|
|
|
GameObject inputContent;
|
2025-09-24 19:24:19 +08:00
|
|
|
|
GameObject MicrophoneImg;
|
|
|
|
|
|
GameObject btnsContent;
|
|
|
|
|
|
Action<bool> sendAction;
|
|
|
|
|
|
string tipTxt;
|
|
|
|
|
|
string stepName;
|
|
|
|
|
|
int score;
|
|
|
|
|
|
int id;
|
|
|
|
|
|
bool clickTip;
|
2025-09-08 14:51:28 +08:00
|
|
|
|
Coroutine coroutine;
|
|
|
|
|
|
public override void Init(IUIManager uictrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Init(uictrl);
|
2025-09-24 19:24:19 +08:00
|
|
|
|
tip = transform.FindFirst<Button>("Tip_Btn");
|
|
|
|
|
|
Send = transform.FindFirst<Button>("Send_Btn");
|
|
|
|
|
|
Voice = transform.FindFirst<Button>("Voice_Btn");
|
|
|
|
|
|
content = transform.FindFirst("Content");
|
|
|
|
|
|
inputContent = transform.FindFirst("InputContent");
|
|
|
|
|
|
MicrophoneImg = transform.FindFirst("MicrophoneImg");
|
|
|
|
|
|
btnsContent = transform.FindFirst("Btns");
|
|
|
|
|
|
userInput = transform.FindFirst<ItemInput>("EditorPanel");
|
|
|
|
|
|
UIBehaviourExtension.OnEventButtonEvent(Voice.gameObject, EventTriggerType.PointerDown, onMicrophoneDown);
|
|
|
|
|
|
UIBehaviourExtension.OnEventButtonEvent(Voice.gameObject, EventTriggerType.PointerUp, onMicrophoneUp);
|
2025-09-08 14:51:28 +08:00
|
|
|
|
userInput.onValidateInput += OnValidateInput;
|
2025-09-24 19:24:19 +08:00
|
|
|
|
Send.onClick.AddListener(Submit);
|
2025-09-26 16:24:55 +08:00
|
|
|
|
tip.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
userInput.text = tipTxt;
|
|
|
|
|
|
clickTip = true;
|
2025-09-08 14:51:28 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private char OnValidateInput(string text, int charIndex, char addedChar)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˻س<CBBB><D8B3><EFBFBD>
|
|
|
|
|
|
if (addedChar == '\n' || addedChar == '\r')
|
|
|
|
|
|
{
|
|
|
|
|
|
// ִ<><D6B4><EFBFBD>ύ<EFBFBD><EFBFBD>
|
|
|
|
|
|
Submit();
|
|
|
|
|
|
// <20><><EFBFBD>ؿ<EFBFBD><D8BF>ַ<EFBFBD><D6B7><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>
|
|
|
|
|
|
return '\0';
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
|
return addedChar;
|
|
|
|
|
|
}
|
2025-09-24 19:24:19 +08:00
|
|
|
|
|
2025-09-08 14:51:28 +08:00
|
|
|
|
public void Submit()
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><>ֹ<EFBFBD><D6B9><EFBFBD>Ϳ<EFBFBD><CDBF>ַ<EFBFBD>
|
2025-09-24 19:24:19 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(userInput.text) && !string.IsNullOrEmpty(tipTxt))
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
btnsContent.SetActive(false);
|
|
|
|
|
|
userInput.readOnly = true;
|
2025-09-26 16:24:55 +08:00
|
|
|
|
ChatAI.Instance.SendData("<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ڣ<EFBFBD>" + stepName + "<22><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + userInput.text + "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6><CFA3><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>true<75><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>false", str =>
|
|
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
if (str.Contains("true"))
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
if (clickTip)
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
GameManager.Instance.kaoheManager.AddScore(0, id, null);
|
|
|
|
|
|
Game.Instance.eventManager.Raise(new PlayTrueOrFalseEvent() { isTrue = true });
|
|
|
|
|
|
sendAction?.Invoke(true);
|
2025-09-08 14:51:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-09-26 16:24:55 +08:00
|
|
|
|
GameManager.Instance.kaoheManager.AddScore(score, id, (s, t) =>
|
|
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
GameManager.Instance.uiManager.GetUI<ScorePanel>().SetScore(s.ToString(), t.ToString());
|
|
|
|
|
|
});
|
|
|
|
|
|
Game.Instance.eventManager.Raise(new PlayTrueOrFalseEvent() { isTrue = true });
|
|
|
|
|
|
sendAction?.Invoke(true);
|
2025-09-08 14:51:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-24 19:24:19 +08:00
|
|
|
|
else if (str.Contains("false"))
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
GameManager.Instance.kaoheManager.AddScore(0, id, null);
|
|
|
|
|
|
Game.Instance.eventManager.Raise(new PlayTrueOrFalseEvent() { isTrue = false });
|
|
|
|
|
|
if (MVC.GetModel<Main.GameModel>().modeType == ModeType.ShiXun)
|
|
|
|
|
|
{
|
2025-09-26 16:24:55 +08:00
|
|
|
|
Game.Instance.IEnumeratorManager.Run(0.1f, () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ChatUI.Instance.SendAINext("<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ڣ<EFBFBD>" + stepName + "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD>ܱ<EFBFBD><DCB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ𰸺<C4B4><F0B0B8BA><EFBFBD><EFBFBD><EFBFBD>", () =>
|
|
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
userInput.text = tipTxt;
|
|
|
|
|
|
sendAction?.Invoke(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sendAction?.Invoke(false);
|
|
|
|
|
|
}
|
2025-09-08 14:51:28 +08:00
|
|
|
|
}
|
2025-09-26 16:24:55 +08:00
|
|
|
|
else if (str.Contains("error") || string.IsNullOrEmpty(str))
|
2025-09-24 19:24:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
GameManager.Instance.fsm.AddScore(0, id);
|
|
|
|
|
|
userInput.text = tipTxt;
|
|
|
|
|
|
sendAction?.Invoke(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userInput.text) && string.IsNullOrEmpty(tipTxt))
|
|
|
|
|
|
{
|
|
|
|
|
|
GameManager.Instance.fsm.AddScore(score, id);
|
|
|
|
|
|
Game.Instance.eventManager.Raise(new PlayTrueOrFalseEvent() { isTrue = true });
|
2025-09-08 14:51:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-24 19:24:19 +08:00
|
|
|
|
public void ShowSpeakPanel(string stepName, string tipTxt, Vector2 v, int delayShowTime, int id, int score, Action<bool> callBack)
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
2025-09-26 16:24:55 +08:00
|
|
|
|
coroutine = Game.Instance.IEnumeratorManager.Run((int)delayShowTime, () =>
|
|
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
this.id = id;
|
|
|
|
|
|
this.tipTxt = tipTxt;
|
|
|
|
|
|
this.score = score;
|
|
|
|
|
|
sendAction = callBack;
|
|
|
|
|
|
this.stepName = stepName;
|
|
|
|
|
|
userInput.readOnly = false;
|
2025-09-08 14:51:28 +08:00
|
|
|
|
SetActive(true);
|
2025-09-24 19:24:19 +08:00
|
|
|
|
btnsContent.SetActive(true);
|
|
|
|
|
|
userInput.GetComponent<RectTransform>().anchoredPosition = new Vector2(-157.5f, 90f);
|
|
|
|
|
|
content.GetComponent<RectTransform>().anchoredPosition = v;
|
2025-09-08 14:51:28 +08:00
|
|
|
|
userInput.text = "";
|
|
|
|
|
|
// <20><>InputField<6C><64>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
userInput.Select();
|
|
|
|
|
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
userInput.ActivateInputField();
|
2025-09-24 19:24:19 +08:00
|
|
|
|
if (string.IsNullOrEmpty(tipTxt))
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
tip.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
tip.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-09-24 19:24:19 +08:00
|
|
|
|
|
|
|
|
|
|
void onMicrophoneDown(BaseEventData down)
|
2025-09-08 14:51:28 +08:00
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
inputContent.SetActive(false);
|
|
|
|
|
|
MicrophoneImg.SetActive(true);
|
|
|
|
|
|
transform.FindFirst<Animator>("boxing").enabled = true;
|
|
|
|
|
|
ChatAI.Instance.StartRecord();
|
2025-09-08 14:51:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-24 19:24:19 +08:00
|
|
|
|
void onMicrophoneUp(BaseEventData up)
|
|
|
|
|
|
{
|
|
|
|
|
|
inputContent.SetActive(true);
|
|
|
|
|
|
MicrophoneImg.SetActive(false);
|
|
|
|
|
|
transform.FindFirst<Animator>("boxing").enabled = false;
|
2025-09-26 16:24:55 +08:00
|
|
|
|
ChatAI.Instance.StopRecord(str =>
|
|
|
|
|
|
{
|
2025-09-24 19:24:19 +08:00
|
|
|
|
userInput.text += str;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-09-08 14:51:28 +08:00
|
|
|
|
public override void Hide()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Hide();
|
|
|
|
|
|
Game.Instance.IEnumeratorManager.Stop(coroutine);
|
2025-09-24 19:24:19 +08:00
|
|
|
|
ChatUI.Instance.CloseChatTxt();
|
|
|
|
|
|
clickTip = false;
|
2025-09-08 14:51:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|