103 lines
1.9 KiB
C#
103 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.Pool;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace BITKit.UX
|
|
{
|
|
public class UXAllowInput : MonoBehaviour
|
|
{
|
|
[RuntimeInitializeOnLoadMethod]
|
|
private static void Reload()
|
|
{
|
|
Allow.Clear();
|
|
}
|
|
internal static readonly ValidHandle Allow=new();
|
|
[SerializeField] private UIDocument document;
|
|
private IPanel _panel;
|
|
|
|
[SerializeField, ReadOnly] private bool isAllow;
|
|
[SerializeField, ReadOnly] private bool globalAllow;
|
|
[SerializeField, ReadOnly] private string blockBy;
|
|
|
|
private bool isLocked;
|
|
private void Start()
|
|
{
|
|
_panel = document.rootVisualElement.panel;
|
|
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Allow.AddElement(this);
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
Allow.RemoveElement(this);
|
|
}
|
|
private void Update()
|
|
{
|
|
var mousePos = Mouse.current.position.ReadValue();
|
|
|
|
mousePos.y = Screen.height - mousePos.y;
|
|
|
|
var ve =_panel.Pick(RuntimePanelUtils.ScreenToPanel(_panel,mousePos ));
|
|
|
|
if (ve is not null)
|
|
{
|
|
var list = ListPool<string>.Get();
|
|
var v = ve;
|
|
{
|
|
while (true)
|
|
{
|
|
list.Add(v.name);
|
|
if (v.parent is not null)
|
|
{
|
|
v = v.parent;
|
|
continue;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
blockBy = string.Join("\\", list);
|
|
|
|
list.Clear();
|
|
ListPool<string>.Release(list);
|
|
}
|
|
else
|
|
{
|
|
blockBy = "unblocked";
|
|
}
|
|
switch (ve,Mouse.current.press.isPressed)
|
|
{
|
|
|
|
case (null,false) when isLocked is false:
|
|
Allow.AddElement(this);
|
|
Allow.RemoveDisableElements(this);
|
|
break;
|
|
case (not null,false):
|
|
Allow.RemoveElement(this);
|
|
Allow.AddDisableElements(this);
|
|
break;
|
|
case (not null,true):
|
|
isLocked = true;
|
|
break;
|
|
case (null,false):
|
|
isLocked = false;
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
isAllow = ve is null;
|
|
globalAllow = Allow.Allow;
|
|
}
|
|
}
|
|
}
|
|
|