예제 #1
0
        public virtual void FixedUpdate()
        {
            if (!Lib.IsFlight() || module == null)
            {
                return;
            }

            if (broken)
            {
                if (broken != lastFixedBrokenState)
                {
                    lastFixedBrokenState = broken;
                    FixModule(!broken);
                }
            }
            else if (hasFixedEnergyChanged != hasEnergy)
            {
                // Wait 1 second before start consum EC.
                if (hasEnergy)
                {
                    Lib.Delay(1f);
                }

                hasFixedEnergyChanged = hasEnergy;
                lastFixedBrokenState  = false;
                // Update module
                FixModule(hasEnergy);
            }

            // If isConsuming
            if (isConsuming && resources != null)
            {
                resources.Consume(actualCost * Kerbalism.elapsed_s);
            }
        }
예제 #2
0
        public override void OnUpdate()
        {
            if (!Lib.IsFlight() || module == null)
            {
                return;
            }

            // get energy from cache
            resources = ResourceCache.Info(vessel, "ElectricCharge");
            hasEnergy = resources.amount > double.Epsilon;

            // Update UI only if hasEnergy has changed or if is broken state has changed
            if (broken)
            {
                if (broken != lastBrokenState)
                {
                    lastBrokenState = broken;
                    Update_UI(!broken);
                }
            }
            else if (hasEnergyChanged != hasEnergy)
            {
                Lib.Debug("Energy state has changed: {0}", hasEnergy);

                // Wait 1 second before enabled UI.
                if (hasEnergy)
                {
                    Lib.Delay(1f);
                }

                hasEnergyChanged = hasEnergy;
                lastBrokenState  = false;
                // Update UI
                Update_UI(hasEnergy);
            }
            // Constantly Update UI for special modules
            if (broken)
            {
                Constant_OnGUI(!broken);
            }
            else
            {
                Constant_OnGUI(hasEnergy);
            }

            if (!hasEnergy || broken)
            {
                actualCost  = 0;
                isConsuming = false;
            }
            else
            {
                isConsuming = GetIsConsuming();
            }
        }