using System;
using Sirenix.OdinInspector;
using UnityEngine;
namespace VOID.Generic.AreaOfEffect
{
[Serializable]
public abstract class AbstractAreaOfEffect
{
[SerializeField] private bool fixedRotation;
[SerializeField] [MinValue(-180), MaxValue(180)] private float offsetRotation;
///
/// Calculates final rotation that include AOE offset rotation and/or fixed rotation.
///
/// Position on AOE collider
/// Position where AOE collider should look
/// Quaternion to put into tranform.rotation
public Quaternion GetRotation(Vector3 from, Vector3 to)
{
// Ignore look angle, we use only offset rotation
if (fixedRotation) return Quaternion.Euler(new Vector3(0, offsetRotation, 0));
// Include offset rotation into look rotation
var directionNormalized = (new Vector2(to.x, to.z) - new Vector2(from.x, from.z)).normalized;
var lookAngleY = Vector2.SignedAngle(Vector2.up, directionNormalized) * -1;
return Quaternion.Euler(new Vector3(0, lookAngleY + offsetRotation, 0));
}
///
/// Returns mesh of this area of effect.
///
public abstract Mesh GetMesh();
///
/// Adds prepared collider to given GameObject.
///
public abstract Collider AddCollider(GameObject gameObject);
}
}