123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 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;
- }
- void OnEnable()
- {
- initBG(BaoGaoWindowManager.Instance.XQData);
- }
- public void initBG(BaoBiaoDetail data)
- {
- for (int i = 0;i< data.workOrder.reports.paperReports.Count;i++)
- {
- downloadimg(data.workOrder.reports.paperReports[i]);
- }
-
- }
- public void downloadimg(string path)
- {
- Debug.Log("开始下载图片===》"+path);
- DownLoadResources dlr = new DownLoadResources();
- dlr.path = path;
-
- DownLoadXRManager.DownLoadForTexture(dlr, msg =>
- {
- Texture2D t2d = msg;
- UpLoadmageItem nitem = GameObject.Instantiate(item,item.transform.parent);
- nitem.gameObject.SetActive(true);
- nitem.init(t2d,imgpath);
- itemlist.Add(nitem);
- },(f)=>{
- });
- }
- 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)
- {
- JsonData data= new JsonData();
- data["workOrderId"] = BaoGaoWindowManager.Instance.XQData.workOrder.id;
- data["reportsType"] = 2;
- data["isDraft"] = isDraft;
- data["paperReports"] = new JsonData();
- for (int i=0;i<itemlist.Count;i++)
- {
- data["paperReports"].Add(itemlist[i].path);
- }
-
- if( data["paperReports"].Count<=0)
- {
- TianJiWindowManager.Instance.showPop(4,"请上传图片");
- Debug.Log("请上传图片");
- return;
-
- }
- DataManager.Instance.completeGongdan(data,(str)=>{
- 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;
- }
- }
|