1
This commit is contained in:
107
Src/Unity/Scripts/UX/Input/UXAllowInput.cs
Normal file
107
Src/Unity/Scripts/UX/Input/UXAllowInput.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
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
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class UXAllow : ICondition
|
||||
{
|
||||
public bool OnCheck() => UXAllowInput.Allow.Allow;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
Src/Unity/Scripts/UX/Input/UXAllowInput.cs.meta
Normal file
11
Src/Unity/Scripts/UX/Input/UXAllowInput.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 897637fa096036c4d9bf2b210c0ba558
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user