123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using LitJson;
- using UnityEngine;
- using UnityEngine.UI;
- using static DownLoadXRManager;
- public class BaoGaoUpLoadManager : MonoBehaviour
- {
- public static BaoGaoUpLoadManager Instance;
- void Awake()
- {
- Instance = this;
- }
- public void initBG()
- {
- for (int i = 0;i<itemlist.Count;i++)
- {
- Destroy(itemlist[i].gameObject);
- }
- itemlist.Clear();
- Debug.Log("BaoGaoWindowManager.Instance.XQData.workOrder.reports.paperReports==>");
- if(BaoGaoWindowManager.Instance.XQData.workOrder.reports!=null&&BaoGaoWindowManager.Instance.XQData.workOrder.reports.paperReports!=null)
- {
- Debug.Log("BaoGaoWindowManager.Instance.XQData.workOrder.reports.paperReports==>"+BaoGaoWindowManager.Instance.XQData.workOrder.reports.paperReports.Count);
- for (int i = 0;i< BaoGaoWindowManager.Instance.XQData.workOrder.reports.paperReports.Count;i++)
- {
- downloadimg(BaoGaoWindowManager.Instance.XQData.workOrder.reports.paperReports[i]);
- }
- }
-
- }
- public void downloadimg(string path)
- {
- Debug.Log("开始下载图片===》"+path);
- UpLoadmageItem nitem = GameObject.Instantiate(item,item.transform.parent);
- nitem.GetComponent<ImageLoadManager>().loadimage(path);
- nitem.gameObject.SetActive(true);
- nitem.path = path;
- itemlist.Add(nitem);
- }
- string imgpath="";
- public UpLoadmageItem item;
- public List<UpLoadmageItem> itemlist;
- public void showImg()
- {
-
- if( itemlist.Count>=5)
- {
- TianJiWindowManager.Instance.showPop(4,"最多上传5张图");
- Debug.Log("最多上传5张图");
- return;
-
- }
- NativeGallery.GetImageFromGallery((string path) => {
- Debug.Log("Image path: " + path);
- imgpath = path;
-
- });
- }
- void Update()
- {
- if(imgpath!="")
- {
- Texture2D t2d = LoadTextureFromPath(imgpath);
- UpLoadmageItem nitem = GameObject.Instantiate(item,item.transform.parent);
- nitem.gameObject.SetActive(true);
- nitem.init(t2d,imgpath);
- itemlist.Add(nitem);
- imgpath="";
- }
- }
- public void gotocompleteGongdan(bool isDraft)
- {
- StartCoroutine(uploadfile(isDraft));
- }
- IEnumerator uploadfile(bool isDraft)
- {
- JsonData data= new JsonData();
- data["workOrderId"] =int.Parse(ChuLiItemManager.ChooseData["id"].ToString()) ;
- data["reportsType"] = 1;
- data["isDraft"] = isDraft;
- data["paperReports"] = new JsonData();
- for (int i=0;i<itemlist.Count;i++)
- {
- data["paperReports"].Add(itemlist[i].path);
- }
-
- if( itemlist.Count<=0&&!isDraft)
- {
- TianJiWindowManager.Instance.showPop(4,"请上传图片");
- Debug.Log("请上传图片");
-
- }
- else
- {
- int ct =0;
- TianJiWindowManager.Instance.showPop(7,"");
- for (int i=0;i<itemlist.Count;i++)
- {
- UpLoadmageItem n = itemlist[i].GetComponent<UpLoadmageItem>();
- if(itemlist[i].fildData==null)
- {
- ct++;
- }
- else
- {
- itemlist[i].startUpLoad((b)=>{
- ct++;
- });
- }
- }
- while(itemlist.Count!=ct)
- {
- yield return null;
- }
- DataManager.Instance.completeGongdan(data,(str)=>{
- TianJiWindowManager.Instance.closepop();
- Debug.Log("completeGongdancompleteGongdan====>"+str);
- QuanJuBackManager.Instance.back();
- });
- }
- }
- public Texture2D LoadTextureFromPath(string imagePath)
- {
-
- if (!System.IO.File.Exists(imagePath))
- {
- Debug.LogError("File not found at path: " + imagePath);
- return null;
- }
-
- byte[] fileData = System.IO.File.ReadAllBytes(imagePath);
-
-
- Texture2D tex = new Texture2D(2, 2);
-
-
- if (tex.LoadImage(fileData))
- {
- return tex;
- }
-
- return null;
- }
- }
|