| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class DialogueScript : MonoBehaviour
- {
- public GameObject CanvasParent;
- public GameObject AiBtn;
- public RectTransform RectTransform;
- public RectTransform AiShowBtn;
- public InputField inputField;
- public Text messgaeText;
- public string ask = "换流变压器包含什么";
- public string userID = "1a1123fds12";
- public string chatId = "0e841c01-a8c0-11f0-8363-10ffe0282e4b";
- public string InputUrl;
- public float moveTime;
- private bool ifShow = false;
- private void Start()
- {
- btnOnclickShowCanvas();
- //RectTransform.anchoredPosition = new Vector2( Screen.width, 0);
- }
- public void SendRequest()
- {
- if (inputField.text.Equals(""))
- {
- Debug.LogError("输入为空");
- }
- else
- {
- ask = inputField.text;
- StartCoroutine(SendRequestIE());
- }
- }
- IEnumerator SendRequestIE()
- {
- string url = InputUrl + "userId=" + userID + "&chatId=" + chatId + "&ask=" + UnityWebRequest.EscapeURL(ask);
- UnityWebRequest request = UnityWebRequest.Get(url);
- request.SetRequestHeader("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiJzeXNfdXNlcjoxOTc4MzgxNDE1NTc2NDUzMTIyIiwicm5TdHIiOiJGQlg2TXlWbzFuTUE1WU9Lb3B0UTk0cmJxZGREeGJMeCIsImNsaWVudGlkIjoiYmRkY2QwOTZmMGJkMzE1MjAwODhmNmVkNTFiOGQxNTgiLCJ0ZW5hbnRJZCI6IjAwMDAwMCIsInVzZXJJZCI6MTk3ODM4MTQxNTU3NjQ1MzEyMiwidXNlck5hbWUiOiJ4OXQ0azJ2OG4iLCJkZXB0SWQiOjE5NzgzOTMxNDU4Nzg2OTU5MzcsImRlcHROYW1lIjoi56ys5LiJ5pa55o6I5p2D6YOo6ZeoIiwiZGVwdENhdGVnb3J5IjoiIn0.c99_dEsWkWmDcLQmmkqwNgU4DvJR9QGKueQpB6Y7LoE");
- request.SetRequestHeader("clientId", "bddcd096f0bd31520088f6ed51b8d158");
- request.timeout = 300;
- messgaeText.text = "数据响应加载中...";
- yield return request.SendWebRequest();
- if (request.error == null)
- {
- Debug.Log(request.downloadHandler.text);
- getMessage message = JsonUtility.FromJson<getMessage>(request.downloadHandler.text);
- messgaeText.text = message.msg.Replace(" ", "\u00A0");
- if (messgaeText.text.Equals("timeout"))
- {
- messgaeText.text = "请求超时,请重新发送...";
- }
- else if (messgaeText.text.Equals(""))
- {
- messgaeText.text = "数据解析失败,请重新发送...";
- }
- }
- else
- {
- Debug.Log("报错:" + request.error);
- Debug.Log("响应代码:" + request.responseCode);
- if (request.error.Equals("Request timeout"))
- {
- messgaeText.text = "请求超时,请重新发送...";
- }
- }
- request.Dispose();
- }
- public void btnOnclickShowCanvas()
- {
- RectTransform.transform.gameObject.SetActive(ifShow);
- inputField.text = "";
- messgaeText.text = "";
- ifShow = !ifShow;
-
- }
- public void PointerShowAIBtn()
- {
- StopAllCoroutines();
- StartCoroutine(showAiBtn());
- }
- IEnumerator showAiBtn()
- {
- float Ttime = 0;
- while (Ttime < 1 )
- {
- AiShowBtn.anchoredPosition = new Vector2(Mathf.Lerp(AiShowBtn.anchoredPosition.x, -25, Ttime / 1), 0);
- Ttime += Time.deltaTime;
- yield return null;
- }
- }
- public void PointerHideAIBtn()
- {
- StopAllCoroutines();
- StartCoroutine(hideAiBtn());
- }
- IEnumerator hideAiBtn()
- {
- float Ttime = 0;
- while (Ttime < 1)
- {
- AiShowBtn.anchoredPosition = new Vector2(Mathf.Lerp(AiShowBtn.anchoredPosition.x, 0, Ttime / 1), 0);
- Ttime += Time.deltaTime;
- yield return null;
- }
- }
- class getMessage{
- public string msg;
- public string code;
- public string chatId;
- }
-
- }
|