101 lines
2.6 KiB
C#
101 lines
2.6 KiB
C#
using UnityEngine;
|
|
|
|
public class idolRadarController : MonoBehaviour
|
|
{
|
|
[Header("Radar")]
|
|
public URadarChartController radarChartController;
|
|
public bool rebuildOnEnable = true;
|
|
[Range(0f, 100f)] public float referenceValue = 60f;
|
|
[Range(0f, 100f)] public float emptyValue = 0f;
|
|
|
|
private AllyHero_SO pendingHero;
|
|
private bool rebuildQueued;
|
|
|
|
private void Awake()
|
|
{
|
|
EnsureController();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (rebuildOnEnable)
|
|
{
|
|
rebuildQueued = true;
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (!rebuildQueued)
|
|
{
|
|
return;
|
|
}
|
|
|
|
TryApplyPendingHero();
|
|
}
|
|
|
|
public void ApplyHero(AllyHero_SO hero)
|
|
{
|
|
pendingHero = hero;
|
|
rebuildQueued = true;
|
|
TryApplyPendingHero();
|
|
}
|
|
|
|
private void TryApplyPendingHero()
|
|
{
|
|
EnsureController();
|
|
if (radarChartController == null || radarChartController.chartBridge == null || radarChartController.chartBridge.Profile == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ApplyHeroInternal(pendingHero);
|
|
rebuildQueued = false;
|
|
}
|
|
|
|
private void EnsureController()
|
|
{
|
|
if (radarChartController == null)
|
|
{
|
|
radarChartController = GetComponent<URadarChartController>();
|
|
}
|
|
|
|
if (radarChartController == null)
|
|
{
|
|
radarChartController = GetComponentInChildren<URadarChartController>(true);
|
|
}
|
|
}
|
|
|
|
private void ApplyHeroInternal(AllyHero_SO hero)
|
|
{
|
|
if (radarChartController == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
radarChartController.axisCount = AllyHero_SO.BehaviourAxisNames.Length;
|
|
radarChartController.showReferenceSeries = false;
|
|
radarChartController.NormalizeAxesForExternalUse();
|
|
|
|
for (int i = 0; i < AllyHero_SO.BehaviourAxisNames.Length; i++)
|
|
{
|
|
string axisName = AllyHero_SO.BehaviourAxisNames[i];
|
|
float axisValue = emptyValue;
|
|
|
|
if (hero != null)
|
|
{
|
|
hero.EnsureBehaviourAxes();
|
|
if (hero.behaviourAxes != null && i < hero.behaviourAxes.Count && hero.behaviourAxes[i] != null)
|
|
{
|
|
axisName = string.IsNullOrWhiteSpace(hero.behaviourAxes[i].axisName) ? axisName : hero.behaviourAxes[i].axisName.Trim();
|
|
axisValue = Mathf.Clamp(hero.behaviourAxes[i].value, 0f, 100f);
|
|
}
|
|
}
|
|
|
|
radarChartController.SetAxisData(i, axisName, axisValue, referenceValue);
|
|
}
|
|
|
|
radarChartController.RebuildNow();
|
|
}
|
|
}
|