public bool RemoveWeapon(WeaponController_Photon weaponInstance) { // Look through our slots for that weapon for (int i = 0; i < m_WeaponSlots.Length; i++) { // when weapon found, remove it if (m_WeaponSlots[i] == weaponInstance) { m_WeaponSlots[i] = null; if (onRemovedWeapon != null) { onRemovedWeapon.Invoke(weaponInstance, i); } Destroy(weaponInstance.gameObject); // Handle case of removing active weapon (switch to next weapon) if (i == activeWeaponIndex) { SwitchWeapon(true); } return(true); } } return(false); }
void OnPickupWeaponPhoton(WeaponController_Photon weaponController, int index) { if (index != 0) { CreateNotification("Picked up weapon : " + weaponController.weaponName); } }
void OnWeaponSwitched(WeaponController_Photon newWeapon) { if (newWeapon != null) { newWeapon.ShowWeapon(true); } }
void Start() { if (online) { m_Weapon_p = GetComponent <WeaponController_Photon>(); DebugUtility.HandleErrorIfNullGetComponent <WeaponController_Photon, WeaponFuelCellHandler>(m_Weapon_p, this, gameObject); m_FuelCellsCooled = new bool[fuelCells.Length]; for (int i = 0; i < m_FuelCellsCooled.Length; i++) { m_FuelCellsCooled[i] = true; } } else { m_Weapon = GetComponent <WeaponController>(); DebugUtility.HandleErrorIfNullGetComponent <WeaponController, WeaponFuelCellHandler>(m_Weapon, this, gameObject); m_FuelCellsCooled = new bool[fuelCells.Length]; for (int i = 0; i < m_FuelCellsCooled.Length; i++) { m_FuelCellsCooled[i] = true; } } }
// Switches to the given weapon index in weapon slots if the new index is a valid weapon that is different from our current one public void SwitchToWeaponIndex(int newWeaponIndex, bool force = false) { if (force || (newWeaponIndex != activeWeaponIndex && newWeaponIndex >= 0)) { // Store data related to weapon switching animation m_WeaponSwitchNewWeaponIndex = newWeaponIndex; m_TimeStartedWeaponSwitch = Time.time; // Handle case of switching to a valid weapon for the first time (simply put it up without putting anything down first) if (GetActiveWeapon() == null) { m_WeaponMainLocalPosition = downWeaponPosition.localPosition; m_WeaponSwitchState = WeaponSwitchState.PutUpNew; activeWeaponIndex = m_WeaponSwitchNewWeaponIndex; WeaponController_Photon newWeapon = GetWeaponAtSlotIndex(m_WeaponSwitchNewWeaponIndex); if (onSwitchedToWeapon != null) { onSwitchedToWeapon.Invoke(newWeapon); } } // otherwise, remember we are putting down our current weapon for switching to the next one else { m_WeaponSwitchState = WeaponSwitchState.PutDownPrevious; } } }
void Awake() { var emissionModule = steamVFX.emission; emissionModule.rateOverTimeMultiplier = 0f; m_OverheatingRenderersData = new List <RendererIndexData>(); foreach (var renderer in GetComponentsInChildren <Renderer>(true)) { for (int i = 0; i < renderer.sharedMaterials.Length; i++) { if (renderer.sharedMaterials[i] == overheatingMaterial) { m_OverheatingRenderersData.Add(new RendererIndexData(renderer, i)); } } } overheatMaterialPropertyBlock = new MaterialPropertyBlock(); m_SteamVFXEmissionModule = steamVFX.emission; m_Weapon = GetComponent <WeaponController_Photon>(); DebugUtility.HandleErrorIfNullGetComponent <WeaponController_Photon, OverheatBehavior>(m_Weapon, this, gameObject); m_AudioSource = gameObject.AddComponent <AudioSource>(); m_AudioSource.clip = coolingCellsSound; m_AudioSource.outputAudioMixerGroup = AudioUtility.GetAudioGroup(AudioUtility.AudioGroups.WeaponOverheat); }
void AddWeapon(WeaponController_Photon newWeapon, int weaponIndex) { GameObject ammoCounterInstance = Instantiate(ammoCounterPrefab, ammosPanel); AmmoCounter_Photon newAmmoCounter = ammoCounterInstance.GetComponent <AmmoCounter_Photon>(); DebugUtility.HandleErrorIfNullGetComponent <AmmoCounter_Photon, WeaponHUDManager_Photon>(newAmmoCounter, this, ammoCounterInstance.gameObject); newAmmoCounter.Initialize(newWeapon, weaponIndex); m_AmmoCounters.Add(newAmmoCounter); }
// Adds a weapon to our inventory public bool AddWeapon(WeaponController_Photon weaponPrefab) { // if we already hold this weapon type (a weapon coming from the same source prefab), don't add the weapon if (HasWeapon(weaponPrefab)) { return(false); } // search our weapon slots for the first free one, assign the weapon to it, and return true if we found one. Return false otherwise for (int i = 0; i < m_WeaponSlots.Length; i++) { // only add the weapon if the slot is free if (m_WeaponSlots[i] == null) { // spawn the weapon prefab as child of the weapon socket WeaponController_Photon weaponInstance = Instantiate(weaponPrefab, weaponParentSocket); weaponInstance.atribuire = playerWapMan; weaponInstance.transform.localPosition = Vector3.zero; weaponInstance.transform.localRotation = Quaternion.identity; // Set owner to this gameObject so the weapon can alter projectile/damage logic accordingly weaponInstance.owner = gameObject; weaponInstance.sourcePrefab = weaponPrefab.gameObject; weaponInstance.ShowWeapon(false); // Assign the first person layer to the weapon // int layerIndex = Mathf.RoundToInt(Mathf.Log(FPSWeaponLayer.value, 2)); // This function converts a layermask to a layer index // foreach (Transform t in weaponInstance.gameObject.GetComponentsInChildren<Transform>(true)) // { // t.gameObject.layer = layerIndex; // } m_WeaponSlots[i] = weaponInstance; if (onAddedWeapon != null) { onAddedWeapon.Invoke(weaponInstance, i); } return(true); } } // Handle auto-switching to weapon if no weapons currently if (GetActiveWeapon() == null) { SwitchWeapon(true); } return(false); }
public void Initialize(WeaponController_Photon weapon, int weaponIndex) { m_Weapon = weapon; weaponCounterIndex = weaponIndex; weaponImage.sprite = weapon.weaponIcon; m_PlayerWeaponsManager_Photon = FindObjectOfType <PlayerWeaponsManager_Photon>(); DebugUtility.HandleErrorIfNullFindObject <PlayerWeaponsManager_Photon, AmmoCounter_Photon>(m_PlayerWeaponsManager_Photon, this); weaponIndexText.text = (weaponCounterIndex + 1).ToString(); FillBarColorChange.Initialize(1f, m_Weapon.GetAmmoNeededToShoot()); }
public void ShootPhoton(WeaponController_Photon controller) { owner = controller.owner; initialPosition = transform.position; initialDirection = transform.forward; inheritedMuzzleVelocity = controller.muzzleWorldVelocity; initialCharge = controller.currentCharge; if (onShoot != null) { onShoot.Invoke(); } }
public bool HasWeapon(WeaponController_Photon weaponPrefab) { // Checks if we already have a weapon coming from the specified prefab foreach (var w in m_WeaponSlots) { if (w != null && w.sourcePrefab == weaponPrefab.gameObject) { return(true); } } return(false); }
void Start() { m_PlayerWeaponsManager = manager.m_Player.m_WeaponsManager; WeaponController_Photon activeWeapon = m_PlayerWeaponsManager.GetActiveWeapon(); if (activeWeapon) { AddWeapon(activeWeapon, m_PlayerWeaponsManager.activeWeaponIndex); ChangeWeapon(activeWeapon); } m_PlayerWeaponsManager.onAddedWeapon += AddWeapon; m_PlayerWeaponsManager.onRemovedWeapon += RemoveWeapon; m_PlayerWeaponsManager.onSwitchedToWeapon += ChangeWeapon; }
void RemoveWeapon(WeaponController_Photon newWeapon, int weaponIndex) { int foundCounterIndex = -1; for (int i = 0; i < m_AmmoCounters.Count; i++) { if (m_AmmoCounters[i].weaponCounterIndex == weaponIndex) { foundCounterIndex = i; Destroy(m_AmmoCounters[i].gameObject); } } if (foundCounterIndex >= 0) { m_AmmoCounters.RemoveAt(foundCounterIndex); } }
// Updates weapon position and camera FoV for the aiming transition void UpdateWeaponAiming() { if (m_PlayerCharacterController.playerCamera != null) { if (m_WeaponSwitchState == WeaponSwitchState.Up) { WeaponController_Photon activeWeapon = GetActiveWeapon(); if (isAiming && activeWeapon) { m_WeaponMainLocalPosition = Vector3.Lerp(m_WeaponMainLocalPosition, aimingWeaponPosition.localPosition + activeWeapon.aimOffset, aimingAnimationSpeed * Time.deltaTime); SetFOV(Mathf.Lerp(m_PlayerCharacterController.playerCamera.fieldOfView, activeWeapon.aimZoomRatio * defaultFOV, aimingAnimationSpeed * Time.deltaTime)); } else { m_WeaponMainLocalPosition = Vector3.Lerp(m_WeaponMainLocalPosition, defaultWeaponPosition.localPosition, aimingAnimationSpeed * Time.deltaTime); SetFOV(Mathf.Lerp(m_PlayerCharacterController.playerCamera.fieldOfView, defaultFOV, aimingAnimationSpeed * Time.deltaTime)); } } } }
void ChangeWeapon(WeaponController_Photon weapon) { UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(ammosPanel); }
// Updates the animated transition of switching weapons void UpdateWeaponSwitching() { // Calculate the time ratio (0 to 1) since weapon switch was triggered float switchingTimeFactor = 0f; if (weaponSwitchDelay == 0f) { switchingTimeFactor = 1f; } else { switchingTimeFactor = Mathf.Clamp01((Time.time - m_TimeStartedWeaponSwitch) / weaponSwitchDelay); } // Handle transiting to new switch state if (switchingTimeFactor >= 1f) { if (m_WeaponSwitchState == WeaponSwitchState.PutDownPrevious) { // Deactivate old weapon WeaponController_Photon oldWeapon = GetWeaponAtSlotIndex(activeWeaponIndex); if (oldWeapon != null) { oldWeapon.ShowWeapon(false); } activeWeaponIndex = m_WeaponSwitchNewWeaponIndex; switchingTimeFactor = 0f; // Activate new weapon WeaponController_Photon newWeapon = GetWeaponAtSlotIndex(activeWeaponIndex); if (onSwitchedToWeapon != null) { onSwitchedToWeapon.Invoke(newWeapon); } if (newWeapon) { m_TimeStartedWeaponSwitch = Time.time; m_WeaponSwitchState = WeaponSwitchState.PutUpNew; } else { // if new weapon is null, don't follow through with putting weapon back up m_WeaponSwitchState = WeaponSwitchState.Down; } } else if (m_WeaponSwitchState == WeaponSwitchState.PutUpNew) { m_WeaponSwitchState = WeaponSwitchState.Up; } } // Handle moving the weapon socket position for the animated weapon switching if (m_WeaponSwitchState == WeaponSwitchState.PutDownPrevious) { m_WeaponMainLocalPosition = Vector3.Lerp(defaultWeaponPosition.localPosition, downWeaponPosition.localPosition, switchingTimeFactor); } else if (m_WeaponSwitchState == WeaponSwitchState.PutUpNew) { m_WeaponMainLocalPosition = Vector3.Lerp(downWeaponPosition.localPosition, defaultWeaponPosition.localPosition, switchingTimeFactor); } }
private void Update() { // shoot handling WeaponController_Photon activeWeapon = GetActiveWeapon(); if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up) { // handle aiming down sights isAiming = m_InputHandler.GetAimInputHeld(); // handle shooting bool hasFired = activeWeapon.HandleShootInputs( m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased()); // Handle accumulating recoil if (hasFired) { m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce; m_AccumulatedRecoil = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance); } } // weapon switch handling if (!isAiming && (activeWeapon == null || !activeWeapon.isCharging) && (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down)) { int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput(); if (switchWeaponInput != 0) { bool switchUp = switchWeaponInput > 0; SwitchWeapon(switchUp); } else { switchWeaponInput = m_InputHandler.GetSelectWeaponInput(); if (switchWeaponInput != 0) { if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null) { SwitchToWeaponIndex(switchWeaponInput - 1); } } } } // Pointing at enemy handling isPointingAtEnemy = false; if (activeWeapon) { if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore)) { if (hit.collider.GetComponentInParent <EnemyController>()) { isPointingAtEnemy = true; } } } }