public static void CreateNewEggs() { foreach (var setting in CustomizeCritterState.StateManager.State.egg_settings) { if (setting?.eggId == null) { continue; //eggId isn't allowed to be null } if (Assets.Prefabs.Find(a => a.gameObject?.name == setting.eggId) == null) { if (CustomizeCritterState.StateManager.State.debug) { Debug.Log("[CustomizeCritter] Adding new egg type: " + setting.eggId); } // configurations string eggId = setting.eggId; string eggName = setting.eggName ?? "No Name"; string eggDesc = setting.eggDesc ?? "No Description"; string egg_anim = setting.anim_egg ?? "egg_hatch_kanim"; string baby_id = setting.babyId ?? "HatchHardBaby"; float egg_mass = setting.egg_mass ?? 2f; int eggSortOrder = setting.egg_sortorder ?? 0; float base_incubation_rate = 100f / (600f * setting.incubation_cycles ?? 20f); float egg_anim_scale = setting.egg_scale ?? 1f; bool is_fish = setting.is_fish ?? false; string symbolPrefix = setting.override_prefix; // end of configurations GameObject egg = EggConfig.CreateEgg(eggId, eggName, eggDesc, baby_id, egg_anim, egg_mass, eggSortOrder, base_incubation_rate); if (egg_anim_scale != 1f) { KBatchedAnimController component = egg.GetComponent <KBatchedAnimController>(); component.animWidth = egg_anim_scale; component.animHeight = egg_anim_scale; } if (is_fish) { egg.AddOrGetDef <FishOvercrowdingMonitor.Def>(); } if (!string.IsNullOrEmpty(symbolPrefix)) { SymbolOverrideControllerUtil.AddToPrefab(egg).ApplySymbolOverridesByAffix(Assets.GetAnim(egg_anim), symbolPrefix, null, 0); } } } }
public static GameObject ExtendEntityToFertileCreature(GameObject prefab, string eggId, string eggName, string eggDesc, string egg_anim, float egg_mass, string baby_id, float fertility_cycles, float incubation_cycles, List <FertilityMonitor.BreedingChance> egg_chances, int eggSortOrder = -1, bool is_ranchable = true, bool add_fish_overcrowding_monitor = false, bool add_fixed_capturable_monitor = true, float egg_anim_scale = 1f) { FertilityMonitor.Def def = prefab.AddOrGetDef <FertilityMonitor.Def>(); def.baseFertileCycles = fertility_cycles; DebugUtil.DevAssert(eggSortOrder > -1, "Added a fertile creature without an egg sort order!"); float base_incubation_rate = 100f / (600f * incubation_cycles); GameObject gameObject = EggConfig.CreateEgg(eggId, eggName, eggDesc, baby_id, egg_anim, egg_mass, eggSortOrder, base_incubation_rate); def.eggPrefab = new Tag(eggId); def.initialBreedingWeights = egg_chances; if (egg_anim_scale != 1f) { KBatchedAnimController component = gameObject.GetComponent <KBatchedAnimController>(); component.animWidth = egg_anim_scale; component.animHeight = egg_anim_scale; } KPrefabID egg_prefab_id = gameObject.GetComponent <KPrefabID>(); SymbolOverrideController symbol_override_controller = SymbolOverrideControllerUtil.AddToPrefab(gameObject); string symbolPrefix = prefab.GetComponent <CreatureBrain>().symbolPrefix; if (!string.IsNullOrEmpty(symbolPrefix)) { symbol_override_controller.ApplySymbolOverridesByAffix(Assets.GetAnim(egg_anim), symbolPrefix, null, 0); } KPrefabID creature_prefab_id = prefab.GetComponent <KPrefabID>(); creature_prefab_id.prefabSpawnFn += delegate { WorldInventory.Instance.Discover(eggId.ToTag(), WorldInventory.GetCategoryForTags(egg_prefab_id.Tags)); WorldInventory.Instance.Discover(baby_id.ToTag(), WorldInventory.GetCategoryForTags(creature_prefab_id.Tags)); }; if (is_ranchable) { prefab.AddOrGetDef <RanchableMonitor.Def>(); } if (add_fixed_capturable_monitor) { prefab.AddOrGetDef <FixedCapturableMonitor.Def>(); } if (add_fish_overcrowding_monitor) { gameObject.AddOrGetDef <FishOvercrowdingMonitor.Def>(); } return(prefab); }
public GameObject CreatePrefab() { //GameObject prefab = null; string eggId = "UnknownEgg"; string eggName = "Unknown Egg"; string eggDesc = "Unknown Egg"; string egg_anim = "floral_hatch_egg_kanim"; float egg_mass = 1f; string baby_id = BabyHatchConfig.ID; float fertility_cycles = 20.0f; float incubation_cycles = 1f; List <FertilityMonitor.BreedingChance> egg_chances = null; int eggSortOrder = 999; bool is_ranchable = false; bool add_fish_overcrowding_monitor = false; bool add_fixed_capturable_monitor = true; float egg_anim_scale = 1f; //FertilityMonitor.Def def = prefab.AddOrGetDef<FertilityMonitor.Def>(); //def.baseFertileCycles = fertility_cycles; DebugUtil.DevAssert(eggSortOrder > -1, "Added a fertile creature without an egg sort order!"); float base_incubation_rate = (float)(100.0 / (600.0 * (double)incubation_cycles)); GameObject egg = EggConfig.CreateEgg(eggId, eggName, eggDesc, (Tag)baby_id, egg_anim, egg_mass, eggSortOrder, base_incubation_rate); //def.eggPrefab = new Tag(eggId); //def.initialBreedingWeights = egg_chances; if ((double)egg_anim_scale != 1.0) { KBatchedAnimController component = egg.GetComponent <KBatchedAnimController>(); component.animWidth = egg_anim_scale; component.animHeight = egg_anim_scale; } KPrefabID egg_prefab_id = egg.GetComponent <KPrefabID>(); return(egg); }