using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 路段车辆流量检测器 /// public class RoadChecker : MonoBehaviour { public enum CheckerDirType { None=0, Up, Down, Left, Right } public CheckerDirType type = CheckerDirType.None; public string roadName = ""; private RoadInfo info = null; private void Start() { if (roadName != null) { info= GameRoot.Instance.infoWnd.GetRoadInfo(roadName); } } private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Car") { GameRoot.Instance.roadSys.SetCheckerValue(this.gameObject.name,1); if (roadName != "") { Vector3 carDir = other.transform.forward.normalized; float dot = Vector3.Dot(carDir,this.transform.forward.normalized); switch (type) { case CheckerDirType.Up: if (dot >= 0) { info.carFlow += 1; } else { info.carFlow -= 1; } break; case CheckerDirType.Down: if (dot >= 0) { info.carFlow -= 1; } else { info.carFlow += 1; } break; case CheckerDirType.Left: if (dot >= 0) { info.carFlow -= 1; } else { info.carFlow += 1; } break; case CheckerDirType.Right: if (dot >= 0) { info.carFlow += 1; } else { info.carFlow -= 1; } break; } info.flowRate =Mathf.Lerp(0f,100f,( 1f - info.carFlow/98f)); GameRoot.Instance.infoWnd.UpdateRoadDict(roadName); } } } private void OnTriggerExit(Collider other) { if (other.gameObject.tag == "Car") { GameRoot.Instance.roadSys.SetCheckerValue(this.gameObject.name, -1); } } }