using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif namespace BioIK { public static class Utility { public const double Deg2Rad = 0.017453292; public const double Rad2Deg = 57.29578049; public const double PI = 3.14159265358979; public static void Destroy(Component c) { if(c == null) { return; } #if UNITY_EDITOR if(Application.isPlaying) { Object.Destroy(c); } else if(!EditorApplication.isPlayingOrWillChangePlaymode) { Undo.DestroyObjectImmediate(c); } #else Object.Destroy(c); #endif } public static Vector3 DAZ2Unity(Vector3 angles) { return (Quaternion.Euler(180f, 0f, 0f) * Quaternion.Euler(angles.x, angles.y, angles.z)).eulerAngles; } public static Vector3 Unity2DAZ(Vector3 angles) { return (Quaternion.Euler(-180f, 0f, 0f) * Quaternion.Euler(angles.x, angles.y, angles.z)).eulerAngles; } public static System.DateTime GetTimestamp() { return System.DateTime.Now; } public static double GetElapsedTime(System.DateTime timestamp) { return (System.DateTime.Now-timestamp).Duration().TotalSeconds; } public static void Cleanup(Transform t) { /* BioSegment segment = t.GetComponent(); if(segment != null) { if(segment.Joint != null) { segment.Joint.Remove(); } foreach(BioObjective objective in segment.Objectives) { objective.Remove(); } Destroy(segment); } */ foreach(BioJoint joint in t.GetComponents()) { joint.Erase(); } foreach(BioObjective objective in t.GetComponents()) { objective.Erase(); } foreach(BioSegment segment in t.GetComponents()) { Destroy(segment); } for(int i=0; i