道路路况分析功能细化

master
GamerHJD 3 years ago
parent fbcd4bc8f4
commit 7ac5f260bd

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 37 KiB

File diff suppressed because it is too large Load Diff

@ -17,7 +17,7 @@ public static class Const
public static float RefreshCarminTime = 0.25f;
public static float RefreshCarmaxTime = 0.5f;
public static int RoadCheckNumber = 5;
public static int RoadCheckNumber = 7;
/// <summary>
/// 索引法随机

@ -41,6 +41,8 @@ public class GameRoot : MonoBehaviour
private void Start()
{
StartCoroutine(carSys.RandomTimeCreat());
}
private void Update()

@ -7,14 +7,86 @@ using UnityEngine;
/// </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);
// Debug.Log(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);
}
}
}
@ -23,7 +95,8 @@ public class RoadChecker : MonoBehaviour
if (other.gameObject.tag == "Car")
{
GameRoot.Instance.roadSys.SetCheckerValue(this.gameObject.name, -1);
// Debug.Log(this.gameObject.name + "-1");
}
}

@ -14,8 +14,9 @@ public class InfoWnd : MonoBehaviour
public Button roadInfoCloseBtn;
//路况检测窗口
public GameObject RoadInfoWnd;
public GameObject roadInfoWnd;
public GameObject colorTitle;
public Transform roadInfoGroup;
public string date;
@ -24,7 +25,7 @@ public class InfoWnd : MonoBehaviour
public void Init()
{
if (RoadInfoWnd.activeSelf)
if (roadInfoWnd.activeSelf)
{
SetRoadInfoActive(false);
}
@ -36,23 +37,44 @@ public class InfoWnd : MonoBehaviour
//初始化路况字典
private void InitRoadDict()
{
GameObject roadGroup= GameObject.FindGameObjectWithTag("RoadInfoGroup");
for (int i = 0; i < roadGroup.transform.childCount; i++)
for (int i = 0; i < roadInfoGroup.childCount; i++)
{
RoadInfo info = new RoadInfo();
info.roadName = roadGroup.transform.GetChild(i).name;
info.flowRate = 80;
info.carFlow = UnityEngine.Random.Range(15, 35);
Text txt = roadInfoGroup.transform.GetChild(i).GetComponent<Text>();
info.roadName = roadInfoGroup.transform.GetChild(i).name;
info.flowRate = 100;
info.carFlow = 0;
info.Iswarning = false;
txt.text = string.Format(" ▶ "+"{0:G}"+" "+"{1:G}"+" "+ "{2:00.00}"+ "%"+" "+ "{3:G}", info.roadName,info.carFlow,info.flowRate,info.Iswarning?"是":"否");
Road_Dict.Add(info.roadName, info);
}
}
//TODo
public void UpdateRoadDict()
//更新路况信息方法
public void UpdateRoadDict(string roadName)
{
RoadInfo info = null;
if(Road_Dict.TryGetValue(roadName,out info))
{
Text txt= roadInfoGroup.Find(roadName).GetComponent<Text>();
txt.text = string.Format(" ▶ " + "{0:G}" + " " + "{1:G}" + " " + "{2:00.00}" + "%" + " " + "{3:G}", info.roadName, info.carFlow, info.flowRate, info.Iswarning ? "是" : "否");
}
}
//TODo
public RoadInfo GetRoadInfo(string roadName)
{
RoadInfo info = new RoadInfo();
if(Road_Dict.TryGetValue(roadName, out info))
{
return info;
}
return null;
}
public void SetCarInText(int Addvalue)
@ -102,6 +124,8 @@ public class InfoWnd : MonoBehaviour
public void SetRoadInfoActive(bool t)
{
RoadInfoWnd.SetActive(t);
roadInfoWnd.SetActive(t);
}
}

@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tsds1 : MonoBehaviour
{
public Transform cleft;
public Transform cright;
public Transform checker;
// Start is called before the first frame update
void Start()
{
Vector3 rightDir = cright.transform.forward.normalized;
Vector3 leftDir = cleft.transform.forward.normalized;
Debug.Log(Vector3.Dot(rightDir, checker.forward.normalized));
Debug.Log(Vector3.Dot(leftDir, checker.forward.normalized));
}
// Update is called once per frame
void Update()
{
}
}

Binary file not shown.
Loading…
Cancel
Save