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

54 lines
1.6 KiB
C#
Raw 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;
/// <summary>
/// Поставляет описания настроек по ID настройки
/// </summary>
public class SettingDescriptionProvider : MonoBehaviour
{
public List<SettingDescription> settingDescriptions;
public GameObject defaultDescription;
public GameObject GetDescription(string id)
{
//Проверки заполнения
if (settingDescriptions == null)
{
Debug.LogError("Не заданы описания настроек"); return null;
}
if (defaultDescription == null)
{
Debug.LogError("Не задано описание настройки по умолчанию"); return null;
}
//поиск по id
GameObject foundDescription = null;
for (int i = 0; i < settingDescriptions.Count; i++)
{
if (settingDescriptions[i].id == id)
{
foundDescription = settingDescriptions[i].descriptionPrefab;
break;
}
}
//возврат
if(foundDescription == null)
{
Debug.LogError($"Описание настройки с id: {id} не найдено. Возврат дефолтного значения");
return defaultDescription;
}
return foundDescription;
}
[Serializable]
public class SettingDescription
{
public string id;
public GameObject descriptionPrefab;
}
}