GongShi2.cs 3.7 KB

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