GongShi2.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. Transform parent = (SceneIOCContainer.Instance.Pull("mesh_test") as GameObject).transform;
  20. parent.transform.localPosition = Vector3.zero;
  21. parent.transform.eulerAngles = Vector3.zero;
  22. if (WebPosObj == null)
  23. WebPosObj = new GameObject();
  24. if (WebPosObj2 == null)
  25. WebPosObj2 = new GameObject();
  26. // Transform meshTestParent =(SceneIOCContainer.Instance.Pull("ARSpaceForAll") as GameObject).transform;
  27. //创建空锚点GameObject
  28. GameObject go = WebPosObj;
  29. go.transform.parent = parent.parent;
  30. Vector2 p1 = new Vector2(x2 / tw * sceneLength, (th - (y2)) / th * sceneWidth);
  31. Vector2 p2 = Vector2.zero - p1;
  32. Vector3 newPosition = new Vector3(p2.x, 0, p2.y);
  33. parent.localPosition = newPosition;
  34. yield return new WaitForSeconds(0.1f);
  35. go.transform.localPosition = Vector3.zero;
  36. parent.parent = go.transform;
  37. yield return new WaitForSeconds(0.1f);
  38. //创建空锚点 朝向
  39. p1 = new Vector2(x22 / tw * sceneLength, (th - (y22)) / th * sceneWidth);
  40. p2 = Vector2.zero - p1;
  41. newPosition = new Vector3(-p2.x, 0, -p2.y);
  42. GameObject go2 = WebPosObj2;
  43. GameObject go3 = new GameObject();
  44. go2.transform.parent = parent;
  45. go3.transform.parent = parent;
  46. go3.transform.localPosition = newPosition;
  47. go2.transform.localPosition = newPosition;
  48. yield return new WaitForSeconds(0.1f);
  49. go2.transform.parent = go.transform.parent;
  50. yield return new WaitForSeconds(0.1f);
  51. // go.transform.parent = parent.parent;
  52. // yield return new WaitForSeconds(0.1f);
  53. //把当前物体设置到锚点内
  54. // yield return new WaitForSeconds(0.1f);
  55. go.transform.LookAt(go2.transform);
  56. go.transform.localEulerAngles = new Vector3(0, 360-go.transform.localEulerAngles.y, 0);
  57. yield return new WaitForSeconds(0.1f);
  58. //设置回来
  59. parent.parent = go.transform.parent;
  60. yield return new WaitForSeconds(0.1f);
  61. // Destroy(go);
  62. // Destroy(go2);
  63. Destroy(WebPosObj2);
  64. WebPosObj2= go3;
  65. WebPosObj.transform.parent = parent.parent;
  66. WebPosObj2.transform.parent = parent.parent;
  67. CommandSystem.Instance.Send(new InitSuccessCommand());
  68. }
  69. public static List<Vector2> GetWebPos(float th, float tw, float sceneLength, float sceneWidth)
  70. {
  71. Transform parent = (SceneIOCContainer.Instance.Pull("mesh_test") as GameObject).transform;
  72. WebPosObj.transform.parent = parent;
  73. WebPosObj2.transform.parent = parent;
  74. List<Vector2> lvlist = new List<Vector2>();
  75. Vector2 p1 = new Vector2(WebPosObj.transform.localPosition.x / sceneLength * tw , th-((WebPosObj.transform.localPosition.z) / sceneWidth * th ));
  76. lvlist.Add(p1);
  77. Vector2 p2 = new Vector2(WebPosObj2.transform.localPosition.x / sceneLength * tw , th-((WebPosObj2.transform.localPosition.z )/ sceneWidth * th ));
  78. lvlist.Add(p2);
  79. Debug.Log("Web端Pos :" + p1);
  80. Debug.Log("Web端Pos 2 :" + p2);
  81. WebPosObj.transform.parent = parent.parent;
  82. WebPosObj2.transform.parent = parent.parent;
  83. return lvlist;
  84. }
  85. }
  86. public struct InitEvent:IEvent
  87. {
  88. }
  89. public struct InitSuccessCommand : ICommand
  90. {
  91. public void OnExcute()
  92. {
  93. this.SendEvent<InitEvent>();
  94. }
  95. }