123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- using SC.XR.Unity.Module_InputSystem;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- public enum ModelType
- {
- Image,
- Video,
- ABModel,
- Text,
- scene = -1,
- vuforial = -2,
- }
- public class ModelItem : System.ICloneable
- {
- public bool autoPlay;
- public int updateTime { get; set; }
- //WEB端排版
- public string template { get; set; }
- //模型所在组合素材内
- public GameObject modelList;
- public GameObject prefabModel;
- public GameObject _model;
- //模型数据
- public GameObject Model
- {
- get {
- if (_model == null)
- {
- _model = new GameObject(name);
- _model.transform.parent = modelList.transform;
- // _model.transform.localPosition = getInfoPos();
- // _model.transform.localEulerAngles = getInfoEul();
- Debug.Log(" ModelName>>>> " + name + " Type " + type);
- }
- return _model; }
- }
- public void init()
- {
- Debug.LogError("ModelItem Init");
- if (modelType != ModelType.Text)
- LoadManager.Instance.load(this, (float f) =>
- {
- //显示加载
- }, (byte[] obj) =>
- {
- });
- // else
- // SetData(null);
- }
- //模型地址
- public string url;
- //模型类型
- public ModelType modelType;
- ////模型原始信息
- //public string info;
- //模型版本
- public string Version { get; set; }
- Vector3 getInfoPos()
- {
- Debug.Log("DGJ2 ====> " + name + "_" + prefabModel.transform.localPosition + "_" + prefabModel.transform.name);
- if (prefabModel.transform.localPosition != Vector3.zero)
- {
- YangShiTextItem ysi = prefabModel.GetComponent<YangShiTextItem>();
- if (ysi&&((prefabModel.transform.localPosition.y == ysi.buttomf)|| (prefabModel.transform.localPosition.y == ysi.topf)) && prefabModel.transform.localPosition.x == 0 && prefabModel.transform.localPosition.z == 0)
- {
- Debug.Log("objectTransform.nowPos===>" + objectTransform.nowPos);
- }else
- {
- return prefabModel.transform.localPosition;
- }
- }
- if (prefabModel == null || objectTransform.nowPos==null)
- return Vector3.zero;
- Debug.Log("获取modelItem坐标==》"+prefabModel.name+ objectTransform.nowPos);
- //return Vector3.zero;
- if (objectTransform.nowPos == Vector3.zero&& prefabModel.transform.localPosition!=Vector3.zero)
- return objectTransform.startPos;
- else
- return objectTransform.nowPos;
- }
- Vector3 getInfoEul()
- {
- if (prefabModel.transform.localEulerAngles != Vector3.zero)
- {
- return prefabModel.transform.localEulerAngles;
- }
- if (prefabModel == null || objectTransform.nowPos == null)
- return Vector3.zero;
- if (objectTransform.nowRot == Vector3.zero && prefabModel.transform.localEulerAngles != Vector3.zero)
- return objectTransform.startRot;
- else
- return objectTransform.nowRot;
- // return Vector3.zero;
- }
- Vector3 getInfoScale()
- {
- Debug.Log("DGJ2 ==getInfoScale==> " + name + "_" + prefabModel.transform.localScale + "_" + prefabModel.transform.name);
- if (prefabModel.transform.localScale != Vector3.zero&& prefabModel.transform.localScale != Vector3.one)
- {
- return prefabModel.transform.localScale;
- }
- if ( objectTransform.nowPos == null)
- return Vector3.one;
- if (objectTransform.nowScale == Vector3.zero)
- return Vector3.one;
- else
- return objectTransform.nowScale;
- }
- //模型id
- public string uid { get; set; }
- //模型name
- public string name { get; set; }
- /// <summary>
- /// 模型类型
- /// </summary>
- public int type { get; set; }
- /// <summary>
- /// 文本内容
- /// </summary>
- public string textContent { get; set; }
- /// <summary>
- /// 文本框背景
- /// </summary>
- public string TextBJ { get; set; }
- public string textPosition { get; set; }
- /// <summary>
- /// 下载地址
- /// </summary>
- public string DownloadPath { get; set; }
- /// <summary>
- /// 本地保存地址
- /// </summary>
- public string localSavePath { get; set; }
- /// <summary>
- /// 坐标
- /// </summary>
- public ObjectTransform objectTransform { get; set; }
- public int fileId { get; set; }
- public int id { get; set; }
- Timer itemI;
- public void init(GameObject modelList)
- {
- switch (type)
- {
- case 1: // 图片
- modelType = ModelType.Image;
- break;
- case 2: // 视频
- modelType = ModelType.Video;
- break;
- case 3: // 模型
- modelType = ModelType.ABModel;
- break;
- case 4: // 文字
- modelType = ModelType.Text;
- break;
- default:
- Debug.LogError(name + " 素材结构类型异常!!!");
- break;
- }
- if (type == 0)
- return;
- url = DownloadPath;
- Debug.Log(url);
- this.modelList = modelList;
- if (Version == null)
- Version = Application.version.ToString();
- init();
- // if (Model != null)
- // Debug.Log(" 添加模型 " + name);
- }
- public object Clone()
- {
- ModelItem clonedObject = (ModelItem)this.MemberwiseClone();
- return clonedObject;
- }
- public byte[] abByte;
- public DownLoadMaterial dmdown;
- public static bool isLoad;
- public static Queue<ModelItem> loadAB = new Queue<ModelItem>();
- public void SetData(byte[] data, DownLoadMaterial dm)
- {
- if(data ==null && modelType!= ModelType.Video)
- {
- Debug.LogError(name + " 未下载完成 !!!!!");
- }
- abByte = data;
- }
- bool isload=false;
- public IEnumerator loadmodel()
- {
- DownLoadItem dloadi = LoadManager.Instance.getdownloaditem(this);
- Debug.Log("getdownloaditem=====>" + dloadi+"_"+ isload+"_"+id);
- if (dloadi&& !isload)
- {
- isload = true;
- while (dloadi.downLoadData== null)
- {
- yield return null;
- }
- abByte = dloadi.downLoadData;
- dmdown = dloadi.data;
- Debug.Log("HJJTEST ModelType " + modelType);
- switch (modelType)
- {
- case ModelType.Image:
- Texture2D texture = new Texture2D(1, 1);
- OpenCVForUnity.CoreModule.Mat _mat = null;
- GameManager.Instance.AddThead(() =>
- {
- Debug.Log("加載完成222222222222222222");
- _mat = GameManager.zoomByteByOpenCV(abByte);
- }, () =>
- {
- Debug.Log("加載完成111111111111");
- texture = GameManager.TextureByMat(_mat);
- Debug.Log(" LoadManager " + texture.width + "_" + texture.height);
- Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f);
- TemplateImage tlimg = prefabModel.GetComponent<TemplateImage>();
- Texture2D tex = texture;
- if (tex.height > tex.width)
- {
- float bl = ((float)tex.height / (float)tex.width);
- tlimg.transform.Find("Canvas").GetComponent<RectTransform>().sizeDelta = new Vector2(500 / bl, 500);
- }
- else
- {
- float bl = ((float)tex.width / (float)tex.height);
- tlimg.transform.Find("Canvas").GetComponent<RectTransform>().sizeDelta = new Vector2(500, 500 / bl);
- }
- tlimg.M_Image.sprite = sprite;
- });
- break;
- case ModelType.Video:
- Debug.Log(" DownloadPath video " );
- Debug.Log(" DownloadPath video " + prefabModel.name);
- Debug.Log(" DownloadPath video " + Application.persistentDataPath + "/Material/" + Path.GetFileName(DownloadPath));
- prefabModel.GetComponent<TemplateVideo>().localSavePath = Application.persistentDataPath + "/Material/" + Path.GetFileName(DownloadPath);
- prefabModel.GetComponent<TemplateVideo>().autoplay = autoPlay;
- // prefabModel.GetComponent<TemplateVideo>().SetData(HttpAction.baseurvideo + DownloadPath);
- prefabModel.GetComponent<TemplateVideo>().SetData(Application.persistentDataPath + "/Material/" + Path.GetFileName(DownloadPath));
- break;
- case ModelType.ABModel:
- prefabModel.GetComponent<TemplateModel>().Data = dmdown;
- loadAB.Enqueue(this);
- /*
- AssetBundle assetBundle = AssetBundle.LoadFromMemory(data);
- Debug.Log(data.Length);
- prefabModel.GetComponent<TemplateModel>().LoadModel(assetBundle);*/
- break;
- case ModelType.Text:
- Debug.Log("HJJTEST ModelType.Text " + DownloadPath);
- prefabModel.GetComponent<TemplateText>().SetData(textContent, TextBJ);
- break;
- default:
- break;
- }
- }
- }
- public void Clear()
- {
- switch (modelType)
- {
- case ModelType.Image:
- if(prefabModel)
- {
- Debug.Log("Clear SpotsList modelitem prefabModel" + prefabModel.name);
- TemplateImage tlimg = prefabModel.GetComponent<TemplateImage>();
- GameManager.Instance.destroyGo(tlimg.M_Image.sprite.texture);
- Debug.Log("Clear SpotsList modelitem prefabModel"+ prefabModel.name);
- }
- break;
- case ModelType.Video:
- break;
- case ModelType.ABModel:
- break;
- case ModelType.Text:
- break;
- default:
- break;
- }
- GameManager.Instance.destroyGo(prefabModel);
- prefabModel = null;
- isload = false;
- Debug.Log("Clear SpotsList modelitem[i]");
- }
- public void initModelObj()
- {
- GameManager.Instance.StartCoroutine(loadmodel());
- if (getInfoPos() != Vector3.zero)
- {
- prefabModel.transform.localPosition = getInfoPos();
- }
- if (getInfoEul() != Vector3.zero)
- {
- prefabModel.transform.localEulerAngles = getInfoEul();
- }
- if (getInfoScale() != Vector3.zero)
- {
- prefabModel.transform.localScale = getInfoScale();
- }
- // prefabModel.transform.localPosition = getInfoPos();
- // prefabModel.transform.localEulerAngles = getInfoEul();
- switch (modelType)
- {
- case ModelType.Text:
- prefabModel.GetComponent<TemplateText>().SetData(textContent, TextBJ);
- YangShiTextItem ysi = prefabModel.GetComponent<YangShiTextItem>();
- float topf = 0.4f;
- float buttomf = -0.4f;
- if (ysi!=null)
- {
- topf = ysi.topf;
- buttomf = ysi.buttomf;
- }
- //Set text position
- if (textPosition == "top")
- {
- if (objectTransform.nowPos == Vector3.zero && prefabModel.transform.localPosition!= new Vector3(0, topf, 0))
- {
- prefabModel.transform.localPosition = new Vector3(0, topf, 0);
- }
- }
- else if (textPosition == "bottom")
- {
- if (objectTransform.nowPos == Vector3.zero && prefabModel.transform.localPosition != new Vector3(0, buttomf, 0))
- {
- prefabModel.transform.localPosition = new Vector3(0, buttomf, 0);
- }
- }
- else if (textPosition == "left")
- {
- if (objectTransform.nowPos == Vector3.zero && prefabModel.transform.localPosition != new Vector3(0, 0.3f, 0))
- {
- prefabModel.transform.localPosition = new Vector3(-0.3f, 0, 0);
- }
- }
- else if (textPosition == "right")
- {
- if (objectTransform.nowPos == Vector3.zero && prefabModel.transform.localPosition != new Vector3(0, 0.3f, 0))
- {
- prefabModel.transform.localPosition = new Vector3(0.3f, 0f, 0);
- }
- }
- Debug.Log(" ddddddddddddddddddddd"+prefabModel.name+"_" + textPosition);
- break;
- default:
- break;
- }
- }
- }
|