BITFALL/Assets/Artists/Scripts/HotFix/PlayerSocketService.cs

42 lines
971 B
C#
Raw Normal View History

2024-03-29 00:58:24 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BITFALL.Cosmetic;
using BITKit;
using BITKit.Entities;
using UnityEngine;
namespace BITFALL.HotFix
{
public class PlayerSocketService : EntityBehavior
{
[Inject(true)] private ICosmeticService _cosmeticService;
public override void OnAwake()
{
base.OnAwake();
_cosmeticService.OnCosmeticsChanged += OnCosmeticsChanged;
OnCosmeticsChanged();
}
public override void OnDestroyComponent()
{
base.OnDestroyComponent();
_cosmeticService.OnCosmeticsChanged -= OnCosmeticsChanged;
}
private void OnCosmeticsChanged()
{
var tags = GetComponentsInChildren<Tag>(true);
foreach (var socketComponent in GetComponentsInChildren<PlayerSocketComponent>())
{
var target = tags.FirstOrDefault(x => x.GetTags().Contains(socketComponent.Reference));
if (target is not null)
{
socketComponent.SetParent(target.transform);
}
}
}
}
}