LoadReference.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. using Blue;
  3. public class LoadReference : AbstractController
  4. {
  5. public GameObject goRefrence;
  6. private Transform meshTest=>(SceneIOCContainer.Instance.Pull("mesh_test")as GameObject).transform;
  7. private Transform meshTestParent=>(SceneIOCContainer.Instance.Pull("ARSpaceForAll")as GameObject).transform;
  8. private bool bool_GetReferencePosEvent=false;
  9. private bool bool_InitEvent=false;
  10. private Vector3 pos;
  11. private void Start()
  12. {
  13. this.RegisterEvent<GetReferencePosEvent>(GetObjOfRefrencePosRotSuccess).UnRegisterWhenGameObjectDestroyed(gameObject);
  14. this.RegisterEvent<InitEvent>(InitEventSuccess).UnRegisterWhenGameObjectDestroyed(gameObject);
  15. }
  16. private void GetObjOfRefrencePosRotSuccess(GetReferencePosEvent e)
  17. {
  18. bool_GetReferencePosEvent = true;
  19. pos = new Vector3(e.PosRot.x, e.PosRot.y, e.PosRot.z);
  20. if(bool_GetReferencePosEvent && bool_InitEvent)
  21. {
  22. SetPosRot(pos);
  23. }
  24. }
  25. private void InitEventSuccess(InitEvent e)
  26. {
  27. bool_InitEvent = true;
  28. if(bool_GetReferencePosEvent && bool_InitEvent)
  29. {
  30. SetPosRot(pos);
  31. }
  32. }
  33. private void SetPosRot(Vector3 pos)
  34. {
  35. goRefrence = Instantiate(goRefrence,meshTest);
  36. goRefrence.name = "goRefrence";
  37. SceneIOCContainer.Instance.Push("goRefrence",goRefrence);
  38. goRefrence.transform.localPosition = pos;
  39. goRefrence.transform.parent = meshTestParent;
  40. SetSceneActive.Instance.goReference_y = goRefrence.transform.position.y;
  41. goRefrence.SetActive(false);
  42. }
  43. }