1
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c8c71e08d0a2544aae8e62cd2b86af2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user