Files
bansonic_beta_main/Assets/__so/levelConfig/RankConfig.cs
T

50 lines
1.5 KiB
C#

using UnityEngine;
using System.Collections.Generic;
[System.Serializable]
public class RankThreshold
{
public string rankName;
public float thresholdPercent;
public Sprite rankSprite;
}
[CreateAssetMenu(fileName = "RankConfig", menuName = "Config/RankConfig")]
public class RankConfig : ScriptableObject
{
public float baseScore = 2000000f;
public Sprite defaultSprite; // Equivalent to ufSprite
[Tooltip("Thresholds should be ordered from highest to lowest percent.")]
public List<RankThreshold> thresholds = new List<RankThreshold>();
public Sprite GetRankSprite(float score)
{
if (score <= 0) return defaultSprite;
Sprite bestSprite = defaultSprite;
float highestMatchingPercent = -1f;
// Ensure we handle baseScore correctly to avoid division by zero if we were to use percentages
// But multiplying is safer as long as baseScore is set.
foreach (var threshold in thresholds)
{
if (threshold == null || threshold.rankSprite == null) continue;
float requiredScore = baseScore * threshold.thresholdPercent;
if (score >= requiredScore)
{
// We want the threshold with the HIGHEST percentage that the score satisfies
if (threshold.thresholdPercent > highestMatchingPercent)
{
highestMatchingPercent = threshold.thresholdPercent;
bestSprite = threshold.rankSprite;
}
}
}
return bestSprite;
}
}