ModelList.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using ShadowStudio.Model;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using XRTool.Util;
  6. using static LangChaoRommMinIo;
  7. public class ModelList : UnitySingleton<ModelList>
  8. {
  9. public void AddItem(FileConfig fileConfig)
  10. {
  11. if (RoomFile.Instance.FilePrefabConfigList.Contains(fileConfig))
  12. {
  13. RoomFile.IfFilePrefabConfigListAction?.Invoke(fileConfig);
  14. }
  15. else
  16. {
  17. RoomFile.Instance.FilePrefabConfigList.Add(fileConfig);
  18. string url = fileConfig.Url;
  19. LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => {
  20. Debug.Log("rfd==>" + rfd.url);
  21. Debug.Log("rfd==>" + rfd.bytes.Length);
  22. url = rfd.url;
  23. });
  24. if (!url.Contains("http"))
  25. {
  26. url = "https://" + fileConfig.Url;
  27. }
  28. ArtInfo artInfo = new ArtInfo();
  29. artInfo.ArtId = "ArtId" + UnityEngine.Random.Range(10000000, 99999999).ToString();
  30. artInfo.ArtName = fileConfig.FileName;
  31. artInfo.Url = url;
  32. artInfo.ArtType = ArtType.Model;
  33. artInfo.InstaceType = InstaceType.ExtralURLDownload;
  34. ArtHandler handler = ArtInfoMgr.Instance.CreateArtHandler(artInfo);
  35. var container = handler.CreateArt();
  36. Transform objTran = container.GetInstace().transform;
  37. objTran.SetParent(this.transform);
  38. //objTran.position = RoomFile.Instance.ModelPoint.position + new Vector3(RoomFile.Instance.fileIndex * 1f, 0, 0);
  39. //objTran.eulerAngles = RoomFile.Instance.Mp4Point.eulerAngles;
  40. Transform filePos = RoomFile.Instance.GetFilePos();
  41. objTran.transform.eulerAngles = filePos.eulerAngles;
  42. objTran.transform.position = filePos.position;
  43. ModelItem modelItem = objTran.GetComponent<ModelItem>();
  44. modelItem.Init(fileConfig);
  45. RoomFile.IfFilePrefabConfigListAction?.Invoke(fileConfig);
  46. }
  47. }
  48. public void DeleteAll()
  49. {
  50. if (transform.childCount > 0)
  51. {
  52. for (int i = 0; i < transform.childCount; i++)
  53. {
  54. Destroy(transform.GetChild(i).gameObject);
  55. }
  56. }
  57. }
  58. }