chip-gameV3/Assets/Scripts/Settings/HeaderIconsProvider.cs
2026-07-14 11:14:13 +03:00

51 lines
1.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeaderIconsProvider : MonoBehaviour
{
public List<HeaderIcon> Icons;
public GameObject defaultIcon;
public GameObject GetIcon(string header)
{
//Проверки заполнения
if (Icons == null)
{
Debug.LogError("Не заданы иконки"); return null;
}
if (defaultIcon == null)
{
Debug.LogError("Не задана иконка по умолчанию"); return null;
}
//поиск по id
GameObject foundIcon = null;
for (int i = 0; i < Icons.Count; i++)
{
if (Icons[i].Name == header)
{
foundIcon = Icons[i].IconPrefab;
break;
}
}
//возврат
if (foundIcon == null)
{
Debug.LogError($"Иконка с id: {header} не найдено. Возврат дефолтного значения");
return defaultIcon;
}
return foundIcon;
}
[Serializable]
public class HeaderIcon
{
public string Name;
public GameObject IconPrefab;
}
}