UIModelManager.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using SC.XR.Unity;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class UIModelManager : SingletonMono<UIModelManager>
  6. {
  7. public bool isinit = true;
  8. public string loadModelName = "";
  9. public List<ZiYuanFileItem> listItem;
  10. public GameObject ziYuanKuObj;
  11. public GameObject button;
  12. public Transform point;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. }
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. if (OpenXRCamera.Instance.head != null && !ziYuanKuObj.activeSelf)
  21. {
  22. transform.position = new Vector3(point.position.x, 1.5f, point.position.z);
  23. transform.eulerAngles = new Vector3(0, point.eulerAngles.y, 0);
  24. }
  25. }
  26. public void CreateModel( string modelName)
  27. {
  28. ZYKOnClick(false);
  29. string id = Random.Range(1000, 9999).ToString() + SynchronizeManager.Instance.modelNume++.ToString();
  30. Vector3 pos = OpenXRCamera.Instance.head.forward * 2f + OpenXRCamera.Instance.head.position;
  31. TransformData tranformData = new TransformData(pos, Vector3.zero, Vector3.one);
  32. ModelData data = new ModelData(id, modelName, tranformData, false, false, false);
  33. GameObject modelc = GameObject.Instantiate(Resources.Load<GameObject>("ModelC"));
  34. GameObject model = GameObject.Instantiate(Resources.Load<GameObject>(data.name));
  35. modelc.GetComponent<ModelC>().AddModel(model.transform);
  36. ModelSynchronize modelSync = modelc.GetComponent<ModelSynchronize>();
  37. modelSync.Init(data);
  38. SynchronizeManager.Instance.CreateModel(data);
  39. SynchronizeManager.Instance.AddModelSynchronize(modelSync);
  40. }
  41. public void CreateModel()
  42. {
  43. for (int i = 0; i < listItem.Count; i++)
  44. {
  45. listItem[i].blueImage.SetActive(false);
  46. }
  47. if (loadModelName != "")
  48. CreateModel(loadModelName);
  49. loadModelName = "";
  50. }
  51. public void DesModel( string ModelId )
  52. {
  53. SynchronizeManager.Instance.DesModel(ModelId);
  54. }
  55. public void ZYKOnClick( bool state )
  56. {
  57. ziYuanKuObj.SetActive(state);
  58. button.SetActive(!state);
  59. }
  60. }