using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace WildAttack
{
///
/// 根据权重随机
///
public class WeightRandomUtils : Singleton
{
public int GetRandomId(List weightList)
{
int rdm = Random.Range(0, GetTotalWeight(weightList) + 1);
int limit = 0;
for (int i = 0; i < weightList.Count; i++)
{
limit += weightList[i];
if (rdm <= limit)
{
return i + 1;
}
}
return -1;
}
private int GetTotalWeight(List weightList)
{
int total = 0;
foreach (var item in weightList)
{
total += item;
}
return total;
}
}
}