chip-game/Assets/Scripts/Settings/Views/ViewPrefabsProvider.cs
2026-01-12 09:36:17 +03:00

38 lines
1.0 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.Collections;
using System.Collections.Generic;
using UnityEngine;
//НАДО НА СВЕЖУЮ ГОЛОВУ ЭТО ПОСМОТРЕТЬ ЭОТ ОТ ДИПСИКА
public class ViewPrefabsProvider : MonoBehaviour
{
[SerializeField] private List<PrefabMapping> mappings = new List<PrefabMapping>();
private Dictionary<string, GameObject> prefabDictionary;
public void Initialize()
{
prefabDictionary = new Dictionary<string, GameObject>();
foreach (var mapping in mappings)
{
if (mapping.prefab != null) prefabDictionary[mapping.id] = mapping.prefab;
}
}
public GameObject GetViewPrefab(string id)
{
if (prefabDictionary.TryGetValue(id, out GameObject prefab))
{
return prefab;
}
Debug.LogError($"Prefab with ID {id} not found!");
return null;
}
[System.Serializable]
public class PrefabMapping
{
public string id;
public GameObject prefab;
}
}