using System; using System.Collections; using System.IO; using UnityEditor; using UnityEngine; namespace DDD { public static class Utils { public static string FixPath(string path) { path = path.Replace('\\', '/'); path = path.Replace("//", "/"); while (path.Length > 0 && path[0] == '/') { path = path.Remove(0, 1); } return path; } public static string FileName(string path) { return Path.GetFileNameWithoutExtension(path); } public static string FolderPath(string path) { return FixPath(Path.GetDirectoryName(path)); } public static void MakeFolderFromFilePath(string filePath) { var paths = FixPath(filePath).Split('/'); var path = ""; for (var i = 0; i < paths.Length - 1; ++i) { path += paths[i] + "/"; if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); AssetDatabase.Refresh(); } } } public static IEnumerator CoolDownCoroutine(float waitTime, Action onCooldownComplete = null) { yield return new WaitForSeconds(waitTime); onCooldownComplete?.Invoke(); } public static void StartUniqueCoroutine(MonoBehaviour owner, ref Coroutine coroutineField, IEnumerator coroutineMethod) { if (coroutineField != null) { owner.StopCoroutine(coroutineField); coroutineField = null; } coroutineField = owner.StartCoroutine(coroutineMethod); } public static void EndUniqueCoroutine(MonoBehaviour owner, ref Coroutine coroutineField) { if (coroutineField != null) { owner.StopCoroutine(coroutineField); coroutineField = null; } } } }