using System; using UnityEngine; public class StationaryAreaMono : MonoBehaviour { private bool isFreeze = false; private StationaryAreaStep stationaryAreaStep; private GroundHeightStep groundHeightStep; private Transform headTransform; private MeshRenderer meshRenderer; void Start() { if (stationaryAreaStep == null) { stationaryAreaStep = SafetyAreaManager.Instance.GetStep(SafetyAreaStepEnum.StationaryArea); } if (groundHeightStep == null) { groundHeightStep = SafetyAreaManager.Instance.GetStep(SafetyAreaStepEnum.GroundHeight); } if (headTransform == null) { headTransform = API_GSXR_Slam.SlamManager.head; } float groundHeight = groundHeightStep.GetPlaneHeight(); MeshFilter meshFilter = this.gameObject.AddComponent(); meshRenderer = this.gameObject.AddComponent(); meshRenderer.material = Resources.Load("Material/SafetyEdgeMat"); meshFilter.mesh = SafetyAreaVertexHelper.GenerateCylinderMesh(new Vector3(0, groundHeight, 0), groundHeight + 5, groundHeight); } void Update() { if (!isFreeze) { Vector3 headPosition = API_GSXR_Slam.SlamManager.head.position; stationaryAreaStep.SetCircleCenter(headPosition); Vector2 circleCenter = stationaryAreaStep.GetCircleCenter(); this.gameObject.transform.position = new Vector3(circleCenter.x, groundHeightStep.GetPlaneHeight(), circleCenter.y); } meshRenderer.sharedMaterial.SetVector("headPosition", new Vector4(headTransform.position.x, headTransform.position.y, headTransform.position.z, 1f)); } public void FreezeStationaryAreaPosition() { isFreeze = true; } public void UnFreezeStationaryAreaPosition() { isFreeze = false; } }