Files
7d2dXG/Mods/0A-KFCommonUtilityLib/KFAttached/Misc/AttachmentReferenceAppended.cs
Nathaniel Cosford e06f2bd282 Add All Mods
2025-05-29 23:33:28 +09:30

45 lines
1.3 KiB
C#

using UnityEngine;
public class AttachmentReferenceAppended : AttachmentReference
{
private Transform[] bindings;
public void Merge(AnimationTargetsAbs targets)
{
if (attachmentReference && targets)
{
foreach (var bindings in attachmentReference.GetComponentsInChildren<TransformActivationBinding>(true))
{
bindings.targets = targets;
}
bindings = new Transform[attachmentReference.childCount];
for (int i = 0; i < attachmentReference.childCount; i++)
{
bindings[i] = attachmentReference.GetChild(i);
bindings[i].SetParent(targets.AttachmentRef, false);
}
Destroy(attachmentReference.gameObject);
attachmentReference = null;
}
}
public void Remove()
{
if (bindings != null)
{
foreach (var binding in bindings)
{
if (binding)
{
binding.SetParent(null, false);
Destroy(binding.gameObject);
}
}
bindings = null;
}
if (attachmentReference)
{
Destroy(attachmentReference.gameObject);
attachmentReference = null;
}
}
}