using System.Collections; using System.Collections.Generic; using System.Linq; using AYellowpaper.SerializedCollections; using BITFALL.Cosmetic; using BITKit; using BITKit.Entities; using UnityEngine; namespace BITFALL.HotFix { [CustomType(typeof(PlayerSocketService))] public class PlayerSocketService : EntityBehavior { [Inject(true)] private ICosmeticService _cosmeticService; [SerializeField] private SerializedDictionary dictionary=new(); public IDictionary Dictionary => dictionary; public override void OnAwake() { base.OnAwake(); _cosmeticService.OnCosmeticsChange += dictionary.Clear; _cosmeticService.OnCosmeticsChanged += OnCosmeticsChanged; OnCosmeticsChanged(); } public override void OnDestroyComponent() { base.OnDestroyComponent(); _cosmeticService.OnCosmeticsChange -= dictionary.Clear; _cosmeticService.OnCosmeticsChanged -= OnCosmeticsChanged; } private void OnCosmeticsChanged() { Dictionary.Clear(); var tags = GetComponentsInChildren(true); foreach (var socketComponent in GetComponentsInChildren(true)) { var target = tags.FirstOrDefault(x => x.GetTags().Contains(socketComponent.Reference)); if (target is null) continue; socketComponent.SetParent(target.transform); dictionary.AddConflictAllowed(socketComponent.Reference, target.transform); } } } }