UIMove.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using DG.Tweening;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class UIMove : MonoBehaviour
  6. {
  7. public Transform Head;
  8. public bool isMove;
  9. private Transform target;
  10. public Transform headpos;
  11. // Start is called before the first frame update
  12. void Start()
  13. {
  14. isMove = false;
  15. // SettingEditor(headpos);
  16. // StartCoroutine(Func());
  17. }
  18. //private void Update()
  19. //{
  20. // if(isMove)
  21. // {
  22. // //if(Mathf.Abs( Vector2.Distance(new Vector2(transform.position.x,transform.position.z),new Vector2(Head.position.x,Head.position.z)))>0.3f)
  23. // //transform.DOMove(new Vector3(Head.position.x, transform.position.y, Head.position.z), 0.1f);
  24. // if(Mathf.Abs(Head.transform.eulerAngles.x)<45)
  25. // {
  26. // transform.position = new Vector3(Head.position.x, transform.position.y, Head.position.z);
  27. // }
  28. // }
  29. //}
  30. //IEnumerator Func()
  31. //{
  32. // while (true)
  33. // {
  34. // yield return new WaitForSeconds(1.0f); // first
  35. // if (isMove)
  36. // {
  37. // Vector2 pos = (new Vector2(target.position.x, target.position.z) + new Vector2(Head.parent.position.x, Head.parent.parent.position.z)) * 0.5f;
  38. // transform.DOMove(new Vector3(pos.x,-0.35f,pos.y), 0.9f);
  39. // }
  40. // // transform.position = Vector3.Lerp(transform.position, SvrManager.Instance.head.position + new Vector3(-1.5f, 0, 0),1f);
  41. // }
  42. //}
  43. private void Update()
  44. {
  45. if(isMove && headpos!=null)
  46. {
  47. //float x = transform.position.x - headpos.position.x;
  48. //float z = transform.position.z - headpos.position.z;
  49. //if (Mathf.Abs(x) > 0.8f || Mathf.Abs(z) > 0.8f)
  50. //{
  51. // //transform.position = new Vector3(headpos.position.x + x > 0 ? 0.8f : -0.8f, -0.3f, headpos.position.z + z > 0 ? 0.8f : -0.8f);
  52. // transform.eulerAngles = new Vector3(30, headpos.eulerAngles.y, 0);
  53. //}
  54. //float dis = Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(headpos.position.x, headpos.position.z));
  55. //if (dis > 0.8f)
  56. //{
  57. // transform.position = new Vector3(headpos.position.x + 0.8f, -0.3f, headpos.position.z + 0.8f);
  58. // transform.eulerAngles = new Vector3(30, headpos.eulerAngles.y, 0);
  59. //}
  60. //Vector3 pos = Vector3.zero;
  61. //float x = transform.position.x - headpos.position.x;
  62. //float z = transform.position.z - headpos.position.z;
  63. //if(x>0.8f)
  64. //{
  65. // pos.x = headpos.position.x + 0.8f;
  66. //}
  67. //else if(x<-0.8f)
  68. //{
  69. // pos.x = headpos.position.x - 0.8f;
  70. //}
  71. //if (z > 0.8f)
  72. //{
  73. // pos.z = headpos.position.x + 0.8f;
  74. //}
  75. //else if (z < -0.8f)
  76. //{
  77. // pos.z = headpos.position.x + 0.8f;
  78. //}
  79. //Debug.Log(pos);
  80. //transform.position = pos;
  81. //transform.eulerAngles = new Vector3(30, headpos.eulerAngles.y, 0);
  82. //float roty = headpos.eulerAngles.y - transform.eulerAngles.y;
  83. //Debug.Log(roty);
  84. //if(roty >15)
  85. //{
  86. // transform.eulerAngles = new Vector3(transform.eulerAngles.x, headpos.eulerAngles.y + 15, transform.eulerAngles.z);
  87. //}
  88. //else if(roty <-15)
  89. //{
  90. // transform.eulerAngles = new Vector3(transform.eulerAngles.x, headpos.eulerAngles.y - 15, transform.eulerAngles.z);
  91. //}
  92. //roty = headpos.eulerAngles.y - transform.eulerAngles.y;
  93. //float x = headpos.position.x + 3 * Mathf.Cos(headpos.eulerAngles.y);
  94. //float z = headpos.position.z + 3 * Mathf.Sin(headpos.eulerAngles.y);
  95. //transform.position = new Vector3(x, transform.position.y, z);
  96. }
  97. }
  98. public void OpenEditor(Transform target)
  99. {
  100. this.target = target;
  101. isMove = true;
  102. transform.eulerAngles = new Vector3(30, target.eulerAngles.y, transform.eulerAngles.z);
  103. transform.DOMove(new Vector3(Head.position.x, transform.position.y, Head.position.z), 0.9f);
  104. }
  105. public void CloseEditor()
  106. {
  107. this.target = null;
  108. isMove = false;
  109. transform.position = new Vector3(10000, 0, 0);
  110. }
  111. public void SettingEditor(Transform headPos)
  112. {
  113. isMove = !isMove;
  114. headpos = headPos;
  115. if (isMove)
  116. {
  117. transform.position = new Vector3(headpos.position.x, -0.3f, headpos.position.z);
  118. transform.eulerAngles = new Vector3(30, headpos.eulerAngles.y, 0);
  119. }
  120. else
  121. {
  122. transform.position = new Vector3(10000, 0, 0);
  123. }
  124. }
  125. }