Esempio n. 1
0
 //Increase current charge
 private void Charge()
 {
     if (chargeRate > 0)
     {
         chargeRate -= Time.deltaTime;
     }
     else
     {
         chargeRate     = settings.chargeRate;
         currentCharge += settings.rechargeAmount;
         if (currentCharge >= settings.maxCharge)
         {
             currentCharge = settings.maxCharge;
         }
         batterySlider.UpdateSlider(currentCharge);
     }
     //If there is some charge turn on light if it is off
     if (currentCharge > 0 && !fieldViewCone.GetLightIsOn())
     {
         fieldViewCone.ToggleLight(true);
     }
     if (currentCharge >= settings.maxCharge)
     {
         OnFullyCharged?.Invoke();
     }
 }
Esempio n. 2
0
        private void Update()
        {
            if (!Enabled)
            {
                UpdateWeightModification();
                return;
            }

            if (!InputDelegate_.LaserPressed && chargedTime_ >= kChargeTime)
            {
                ShootLaser();
                chargedTime_ = 0.0f;
            }

            float previousPercentCharged = chargedTime_ / kChargeTime;

            if (InputDelegate_.LaserPressed && InGameConstants.IsAllowedToChargeLasers(Player_))
            {
                chargedTime_ += Time.deltaTime * kChargeRate;
            }
            else
            {
                chargedTime_ -= Time.deltaTime * kDischargeRate;
            }

            chargedTime_ = Mathf.Clamp(chargedTime_, 0.0f, kChargeTime);
            float percentCharged = chargedTime_ / kChargeTime;

            if (percentCharged <= 0.0f && chargingLaser_ != null)
            {
                ObjectPoolManager.Recycle(chargingLaser_);
                chargingLaser_ = null;
            }
            else if (percentCharged > 0.0f && chargingLaser_ == null)
            {
                chargingLaser_ = ObjectPoolManager.Create <ChargingLaser>(chargingLaserPrefab_, parent: chargingLaserContainer_);
                chargingLaser_.SetColor(Player_.Skin.LaserColor, Player_.Skin.SmearedLaserMaterial);
            }

            if (percentCharged < 1.0f && fullyChargedParticle_ != null)
            {
                DisperseFullyChargedParticle();
            }

            if (chargingLaser_ != null)
            {
                chargingLaser_.UpdateWithPercentage(percentCharged);
                if (!Mathf.Approximately(previousPercentCharged, 1.0f) && Mathf.Approximately(percentCharged, 1.0f))
                {
                    fullyChargedParticle_ = ObjectPoolManager.Create <FullyChargedParticle>(fullyChargedParticlePrefab_, parent: chargingLaserContainer_);
                    fullyChargedParticle_.SetColor(Player_.Skin.LaserColor);

                    OnFullyCharged.Invoke(Player_);
                    OnFullCharge.Invoke();
                }
            }

            UpdateWeightModification();
        }
Esempio n. 3
0
 private void TriggerSwitchEvents()
 {
     if (currentCharge >= 1 && !isFullyCharged)
     {
         isFullyCharged = true;
         OnFullyCharged?.Invoke(SwitchLight);
     }
     else if (currentCharge <= 0 && isFullyCharged)
     {
         isFullyCharged = false;
         OnFullyDeCharged?.Invoke(SwitchLight);
     }
 }