Example #1
0
        private IEnumerator DisplayFlashingText(string text, float speed = 0.5F)
        {
            string initialInfoText = externalTankStatus.Element.text;

            externalTankStatus.SetValueServer(text);
            yield return(WaitFor.Seconds(speed));

            externalTankStatus.SetValueServer("");
            yield return(WaitFor.Seconds(speed / 2));

            externalTankStatus.SetValueServer(text);
            yield return(WaitFor.Seconds(speed));

            externalTankStatus.SetValueServer("");
            yield return(WaitFor.Seconds(speed / 2));

            externalTankStatus.SetValueServer(text);
            yield return(WaitFor.Seconds(speed));

            externalTankStatus.SetValueServer("");
            yield return(WaitFor.Seconds(speed / 2));

            Canister canister = Provider.GetComponent <Canister>();

            if (canister.InsertedContainer != null)
            {
                externalTankStatus.SetValueServer($"{canister.InsertedContainer.Item().InitialName}");
            }
            else
            {
                externalTankStatus.SetValueServer("No Tank Inserted");
            }
        }
Example #2
0
        //server side initialization
        private IEnumerator ServerWaitForProvider()
        {
            while (Provider == null)
            {
                yield return(WaitFor.EndOfFrame);
            }

            canister = Provider.GetComponent <Canister>();
            //init pressure dials
            InternalPressureDial.ServerSpinTo(Mathf.RoundToInt(gasContainer.ServerInternalPressure));
            ReleasePressureDial.ServerSpinTo(Mathf.RoundToInt(gasContainer.ReleasePressure));
            if (canister.HasContainerInserted)
            {
                GasContainer externalTank = canister.InsertedContainer.GetComponent <GasContainer>();
                ExternalPressureDial.ServerSpinTo(Mathf.RoundToInt(externalTank.ServerInternalPressure));
            }
            else
            {
                ExternalPressureDial.ServerSpinTo(0);
            }
            //init connection status
            canister.ServerOnConnectionStatusChange.AddListener(ServerUpdateConnectionStatus);
            ServerUpdateConnectionStatus(canister.IsConnected);
            //init external tank status
            canister.ServerOnExternalTankInserted.AddListener(ServerUpdateExternalTank);
            ServerUpdateExternalTank(canister.HasContainerInserted);

            //init wheel
            ReleasePressureWheel.SetValueServer(Mathf.RoundToInt(gasContainer.ReleasePressure).ToString());
            StartCoroutine(ServerRefreshInternalPressure());
        }
Example #3
0
        //client side  initialization
        private IEnumerator ClientWaitForProvider()
        {
            while (Provider == null)
            {
                yield return(WaitFor.EndOfFrame);
            }
            //set the tab color and label based on the provider
            Canister canister = Provider.GetComponent <Canister>();

            BG.color           = canister.UIBGTint;
            InnerPanelBG.color = canister.UIInnerPanelTint;
            LabelText.text     = "Contains " + canister.ContentsName;
            XButton.color      = canister.UIBGTint;

            OnInternalPressureChanged(InternalPressureDial.SyncedValue);
            InternalPressureDial.OnSyncedValueChanged.AddListener(OnInternalPressureChanged);
        }
Example #4
0
        /// <summary>
        /// Updates the displayed external tank
        /// </summary>
        private void ServerUpdateExternalTank(bool externalExists)
        {
            Canister   canister          = Provider.GetComponent <Canister>();
            GameObject insertedContainer = canister.InsertedContainer;

            if (externalExists)
            {
                externalTankStatus.SetValueServer(insertedContainer.Item().InitialName);
                externalTankImage.SetValueServer("ExternalTankInserted@0");
                GasContainer externalTank = insertedContainer.GetComponent <GasContainer>();
                ExternalPressureDial.ServerSpinTo(Mathf.RoundToInt(externalTank.ServerInternalPressure));
            }
            else
            {
                externalTankStatus.SetValueServer("No Tank Inserted");
                externalTankImage.SetValueServer("ExternalTankEmpty@0");
                ExternalPressureDial.ServerSpinTo(0);
            }
        }
Example #5
0
        public void EjectExternalTank()
        {
            Canister canister = Provider.GetComponent <Canister>();

            if (canister.InsertedContainer != null)
            {
                if (tankValveOpen)
                {
                    StartCoroutine(DisplayFlashingText("Close the valve first!"));
                }
                else
                {
                    canister.RetrieveInsertedContainer();
                    StartCoroutine(DisplayFlashingText("Tank ejected!"));
                }
            }
            else
            {
                StartCoroutine(DisplayFlashingText("No Tank Inserted"));
            }
        }
Example #6
0
        /// <summary>
        /// switch the secondary valve between internals valve and external tank
        /// </summary>
        /// <param name="usingTank">Is the valve set to tank.</param>
        public void ServerToggleSecondary(bool usingTank)
        {
            tankValveOpen = usingTank;
            Canister     canister     = Provider.GetComponent <Canister>();
            GasContainer canisterTank = canister.GetComponent <GasContainer>();
            GasContainer externalTank = canister.InsertedContainer?.GetComponent <GasContainer>();

            if (usingTank && externalTank != null)
            {
                GasMix  canisterGas          = canisterTank.GasMix;
                GasMix  tankGas              = externalTank.GasMix;
                float[] updatedCanisterGases = { 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f };
                float[] updatedTankGases     = { 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f };
                float   updatedTankMoles     = 0f;

                GasMix  totalGas   = canisterGas + tankGas;
                float[] totalGases = totalGas.Gases;

                //while: canister has greater pressure than external tank AND tank isn't full
                while (canisterTank.ServerInternalPressure >= externalTank.ServerInternalPressure &&
                       updatedTankMoles <= externalTank.MaximumMoles)
                {
                    //iterate through gases and distribute between the canister and external tank
                    for (int i = 0; i < totalGases.Length; i++)
                    {
                        if (totalGases[i] > 0f && updatedTankMoles <= externalTank.MaximumMoles)
                        {
                            totalGases[i]           -= 0.02f;
                            updatedCanisterGases[i] += 0.01f;
                            updatedTankGases[i]     += 0.01f;
                            updatedTankMoles        += 0.01f;
                        }
                    }
                }
                //add remaining gases to the canister values
                for (int i = 0; i < totalGases.Length; i++)
                {
                    if (totalGases[i] > 0f)
                    {
                        updatedCanisterGases[i] += totalGases[i];
                        totalGases[i]            = 0f;
                        //compensate for valve blowoff
                        updatedCanisterGases[i] -= 0.02052f;
                    }
                }

                //make sure we're not marginally increasing gas in the tank
                //due to float falloff
                bool accuracyCheck = true;
                for (int i = 0; i < canisterTank.Gases.Length; i++)
                {
                    if (canisterTank.Gases[i] < updatedCanisterGases[i])
                    {
                        accuracyCheck = false;
                    }
                }
                if (accuracyCheck)
                {
                    canisterTank.Gases = updatedCanisterGases;
                    canisterTank.UpdateGasMix();
                }
                externalTank.Gases = updatedTankGases;
                externalTank.UpdateGasMix();
                ExternalPressureDial.ServerSpinTo(Mathf.RoundToInt(externalTank.ServerInternalPressure));
            }
            else if (usingTank && externalTank == null)
            {
                StartCoroutine(DisplayFlashingText("Insert a tank before opening the valve!", 1F));
            }
        }