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; }
void UpdateList() { IWeaponsHolder weapons = inventory.Weapons; IAmmoHolder ammo = inventory.Ammo; List <WeaponIndex> available = weapons.GetAvailableWeaponsInGame(); int availableAmount = available.Count; if (availableAmount == 0) { weaponSelectionObj.SetActive(false); noAvailableWeaponsObj.SetActive(true); } else { weaponSelectionObj.SetActive(true); noAvailableWeaponsObj.SetActive(false); } int counter = 0; foreach (WeaponButton b in buttons.Values) { if (counter < availableAmount) { IWeaponItem w = weapons.Get(available[counter]); IAmmoItem a = ammo.Get(w.AmmoType); //if (!w.IsAmmo || (w.IsAmmo && a.CurrentAmount > 0)) { b.Set(w, a, SelectWeapon, ammoList.HighlightAmmo); } //else //{ // b.gameObject.SetActive(false); //} } else { // disable other buttons b.gameObject.SetActive(false); } counter++; } }
void UpdateWheel() { if (inventory == null) { inventory = GameController.Instance.Inventory; } IWeaponsHolder weapons = inventory.Weapons; IAmmoHolder ammo = inventory.Ammo; List <WeaponIndex> available = weapons.GetAvailableWeaponsInGame(); int availableAmount = available.Count; GameObject wheel = GetWheel(availableAmount); if (wheel == null) { return; } int counter = 0; var bs = wheel.GetComponentsInChildren <WeaponWheelButton>(true); foreach (WeaponWheelButton b in bs) { b.SetColors(defaultColor, highlitedColor, disabledColor); if (counter < availableAmount) { IWeaponItem w = weapons.Get(available[counter]); IAmmoItem a = ammo.Get(w.AmmoType); b.Set(w, a, Select, Highlight, Unhighlight); } else { // disable buttons without weapon b.Disable(); } counter++; } }
/// <summary> /// Init fields from player's items /// </summary> public void Init(WeaponsController controller, WeaponItem playerItem, IAmmoHolder playerAmmo) { Debug.Assert(WController == null, "Several initializations of the same weapon", controller); WController = controller; Owner = controller.CurrentPlayer.gameObject; ammo = playerAmmo; item = playerItem; // load info Data = item.Stats; WeaponIndex = item.This; DamageValue = Data.Damage; AmmoType = Data.AmmoType; AmmoConsumption = Data.AmmoConsumption; ReloadingTime = Data.ReloadingTime; Accuracy = Data.Accuracy; Durability = Data.Durability; refHealth = item.HealthRef; JamProbability = Data.JamProbability; PercentageForJam = Data.PercentageForJam; ShotSound = Data.ShotSound; BreakSound = Data.BreakSound; UnjamSound = Data.UnjamSound; // layers AutoaimLayerMask = LayerMask.GetMask(LayerNames.AutoaimTargets); WeaponLayerMask = LayerMask.GetMask(LayerNames.Default, LayerNames.Damageable); DamageableLayer = LayerMask.NameToLayer(LayerNames.Damageable); // get anim weaponAnimation = GetComponentInChildren <Animation>(true); string tempName = weaponAnimation.clip.name; tempName = tempName.Remove(0, 1); AnimShootName = "S" + tempName; AnimJamName = "J" + tempName; AnimUnjamName = "U" + tempName; AnimBreakName = "B" + tempName; // set hand animation handPivot = GetComponentInChildren <HandPivot>(true); if (handPivot != null) { string handAnimName = "H" + tempName; handPivot.Init(handAnimName); } // set state State = WeaponState.Nothing; wasJammed = false; InitWeapon(); SaveTransforms(); }