62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Continentis.MainGame.Character;
|
|
using DG.Tweening;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI.Extensions;
|
|
|
|
namespace Continentis.MainGame.UI
|
|
{
|
|
public class AttributeRadarMap : MonoBehaviour
|
|
{
|
|
public UIPolygon polygon;
|
|
public List<TMP_Text> attributeTexts;
|
|
|
|
public void Initialize(CharacterBase character)
|
|
{
|
|
List<int> attributeValues = new List<int>
|
|
{
|
|
character.GetAttribute("Strength"),
|
|
character.GetAttribute("Agility"),
|
|
character.GetAttribute("Physique"),
|
|
character.GetAttribute("Intelligence"),
|
|
character.GetAttribute("Perception"),
|
|
character.GetAttribute("Charisma"),
|
|
};
|
|
int maxValue = attributeValues.Max();
|
|
int finalMax = maxValue > 24 ? maxValue : 24;
|
|
float[] distances = attributeValues.Select(v => (float)v / finalMax).ToArray();
|
|
|
|
Sequence graphExpand = DOTween.Sequence();
|
|
for (int index = 0; index < distances.Length; index++)
|
|
{
|
|
polygon.VerticesDistances[index] = 0;
|
|
attributeTexts[index].text = attributeValues[index].ToString();
|
|
JoinGraphSideExpand(index);
|
|
}
|
|
|
|
graphExpand.OnUpdate(() =>
|
|
{
|
|
polygon.SetAllDirty();
|
|
Vector2[] verticesPositions = polygon.GetVerticesPositions();
|
|
for (int index = 0; index < distances.Length; index++)
|
|
{
|
|
Vector2 offset = verticesPositions[index] * 0.15f;
|
|
attributeTexts[index].rectTransform.anchoredPosition = verticesPositions[index] + offset;
|
|
}
|
|
});
|
|
graphExpand.Play();
|
|
|
|
return;
|
|
|
|
void JoinGraphSideExpand(int index)
|
|
{
|
|
graphExpand.Join(DOTween.To(
|
|
() => polygon.VerticesDistances[index],
|
|
x => polygon.VerticesDistances[index] = x,
|
|
distances[index], 0.5f).SetEase(Ease.OutQuad));
|
|
}
|
|
}
|
|
}
|
|
} |