50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace SHINT.UI
|
|
{
|
|
public class UI_UserIcon : MonoBehaviour
|
|
{
|
|
Image background;
|
|
Image[] images;
|
|
TextMeshProUGUI id;
|
|
void Awake()
|
|
{
|
|
background = GetComponent<Image>();
|
|
images = GetComponentsInChildren<Image>();
|
|
id = GetComponentInChildren<TextMeshProUGUI>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
var bg = GetRandomColor();
|
|
var ic = GetComplementaryColor(bg);
|
|
for(int i =0;i<images.Length;++i)
|
|
{
|
|
images[i].color = ic;
|
|
}
|
|
background.color = bg;
|
|
}
|
|
|
|
public void SetId(string id)
|
|
{
|
|
this.id.SetText(id);
|
|
}
|
|
|
|
Color GetRandomColor()
|
|
{
|
|
Color color = new Color(Random.Range(0, 1f), Random.Range(0, 1f), Random.Range(0, 1f));
|
|
return color;
|
|
}
|
|
|
|
Color GetComplementaryColor(Color source)
|
|
{
|
|
Color color = new Color(Mathf.Abs(source.r - 1f), Mathf.Abs(source.g - 1f), Mathf.Abs(source.b - 1f));
|
|
return color;
|
|
}
|
|
}
|
|
}
|