private GasInfo[] ParseGasSettings(string settings, float summPressure, float temp) { string[] gasSets = settings.Split(','); List <GasInfo> gasInfos = new List <GasInfo>(); foreach (var gasSet in gasSets) { string[] namePart = gasSet.Split('-'); string name = namePart[0]; float part = float.Parse(namePart[1], CultureInfo.InvariantCulture); Gas gas = AtmosController.GetGasByName(name); int id = gas.Id; gasInfos.Add(new GasInfo(summPressure * part, id, temp)); } return(gasInfos.ToArray()); }
private void EnsureControllers() { if (VisionController == null) { VisionController = FindObjectOfType <VisionController>(); } if (ServerController == null) { ServerController = FindObjectOfType <ServerController>(); } if (WalkController == null) { WalkController = FindObjectOfType <WalkController>(); } if (AtmosController == null) { AtmosController = FindObjectOfType <AtmosController>(); } }
IEnumerator SpawnGasDelayed() { while (!AtmosController.IsReady) { yield return(new WaitForEndOfFrame()); } try { GasInfo[] gasInfos = ParseGasSettings(_gasNames, _pressure, _temperatureCelsium + 273.15f); foreach (var gasInfo in gasInfos) { AtmosController.AddGas(Cell.x, Cell.y, gasInfo.GasId, 1f, gasInfo.Pressure, _temperatureCelsium + 273.15f); } } catch (Exception ex) { Debug.LogWarning(ex.Message); } }
private void CheckAtmos() { bool ok = true; Vector2Int cell; if (Holder == null) { cell = Cell; } else { cell = Holder.GetComponent <TileObject>().Cell; } Gas oxygen = AtmosController.GetGasByName("Oxygen"); GasInfo[] gasInfos = AtmosController.GetGases(cell.x, cell.y); if (gasInfos == null) { return; } float summPressure = 0; float oxygenPressure = 0; foreach (var gasInfo in gasInfos) { summPressure += gasInfo.Pressure; if (gasInfo.GasId == oxygen.Id) { oxygenPressure += gasInfo.Pressure; } } float oxygenPart; if (summPressure != 0) { oxygenPart = oxygenPressure / summPressure; } else { oxygenPart = 0; } if (oxygenPart < _minimumOxygenPart || oxygenPart > _maximumOxygenPart) { ok = false; } if (summPressure < _minimumPressure || summPressure > _maximumPressure) { ok = false; } //Debug.Log("Oxygen: " + oxygenPart * 100 + "%" + ", pressure: " + summPressure + "kPa"); _oxygenPart = oxygenPart; _pressure = summPressure; if (gasInfos.Length > 0) { _temperature = gasInfos[0].Temperature; } _isOk = ok; }