Example #1
0
        void Start()
        {
            inventoryWeapons = CurrentPlayer.Inventory.Weapons;
            inventoryAmmo    = CurrentPlayer.Inventory.Ammo;

            // init weapons
            Weapon[] ws = GetComponentsInChildren <Weapon>(true);
            weapons = new Dictionary <WeaponIndex, Weapon>();

            foreach (Weapon w in ws)
            {
                // scene's weapon index is not set
                // so parse it
                WeaponIndex index = (WeaponIndex)Enum.Parse(typeof(WeaponIndex), w.gameObject.name);

                // include it only if available in inventory
                // if (inventoryWeapons.IsAvailable(index))
                {
                    weapons.Add(index, w);
                    w.Init(this, inventoryWeapons.Get(index), inventoryAmmo);
                }
            }

            // get audio sources
            audioSources     = GetComponentsInChildren <AudioSource>();
            audioSourceIndex = 0;
            Debug.Assert(audioSources.Length != 0, "No audio source for weapons");

            // animation
            commonAnimation = GetComponent <Animation>();
            Debug.Assert(commonAnimation != null);

            // states
            isSwitching            = false;
            canSwitchToAnotherNext = false;
            currentWeapon          = new Maybe <WeaponIndex>();
            nextWeapon             = new Maybe <WeaponIndex>();

            // events
            SignToEvents();

            // set parameters for weapons particles
            InitParticles();

            // to default
            Reinit();

            isInitialized = true;
        }
Example #2
0
 bool IsAvailableAndHaveAmmo(WeaponIndex w)
 {
     return(inventoryWeapons.IsAvailableInGame(w) &&
            inventoryAmmo.Get(inventoryWeapons.Get(w).AmmoType).CurrentAmount > 0);
 }