BITFALL/Assets/Artists/Scripts/Player/Socket/PlayerSocketService.cs

48 lines
1.4 KiB
C#
Raw Normal View History

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