/
GeekNerd
/
ServerModelingProject
Обзор
Документация
Войти
/
GeekNerd
/
ServerModelingProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/SpawnerLogic/Factory.cs
168 строк
5 KB
Gorney-Alex
Init
30 май 2026, 19:05
30 май 2026, 19:05
3cdcc49
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using DataClasses; using Interfaces; using LoadServices; using UIEntities; using UnityEngine; using Zenject; namespace SpawnerLogic { public class CustomFactory : ICustomFactory { private readonly DiContainer _container; private readonly Dictionary<Type, BaseData> _data; public CustomFactory(DiContainer container, DotButtonData dotButtonData, LineData lineData, DoorData doorData, CracData cracData, ColumnData columnData) { _container = container; _data = new Dictionary<Type, BaseData>() { {typeof(DotButtonView), dotButtonData}, {typeof(LineView), lineData}, { typeof(DoorView), doorData }, { typeof(CracView), cracData }, { typeof(UICircleView), columnData }, }; } public IDoorView CreateDoor(Transform spawnPoint) { Type currentType = typeof(DoorView); string prefabPath = $"GUIEntities/{currentType.Name}"; GameObject prefab = PrefabLoader.LoadPrefab(prefabPath); if (!_data.TryGetValue(currentType, out BaseData baseData)) { Debug.LogError("Could not find DoorData"); return default; } var doorData = baseData as DoorData; if (doorData == null) { Debug.LogError("Data is not DoorData"); return default; } var instance = _container.InstantiatePrefabForComponent<DoorView>(prefab, spawnPoint); instance.Init(doorData); return instance; } public ICracView CreateCrac(Transform spawnPoint) { Type currentType = typeof(CracView); string prefabPath = $"GUIEntities/{currentType.Name}"; GameObject prefab = PrefabLoader.LoadPrefab(prefabPath); if (!_data.TryGetValue(currentType, out BaseData baseData)) { Debug.LogError("Could not find CracData"); return default; } var cracData = baseData as CracData; if (cracData == null) { Debug.LogError("Data is not CracData"); return default; } if (prefab == null) { Debug.LogError($"CRAC prefab missing at Resources/Prefabs/{prefabPath}.prefab"); return default; } var instance = _container.InstantiatePrefabForComponent<CracView>(prefab, spawnPoint); instance.Init(cracData); return instance; } public ILineView CreateLine(Transform spawnPoint) { Type currentType = typeof(LineView); string prefabPath = $"GUIEntities/{currentType.Name}"; GameObject prefab = PrefabLoader.LoadPrefab(prefabPath); if (!_data.TryGetValue(currentType, out BaseData baseData)) { Debug.LogError("Could not find LineData"); return default; } var lineData = baseData as LineData; if (lineData == null) { Debug.LogError("Data is not LineData"); return default; } var instance = _container.InstantiatePrefabForComponent<LineView>(prefab, spawnPoint); instance.Init(lineData); return instance; } public IDotButtonView CreateDotButton(Transform spawnPoint) { Type currentType = typeof(DotButtonView); string prefabPath = $"GUIEntities/{currentType.Name}"; GameObject prefab = PrefabLoader.LoadPrefab(prefabPath); if (!_data.TryGetValue(currentType, out BaseData baseData)) { Debug.LogError("Could not find Data"); return default; } var currentDotButtonData = baseData as DotButtonData; if (currentDotButtonData == null) { Debug.LogError("Data is not DotButtonData"); return default; } var currentInstance = _container.InstantiatePrefabForComponent<DotButtonView>(prefab, spawnPoint); currentInstance.Init(currentDotButtonData); return currentInstance; } public ICircleView CreateCircle(Transform spawnPoint) { Type currentType = typeof(UICircleView); string prefabPath = $"GUIEntities/{currentType.Name}"; GameObject prefab = PrefabLoader.LoadPrefab(prefabPath); if (!_data.TryGetValue(currentType, out BaseData baseData)) { Debug.LogError("Could not find ColumnData"); return default; } var columnData = baseData as ColumnData; if (columnData == null) { Debug.LogError("Data is not ColumnData"); return default; } var instance = _container.InstantiatePrefabForComponent<UICircleView>(prefab, spawnPoint); instance.Init(columnData); return instance; } } }