/
GeekNerd
/
ServerModelingProject
Обзор
Документация
Войти
/
GeekNerd
/
ServerModelingProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/UIEntities/CracView.cs
65 строк
2 KB
Gorney-Alex
Init
30 май 2026, 19:05
30 май 2026, 19:05
3cdcc49
Код
Авторство
О чём код?
using DataClasses; using Interfaces; using UnityEngine; using UnityEngine.UI; namespace UIEntities { public class CracView : MonoBehaviour, ICracView { private RectTransform _rectTransform; private Image _image; public void Init(CracData data) { EnsureComponents(); if (!string.IsNullOrEmpty(data.Name)) { gameObject.name = data.Name; } _image.color = data.Color; _image.raycastTarget = false; } private void EnsureComponents() { _rectTransform = GetComponent<RectTransform>(); if (_rectTransform == null) { _rectTransform = gameObject.AddComponent<RectTransform>(); } _image = GetComponent<Image>(); if (_image == null) { _image = gameObject.AddComponent<Image>(); } } public void SetPosition(Vector2 uiPos) { EnsureComponents(); _rectTransform.anchoredPosition = uiPos; } public void SetRadius(float uiRadius) { EnsureComponents(); float diameter = Mathf.Max(0f, uiRadius) * 2f; _rectTransform.sizeDelta = new Vector2(diameter, diameter); } public void SetColor(Color color) { EnsureComponents(); _image.color = color; } public void SetActive(bool active) { gameObject.SetActive(active); } } }