123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Threading.Tasks;
- using COSXML;
- using COSXML.Auth;
- using COSXML.Transfer;
- using LitJson;
- using Unity.RenderStreaming;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class TaskManager : MonoBehaviour
- {
- public clientTCP ctcp;
- public GameObject Hand;
- public SignalingManager sm;
- private void Awake()
- {
- //SignalingSettings signaling = new WebSocketSignalingSettings("ws://192.168.31.239");
- //sm.SetSignalingSettings(signaling);
- // sm.gameObject.SetActive(true);
- StartCoroutine("Gettest");
- StartCoroutine("Gettest2");
- }
- IEnumerator Gettest()
- {
- //while (true)
- //{
- UnityWebRequest www = UnityWebRequest.Get("https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/3.txt");
- //www.timeout = 30;
- yield return www.SendWebRequest();
- //异常处理,很多博文用了error!=null这是错de
- if (www.isHttpError || www.isNetworkError)
- {
- Debug.Log("err: " + www.error);
- throw new Exception("www download had an error" + www.error);
- }
- else
- {
- }
- if (www.isDone)
- {
- string STR = www.downloadHandler.text;
- print("接受:" + STR);
- SignalingSettings signaling = new WebSocketSignalingSettings(STR);
- sm.SetSignalingSettings(signaling);
- sm.gameObject.SetActive(true);
- }
- }
- IEnumerator Gettest2()
- {
- //while (true)
- //{
- UnityWebRequest www = UnityWebRequest.Get("https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/44.txt");
- //www.timeout = 30;
- yield return www.SendWebRequest();
- //异常处理,很多博文用了error!=null这是错de
- if (www.isHttpError || www.isNetworkError)
- {
- Debug.Log("err: " + www.error);
- throw new Exception("www download had an error" + www.error);
- }
- else
- {
- }
- if (www.isDone)
- {
- string STR = www.downloadHandler.text;
- print("接受:" + STR);
- ctcp.ClickConnect(STR);//"192.168.1.109"
- }
- }
- public static SJ sj;
- public GameObject head;
- bool isa;
- bool isp;
- public int nowindex;
- public Text text;
- public Text ltext;
- public PlayAnManager pm;
- public List<TaskItem> tasklist;
- public List<GameObject> yidonglist;
- bool isGrip;
- bool lisGrip;
- // Start is called before the first frame update
- void Start()
- {
- tasklist[0].starttask(this);
- }
- public static async void creatcsvAsync()
- {
- // 指定文件路径和文件名
- string filePath = Application.persistentDataPath + "/myCSVFile.csv";
- if(File.Exists(filePath))
- {
- File.Delete(filePath);
- }
- //开始时间、结束时间、训练次数、每次完成时长,完成组数,计划组数
- // 创建CSV数据
- string csvData = "开始时间,结束时间,训练次数,每次完成时长,完成组数,计划组数\n" +
- sj.starttime + "," + sj.endtime + "," + sj.xlct + "," + sj.mcsc + "," + sj.wczs + "," + sj.jhzs + "\n";
- // 写入文件
- File.WriteAllText(filePath, csvData);
- Debug.Log("CSV file generated at " + filePath);
- //初始化 CosXmlConfig
- string region = "ap-shanghai"; //设置一个默认的存储桶地域
- CosXmlConfig config = new CosXmlConfig.Builder()
- .IsHttps(true) //设置默认 HTTPS 请求
- .SetRegion(region) //设置一个默认的存储桶地域
- .SetDebugLog(true) //显示日志
- .Build(); //创建 CosXmlConfig 对象
- string secretId = "AKIDWwBqLepvukNlwviGaryAD2e2KXaO0Rgm";// Environment.GetEnvironmentVariable("AKIDWwBqLepvukNlwviGaryAD2e2KXaO0Rgm"); //用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://cloud.tencent.com/document/product/598/37140
- string secretKey = "IbuDSep08HQaimntyz0JZwFVioo5TzY6";// Environment.GetEnvironmentVariable("IbuDSep08HQaimntyz0JZwFVioo5TzY6"); //用户的 SecretKey,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://cloud.tencent.com/document/product/598/37140
- long durationSecond = 600; //每次请求签名有效时长,单位为秒
- QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider(
- secretId, secretKey, durationSecond);
- CosXml cosXml = new CosXmlServer(config, cosCredentialProvider);
- // 初始化 TransferConfig
- TransferConfig transferConfig = new TransferConfig();
- // 初始化 TransferManager
- TransferManager transferManager = new TransferManager(cosXml, transferConfig);
- string bucket = "wx-model-1317557471"; //存储桶,格式:BucketName-APPID
- string cosPath = "ff.csv"; //对象在存储桶中的位置标识符,即称对象键
- string srcPath = filePath;//本地文件绝对路径
- // 上传对象
- COSXMLUploadTask uploadTask = new COSXMLUploadTask(bucket, cosPath);
- uploadTask.SetSrcPath(srcPath);
- uploadTask.progressCallback = delegate (long completed, long total)
- {
- Debug.Log( string.Format("progress = {0:##.##}%", completed * 100.0 / total));
- };
- try
- {
- COSXML.Transfer.COSXMLUploadTask.UploadTaskResult result = await
- transferManager.UploadAsync(uploadTask);
- Console.WriteLine(result.GetResultInfo());
- string eTag = result.eTag;
- }
- catch (Exception e)
- {
- Debug.Log("CosException: " + e);
- }
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.O))
- {
- yidong();
- }
- if (text.text.Contains("Open"))
- {
- isGrip = true;
- }
- else if (isGrip && (text.text.Contains("Grab") || text.text.Contains("Pinch")))
- {
- isGrip = false;
- yidong();
- }
- if (ltext.text.Contains("Open"))
- {
- lisGrip = true;
- }
- else if (lisGrip && (ltext.text.Contains("Grab") || ltext.text.Contains("Pinch")))
- {
- lisGrip = false;
- yidong();
- }
- }
- public GameObject cj;
- public void yidong()
- {
- if (yidonglist.Count > nowindex)
- {
- Vector3 v3 = yidonglist[nowindex].transform.position - OpenXRCamera.Instance.head.transform.localPosition;
- head.transform.position = new Vector3(v3.x, OpenXRCamera.Instance.head.transform.position.y, v3.z);
- }
- if(nowindex== yidonglist.Count-1)
- {
- sj = new SJ();
- sj.starttime = DateTime.Now.ToString();
- creatcsvAsync();
- cj.SetActive(false) ;
- }
- nowindex++;
- isa = false;
- isp = false;
- // Debug.Log("yidong===");
- }
- public class SJ
- {
- public string starttime;
- public string endtime;
- public int xlct;
- public int mcsc;
- public int wczs;
- public int jhzs = 2;
- }
- }
|