176 lines
5.2 KiB
C#
176 lines
5.2 KiB
C#
using UnityEngine;
|
|
using System.IO;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
namespace EasyMotionRecorder
|
|
{
|
|
public class SavePathManager : MonoBehaviour
|
|
{
|
|
[Header("저장 경로 설정")]
|
|
[SerializeField] private string motionSavePath = "Assets/Resources/Motion";
|
|
[SerializeField] private string facialSavePath = "Assets/Resources/Motion";
|
|
[SerializeField] private string objectSavePath = "Assets/Resources/Motion";
|
|
|
|
[Header("설정")]
|
|
[SerializeField] private bool createSubdirectories = true;
|
|
|
|
[Header("자동 출력 옵션")]
|
|
[SerializeField] private bool exportHumanoidOnSave = false;
|
|
[SerializeField] private bool exportGenericOnSave = false;
|
|
[SerializeField] private bool exportFBXAsciiOnSave = false;
|
|
[SerializeField] private bool exportFBXBinaryOnSave = false;
|
|
|
|
[Header("인스턴스 설정")]
|
|
[SerializeField] private string instanceID = "";
|
|
[SerializeField] private bool useDontDestroyOnLoad = false;
|
|
|
|
public bool ExportHumanoidOnSave => exportHumanoidOnSave;
|
|
public bool ExportGenericOnSave => exportGenericOnSave;
|
|
public bool ExportFBXAsciiOnSave => exportFBXAsciiOnSave;
|
|
public bool ExportFBXBinaryOnSave => exportFBXBinaryOnSave;
|
|
public string InstanceID => instanceID;
|
|
|
|
private void Awake()
|
|
{
|
|
// 인스턴스 ID가 비어있으면 자동 생성
|
|
if (string.IsNullOrEmpty(instanceID))
|
|
{
|
|
instanceID = System.Guid.NewGuid().ToString().Substring(0, 8);
|
|
}
|
|
|
|
// DontDestroyOnLoad 설정 (선택적)
|
|
if (useDontDestroyOnLoad)
|
|
{
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
InitializePaths();
|
|
}
|
|
|
|
private void InitializePaths()
|
|
{
|
|
if (createSubdirectories)
|
|
{
|
|
CreateDirectoryIfNotExists(motionSavePath);
|
|
CreateDirectoryIfNotExists(facialSavePath);
|
|
}
|
|
}
|
|
|
|
private void CreateDirectoryIfNotExists(string path)
|
|
{
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
#if UNITY_EDITOR
|
|
AssetDatabase.Refresh();
|
|
#endif
|
|
}
|
|
}
|
|
|
|
public static DirectoryInfo SafeCreateDirectory(string path)
|
|
{
|
|
if (!Directory.Exists(path))
|
|
{
|
|
return Directory.CreateDirectory(path);
|
|
}
|
|
return new DirectoryInfo(path);
|
|
}
|
|
|
|
public string GetMotionSavePath()
|
|
{
|
|
return motionSavePath;
|
|
}
|
|
|
|
public string GetFacialSavePath()
|
|
{
|
|
return facialSavePath;
|
|
}
|
|
|
|
public string GetObjectSavePath()
|
|
{
|
|
return objectSavePath;
|
|
}
|
|
|
|
public void SetMotionSavePath(string path)
|
|
{
|
|
motionSavePath = path;
|
|
if (createSubdirectories)
|
|
CreateDirectoryIfNotExists(path);
|
|
}
|
|
|
|
public void SetFacialSavePath(string path)
|
|
{
|
|
facialSavePath = path;
|
|
if (createSubdirectories)
|
|
CreateDirectoryIfNotExists(path);
|
|
}
|
|
|
|
public void SetObjectSavePath(string path)
|
|
{
|
|
objectSavePath = path;
|
|
if (createSubdirectories)
|
|
CreateDirectoryIfNotExists(path);
|
|
}
|
|
|
|
public void SetCreateSubdirectories(bool create)
|
|
{
|
|
createSubdirectories = create;
|
|
if (create)
|
|
{
|
|
InitializePaths();
|
|
}
|
|
}
|
|
|
|
public void SetInstanceID(string id)
|
|
{
|
|
instanceID = id;
|
|
}
|
|
|
|
public void SetUseDontDestroyOnLoad(bool use)
|
|
{
|
|
useDontDestroyOnLoad = use;
|
|
}
|
|
|
|
public void ResetToDefaults()
|
|
{
|
|
motionSavePath = "Assets/Resources/Motion";
|
|
facialSavePath = "Assets/Resources/Motion";
|
|
objectSavePath = "Assets/Resources/Motion";
|
|
createSubdirectories = true;
|
|
|
|
// 자동 출력 옵션 초기화
|
|
exportHumanoidOnSave = false;
|
|
exportGenericOnSave = false;
|
|
exportFBXAsciiOnSave = false;
|
|
exportFBXBinaryOnSave = false;
|
|
|
|
InitializePaths();
|
|
}
|
|
|
|
public void SynchronizePaths()
|
|
{
|
|
// 모든 경로를 모션 경로와 동일하게 설정
|
|
facialSavePath = motionSavePath;
|
|
objectSavePath = motionSavePath;
|
|
if (createSubdirectories)
|
|
{
|
|
InitializePaths();
|
|
}
|
|
}
|
|
|
|
// 인스턴스별 고유 경로 생성
|
|
public string GetInstanceSpecificPath(string basePath)
|
|
{
|
|
if (string.IsNullOrEmpty(instanceID))
|
|
return basePath;
|
|
|
|
string directory = Path.GetDirectoryName(basePath);
|
|
string fileName = Path.GetFileNameWithoutExtension(basePath);
|
|
string extension = Path.GetExtension(basePath);
|
|
|
|
return Path.Combine(directory, $"{fileName}_{instanceID}{extension}");
|
|
}
|
|
}
|
|
} |