You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							104 lines
						
					
					
						
							2.8 KiB
						
					
					
				
			
		
		
	
	
							104 lines
						
					
					
						
							2.8 KiB
						
					
					
				| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| 
 | |
| /// <summary>
 | |
| /// 路段车辆流量检测器
 | |
| /// </summary>
 | |
| 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);
 | |
|         
 | |
| 
 | |
|         }
 | |
|     }
 | |
| 
 | |
| }
 |