MoveGuideComponent.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Threading.Tasks;
  2. using UnityEngine;
  3. using WS;
  4. [ObjectSystem]
  5. public class MoveGuideComponentLateUpdateSystem : LateUpdateSystem<MoveGuideComponent>
  6. {
  7. public override void LateUpdate(MoveGuideComponent self)
  8. {
  9. self.LateUpdate();
  10. }
  11. }
  12. //移动
  13. public class MoveGuideComponent : OperateComponent<MoveGuideData>
  14. {
  15. /// <summary> 操作开始前用户位置 </summary>
  16. public Vector3 startPos;
  17. /// <summary> 移动的目标点 </summary>
  18. public GameObject targetPoint;
  19. public override void Init() { }
  20. public override void StartOperate()
  21. {
  22. startPos = Player.Inst.transform.position;
  23. targetPoint = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/TeleportPoint"));
  24. targetPoint.transform.position = new Vector3(
  25. OperateData.targetPos.x,
  26. 0.1f,
  27. OperateData.targetPos.z
  28. );
  29. }
  30. public override void Update()
  31. {
  32. //if (VRInputComponent.Instance.GetKeyUp(VRKey.圆盘, VRHand.Any))
  33. //{
  34. // if (
  35. // Vector3.Distance(
  36. // Player.Inst.rigSteamVR.transform.position,
  37. // OperateData.targetPos
  38. // ) <= 1f
  39. // )
  40. // {
  41. // GameObject.Destroy(targetPoint);
  42. // IsComplete = true;
  43. // }
  44. //}
  45. }
  46. public void LateUpdate()
  47. {
  48. //if (VRInputComponent.Instance.GetKeyUp(VRKey.圆盘, VRHand.Any))
  49. //{
  50. // if (
  51. // Vector3.Distance(
  52. // Player.instance.rigSteamVR.transform.position,
  53. // OperateData.targetPos
  54. // ) <= 1f
  55. // )
  56. // {
  57. // GameObject.Destroy(targetPoint);
  58. // IsComplete = true;
  59. // }
  60. //}
  61. }
  62. public override void Prompt()
  63. {
  64. base.Prompt();
  65. }
  66. public override Task StartState()
  67. {
  68. GameObject startPoint = GameObject.Find("StartPoint");
  69. Player.Inst.transform.position = startPoint.transform.position;
  70. Player.Inst.transform.rotation = startPoint.transform.rotation;
  71. return Task.CompletedTask;
  72. }
  73. public override Task EndState()
  74. {
  75. Player.Inst.transform.position = OperateData.targetPos;
  76. return Task.CompletedTask;
  77. }
  78. }
  79. public class MoveGuideData
  80. {
  81. public Vector3 targetPos;
  82. }