123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using System.IO;
- using Newtonsoft.Json.Linq;
- public class UI_AutoDisCussWindow : MonoBehaviour
- {
- /// <summary>
- /// 窗体框单例
- /// </summary>
- private static UI_AutoDisCussWindow pInit = null;
- /// <summary>
- ///
- /// </summary>
- ///
- public InputField InputField_FileName;
- /// <summary>
- ///
- /// </summary>
- public InputField InputField_simulatorUID;
- /// <summary>
- ///
- /// </summary>
- public InputField InputField_simulatorNickName;
- public Text resultText;
- /// <summary>
- /// 读取按钮
- /// </summary>
- public GameObject ReadButton;
- /// <summary>
- /// 保存按钮
- /// </summary>
- public GameObject SaveButton;
- /// <summary>
- /// 按钮
- /// </summary>
- public GameObject CloseButton;
- /// <summary>
- /// 清空按钮
- /// </summary>
- public GameObject ClearButton;
- /// <summary>
- ///
- /// </summary>
- public RectTransform mScrollRectContent;
- /// <summary>
- ///
- /// </summary>
- public Text mContentText;
- /// <summary>
- /// 获取单键
- /// </summary>
- /// <returns>对象</returns>
- public static UI_AutoDisCussWindow Instance()
- {
- return pInit;
- }
- /// <summary>
- /// 初始化
- /// </summary>
- private void Awake()
- {
- //// 初始化
- pInit = this;
- }
- private void Start()
- {
- mScrollRectContent = this.transform.Find("Panel/Scroll View/Viewport/Content").GetComponent<RectTransform>();
- ////mPrefab = this.transform.Find("Panel/Scroll View/Viewport/Content/prefab").gameObject;
- ////mPrefab.SetActive(false);
- mContentText = this.transform.Find("Panel/Scroll View/Viewport/Content/Text").GetComponent<Text>();
- mContentText.text = string.Empty;
- InputField_FileName = this.transform.Find("Panel/InputField_FileName").GetComponent<InputField>();
- InputField_simulatorUID = this.transform.Find("Panel/InputField_simulatorUID").GetComponent<InputField>();
- InputField_simulatorNickName = this.transform.Find("Panel/InputField_simulatorNickName").GetComponent<InputField>();
- SaveButton = this.transform.Find("Panel/SaveButton").gameObject;
- CloseButton = this.transform.Find("Panel/CloseButton").gameObject;
- ReadButton = this.transform.Find("Panel/ReadButton").gameObject;
- ClearButton = this.transform.Find("Panel/ClearButton").gameObject;
- resultText = this.transform.Find("Panel/resultText").GetComponent<Text>();
- resultText.text = string.Empty;
- EventTriggerListener.Get(ReadButton).onClick = OnClicked_Createcontent;
- EventTriggerListener.Get(CloseButton).onClick = OnClicked_CloseButton;
- EventTriggerListener.Get(ClearButton).onClick = OnClicked_ClearButton;
- EventTriggerListener.Get(SaveButton).onClick = OnClicked_SaveButton;
- }
- private void OnClicked_ClearButton(GameObject btn)
- {
- str_info = string.Empty;
- InputField_simulatorUID.text = string.Empty;
- InputField_simulatorNickName.text = string.Empty;
- //////if (mScrollRectContent.childCount > 0)
- //////{
- ////// for (int i = mScrollRectContent.childCount - 1; i >= 0; i--)
- ////// {
- ////// Transform go = mScrollRectContent.GetChild(i);
- ////// if (go.name.Contains("message"))
- ////// {
- ////// Destroy(go.gameObject);
- ////// }
- ////// }
- //////}
- mContentText.text = string.Empty;
- }
- private string str_info = string.Empty;
- private void OnClicked_Createcontent(GameObject go)
- {
- if (string.IsNullOrEmpty(InputField_simulatorUID.text))
- return;
- if (string.IsNullOrEmpty(InputField_simulatorNickName.text))
- return;
- str_info = string.Empty;
- string readFilePath = Application.dataPath + "/Resources/" + InputField_FileName.text + ".txt";
- if (!File.Exists(readFilePath))
- {
- Debug.LogError(readFilePath);
- return;
- }
-
- TextAsset headFile = (TextAsset)Resources.Load(InputField_FileName.text);
- string[] recordArray = headFile.text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (string msg in recordArray)
- {
- string msg11111 = msg.Trim().Replace("\r", string.Empty);
- msg11111 = msg.Replace(" ", "...");
- if (string.IsNullOrEmpty(msg11111))
- continue;
- string modelId = msg11111.Substring(0, 6);
- string content = msg11111.Substring(6);
- ////GameObject tempOne = GameObject.Instantiate(mPrefab);
- ////tempOne.transform.SetParent(mScrollRectContent);
- ////tempOne.transform.localScale = Vector3.one;
- ////tempOne.transform.localPosition = Vector3.zero;
- ////tempOne.name = "message_";
- ////tempOne.SetActive(true);
- ////Text value_nickText = tempOne.transform.Find("Text").GetComponent<Text>();
- int ts = (int)UserProxy.Instance.GetCurrentUnixTimeStamp();
- string sss = "HSET \"gamerun-herodiscuss-";
- sss += modelId + "-item\" ";
- sss += "\"" + InputField_simulatorUID.text + "\" ";
- tempDis aaaa = new tempDis();
- aaaa.uid = InputField_simulatorUID.text;
- aaaa.name = InputField_simulatorNickName.text;
- aaaa.msg = content.Replace("\r", string.Empty);
- aaaa.ts = ts;
- sss += JsonUtility.ToJson(aaaa);
- mContentText.text += "<color=#f0F000>" + sss + "</color>\n";
- sss += "\r";
- //////ZADD "gamerun-herodiscuss-101013-score" 1520315307 "gg0006"
- string score = string.Empty;
- score += "ZADD \"gamerun-herodiscuss-" + modelId + "-score\"";
- score += " " + ts + " ";
- score += "\"" + InputField_simulatorUID.text + "\"";
- mContentText.text += "<color=#0fFF00>" + score + "</color>\n";
- score += "\r";
- //////value_nickText.text = sss;
- str_info += sss + score;
- }
- mContentText.text += "\n<color=#00FF00>Over</color>";
- mContentText.rectTransform.sizeDelta = new Vector2(1000,mContentText.preferredHeight+100);
- mScrollRectContent.sizeDelta = mContentText.rectTransform.sizeDelta;
- ////GameObject end = GameObject.Instantiate(mPrefab);
- ////end.transform.SetParent(mScrollRectContent);
- ////end.transform.localScale = Vector3.one;
- ////end.transform.localPosition = Vector3.zero;
- ////end.name = "message_";
- ////end.SetActive(true);
- ////Text txt = end.transform.Find("Text").GetComponent<Text>();
- ////txt.text ="<color=#00FF00>Over</color>";
- }
- /// <summary>
- /// 发送消息
- /// </summary>
- /// <param name="go">点击对象</param>
- public void OnClicked_SaveButton(GameObject go)
- {
- if (string.IsNullOrEmpty(str_info))
- return;
- if (string.IsNullOrEmpty(InputField_simulatorUID.text))
- return;
- //写入数据到 discuss文本
- string saveFilePath = Application.dataPath + "/Resources/" + InputField_simulatorUID.text + ".txt";
- StreamWriter sw;
- if (!File.Exists(saveFilePath))
- {
- sw = File.CreateText(saveFilePath);//创建一个用于写入 UTF-8 编码的文本
- Debug.Log("文件创建成功!");
- }
- else
- {
- sw = File.AppendText(saveFilePath);//打开现有 UTF-8 编码文本文件以进行读取
- }
- sw.WriteLine(str_info);//以行为单位写入字符串
- sw.Close();
- sw.Dispose();//文件流释放
- resultText.text = "保存成功";
- }
- public class tempDis
- {
- /// <summary>
- /// 评论的UID
- /// </summary>
- public string uid;
- public string name;
- public string msg;
- public int ts;
- /// <summary>
- /// 点赞次数
- /// </summary>
- public int praise;
- public string[] praised_uids = new string[0];
- }
- public void OnClicked_CloseButton(GameObject go)
- {
- PanelHelper.Instance.ClosePanel("UI_AutoDisCussWindow");
- }
- }
|