ProjectDDD/Assets/_Datas/02.Scripts/Utilities/Utils.cs
2025-07-04 16:20:28 +09:00

79 lines
2.1 KiB (Stored with Git LFS)
C#

using System;
using System.Collections;
using System.IO;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
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);
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
}
}
}
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;
}
}
}
}