using System.Collections.Generic; using UMA; using UMA.CharacterSystem; using UnityEngine; public class UMAUVAttachedItemPreprocessor : MonoBehaviour { DynamicCharacterAvatar avatar; public List launchers = new List(); /// /// Awake is called when the script instance is being loaded. This is before Start() /// This is done so that the preprocessor can add the event listeners before the avatar is built. /// void Awake() { avatar = GetComponent(); avatar.BuildCharacterBegun.AddListener(OnBuildCharacterBegun); avatar.WardrobeSuppressed.AddListener(OnWardrobeSuppressed); avatar.SlotsHidden.AddListener(OnSlotsHidden); } /// /// This is called when the character is being built in BuildCharacter() /// /// private void OnBuildCharacterBegun(UMAData umaData) { launchers = new List(); } /// /// This is called when the character has loaded all the slots/overlays in LoadCharacter() /// /// private void OnSlotsHidden(List hiddenSlots) { for (int i1 = 0; i1 < hiddenSlots.Count; i1++) { SlotData slot = hiddenSlots[i1]; if (slot.asset.SlotProcessed == null) { continue; } if (slot.asset.SlotProcessed.GetPersistentEventCount() == 0) { continue; } for(int i = 0; i < slot.asset.SlotProcessed.GetPersistentEventCount(); i++) { var target = slot.asset.SlotProcessed.GetPersistentTarget(i); if (target is UMAUVAttachedItemLauncher) { launchers.Add(target as UMAUVAttachedItemLauncher); } } } } /// /// This is called when the character has loaded all the slots/overlays in LoadCharacter() /// /// private void OnWardrobeSuppressed(List suppressedRecipes) { for (int i1 = 0; i1 < suppressedRecipes.Count; i1++) { UMATextRecipe recipe = suppressedRecipes[i1]; var items = UMAAssetIndexer.Instance.GetAssetItems(recipe); for (int i2 = 0; i2 < items.Count; i2++) { AssetItem ai = items[i2]; if (ai._Type == typeof(SlotDataAsset)) { var slot = ai.Item as SlotDataAsset; if (slot.SlotProcessed != null) { if (slot.SlotProcessed.GetPersistentEventCount() == 0) { continue; } for (int i = 0; i < slot.SlotProcessed.GetPersistentEventCount(); i++) { var target = slot.SlotProcessed.GetPersistentTarget(i); if (target is UMAUVAttachedItemLauncher) { launchers.Add(target as UMAUVAttachedItemLauncher); } } } launchers.Add(ai.Item as UMAUVAttachedItemLauncher); } } } } }