경로 선택 탐색기 팝업 기능 구현
- StandaloneFileBrowser 에셋을 활용한 방법 - dll을 활용한 방법 - 유니티 에디터 자체 기능을 활용한 방
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using SFB;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEditor;
|
||||
|
||||
public class DirectorySelect : MonoBehaviour
|
||||
{
|
||||
const string BASIC_DIRECTORY = "C://";
|
||||
public string fileDirectory;
|
||||
public string selectedFolderPath;
|
||||
|
||||
// OS별 기본 경로를 const 대신 static readonly 또는 private 필드로 정의
|
||||
private static readonly string WINDOWS_DIRECTORY = "C:\\"; // Windows 경로는 이중 백슬래시를 사용하거나 @"C:\" 형태로 사용하는 것이 일반적입니다.
|
||||
@@ -20,29 +25,79 @@ public class DirectorySelect : MonoBehaviour
|
||||
// OS에 맞는 기본 경로 설정
|
||||
string basicDirectory = GetBasicDirectory();
|
||||
inputDirectory.text = basicDirectory;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnSelect(string[] path)
|
||||
{
|
||||
Debug.Log(path.ToString());
|
||||
|
||||
if (path.Length > 0)
|
||||
{
|
||||
selectedFolderPath = path[0];
|
||||
}
|
||||
}
|
||||
|
||||
public void Search()
|
||||
{
|
||||
StandaloneFileBrowser.OpenFolderPanelAsync(
|
||||
"폴더 선택", // 팝업 제목
|
||||
"", // 기본 디렉토리
|
||||
false, // 다중 폴더 선택 허용 여부 (false: 1개만 선택)
|
||||
(string[] paths) => {
|
||||
if (paths.Length > 0)
|
||||
{
|
||||
string selectedPath = paths[0];
|
||||
Debug.Log("선택된 폴더 경로: " + selectedPath);
|
||||
// TODO: 선택된 폴더 경로를 사용하여 로직 구현
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("폴더 선택 취소됨.");
|
||||
}
|
||||
}
|
||||
);
|
||||
// 유니티 에디터 자체 기능 사용 작동함...ㅠ
|
||||
EditorUtility.OpenFolderPanel("디렉토리 선택", inputDirectory.text, "");
|
||||
|
||||
// StandaloneFileBrowser.OpenFolderPanelAsync("", "", false, OnSelect);
|
||||
|
||||
// // Windows
|
||||
// if (UnityEngine.Application.platform == RuntimePlatform.WindowsPlayer ||
|
||||
// UnityEngine.Application.platform == RuntimePlatform.WindowsEditor)
|
||||
// {
|
||||
// FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
|
||||
// folderBrowserDialog.Description = "디렉토리 선택";
|
||||
//
|
||||
// if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||||
// {
|
||||
// selectedFolderPath = folderBrowserDialog.SelectedPath;
|
||||
// }
|
||||
// }
|
||||
// // macOS (OSX) 및 Linux
|
||||
// else if (UnityEngine.Application.platform == RuntimePlatform.OSXPlayer ||
|
||||
// UnityEngine.Application.platform == RuntimePlatform.OSXEditor ||
|
||||
// UnityEngine.Application.platform == RuntimePlatform.LinuxPlayer ||
|
||||
// UnityEngine.Application.platform == RuntimePlatform.LinuxEditor)
|
||||
// {
|
||||
// // 1. OpenFolderPanelAsync를 사용하여 폴더 선택 팝업을 띄웁니다.
|
||||
// // 비동기 방식이므로, 팝업이 닫힐 때 실행될 콜백 함수를 인자로 넘깁니다.
|
||||
// StandaloneFileBrowser.OpenFolderPanelAsync(
|
||||
// "경로를 선택하세요", // 팝업 창 제목
|
||||
// inputDirectory.text, // 시작 경로: 현재 inputField의 경로를 기본값으로 사용
|
||||
// false, // 다중 선택 허용 여부 (false: 폴더 1개만 선택)
|
||||
// (string[] paths) => {
|
||||
// // 2. 팝업이 닫힌 후 실행되는 콜백 함수 (람다 표현식)
|
||||
// if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0]))
|
||||
// {
|
||||
// // 선택된 경로가 있다면
|
||||
// selectedFolderPath = paths[0];
|
||||
//
|
||||
// // InputField에 선택된 경로를 업데이트합니다.
|
||||
// if (inputDirectory != null)
|
||||
// {
|
||||
// inputDirectory.text = selectedFolderPath;
|
||||
// }
|
||||
//
|
||||
// Debug.Log("선택된 폴더 경로: " + selectedFolderPath);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // 선택 취소됨
|
||||
// Debug.Log("폴더 선택이 취소되었습니다.");
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // 기타 플랫폼 (예: WebGL, Android, iOS)
|
||||
// // macOS/Linux와 동일한 경로를 기본값으로 사용하거나,
|
||||
// // 해당 플랫폼에 맞는 다른 경로를 반환할 수 있습니다.
|
||||
// // return MAC_LINUX_DIRECTORY;
|
||||
// }
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -62,16 +117,16 @@ public class DirectorySelect : MonoBehaviour
|
||||
// macOS와 Linux는 파일 시스템 구조가 유사합니다 (슬래시 / 사용).
|
||||
// 유니티 편집기(Editor)나 빌드된 플레이어(Player) 모두에서 확인 가능합니다.
|
||||
|
||||
if (Application.platform == RuntimePlatform.WindowsPlayer ||
|
||||
Application.platform == RuntimePlatform.WindowsEditor)
|
||||
if (UnityEngine.Application.platform == RuntimePlatform.WindowsPlayer ||
|
||||
UnityEngine.Application.platform == RuntimePlatform.WindowsEditor)
|
||||
{
|
||||
// Windows
|
||||
return WINDOWS_DIRECTORY;
|
||||
}
|
||||
else if (Application.platform == RuntimePlatform.OSXPlayer ||
|
||||
Application.platform == RuntimePlatform.OSXEditor ||
|
||||
Application.platform == RuntimePlatform.LinuxPlayer ||
|
||||
Application.platform == RuntimePlatform.LinuxEditor)
|
||||
else if (UnityEngine.Application.platform == RuntimePlatform.OSXPlayer ||
|
||||
UnityEngine.Application.platform == RuntimePlatform.OSXEditor ||
|
||||
UnityEngine.Application.platform == RuntimePlatform.LinuxPlayer ||
|
||||
UnityEngine.Application.platform == RuntimePlatform.LinuxEditor)
|
||||
{
|
||||
// macOS (OSX) 및 Linux
|
||||
return MAC_LINUX_DIRECTORY;
|
||||
|
||||
Reference in New Issue
Block a user