StationaryAreaMono.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using UnityEngine;
  3. public class StationaryAreaMono : MonoBehaviour
  4. {
  5. private bool isFreeze = false;
  6. private StationaryAreaStep stationaryAreaStep;
  7. private GroundHeightStep groundHeightStep;
  8. private Transform headTransform;
  9. private MeshRenderer meshRenderer;
  10. void Start()
  11. {
  12. if (stationaryAreaStep == null)
  13. {
  14. stationaryAreaStep = SafetyAreaManager.Instance.GetStep<StationaryAreaStep>(SafetyAreaStepEnum.StationaryArea);
  15. }
  16. if (groundHeightStep == null)
  17. {
  18. groundHeightStep = SafetyAreaManager.Instance.GetStep<GroundHeightStep>(SafetyAreaStepEnum.GroundHeight);
  19. }
  20. if (headTransform == null)
  21. {
  22. headTransform = API_GSXR_Slam.SlamManager.head;
  23. }
  24. float groundHeight = groundHeightStep.GetPlaneHeight();
  25. MeshFilter meshFilter = this.gameObject.AddComponent<MeshFilter>();
  26. meshRenderer = this.gameObject.AddComponent<MeshRenderer>();
  27. meshRenderer.material = Resources.Load<Material>("Material/SafetyEdgeMat");
  28. meshFilter.mesh = SafetyAreaVertexHelper.GenerateCylinderMesh(new Vector3(0, groundHeight, 0), groundHeight + 5, groundHeight);
  29. }
  30. void Update()
  31. {
  32. if (!isFreeze)
  33. {
  34. Vector3 headPosition = API_GSXR_Slam.SlamManager.head.position;
  35. stationaryAreaStep.SetCircleCenter(headPosition);
  36. Vector2 circleCenter = stationaryAreaStep.GetCircleCenter();
  37. this.gameObject.transform.position = new Vector3(circleCenter.x, groundHeightStep.GetPlaneHeight(), circleCenter.y);
  38. }
  39. meshRenderer.sharedMaterial.SetVector("headPosition", new Vector4(headTransform.position.x, headTransform.position.y, headTransform.position.z, 1f));
  40. }
  41. public void FreezeStationaryAreaPosition()
  42. {
  43. isFreeze = true;
  44. }
  45. public void UnFreezeStationaryAreaPosition()
  46. {
  47. isFreeze = false;
  48. }
  49. }