87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Threading;
|
||
|
using BITKit;
|
||
|
using BITKit.Tween;
|
||
|
using Net.Project.B.NodeCanvas;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using Vuplex.WebView;
|
||
|
using Keyboard = UnityEngine.InputSystem.Keyboard;
|
||
|
|
||
|
|
||
|
namespace Net.Like.Xue.Tokyo
|
||
|
{
|
||
|
public class WebViewController : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private Canvas canvas;
|
||
|
[SerializeField] private RectTransform rectTransform;
|
||
|
[SerializeField] private CanvasWebViewPrefab canvasWebViewPrefab;
|
||
|
|
||
|
[SerializeField] private Button homeButton;
|
||
|
[SerializeField] private Button returnButton;
|
||
|
|
||
|
private readonly ValidHandle _allow = new();
|
||
|
|
||
|
private CancellationTokenSource _cancellationTokenSource = new();
|
||
|
|
||
|
private async void Start()
|
||
|
{
|
||
|
_allow.AddListener(OnAllow);
|
||
|
canvas.enabled = false;
|
||
|
|
||
|
await canvasWebViewPrefab.WaitUntilInitialized();
|
||
|
canvasWebViewPrefab.WebView.UrlChanged += UrlChanged;
|
||
|
|
||
|
homeButton.onClick.AddListener(OnHome);
|
||
|
returnButton.onClick.AddListener(OnReturn);
|
||
|
}
|
||
|
|
||
|
private void OnReturn()
|
||
|
{
|
||
|
canvasWebViewPrefab.WebView.GoBack();
|
||
|
}
|
||
|
|
||
|
private void OnHome()
|
||
|
{
|
||
|
canvasWebViewPrefab.WebView?.LoadUrl(canvasWebViewPrefab.InitialUrl);
|
||
|
}
|
||
|
|
||
|
private void UrlChanged(object sender, UrlChangedEventArgs e)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
private async void OnAllow(bool obj)
|
||
|
{
|
||
|
//BITAppForUnity.AllowCursor.SetElements(this,obj);
|
||
|
//BITInputSystem.AllowInput.SetDisableElements(this,obj);
|
||
|
|
||
|
_cancellationTokenSource?.Cancel();
|
||
|
_cancellationTokenSource = new();
|
||
|
if (obj)
|
||
|
{
|
||
|
OnHome();
|
||
|
|
||
|
canvas.enabled = true;
|
||
|
await BITween.Lerp(x => rectTransform.localScale = new Vector3(x, x, x), 0f, 1f, 1f,Mathf.LerpAngle,_cancellationTokenSource.Token);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await BITween.Lerp(x => rectTransform.localScale = new Vector3(x, x, x), 1f, 0f, 0.16f,Mathf.LerpAngle,_cancellationTokenSource.Token);
|
||
|
canvas.enabled = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
if (Keyboard.current is { upArrowKey: { wasPressedThisFrame: true } })
|
||
|
{
|
||
|
_allow.SetElements(this,!_allow.Allow);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|