38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
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;
|
||
}
|
||
}
|