LoadReference.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. Debug.Log("DGJ GetObjOfRefrencePosRotSuccess ===> " + e.PosRot.x + " " + e.PosRot.y + " " + e.PosRot.z) ;
  19. bool_GetReferencePosEvent = true;
  20. pos = new Vector3(e.PosRot.x, e.PosRot.y, e.PosRot.z);
  21. if(bool_GetReferencePosEvent && bool_InitEvent)
  22. {
  23. SetPosRot(pos);
  24. }
  25. }
  26. private void InitEventSuccess(InitEvent e)
  27. {
  28. Debug.Log("DGJ InitEventSuccess ===> ");
  29. bool_InitEvent = true;
  30. if(bool_GetReferencePosEvent && bool_InitEvent)
  31. {
  32. SetPosRot(pos);
  33. }
  34. }
  35. private void SetPosRot(Vector3 pos)
  36. {
  37. goRefrence = Instantiate(goRefrence,meshTest);
  38. goRefrence.name = "goRefrence";
  39. SceneIOCContainer.Instance.Push("goRefrence",goRefrence);
  40. goRefrence.transform.localPosition = pos;
  41. goRefrence.transform.parent = meshTestParent;
  42. SetSceneActive.Instance.goReference_y = goRefrence.transform.position.y;
  43. goRefrence.SetActive(false);
  44. }
  45. }