/// <summary> /// Registers a new PickupObject. /// </summary> /// <returns>Prefab object for the newly registered item.</returns> /// <param name="id">ID (including the mod's namespace) for the new item.</param> /// <param name="enc_icon_id">Global ID of the encounter icon to use for this item.</param> /// <param name="sprite_template_id">Global ID of the sprite template to use for this item.</param> /// <param name="name_key">Global ID of the localization string to use for the full name of this item.</param> /// <param name="short_desc_key">Global ID of the localization string to use for the short description of this item.</param> /// <param name="long_desc_key">Global ID of the localization string to use for the long description of this item.</param> /// <typeparam name="T">Component type to initialize as the PickupObject.</typeparam> public T RegisterItem <T>(ID id, ID enc_icon_id, ID sprite_template_id, ID?name_key = null, ID?short_desc_key = null, ID?long_desc_key = null) where T : PickupObject { CheckMode(); id = GetFullID(id, true); enc_icon_id = GetFullID(enc_icon_id, false); sprite_template_id = GetFullID(sprite_template_id, false); if (name_key != null) { name_key = GetFullID(name_key.Value, false); } if (short_desc_key != null) { short_desc_key = GetFullID(short_desc_key.Value, false); } if (long_desc_key != null) { long_desc_key = GetFullID(long_desc_key.Value, false); } var sprite_def = SemiLoader.EncounterIconCollection.GetDefinition(enc_icon_id); if (sprite_def == null) { throw new ArgumentException($"There is no sprite definition '{sprite_def}' in the encounter icon collection"); } var sprite_template = Registry.SpriteTemplates[sprite_template_id]; var new_inst = PickupObjectTreeBuilder.GetNewInactiveObject(id); var pickup_object = PickupObjectTreeBuilder.AddPickupObject <T>(new_inst); ((Patches.PickupObject)(object) pickup_object).UniqueItemID = id; if (pickup_object is Gun) { var gun = pickup_object as Gun; gun.Volley = ScriptableObject.CreateInstance <ProjectileVolleyData>(); gun.Volley.projectiles = new List <ProjectileModule>(); gun.Volley.projectiles.Add(new ProjectileModule()); var barrel = PickupObjectTreeBuilder.GetNewBarrel(); barrel.transform.parent = new_inst.transform; gun.barrelOffset = barrel.transform; } var journal_entry = PickupObjectTreeBuilder.CreateJournalEntry(name_key?.ToLocalizationKey() ?? "", long_desc_key?.ToLocalizationKey() ?? "", short_desc_key?.ToLocalizationKey() ?? "", sprite_def.Value.Name); var enc_track = PickupObjectTreeBuilder.AddEncounterTrackable(new_inst, journal_entry, $"SEMI/Items/{typeof(T).Name}/{id}"); var enc_db_entry = PickupObjectTreeBuilder.CreateEncounterDatabaseEntry(enc_track, $"SEMI/Items/{id}"); PickupObjectTreeBuilder.AddSprite(new_inst, sprite_template); PickupObjectDatabase.Instance.Objects.Add(pickup_object); Registry.Items.Add(id, pickup_object); EncounterDatabase.Instance.Entries.Add(enc_db_entry); return(pickup_object); }
public static Sprite AddSprite(GameObject go, Sprite base_sprite) { return(PickupObjectTreeBuilder.AddSprite(go, base_sprite)); }