Heat Exchanger Stuff

Added heat exchanger building
This commit is contained in:
2026-04-23 14:31:11 +01:00
parent 84d0e1d115
commit dfce7deb17
13 changed files with 1168 additions and 2 deletions

View File

@@ -5,17 +5,37 @@ using UnityEngine;
using System.Linq;
using System.IO;
using System;
using Random = UnityEngine.Random;
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine.UI;
#endif // UNITY_EDITOR
namespace Fruitomation.Game
{
public class BuildingManager : MonoBehaviour
{
[Header("References")]
[SerializeField] private BuildingRegistry Registry;
[SerializeField] private GameObject HeatGrid;
[Header("Colors")]
[SerializeField] private Color FreezingColor;
[SerializeField] private Color ColdColor;
[SerializeField] private Color RoomColor;
[SerializeField] private Color WarmColor;
[SerializeField] private Color BoilingColor;
private enum HeatingLevel
{
Freezing,
Cold,
Room,
Warm,
Boiling
}
private class BuildingInfo
{
public BuildingInfo(Building b, RectTransform rt)
@@ -55,13 +75,55 @@ namespace Fruitomation.Game
private static string Filepath => Path.Combine(Application.persistentDataPath, "buildings.json");
private (HeatingLevel, Image)[,] HeatingLevels { get; } = new (HeatingLevel, Image)[96, 49];
private bool[,] InhabitedCells { get; } = new bool[96, 49];
private List<Building> Buildings { get; } = new();
#if UNITY_EDITOR
private static BuildingManager Instance;
private void Awake() => Instance = this;
public void ToggleGrid() => HeatGrid.SetActive(!HeatGrid.activeSelf);
private Color LevelToColor(HeatingLevel level)
{
return level switch
{
HeatingLevel.Room => RoomColor,
HeatingLevel.Boiling => BoilingColor,
HeatingLevel.Cold => ColdColor,
HeatingLevel.Freezing => FreezingColor,
HeatingLevel.Warm => WarmColor,
var _ => new Color()
};
}
private void Awake()
{
HeatGrid.SetActive(false);
Instance = this;
for (int x = 0; x < HeatingLevels.GetLength(0); x++)
{
for (int y = 0; y < HeatingLevels.GetLength(1); y++)
{
GameObject go = new($"Grid_{x}_{y}");
go.transform.SetParent(HeatGrid.transform);
RectTransform rt = go.AddComponent<RectTransform>();
Image img = go.AddComponent<Image>();
HeatingLevels[x, y].Item1 = (HeatingLevel)Random.Range(0, 5);
HeatingLevels[x, y].Item2 = img;
img.color = LevelToColor(HeatingLevels[x, y].Item1);
rt.localScale = Vector3.one;
img.raycastTarget = false;
}
}
}
[MenuItem("Fruitomation/Clear Buildings")]
public static void ClearBuildings()

View File

@@ -0,0 +1,32 @@
using Fruitomation.Global;
using UnityEngine;
namespace Fruitomation.Game
{
public class HeatExchanger : Building
{
[Header("Heat Exchanger Specific Items")]
[SerializeField] private Animator Animator;
private void Update()
{
if (GameStateController.Is(GameState.Simulation))
{
if (Animator.speed == 0)
{
Animator.Play(0, 0, 0f); // Play from beginning
Animator.speed = 0.2f; // Playing
}
}
else
{
if (Animator.speed != 0)
{
Animator.Play(0, 0, 0f); // Jump back to default frame
Animator.speed = 0; // Paused
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2a40d30ecee1430c9a21ab42f4290132
timeCreated: 1776951500