LoadReference.cs 1.9 KB

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