Homebound / Scripts / EditingAndGizmos / DrawArrow.cs
DrawArrow.cs
Raw
using UnityEngine;

/// <summary>
/// Used to draw arrow Gizmos for various components, such as the launchers and wind direction indicators
/// </summary>
internal static class DrawArrow
{
    /// <summary>
    /// Draws general arrow ray for Gizmo without color parameter
    /// </summary>
    /// <param name="pos">Origin of the Arrow</param>
    /// <param name="direction">The direction that the arrow is pointing towards</param>
    /// <param name="arrowHeadLength">The length that the arrow should span</param>
    /// <param name="arrowHeadAngle">The angle of the tip of the arrow to have the proper shape bent into position</param>
    internal static void ForGizmo(Vector3 pos, Vector3 direction, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
    {
        Gizmos.DrawRay(pos, direction);

        Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + arrowHeadAngle, 0) * new Vector3(0f, 0f, 1f);
        Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - arrowHeadAngle, 0) * new Vector3(0f, 0f, 1f);
        Gizmos.DrawRay(pos + direction, right * arrowHeadLength);
        Gizmos.DrawRay(pos + direction, left * arrowHeadLength);
    }

    /// <summary>
    /// Draws general arrow ray for Gizmo with color included
    /// </summary>
    /// <param name="pos">Origin of the Arrow</param>
    /// <param name="direction">The direction that the arrow is pointing towards</param>
    /// <param name="color">Color of the arrow</param>
    /// <param name="arrowHeadLength">The length that the arrow should span</param>
    /// <param name="arrowHeadAngle">The angle of the tip of the arrow to have the proper shape bent into position</param>
    internal static void ForGizmo(Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
    {
        Gizmos.color = color;
        Gizmos.DrawRay(pos, direction);

        Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + arrowHeadAngle, 0) * new Vector3(0f, 0f, 1f);
        Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - arrowHeadAngle, 0) * new Vector3(0f, 0f, 1f);
        Gizmos.DrawRay(pos + direction, right * arrowHeadLength);
        Gizmos.DrawRay(pos + direction, left * arrowHeadLength);
    }

    /// <summary>
    /// Draws general arrow ray for Debugging with no color parameter
    /// </summary>
    /// <param name="pos">Origin of the Arrow</param>
    /// <param name="direction">The direction that the arrow is pointing towards</param>
    /// <param name="arrowHeadLength">The length that the arrow should span</param>
    /// <param name="arrowHeadAngle">The angle of the tip of the arrow to have the proper shape bent into position</param>
    internal static void ForDebug(Vector3 pos, Vector3 direction, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
    {
        Debug.DrawRay(pos, direction);

        Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + arrowHeadAngle, 0) * new Vector3(0f, 0f, 1f);
        Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - arrowHeadAngle, 0) * new Vector3(0f, 0f, 1f);
        Debug.DrawRay(pos + direction, right * arrowHeadLength);
        Debug.DrawRay(pos + direction, left * arrowHeadLength);
    }

    /// <summary>
    /// Draws general arrow ray for Debugging with color included
    /// </summary>
    /// <param name="pos">Origin of the Arrow</param>
    /// <param name="direction">The direction that the arrow is pointing towards</param>
    /// <param name="color">Color of the arrow</param>
    /// <param name="arrowHeadLength">The length that the arrow should span</param>
    /// <param name="arrowHeadAngle">The angle of the tip of the arrow to have the proper shape bent into position</param>
    internal static void ForDebug(Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
    {
        Debug.DrawRay(pos, direction, color);

        Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + arrowHeadAngle, 0) * new Vector3(0f, 0f, 1f);
        Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - arrowHeadAngle, 0) * new Vector3(0f, 0f, 1f);
        Debug.DrawRay(pos + direction, right * arrowHeadLength, color);
        Debug.DrawRay(pos + direction, left * arrowHeadLength, color);
    }
}