Files
Studio/Assets/Scripts/XED/UI/TreeView/ScrollViewMenu_ImportExport.cs

68 lines
2.3 KiB
C#
Raw Normal View History

2025-02-19 17:24:26 +09:00
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
2025-02-21 11:57:09 +09:00
using XRLib.UI;
2025-02-19 17:24:26 +09:00
using XED.Asset;
using XED.Hierarchy;
namespace XED.UI
{
public class ScrollViewMenu_ImportExport : PanelBase, IDeselectHandler
{
private Canvas canvas;
private CustomScrollRect scrollRect;
private Button btnExport;
private Button btnImport;
private Selectable selectable;
private void Awake()
{
canvas = GetComponentInParent<Canvas>();
selectable = GetComponent<Selectable>();
foreach (Button btn in GetComponentsInChildren<Button>())
{
if (btn.gameObject.name.Equals("Export"))
{
btnExport = btn;
}
else if (btn.gameObject.name.Equals("Import"))
{
btnImport = btn;
}
}
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
public override void AfterAwake()
{
var customAssetConnector = FindSingle<CustomAssetConnector>();
btnExport.onClick.AddListener(customAssetConnector.SaveSelectedAssetDatasToLocal);
btnImport.onClick.AddListener(customAssetConnector.LoadLocalAssetDatas);
scrollRect = FindSingle<Canvas_Windows>().panel_assetlibrary.scrollRect;
scrollRect.menuPopup = gameObject;
SetActive(false);
}
protected override void OnEnable()
{
base.OnEnable();
selectable.Select();
RectTransformUtility.ScreenPointToLocalPointInRectangle(
canvas.transform as RectTransform,
Input.mousePosition,
canvas.worldCamera,
out Vector2 pos
);
transform.position = canvas.transform.TransformPoint(pos);
}
public void OnDeselect(BaseEventData eventData)
{
StartCoroutine(CoroutineDelayedClose());
}
IEnumerator CoroutineDelayedClose()
{
yield return new WaitForSeconds(0.1f);
gameObject.SetActive(false);
yield return null;
}
}
}