UpLoadmageItem.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Agora.Rtc.LitJson;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class UpLoadmageItem : MonoBehaviour
  8. {
  9. public string path;
  10. public void init(Texture2D texture2D,string str)
  11. {
  12. this.transform.GetComponent<RawImage>().texture = texture2D;
  13. string filePath = str;
  14. string uuid = Guid.NewGuid().ToString();
  15. string fileName = uuid+".png";
  16. string objecName = "workorder/"+int.Parse(ChuLiItemManager.ChooseData["id"].ToString())+"/";
  17. // 文件预上传
  18. JsonData jData = new JsonData();
  19. byte[] data = texture2D.EncodeToPNG();
  20. jData["size"] = data.Length;
  21. jData["ext"] = "jpg";
  22. jData["name"] = fileName;
  23. JsonData fileData = new JsonData();
  24. fileData["filePath"] = filePath;
  25. fileData["fileSize"] = data.Length;
  26. fileData["fileName"] = fileName;
  27. // project /{ projectId}/ inspection /{ projectInspectionId}/{ taskId}
  28. fileData["objectName"] = objecName;
  29. JsonData fildData = fileData;
  30. // 文件上传
  31. DownLoadXRManager.PutFile(fildData["filePath"].ToString(), fildData["fileName"].ToString(), fildData["objectName"].ToString() + fildData["fileName"].ToString(),uuid, int.Parse(fildData["fileSize"].ToString()), msg =>
  32. {
  33. Debug.Log(" 文件上传成功 " + msg);
  34. this.path = objecName+fileName;
  35. });
  36. }
  37. public void delete()
  38. {
  39. BaoGaoUpLoadManager.Instance.itemlist.Remove(this);
  40. Destroy(this.transform.GetComponent<RawImage>().texture);
  41. Destroy(this.gameObject);
  42. }
  43. }