using System.Collections; using System.Collections.Generic; using UnityEngine; namespace YKMoon { public static class GizmosEx { /// /// Draws a gizmo arrow going from the origin position and along the direction Vector3 /// /// Origin. /// Direction. /// Color. public static void DrawArrow(Vector3 origin, Vector3 direction, Color color) { float arrowHeadLength = 3.00f; float arrowHeadAngle = 25.0f; Gizmos.color = color; Gizmos.DrawRay(origin, direction); DrawArrowEnd(origin, direction, color, arrowHeadLength, arrowHeadAngle); } private static void DrawArrowEnd(Vector3 arrowEndPosition, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 40.0f) { if(direction == Vector3.zero) { return; } Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(arrowHeadAngle, 0, 0) * Vector3.back; Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(-arrowHeadAngle, 0, 0) * Vector3.back; Vector3 up = Quaternion.LookRotation(direction) * Quaternion.Euler(0, arrowHeadAngle, 0) * Vector3.back; Vector3 down = Quaternion.LookRotation(direction) * Quaternion.Euler(0, -arrowHeadAngle, 0) * Vector3.back; Gizmos.color = color; Gizmos.DrawRay(arrowEndPosition + direction, right * arrowHeadLength); Gizmos.DrawRay(arrowEndPosition + direction, left * arrowHeadLength); Gizmos.DrawRay(arrowEndPosition + direction, up * arrowHeadLength); Gizmos.DrawRay(arrowEndPosition + direction, down * arrowHeadLength); } /// /// Draw a Rectangle with given offset and size. /// /// /// /// public static void DrawRectangle(Transform transform, Vector3 offset, Vector3 size) { Gizmos.matrix = Matrix4x4.TRS(transform.TransformPoint(offset), transform.rotation, transform.lossyScale); Gizmos.DrawWireCube(Vector3.zero, size); } /// /// Reset Gizmos color to white. /// public static void ResetGizmosColor() { Gizmos.color = Color.white; } } }