示例#1
0
    /// <summary>
    /// Moves gas to another atmosphere. Temperature is transferred accordingly.
    /// </summary>
    /// <param name="destination">Destination of the gas.</param>
    /// <param name="amount">Amount of gas to move.</param>
    public void MoveGasTo(AtmosphereComponent destination, float amount)
    {
        if (destination == null)
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Destination can not be null");
            return;
        }

        if (amount < 0 || float.IsNaN(amount))
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Amount can not be negative: " + amount);
            return;
        }

        amount = Mathf.Min(this.TotalGas, amount);

        string[] gasNames = this.GetGasNames();
        for (int i = 0; i < gasNames.Length; i++)
        {
            float partialAmount = amount * GetGasFraction(gasNames[i]);
            this.ChangeGas(gasNames[i], -partialAmount);
            destination.ChangeGas(gasNames[i], partialAmount);
        }

        float thermalDelta = amount * internalTemperature.InKelvin;

        this.ThermalEnergy        -= thermalDelta;
        destination.ThermalEnergy += thermalDelta;
    }
    /// <summary>
    /// Moves gas to another atmosphere. Thermal energy is transferred accordingly.
    /// </summary>
    /// <param name="destination">Destination of the gas.</param>
    /// <param name="amount">Amount of gas to move.</param>
    public void MoveGasTo(AtmosphereComponent destination, float amount)
    {
        if (destination == null)
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Destination can not be null");
            return;
        }

        if (amount < 0 || float.IsNaN(amount))
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Amount can not be negative: " + amount);
            return;
        }

        amount = Mathf.Min(this.TotalGas, amount);

        float thermalDelta = amount * this.GetTemperature();

        this.ThermalEnergy        -= thermalDelta;
        destination.ThermalEnergy += thermalDelta;

        foreach (var gasName in this.GetGasNames())
        {
            float partialAmount = amount * GetGasFraction(gasName);
            this.ChangeGas(gasName, -partialAmount);
            destination.ChangeGas(gasName, partialAmount);
        }
    }
    public void MoveGasTo(AtmosphereComponent destination, string gasName, float amount)
    {
        if (amount < 0)
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Amount can not be negative: " + amount);
            return;
        }

        amount = Mathf.Min(this.GetGasAmount(gasName), amount);
        this.ChangeGas(gasName, -amount);
        destination.ChangeGas(gasName, amount);

        float thermalDelta = amount * internalTemperature.InKelvin;

        this.ThermalEnergy        -= thermalDelta;
        destination.ThermalEnergy += thermalDelta;
    }
    /// <summary>
    /// Moves gas to another atmosphere. Temperature is transferred accordingly.
    /// </summary>
    /// <param name="destination">Destination of the gas.</param>
    /// <param name="amount">Amount of gas to move.</param>
    public void MoveGasTo(AtmosphereComponent destination, float amount)
    {
        if (destination == null)
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Destination can not be null");
            return;
        }

        if (amount < 0 || float.IsNaN(amount))
        {
            UnityDebugger.Debugger.LogError("MoveGasTo -- Amount can not be negative: " + amount);
            return;
        }

        amount = Mathf.Min(this.TotalGas, amount);

        string[] gasNames = this.GetGasNames();

        // HACK: tracking the amount to transfer with an array and a separate loop is likely
        // innefficient, it may instead be better to adjust amount appropriately by the amount
        // removed. In our standard rooms gas ratio should remain 20% O2, 80% N2
        float[] partialAmounts = new float[gasNames.Length];
        for (int i = 0; i < gasNames.Length; i++)
        {
            partialAmounts[i] = amount * GetGasFraction(gasNames[i]);
        }

        for (int i = 0; i < gasNames.Length; i++)
        {
            this.ChangeGas(gasNames[i], -partialAmounts[i]);
            destination.ChangeGas(gasNames[i], partialAmounts[i]);
        }

        float thermalDelta = amount * internalTemperature.InKelvin;

        this.ThermalEnergy        -= thermalDelta;
        destination.ThermalEnergy += thermalDelta;
    }