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.

53 lines
1.4 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Const
{
//行车安全距离
public static float SafeDistance = 12f;
//安全检测开始时间
public static float SafeCheckTime = 2f;
//车辆转弯速度
public static float CarTurnSpeed = 5f;
//刷车最小/最大时间
public static float RefreshCarminTime = 0.25f;
public static float RefreshCarmaxTime = 0.5f;
/// <summary>
/// 索引法随机
/// </summary>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <returns></returns>
public static int[] GetIndexRandomNum(int minValue, int maxValue)
{
System.Random random = new System.Random();
int sum = Mathf.Abs(maxValue - minValue);//计算数组范围
int site = sum;//设置索引范围
int[] index = new int[sum];
int[] result = new int[sum];
int temp = 0;
for (int i = minValue; i < maxValue; i++)
{
index[temp] = i;
temp++;
}
for (int i = 0; i < sum; i++)
{
int id = random.Next(0, site - 1);
result[i] = index[id];
index[id] = index[site - 1];//因id随机到的数已经获取到了用最后的一个数来替换它
site--;//缩小索引范围
}
return result;
}
}