99 lines
2.2 KiB
C#
99 lines
2.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit.Mod;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
using static BITKit.Mod.DotNetSdkRoslynService;
|
|
namespace BITKit.UX
|
|
{
|
|
public class UXDotNetSdkRoslynService : MonoBehaviour
|
|
{
|
|
[UXBindPath("install-roslyn-button")]
|
|
private Button _installButton;
|
|
[UXBindPath("uninstall-roslyn-button")]
|
|
private Button _uninstallButton;
|
|
[UXBindPath("install-roslyn-fill")]
|
|
private VisualElement _installFill;
|
|
private void OnEnable()
|
|
{
|
|
OnInstall+=_OnInstall;
|
|
OnInstalled+=_OnInstalled;
|
|
OnUnInstalled+=_OnUnInstalled;
|
|
OnDownloadProgress+=_OnDownloadProgress;
|
|
OnInstallFailed += _OnInstallFailed;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
OnInstall-=_OnInstall;
|
|
OnInstalled-=_OnInstalled;
|
|
OnUnInstalled-=_OnUnInstalled;
|
|
OnDownloadProgress-=_OnDownloadProgress;
|
|
OnInstallFailed -= _OnInstallFailed;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
UXUtils.Inject(this);
|
|
|
|
if (Installed)
|
|
{
|
|
_OnInstalled();
|
|
}
|
|
else
|
|
{
|
|
_OnUnInstalled();
|
|
}
|
|
_installButton.clicked +=()=>Install().Forget();
|
|
_uninstallButton.clicked +=()=>
|
|
{
|
|
_uninstallButton.SetEnabled(false);
|
|
UnInstall().Forget();
|
|
};
|
|
|
|
}
|
|
private void _OnInstall()
|
|
{
|
|
_installButton.text = "准备中...";
|
|
_installButton.SetEnabled(false);
|
|
_uninstallButton.SetEnabled(false);
|
|
}
|
|
private void _OnUnInstalled()
|
|
{
|
|
_installButton.text = "安装";
|
|
_uninstallButton.SetEnabled(false);
|
|
_installButton.SetEnabled(true);
|
|
_installFill.style.width = new StyleLength(Length.Percent(0));
|
|
}
|
|
private void _OnInstalled()
|
|
{
|
|
_installButton.text = "重新安装";
|
|
_installButton.SetEnabled(true);
|
|
_uninstallButton.SetEnabled(true);
|
|
_installFill.style.width = new StyleLength(Length.Percent(0));
|
|
}
|
|
private void _OnDownloadProgress(float progress)
|
|
{
|
|
if (progress >= 1)
|
|
{
|
|
_installButton.text = "安装中...";
|
|
}
|
|
else
|
|
{
|
|
_installButton.text = $"下载中...{progress:P}";
|
|
}
|
|
|
|
_installFill.style.width = new StyleLength(Length.Percent((int)(progress * 100)));
|
|
}
|
|
|
|
private void _OnInstallFailed(Exception e)
|
|
{
|
|
_installButton.tooltip = e.Message;
|
|
}
|
|
}
|
|
|
|
}
|