143 lines
4.0 KiB
C#
143 lines
4.0 KiB
C#
using UnityEngine;
|
|
using System.IO;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
namespace EasyMotionRecorder
|
|
{
|
|
public class SavePathManager : MonoBehaviour
|
|
{
|
|
private static SavePathManager _instance;
|
|
public static SavePathManager Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = FindObjectOfType<SavePathManager>();
|
|
if (_instance == null)
|
|
{
|
|
GameObject go = new GameObject("SavePathManager");
|
|
_instance = go.AddComponent<SavePathManager>();
|
|
DontDestroyOnLoad(go);
|
|
}
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
[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;
|
|
public bool ExportHumanoidOnSave => exportHumanoidOnSave;
|
|
public bool ExportGenericOnSave => exportGenericOnSave;
|
|
|
|
private void Awake()
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
InitializePaths();
|
|
}
|
|
else if (_instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
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 string GetMotionSavePath()
|
|
{
|
|
return motionSavePath;
|
|
}
|
|
|
|
public string GetFacialSavePath()
|
|
{
|
|
return motionSavePath; // 모션 경로와 동일하게 설정
|
|
}
|
|
|
|
public string GetObjectSavePath()
|
|
{
|
|
return motionSavePath; // 모션 경로와 동일하게 설정
|
|
}
|
|
|
|
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 ResetToDefaults()
|
|
{
|
|
motionSavePath = "Assets/Resources/Motion";
|
|
facialSavePath = "Assets/Resources/Motion";
|
|
objectSavePath = "Assets/Resources/Motion";
|
|
createSubdirectories = true;
|
|
InitializePaths();
|
|
}
|
|
|
|
public void SynchronizePaths()
|
|
{
|
|
// 모든 경로를 모션 경로와 동일하게 설정
|
|
facialSavePath = motionSavePath;
|
|
objectSavePath = motionSavePath;
|
|
if (createSubdirectories)
|
|
{
|
|
InitializePaths();
|
|
}
|
|
}
|
|
}
|
|
} |