44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ButtonContentLoader : MonoBehaviour
|
|
{
|
|
[Header("文件夹路径")]
|
|
public string folderPath;
|
|
|
|
private string basePath;
|
|
[Header("展示面板预制体")]
|
|
public GameObject contentPanelPrefab;
|
|
|
|
//[Header("面板挂载位置")]
|
|
Transform parentTransform;
|
|
|
|
private GameObject currentPanelInstance;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
|
|
parentTransform = GameObject.Find("FileReader").transform;
|
|
basePath = Application.streamingAssetsPath;
|
|
GetComponent<Button>().onClick.AddListener(OnClick);
|
|
folderPath = basePath + "/展示资源/" + folderPath;
|
|
}
|
|
public void OnClick()
|
|
{
|
|
// 如果已经打开面板,就先关闭
|
|
//if (currentPanelInstance != null)
|
|
//{
|
|
// Destroy(currentPanelInstance);
|
|
//}
|
|
|
|
// 实例化预制体
|
|
currentPanelInstance = Instantiate(contentPanelPrefab, parentTransform);
|
|
|
|
// 获取 ContentViewer 组件
|
|
ContentViewer viewer = currentPanelInstance.GetComponentInChildren<ContentViewer>();
|
|
viewer.LoadFolder(folderPath);
|
|
}
|
|
}
|