SSTUTools.SSTUVolumeContainer.setContainerPercents C# (CSharp) Method

setContainerPercents() public method

public setContainerPercents ( float percents, float totalVolume ) : void
percents float
totalVolume float
return void
        public void setContainerPercents(float[] percents, float totalVolume)
        {
            int len = containers.Length;
            if (len != percents.Length) { throw new IndexOutOfRangeException("Input container percents length does not match containers length: "+percents.Length+" : "+len); }
            float total = 0;
            for (int i = 0; i < len-1; i++)
            {
                total += percents[i];
                containers[i].setContainerPercent(percents[i]);
            }
            if (total > 1) { throw new InvalidOperationException("Input percents total > 1"); }
            containers[len - 1].setContainerPercent(1.0f - total);
            volume = totalVolume;
            updateContainerVolumes();
            updateMassAndCost();
            updateTankResources();
            updateFuelSelections();
            updatePersistentData();
            SSTUStockInterop.fireEditorUpdate();
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Updates the min/max quantities of resource in the part based on the current 'totalFuelVolume' field and currently set fuel type
        /// </summary>
        private void updateContainerVolume()
        {
            SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>();

            if (vc != null)
            {
                float   tankPercent = 100 - supportPercent;
                float   monoPercent = supportPercent;
                float[] pcts        = new float[2];
                pcts[0] = tankPercent * 0.01f;
                pcts[1] = monoPercent * 0.01f;
                vc.setContainerPercents(pcts, totalTankVolume * 1000f);
            }
            else
            {
                //real-fuels handling....
                SSTUModInterop.onPartFuelVolumeUpdate(part, totalTankVolume * 1000f);
            }
        }
All Usage Examples Of SSTUTools.SSTUVolumeContainer::setContainerPercents