2024-04-19 23:32:37 +02:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Assertions;
|
|
|
|
|
|
|
|
[RequireComponent(typeof(HealthComponent))]
|
|
|
|
public abstract class Tower : MonoBehaviour
|
|
|
|
{
|
2024-04-20 15:56:26 +02:00
|
|
|
public bool towerSelected { get; set; } = true;
|
|
|
|
|
2024-04-20 13:15:33 +02:00
|
|
|
[SerializeField] protected EditableArc horizontalArc;
|
|
|
|
[SerializeField] protected EditableArc verticalArc;
|
2024-04-19 23:32:37 +02:00
|
|
|
|
2024-04-20 13:15:33 +02:00
|
|
|
protected HealthComponent healthComp;
|
2024-04-19 23:32:37 +02:00
|
|
|
|
2024-04-20 01:40:53 +02:00
|
|
|
// Getters
|
|
|
|
public Vector2 HorizontalRotationMinMax => horizontalArc.RotationMinMax;
|
|
|
|
public Vector2 VerticalRotationMinMax => verticalArc.RotationMinMax;
|
|
|
|
public float HorizontalRotation => horizontalArc.Value;
|
|
|
|
public float VerticalRotation => verticalArc.Value;
|
|
|
|
|
|
|
|
protected virtual void Awake()
|
2024-04-19 23:32:37 +02:00
|
|
|
{
|
|
|
|
healthComp = GetComponent<HealthComponent>();
|
|
|
|
Assert.IsNotNull(healthComp);
|
2024-04-20 14:23:55 +02:00
|
|
|
|
|
|
|
horizontalArc.Value.AddListener(SnapVerticalToHorizontal);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SnapVerticalToHorizontal(float horizontalAngle)
|
|
|
|
{
|
|
|
|
verticalArc.transform.rotation = Quaternion.Euler(verticalArc.transform.rotation.eulerAngles.x, horizontalAngle, verticalArc.transform.rotation.eulerAngles.z);
|
2024-04-20 13:15:33 +02:00
|
|
|
}
|
2024-04-19 23:32:37 +02:00
|
|
|
|
2024-04-20 13:15:33 +02:00
|
|
|
protected virtual void OnDestroy()
|
|
|
|
{
|
2024-04-20 14:23:55 +02:00
|
|
|
horizontalArc.Value.RemoveListener(SnapVerticalToHorizontal);
|
2024-04-19 23:32:37 +02:00
|
|
|
}
|
|
|
|
}
|