LaboratoryProtection/Assets/UnityTest/Common/Scripts/Set/RuntimeObjectSetInitializer.cs

45 lines
993 B
C#

using PMaker.DependencyInjection;
using PMaker.Extension;
using PMaker.Set;
using Sirenix.OdinInspector;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class RuntimeObjectSetInitializer : BaseBehaviour
{
public List<GameObject> objects = new List<GameObject>();
[ReadOnly]
[SerializeField]
private Dictionary<string, GameObject> _mapper;
private void Awake()
{
this._mapper = new Dictionary<string, GameObject>();
foreach (var obj in objects)
{
this._mapper.Add(obj.name, obj);
}
}
private void OnEnable()
{
IoC.GetSingleton<ObjectSet>()?.subObjectSetMapper.Add(_mapper);
}
private void OnDisable()
{
IoC.GetSingleton<ObjectSet>()?.subObjectSetMapper.Remove(this._mapper);
}
[Button]
public void GetChildren()
{
var gos = this.transform.Children().Select(_=>_.gameObject);
this.objects = gos.ToList();
}
}