private void Awake() { Instance = this; logbookBodyOptions = MapBodiesToOptions( SurvivorCatalog.orderedSurvivorDefs.Select(survivorDef => BodyCatalog.GetBodyPrefabBodyComponent(SurvivorCatalog.GetBodyIndexFromSurvivorIndex(survivorDef.survivorIndex))) .Union(BodyCatalog.allBodyPrefabBodyBodyComponents.Where(characterBody => characterBody && characterBody.GetComponent <DeathRewards>()?.logUnlockableDef))); allBodyOptions = MapBodiesToOptions(BodyCatalog.allBodyPrefabBodyBodyComponents); dropdown.Options = logbookBodyOptions; (dropdown.OnItemSelected ?? (dropdown.OnItemSelected = new SearchableDropdown.DropdownEvent())).AddListener(SelectModel); List <SearchableDropdown.OptionData> MapBodiesToOptions(IEnumerable <CharacterBody> bodies) { return(bodies .Select(characterBody => (characterBody, characterModel: characterBody.GetComponentInChildren <CharacterModel>())) .Where(el => el.characterModel) .Select(el => { var modelInfo = new ModelPrefabInfo { modelPrefab = el.characterModel.gameObject, bodyName = el.characterBody.name, modelName = el.characterModel.name, localizedBodyName = Language.GetString(el.characterBody.baseNameToken), characterBody = el.characterBody }; return new SearchableDropdown.OptionData(modelInfo, $"{modelInfo.localizedBodyName} || {modelInfo.bodyName} || {modelInfo.modelName}"); }) .ToList()); } }
public void SelectModel(object modelInfo) { if (modelInfo as ModelPrefabInfo == this.modelInfo) { return; } DestroyModelInstance(); this.modelInfo = modelInfo as ModelPrefabInfo; BuildModelInstance(); ConfigureSkinVariants(); OnModelChanged?.Invoke(CharacterModel); }