mirror of
https://github.com/nothke/quality-control.git
synced 2024-11-12 22:03:42 +00:00
36 lines
824 B
C#
36 lines
824 B
C#
|
using System;
|
|||
|
using UnityEngine;
|
|||
|
using Random = UnityEngine.Random;
|
|||
|
|
|||
|
[CreateAssetMenu(fileName = "New Product Description", menuName = "Data/Product Description", order = 0)]
|
|||
|
public class ProductDescription : ScriptableObject
|
|||
|
{
|
|||
|
[Serializable]
|
|||
|
public struct Product
|
|||
|
{
|
|||
|
public GameObject Prefab;
|
|||
|
[Range(0,100)]
|
|||
|
public int Probability;
|
|||
|
}
|
|||
|
|
|||
|
public Product[] Products;
|
|||
|
|
|||
|
public GameObject GetRandomProduct()
|
|||
|
{
|
|||
|
float randomValue = Random.value;
|
|||
|
float sum = 0;
|
|||
|
|
|||
|
for (var i = 0; i < Products.Length; i++)
|
|||
|
{
|
|||
|
var product = Products[i];
|
|||
|
|
|||
|
sum += product.Probability / 100f;
|
|||
|
if (randomValue <= sum)
|
|||
|
{
|
|||
|
return product.Prefab;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|