using System.Collections.Generic; namespace SWB.Base; /* * Attach this component somewhere in the root of your scene. * Register all weapons that you want to use in here */ [Group( "SWB" )] [Title( "Weapon Registry" )] public class WeaponRegistry : Component { [Property] public List WeaponPrefabs { get; set; } = new(); public Dictionary Weapons { get; set; } = new(); static public WeaponRegistry Instance { get { return Game.ActiveScene.Components.GetInChildren(); } } protected override void OnAwake() { WeaponPrefabs.ForEach( weaponPrefab => { var weaponGO = weaponPrefab.Clone(); weaponGO.SetParent( this.GameObject ); weaponGO.Enabled = false; var weapon = weaponGO.Components.Get( true ); Weapons.TryAdd( weapon.ClassName, weaponGO ); weaponGO.Name = weapon.ClassName; } ); } public GameObject Get( string className ) { if ( className is null ) return null; Weapons.TryGetValue( className, out var weaponGO ); return weaponGO; } public Weapon GetWeapon( string className ) { var weaponGO = Get( className ); if ( weaponGO is null ) return null; return weaponGO.Components.Get( true ); } }