This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SH-INT/Assets/Scripts/UI_UserIcon.cs
정영민 f4cf556cde update
2025-02-20 10:30:18 +09:00

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;
}
}
}