/// <summary> /// /// </summary> protected virtual void Start() { // store a reference to the FPSWeapon m_Weapon = transform.GetComponent<vp_Weapon>(); }
/// <summary> /// upon success, drops all the player's weapons /// </summary> protected virtual void TryDropAllWeapons() { if (WeaponHandler == null) { return; } foreach (KeyValuePair <vp_Weapon, vp_ItemIdentifier> w in Inventory.WeaponIdentifiers) { vp_Weapon weapon = w.Key; vp_ItemIdentifier weaponIdentifier = w.Value; // skip if weapon identifier has no item type vp_ItemType itemType = weaponIdentifier.GetItemType(); if (itemType == null) { continue; } // for unitbank weapons, try and set the weapon pickup's ammo // to the amount of ammo in the dropped weapon int units = 0; vp_UnitBankInstance unitBank = Inventory.GetUnitBankInstanceOfWeapon(weapon); if (unitBank != null) { units = unitBank.Count; } // drop the weapon TryDropWeapon(itemType, units, weaponIdentifier.ID); } }
/// <summary> /// /// </summary> public int GetExtraAmmoForWeapon(vp_Weapon weapon) { vp_UnitBankInstance unitBank = GetUnitBankInstanceOfWeapon(weapon); if (unitBank == null) { return(0); } return(GetUnitCount(unitBank.UnitType)); }
/// <summary> /// /// </summary> public int GetAmmoInWeapon(vp_Weapon weapon) { vp_UnitBankInstance unitBank = GetUnitBankInstanceOfWeapon(weapon); if (unitBank == null) { return(0); } return(unitBank.Count); }
/// <summary> /// /// </summary> public void ActivateWeapon(int index) { m_CurrentWeaponIndex = index; m_CurrentWeapon = null; if (m_CurrentWeaponIndex > 0) { m_CurrentWeapon = Weapons[m_CurrentWeaponIndex - 1]; if (m_CurrentWeapon != null) { m_CurrentWeapon.ActivateGameObject(true); } } }
/// <summary> /// /// </summary> public vp_ItemInstance GetItemInstanceOfWeapon(vp_Weapon weapon) { vp_ItemIdentifier itemIdentifier = GetWeaponIdentifier(weapon); if (itemIdentifier == null) { return(null); } vp_ItemInstance ii = GetItem(itemIdentifier.Type); return(ii); }
/// <summary> /// hooks up the FPSCamera object to the inspector target /// </summary> public void OnEnable() { m_Component = (vp_Weapon)target; if (m_Persister == null) { m_Persister = new vp_ComponentPersister(); } m_Persister.Component = m_Component; m_Persister.IsActive = true; if (m_Component.DefaultState == null) { m_Component.RefreshDefaultState(); } }
/// <summary> /// /// </summary> public void ActivateWeapon(int index) { m_CurrentWeaponIndex = index; m_CurrentWeapon = null; if (m_CurrentWeaponIndex > 0) { m_CurrentWeapon = Weapons[m_CurrentWeaponIndex - 1]; if (m_CurrentWeapon != null) { m_CurrentWeapon.ActivateGameObject(true); } } if (m_CurrentWeapon != null) { m_CurrentShooter = CurrentWeapon.GetComponent <vp_Shooter>(); } }
/// <summary> /// Calls on awake, initialize components /// </summary> protected void Awake() { if (bPlacer == null) { bPlacer = GetComponentInParent <UFPSBuildingPlacer>(); if (bPlacer == null) // if still equals to null { Debug.LogError("UFPSBuildingPlacer isn't assigned on : " + transform.root.name + " uConstruct equipment is disabled."); this.enabled = false; } } if (weaponInstance == null) { weaponInstance = GetComponent <vp_Weapon>(); if (weaponInstance == null) // if still equals to null { Debug.LogError("vp_weapon isn't assigned on : " + transform.name + " uConstruct equipment is disabled."); this.enabled = false; } } }
/// <summary> /// /// </summary> protected virtual vp_ItemIdentifier GetWeaponIdentifier(vp_Weapon weapon) { if (!Application.isPlaying) { return(null); } if (weapon == null) { return(null); } if (!WeaponIdentifiers.TryGetValue(weapon, out m_WeaponIdentifierResult)) { if (weapon == null) { return(null); } m_WeaponIdentifierResult = weapon.GetComponent <vp_ItemIdentifier>(); if (m_WeaponIdentifierResult == null) { return(null); } if (m_WeaponIdentifierResult.Type == null) { return(null); } WeaponIdentifiers.Add(weapon, m_WeaponIdentifierResult); } return(m_WeaponIdentifierResult); }
/// <summary> /// /// </summary> public vp_UnitBankInstance GetUnitBankInstanceOfWeapon(vp_Weapon weapon) { return(GetItemInstanceOfWeapon(weapon) as vp_UnitBankInstance); }
/// <summary> /// sets up simplified 3rd person weapon child objects based on the /// current first person weapons under the vp_FPCamera component /// </summary> public static void ConvertWeaponsTo3rdPerson(GameObject player) { int weaponsConverted = 0; Transform oldWeaponGroup = null; // typically the 'FPSCamera' object GameObject newWeaponGroup = new GameObject("Weapons"); foreach (vp_FPWeapon fpWeapon in player.transform.GetComponentsInChildren <vp_FPWeapon>()) { // detect old weapons parent and put the new one alongside it in hierarchy if (oldWeaponGroup == null) { oldWeaponGroup = fpWeapon.transform.parent; newWeaponGroup.transform.parent = oldWeaponGroup.parent; newWeaponGroup.transform.localPosition = Vector3.zero; newWeaponGroup.transform.localEulerAngles = Vector3.zero; newWeaponGroup.transform.localScale = Vector3.one; } // create a new gameobject for each weapon. this way we get rid of // any custom components that may be hard for the editor code to // delete because of component interdependencies GameObject newWeaponGO = new GameObject(fpWeapon.gameObject.name); newWeaponGO.transform.parent = newWeaponGroup.transform; // NOTE: position of this transform is irrelevant because a 3rd // person vp_Weapon is just an invisible, locigal entity, represented // by its '3rdPersonWeapon' gameobject reference in the 3d world. // still, let's place the weapons in a fairly neutral position for // clarity: say, the center of the player facing forwards newWeaponGO.transform.localPosition = Vector3.up; newWeaponGO.transform.localEulerAngles = Vector3.zero; newWeaponGO.transform.localScale = Vector3.one; // convert vp_FPWeapon component into a vp_Weapon component on the new gameobject vp_Weapon tdpWeapon = newWeaponGO.AddComponent <vp_Weapon>(); vp_EditorUtility.CopyValuesFromDerivedComponent(fpWeapon, tdpWeapon, true, true, null); if (m_CopyStates && !string.IsNullOrEmpty(m_StatePath)) { vp_EditorUtility.GenerateStatesAndPresetsFromDerivedComponent(fpWeapon, tdpWeapon, m_StatePath); } // FP shooters (used for projectile weapons) vp_FPWeaponShooter fpShooter = fpWeapon.GetComponent <vp_FPWeaponShooter>(); if (fpShooter != null) { vp_WeaponShooter tdpFpShooter = newWeaponGO.AddComponent <vp_WeaponShooter>(); vp_EditorUtility.CopyValuesFromDerivedComponent(fpShooter, tdpFpShooter, true, true, null); if (m_CopyStates && !string.IsNullOrEmpty(m_StatePath)) { vp_EditorUtility.GenerateStatesAndPresetsFromDerivedComponent(fpShooter, tdpFpShooter, m_StatePath); } } // regular shooters (used for melee weapons) vp_WeaponShooter shooter = fpWeapon.GetComponent <vp_WeaponShooter>(); if ((shooter != null) && !(shooter is vp_FPWeaponShooter)) { vp_WeaponShooter tdpShooter = newWeaponGO.AddComponent <vp_WeaponShooter>(); vp_EditorUtility.CopyValuesFromDerivedComponent(shooter, tdpShooter, true, true, null); if (m_CopyStates && !string.IsNullOrEmpty(m_StatePath)) { vp_EditorUtility.GenerateStatesAndPresetsFromDerivedComponent(shooter, tdpShooter, m_StatePath); } } // reloaders vp_FPWeaponReloader fpReloader = fpWeapon.GetComponent <vp_FPWeaponReloader>(); if (fpReloader != null) { vp_WeaponReloader tdpReloader = newWeaponGO.AddComponent <vp_WeaponReloader>(); vp_EditorUtility.CopyValuesFromDerivedComponent(fpReloader, tdpReloader, true, true, null); // reloader is no vp_Component so don't generate states & presets } // copy weapon thrower vp_FPWeaponThrower fpThrower = fpWeapon.GetComponent <vp_FPWeaponThrower>(); if (fpThrower != null) { vp_WeaponThrower tdpThrower = newWeaponGO.AddComponent <vp_WeaponThrower>(); vp_EditorUtility.CopyValuesFromDerivedComponent(fpWeapon, tdpThrower, true, true, null); } // copy item identifier vp_ItemIdentifier identifier = fpWeapon.GetComponent <vp_ItemIdentifier>(); if (identifier != null) { vp_ItemIdentifier newIdentifier = newWeaponGO.AddComponent <vp_ItemIdentifier>(); newIdentifier.Type = identifier.Type; } weaponsConverted++; } // delete the old weapon group (FPSCamera object) if (oldWeaponGroup != null) { GameObject.DestroyImmediate(oldWeaponGroup.gameObject); } EditorUtility.DisplayDialog( weaponsConverted + " weapons converted", (weaponsConverted > 0 ? ( ((m_CopyStates && !string.IsNullOrEmpty(m_StatePath)) ? ("Any states with compatible values have been retained and their presets can be found in the folder:\n\t\t'" + m_StatePath + "'") : "") ) : ""), "OK"); }
/// <summary> /// hooks up the FPSCamera object to the inspector target /// </summary> public void OnEnable() { m_Component = (vp_Weapon)target; if (m_Persister == null) m_Persister = new vp_ComponentPersister(); m_Persister.Component = m_Component; m_Persister.IsActive = true; if (m_Component.DefaultState == null) m_Component.RefreshDefaultState(); }
/// <summary> /// /// </summary> public int GetExtraAmmoForWeapon(vp_Weapon weapon) { vp_UnitBankInstance unitBank = GetUnitBankInstanceOfWeapon(weapon); if (unitBank == null) return 0; return GetUnitCount(unitBank.UnitType); }
/// <summary> /// /// </summary> public int GetAmmoInWeapon(vp_Weapon weapon) { vp_UnitBankInstance unitBank = GetUnitBankInstanceOfWeapon(weapon); if (unitBank == null) return 0; return unitBank.Count; }
/// <summary> /// /// </summary> public void ActivateWeapon(int index) { m_CurrentWeaponIndex = index; m_CurrentWeapon = null; if (m_CurrentWeaponIndex > 0) { m_CurrentWeapon = Weapons[m_CurrentWeaponIndex - 1]; if (m_CurrentWeapon != null) m_CurrentWeapon.ActivateGameObject(true); } }
/// <summary> /// /// </summary> public int GetWeaponIndex(vp_Weapon weapon) { return Weapons.IndexOf(weapon) + 1; }
/// <summary> /// /// </summary> protected virtual vp_ItemIdentifier GetWeaponIdentifier(vp_Weapon weapon) { if (!Application.isPlaying) return null; if (weapon == null) return null; if (!WeaponIdentifiers.TryGetValue(weapon, out m_WeaponIdentifierResult)) { if (weapon == null) return null; m_WeaponIdentifierResult = weapon.GetComponent<vp_ItemIdentifier>(); if (m_WeaponIdentifierResult == null) return null; if (m_WeaponIdentifierResult.Type == null) return null; WeaponIdentifiers.Add(weapon, m_WeaponIdentifierResult); } return m_WeaponIdentifierResult; }
/// <summary> /// /// </summary> public int GetWeaponIndex(vp_Weapon weapon) { return(Weapons.IndexOf(weapon) + 1); }
/// <summary> /// /// </summary> protected virtual void Start() { // store a reference to the FPSWeapon m_Weapon = transform.GetComponent <vp_Weapon>(); }
/// <summary> /// /// </summary> public vp_UnitBankInstance GetUnitBankInstanceOfWeapon(vp_Weapon weapon) { return GetItemInstanceOfWeapon(weapon) as vp_UnitBankInstance; }
/// <summary> /// /// </summary> public vp_ItemInstance GetItemInstanceOfWeapon(vp_Weapon weapon) { vp_ItemIdentifier itemIdentifier = GetWeaponIdentifier(weapon); if (itemIdentifier == null) return null; vp_ItemInstance ii = GetItem(itemIdentifier.Type); return ii; }