경로 선택 탐색기 팝업 기능 구현

- StandaloneFileBrowser 에셋을 활용한 방법
- dll을 활용한 방법
- 유니티 에디터 자체 기능을 활용한 방
This commit is contained in:
Mingu Kim
2025-12-10 23:28:31 +09:00
parent f0acbe21ad
commit c7d637383f
54 changed files with 3961 additions and 37 deletions

View File

@@ -0,0 +1,52 @@
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using SFB;
[RequireComponent(typeof(Button))]
public class CanvasSampleSaveFileText : MonoBehaviour, IPointerDownHandler {
public Text output;
// Sample text data
private string _data = "Example text created by StandaloneFileBrowser";
#if UNITY_WEBGL && !UNITY_EDITOR
//
// WebGL
//
[DllImport("__Internal")]
private static extern void DownloadFile(string gameObjectName, string methodName, string filename, byte[] byteArray, int byteArraySize);
// Broser plugin should be called in OnPointerDown.
public void OnPointerDown(PointerEventData eventData) {
var bytes = Encoding.UTF8.GetBytes(_data);
DownloadFile(gameObject.name, "OnFileDownload", "sample.txt", bytes, bytes.Length);
}
// Called from browser
public void OnFileDownload() {
output.text = "File Successfully Downloaded";
}
#else
//
// Standalone platforms & editor
//
public void OnPointerDown(PointerEventData eventData) { }
// Listen OnClick event in standlone builds
void Start() {
var button = GetComponent<Button>();
button.onClick.AddListener(OnClick);
}
public void OnClick() {
var path = StandaloneFileBrowser.SaveFilePanel("Title", "", "sample", "txt");
if (!string.IsNullOrEmpty(path)) {
File.WriteAllText(path, _data);
}
}
#endif
}