GongShi2.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Blue;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class GongShi2 : MonoBehaviour
  7. {
  8. public static float ff = 0;
  9. public static Vector3 vp3;
  10. public static Vector3 ve3;
  11. public static void F2Dto3D(float x2, float y2, float th,float tw, float x22, float y22,float sceneLength, float sceneWidth)
  12. {
  13. GameManager.Instance.StartCoroutine(startjisuan(x2,y2,th,tw,x22,y22, sceneLength, sceneWidth));
  14. }
  15. public static GameObject WebPosObj;
  16. public static GameObject WebPosObj2;
  17. static IEnumerator startjisuan(float x2, float y2, float th, float tw, float x22, float y22, float sceneLength, float sceneWidth)
  18. {
  19. Debug.Log("startjisuanstartjisuanstartjisuanstartjisuan");
  20. Transform parent = (SceneIOCContainer.Instance.Pull("mesh_test") as GameObject).transform;
  21. parent.transform.localPosition = Vector3.zero;
  22. parent.transform.localEulerAngles = Vector3.zero;
  23. if (WebPosObj == null)
  24. WebPosObj = new GameObject();
  25. if (WebPosObj2 == null)
  26. WebPosObj2 = new GameObject();
  27. WebPosObj.name = "WebPosObj";
  28. WebPosObj2.name = "WebPosObj2";
  29. WebPosObj.transform.position = Vector3.zero;
  30. WebPosObj.transform.eulerAngles = Vector3.zero;
  31. WebPosObj2.transform.position = Vector3.zero;
  32. WebPosObj2.transform.eulerAngles = Vector3.zero;
  33. // Transform meshTestParent =(SceneIOCContainer.Instance.Pull("ARSpaceForAll") as GameObject).transform;
  34. //创建空锚点GameObject
  35. GameObject go = WebPosObj;
  36. go.transform.parent = parent.parent;
  37. Vector2 p1 = new Vector2(x2 / tw * sceneLength, (th - (y2)) / th * sceneWidth);
  38. Vector2 p2 = Vector2.zero - p1;
  39. Vector3 newPosition = new Vector3(p2.x, 0, p2.y);
  40. parent.localPosition = newPosition;
  41. yield return new WaitForSeconds(0.1f);
  42. go.transform.localPosition = Vector3.zero;
  43. parent.parent = go.transform;
  44. yield return new WaitForSeconds(0.1f);
  45. //创建空锚点 朝向
  46. p1 = new Vector2(x22 / tw * sceneLength, (th - (y22)) / th * sceneWidth);
  47. p2 = Vector2.zero - p1;
  48. newPosition = new Vector3(-p2.x, 0, -p2.y);
  49. GameObject go2 = WebPosObj2;
  50. GameObject go3 = new GameObject();
  51. go2.transform.parent = parent;
  52. go3.transform.parent = parent;
  53. go3.transform.localPosition = newPosition;
  54. go2.transform.localPosition = newPosition;
  55. yield return new WaitForSeconds(0.1f);
  56. go2.transform.parent = go.transform.parent;
  57. yield return new WaitForSeconds(0.1f);
  58. // go.transform.parent = parent.parent;
  59. // yield return new WaitForSeconds(0.1f);
  60. //把当前物体设置到锚点内
  61. // yield return new WaitForSeconds(0.1f);
  62. go.transform.LookAt(go2.transform);
  63. go.transform.localEulerAngles = new Vector3(0, 360-go.transform.localEulerAngles.y, 0);
  64. yield return new WaitForSeconds(0.1f);
  65. //设置回来
  66. parent.parent = go.transform.parent;
  67. yield return new WaitForSeconds(0.1f);
  68. // Destroy(go);
  69. // Destroy(go2);
  70. Destroy(WebPosObj2);
  71. WebPosObj2= go3;
  72. WebPosObj.transform.parent = parent.parent;
  73. WebPosObj2.transform.parent = parent.parent;
  74. CommandSystem.Instance.Send(new InitSuccessCommand());
  75. }
  76. public static List<Vector2> GetWebPos(float th, float tw, float sceneLength, float sceneWidth)
  77. {
  78. Transform parent = (SceneIOCContainer.Instance.Pull("mesh_test") as GameObject).transform;
  79. WebPosObj.transform.parent = parent;
  80. WebPosObj2.transform.parent = parent;
  81. List<Vector2> lvlist = new List<Vector2>();
  82. Vector2 p1 = new Vector2(WebPosObj.transform.localPosition.x / sceneLength * tw , th-((WebPosObj.transform.localPosition.z) / sceneWidth * th ));
  83. lvlist.Add(p1);
  84. Vector2 p2 = new Vector2(WebPosObj2.transform.localPosition.x / sceneLength * tw , th-((WebPosObj2.transform.localPosition.z )/ sceneWidth * th ));
  85. lvlist.Add(p2);
  86. Debug.Log("Web端Pos :" + p1);
  87. Debug.Log("Web端Pos 2 :" + p2);
  88. WebPosObj.transform.parent = parent.parent;
  89. WebPosObj2.transform.parent = parent.parent;
  90. return lvlist;
  91. }
  92. }
  93. public struct InitEvent:IEvent
  94. {
  95. }
  96. public struct InitSuccessCommand : ICommand
  97. {
  98. public void OnExcute()
  99. {
  100. this.SendEvent<InitEvent>();
  101. }
  102. }