You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
54
Assets/Scripts/System/RandomPool/RandomNode.cs
Normal file
54
Assets/Scripts/System/RandomPool/RandomNode.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用随机单元
|
||||
/// </summary>
|
||||
public class RandomNode<T> where T : class
|
||||
{
|
||||
public int key; // 承载key
|
||||
public T value; // 承载内容
|
||||
public int count; // 最大数量
|
||||
public int weight; // 随机权重
|
||||
public int minRange; //至少抽取次数阈值
|
||||
public int maxRange; //至多抽取次数阈值
|
||||
|
||||
public int curWeight; //当前的权重值,用于权重随机中的值比较。
|
||||
|
||||
public RandomNode(int key, T value, int count, int weight, int minRange, int maxRange)
|
||||
{
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.count = count;
|
||||
this.weight = weight;
|
||||
this.minRange = minRange;
|
||||
this.maxRange = maxRange;
|
||||
}
|
||||
|
||||
public RandomNode(int key, T value, int count, int weight, string range)
|
||||
{
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.count = count;
|
||||
this.weight = weight;
|
||||
if (range.Equals("-1", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
this.minRange = -1;
|
||||
this.maxRange = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var rs = range.Split(',');
|
||||
this.minRange = int.Parse(rs[0]);
|
||||
this.maxRange = int.Parse(rs.Length == 2 ? rs[1] : rs[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValid(int nowCount)
|
||||
{
|
||||
return this.count == -1 || nowCount < this.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user