OldBlueWater/BlueWater/Assets/02.Scritps/Utility/Utils.cs

53 lines
1.9 KiB
C#
Raw Normal View History

using System.Diagnostics;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Assertions;
// ReSharper disable once CheckNamespace
namespace BlueWater
{
public class Utils
{
/// <summary>
/// 각도를 통해 방향값을 반환하는 함수
/// </summary>
public static Vector3 AngleToDir(float angle)
{
var radian = angle * Mathf.Deg2Rad;
return new Vector3(Mathf.Sin(radian), 0f, Mathf.Cos(radian)).normalized;
}
// public static T FindTaskAndAssert<T>(BehaviorTree behaviorTree) where T : Task
// {
// var newBehaviorTask = behaviorTree.FindTask<T>();
// Assert.IsNotNull(newBehaviorTask, typeof(T) + "타입의 Task가 존재하지 않습니다.");
//
// return newBehaviorTask;
// }
public static T GetComponentAndAssert<T>(Transform componentLocation) where T : class
{
var newComponent = componentLocation.GetComponent<T>();
Assert.IsNotNull(newComponent, typeof(T) + "타입의 Component가 존재하지 않습니다.");
return newComponent;
}
public static bool ArrivedAgentDestination(NavMeshAgent agent) =>
!agent.pathPending && agent.remainingDistance <= agent.stoppingDistance;
/// <summary>
/// 메서드를 누가 호출하는지 알려주는 메서드입니다
/// 메서드 마지막에 이 함수를 호출하면 됩니다
/// </summary>
public static void WhereCallThisFunction()
{
var stackTrace = new StackTrace();
var stackFrame = stackTrace.GetFrame(1);
var method = stackFrame.GetMethod();
var className = method.DeclaringType?.Name;
var methodName = method.Name;
UnityEngine.Debug.Log($"Call {className}.{methodName}");
}
}
}