73 lines
1.8 KiB
C#
73 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using AsteroidGame.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace AsteroidGame.Handlers
|
|
{
|
|
public class PowerHandler : HandlerBase
|
|
{
|
|
[Header("State")]
|
|
[SerializeField] private int _powerConsumption;
|
|
[SerializeField] private int _powerCapacity;
|
|
[SerializeField] private float _powerFactor;
|
|
|
|
[Header("Connections")]
|
|
[SerializeField] private BuildingHandler _buildingHandler;
|
|
|
|
#region Private
|
|
|
|
[SerializeField] private List<StructureBase> _activeStructures = new();
|
|
|
|
#endregion
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
_buildingHandler = FindObjectOfType<BuildingHandler>();
|
|
_activeStructures = _buildingHandler.GetActiveStructures();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
_powerConsumption = 0;
|
|
_powerCapacity = 0;
|
|
foreach (var structure in _activeStructures)
|
|
{
|
|
if (structure.IsConsumer)
|
|
{
|
|
_powerConsumption += structure.GetMaxPower();
|
|
}
|
|
|
|
if (structure.IsGenerator)
|
|
{
|
|
_powerCapacity += structure.GetMaxPower();
|
|
}
|
|
}
|
|
|
|
if (_powerCapacity > 0)
|
|
{
|
|
_powerFactor = (float)_powerConsumption / _powerCapacity;
|
|
}
|
|
else
|
|
{
|
|
_powerFactor = 0;
|
|
}
|
|
}
|
|
|
|
public int GetMaxPower()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int GetCurrentPower()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public float GetPowerFactor()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |