Net.Like.Xue.Tokyo/Assets/BITKit/Unity/Scripts/UX/ApplicationFile/UXApplicationFile.cs

58 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using BITKit.IO;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.UIElements;
namespace BITKit.UX
{
#if UNITY_5_3_OR_NEWER
public class UXApplicationFile : MonoBehaviour
{
[SerializeReference, SubclassSelector] private IApplicationFile applicationFile;
[UXBindPath("save-button")]
private Button _saveButton;
[UXBindPath("save-as-button")]
private Button _saveAsButton;
[UXBindPath("reload-button")]
private Button _reloadButton;
[UXBindPath("load-button")]
private Button _loadButton;
[UXBindPath("save-path-label")]
private Label _savePathLabel;
private void Start()
{
UXUtils.Inject(this);
_saveButton.clicked += applicationFile.Save;
_loadButton.clicked += ()=>applicationFile.Load();
_saveAsButton.clicked += ()=>applicationFile.SaveAs();
_reloadButton.clicked += applicationFile.Reload;
applicationFile.OnPathChanged+=OnPathChanged;
OnPathChanged(null,applicationFile.Current);
_reloadButton.SetEnabled(false);
}
private async void OnPathChanged(string arg1, string arg2)
{
await UniTask.SwitchToMainThread();
if (destroyCancellationToken.IsCancellationRequested) return;
if (arg2 is not null)
{
_savePathLabel.text = arg2;
_reloadButton.SetEnabled(true);
}
else
{
_reloadButton.SetEnabled(false);
}
}
}
#endif
}