void HandleOxygenLevels() { // regenerate oxygen var shouldRegen = holes.Count <= 0 && !this.isOnFire; if (shouldRegen) { if (!this.wasThiefed) { oxygen = Mathf.Clamp(oxygen + oxygenRegen, 0, maxOxygen); m_Shader.Air(1f - (oxygen / 100f)); return; } else { this.wasThiefed = false; } } // steal from nearby rooms var nearbyOpenRooms = this.halfAirlocks.Where(ha => ha.isOpen && ha.pairedAirlock.isOpen); var nearbyRoomsWithAir = nearbyOpenRooms.Select(ha => ha.pairedAirlock.room).Where(r => r.oxygen > 0); var nearbyRoomsWithMoreAir = nearbyRoomsWithAir.Where(r => r.oxygen > this.oxygen).OrderByDescending(r => r.oxygen); foreach (var otherRoom in nearbyRoomsWithMoreAir) { var oxygenDifference = otherRoom.oxygen - this.oxygen; var oxygenEqualizationDifference = oxygenDifference / 2; var targetThiefRate = Mathf.Clamp(maxOxygenThiefRate, 0, oxygenEqualizationDifference); if (targetThiefRate > 0) { oxygen = Mathf.Clamp(oxygen + targetThiefRate, 0, maxOxygen); otherRoom.oxygen = Mathf.Clamp(otherRoom.oxygen - targetThiefRate, 0, otherRoom.maxOxygen); otherRoom.wasThiefed = true; } else { break; } } // lose oxygen var oxygenLossDueToHoles = oxygenLossPerHole * holes.Count; var oxygenLossDueToFire = this.isOnFire ? oxygenLossForFire : 0; var oxygenLoss = oxygenLossDueToHoles + oxygenLossDueToFire; oxygen = Mathf.Clamp(oxygen - oxygenLoss, 0, maxOxygen); m_Shader.Air(1f - (oxygen / 100f)); }
// Start is called before the first frame update void Start() { m_ShaderManip = GetComponent <ShaderManip>(); m_ShaderManip.Fire(.5f); m_ShaderManip.Air(.5f); //m_Material = GetComponent<Renderer>().material; // Debug.Log(m_Material); // Debug.Log(m_Material.GetFloat("OneForFire")); // m_Material.SetFloat("OneForFire", 1.0f); // Debug.Log(m_Material.GetFloat("OneForFire")); }