1.随机时间刷新车辆
2.车辆AI完善
3.滚动监视视窗
master
GamerHJD 3 years ago
parent ceecebd962
commit c1e9ea71ac

@ -31,7 +31,7 @@ AnimationClip:
outWeight: 0.33333334
- serializedVersion: 3
time: 0.6666667
value: -47
value: -560
inSlope: 0
outSlope: 0
tangentMode: 136
@ -201,7 +201,7 @@ AnimationClip:
outWeight: 0.33333334
- serializedVersion: 3
time: 0.6666667
value: -47
value: -560
inSlope: 0
outSlope: 0
tangentMode: 136

@ -6,7 +6,7 @@ RenderTexture:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: New Render Texture
m_Name: Camera01
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000

@ -0,0 +1,37 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!84 &8400000
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Camera02
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 256
m_Height: 256
m_AntiAliasing: 1
m_MipCount: -1
m_DepthFormat: 2
m_ColorFormat: 8
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1

File diff suppressed because it is too large Load Diff

@ -14,8 +14,8 @@ public static class Const
public static float CarTurnSpeed = 5f;
//刷车最小/最大时间
public static int RefreshCarminTime = 3;
public static int RefreshCarmaxTime = 11;
public static int RefreshCarminTime = 1;
public static int RefreshCarmaxTime = 10;

@ -15,6 +15,8 @@ public class GameRoot : MonoBehaviour
//信息窗口
public InfoWnd infoWnd;
//菜单按钮窗口
public MenuWnd menuWnd;
private void Awake()
{
@ -26,17 +28,24 @@ public class GameRoot : MonoBehaviour
//车辆流量监控初始化
roadSys = GetComponent<RoadSys>();
roadSys.Init();
//UI窗口初始化
menuWnd.Init();
//定时任务服务
pt = new PETimer();
}
private void Start()
{
StartCoroutine(carSys.RandomTimeCreat());
}
private void Update()
{
pt.Update();
carSys.CreatCar();//每n秒随机出发点创建汽车
roadSys.RoadStateUpdate(3);//每n秒检测路段状态

@ -21,7 +21,8 @@ public class CarSys : MonoBehaviour
public Dictionary<int, GameObject> carList = new Dictionary<int, GameObject>();
//
public int CarID = 0;
private bool canCreat = true;
public bool canCreat = false;
//移动点列表
private Dictionary<string, Transform> MoveList = new Dictionary<string, Transform>();
@ -37,6 +38,7 @@ public class CarSys : MonoBehaviour
}
#region CarAI
//检索移动点
public void CheckBornoint()
{
@ -143,21 +145,51 @@ public class CarSys : MonoBehaviour
}
public IEnumerator RandomTimeCreatCar(float time,Transform parent)
//检测前方车辆
public bool CheckFrontCar(Drive drive)
{
if (drive.FrontCar == null) return false;
if (timer < time) {
canCreat = false;
}
else
if (Vector3.Distance(drive.transform.position, drive.FrontCar.transform.position) < Const.SafeDistance)
{
canCreat = true;
timer = 0;
return true;
}
if (canCreat == false) yield break;
return false;
#region MyRegion
//for (int i = 0; i < carList.Count; i++)
//{
// Vector3 target = carList[i].transform.position;
// Vector3 dir = target - drive.transform.position;
// drive.dot = Vector3.Dot(drive.transform.forward.normalized,dir.normalized);
// //判断是否前方有小于安全距离的车辆
// if (Vector3.Dot(drive.transform.forward.normalized, dir.normalized) > Mathf.Cos(Mathf.PI/6) && Vector3.Distance(target, drive.transform.position) <= Const.SafeDistance)
// {
// Debug.Log(drive.gameObject.name);
// return true;
// }
// else
// {
// continue;
// }
//}
//return false;
#endregion
}
#endregion
//Debug.Log(time);
yield return new WaitForSeconds(time);
#region 汽车随机生成
public void CreatCar(Transform parent)
{
// 随机创建车辆种类
int carIndex = Random.Range(0, carTypeList.Length - 1);
//实例化车辆
@ -183,69 +215,41 @@ public class CarSys : MonoBehaviour
{
StartCoroutine(CarMove(parent.name, agent));
}
}
int temp = 0;
//汽车生成函数
public void CreatCar()
public IEnumerator RandomTimeCreat()
{
//计时
timer += Time.deltaTime;
//随机获取出生点
Transform parent = null;
int pointIndex = Random.Range(1, BornList.Count);
BornList.TryGetValue("0" + pointIndex.ToString(), out parent);
//创建车辆
if (parent != null)
{
//随机时间
int t = Random.Range(Const.RefreshCarminTime, Const.RefreshCarmaxTime);
if (t == temp) return;
temp = t;
StartCoroutine(RandomTimeCreatCar(t,parent));
}
}
//检测前方车辆
public bool CheckFrontCar(Drive drive)
Debug.Log(t);
while (true)
{
if (drive.FrontCar==null) return false;
yield return new WaitForEndOfFrame();
timer += Time.deltaTime;
if (Vector3.Distance(drive.transform.position, drive.FrontCar.transform.position) < Const.SafeDistance)
if (timer >= t)
{
return true;
timer = 0;
break;
}
return false;
#region MyRegion
//for (int i = 0; i < carList.Count; i++)
//{
// Vector3 target = carList[i].transform.position;
// Vector3 dir = target - drive.transform.position;
// drive.dot = Vector3.Dot(drive.transform.forward.normalized,dir.normalized);
// //判断是否前方有小于安全距离的车辆
// if (Vector3.Dot(drive.transform.forward.normalized, dir.normalized) > Mathf.Cos(Mathf.PI/6) && Vector3.Distance(target, drive.transform.position) <= Const.SafeDistance)
// {
// Debug.Log(drive.gameObject.name);
// return true;
// }
// else
// {
// continue;
}
// }
CreatCar(parent);
}
//}
//return false;
#endregion
StartCoroutine(RandomTimeCreat());
}
#endregion
}

@ -11,10 +11,7 @@ public class MenuWnd : MonoBehaviour
public GameObject threeDcamera;
public GameObject twoDcamera;
// Start is called before the first frame update
void Start()
{
Init();
}
public void Init()

Loading…
Cancel
Save