1
This commit is contained in:
@@ -27,7 +27,7 @@ namespace BITKit
|
||||
public class MyHandle:IDisposable
|
||||
{
|
||||
private readonly ValidHandle _validHandle;
|
||||
private bool _isDisable = false;
|
||||
private readonly bool _isDisable;
|
||||
public MyHandle(ValidHandle validHandle,bool isDisable = false)
|
||||
{
|
||||
_validHandle = validHandle;
|
||||
@@ -61,106 +61,76 @@ namespace BITKit
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Allow:{enableHandle}\nElements:{string.Join("\n",objs)}\nDisableElements:{string.Join("\n",disableObjs)}";
|
||||
return $"Allow:{_enableHandle}\nElements:{string.Join("\n",_objs)}\nDisableElements:{string.Join("\n",_disableObjs)}";
|
||||
}
|
||||
|
||||
public ValidHandle() {}
|
||||
public ValidHandle(Action<bool> boolDelegate)
|
||||
{
|
||||
AddListener(boolDelegate);
|
||||
EventOnEnableChanged?.Invoke(enableHandle);
|
||||
_eventOnEnableChanged?.Invoke(_enableHandle);
|
||||
}
|
||||
public static implicit operator bool(ValidHandle validHandle)
|
||||
{
|
||||
return !validHandle._isDisposed && validHandle.enableHandle;
|
||||
return !validHandle._isDisposed && validHandle._enableHandle;
|
||||
}
|
||||
|
||||
public bool Allow => this;
|
||||
|
||||
private bool enableHandle;
|
||||
private bool _enableHandle;
|
||||
/// <summary>
|
||||
/// ⚠️Dont operate this field directly
|
||||
/// </summary>
|
||||
public readonly List<object> objs = new List<object>();
|
||||
private readonly HashSet<object> _objs = new();
|
||||
|
||||
/// <summary>
|
||||
/// ⚠️Dont operate this field directly
|
||||
/// </summary>
|
||||
public readonly List<object> disableObjs = new List<object>();
|
||||
private bool tempEnable;
|
||||
private Action<bool> EventOnEnableChanged;
|
||||
private readonly HashSet<object> _disableObjs = new();
|
||||
private bool _tempEnable;
|
||||
private Action<bool> _eventOnEnableChanged;
|
||||
private readonly ConcurrentQueue<UniTaskCompletionSource> _completionSources = new();
|
||||
private bool _isDisposed;
|
||||
|
||||
public void AddElement(object obj)
|
||||
{
|
||||
if (objs.Contains(obj))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
objs.Add(obj);
|
||||
}
|
||||
_objs.Add(obj);
|
||||
CheckEnable();
|
||||
}
|
||||
|
||||
private void CheckEnable()
|
||||
{
|
||||
tempEnable = objs.Count > 0 && disableObjs.Count == 0;
|
||||
if (tempEnable != enableHandle)
|
||||
_tempEnable = _objs.Count > 0 && _disableObjs.Count == 0;
|
||||
if (_tempEnable == _enableHandle) return;
|
||||
_enableHandle = _tempEnable;
|
||||
_eventOnEnableChanged?.Invoke(_enableHandle);
|
||||
if (_tempEnable) return;
|
||||
if (_completionSources.TryDequeue(out var cs))
|
||||
{
|
||||
enableHandle = tempEnable;
|
||||
if (EventOnEnableChanged is not null)
|
||||
{
|
||||
EventOnEnableChanged.Invoke(enableHandle);
|
||||
}
|
||||
if (tempEnable) return;
|
||||
if (_completionSources.TryDequeue(out var cs))
|
||||
{
|
||||
cs.TrySetResult();
|
||||
}
|
||||
cs.TrySetResult();
|
||||
}
|
||||
}
|
||||
public void RemoveElement(object obj)
|
||||
{
|
||||
if (objs.Contains(obj))
|
||||
if (_objs.Contains(obj))
|
||||
{
|
||||
objs.Remove(obj);
|
||||
_objs.Remove(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
CheckEnable();
|
||||
}
|
||||
public int lenght => objs.Count;
|
||||
public string[] GetElements()
|
||||
{
|
||||
List<string> elementNames = new List<string>();
|
||||
for (int i = 0; i < objs.Count; i++)
|
||||
{
|
||||
elementNames.Add(objs[i].ToString());
|
||||
}
|
||||
return elementNames.ToArray();
|
||||
}
|
||||
public bool Contains(object obj) => objs.Contains(obj);
|
||||
public int Lenght => _objs.Count;
|
||||
public bool Contains(object obj) => _objs.Contains(obj);
|
||||
public void AddDisableElements(object obj)
|
||||
{
|
||||
if (disableObjs.Contains(obj))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
disableObjs.Add(obj);
|
||||
}
|
||||
_disableObjs.Add(obj);
|
||||
CheckEnable();
|
||||
}
|
||||
public void RemoveDisableElements(object obj)
|
||||
{
|
||||
if (disableObjs.Contains(obj))
|
||||
if (_disableObjs.Contains(obj))
|
||||
{
|
||||
disableObjs.Remove(obj);
|
||||
_disableObjs.Remove(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -191,22 +161,22 @@ namespace BITKit
|
||||
}
|
||||
public void Invoke()
|
||||
{
|
||||
var enable = disableObjs.Count == 0 && objs.Count > 0;
|
||||
EventOnEnableChanged?.Invoke(enable);
|
||||
var enable = _disableObjs.Count == 0 && _objs.Count > 0;
|
||||
_eventOnEnableChanged?.Invoke(enable);
|
||||
}
|
||||
public void Invoke(bool value)
|
||||
{
|
||||
EventOnEnableChanged?.Invoke(value);
|
||||
_eventOnEnableChanged?.Invoke(value);
|
||||
}
|
||||
public void AddListener(Action<bool> action)
|
||||
{
|
||||
EventOnEnableChanged+= action;
|
||||
_eventOnEnableChanged+= action;
|
||||
}
|
||||
public void RemoveListener(Action<bool> action)
|
||||
{
|
||||
if(EventOnEnableChanged is not null && action is not null)
|
||||
if(_eventOnEnableChanged is not null && action is not null)
|
||||
{
|
||||
EventOnEnableChanged -= action;
|
||||
_eventOnEnableChanged -= action;
|
||||
}
|
||||
}
|
||||
public UniTask.Awaiter GetAwaiter()
|
||||
@@ -221,17 +191,17 @@ namespace BITKit
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
objs.Clear();
|
||||
disableObjs.Clear();
|
||||
_objs.Clear();
|
||||
_disableObjs.Clear();
|
||||
Invoke();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_isDisposed = true;
|
||||
objs.Clear();
|
||||
disableObjs.Clear();
|
||||
EventOnEnableChanged = null;
|
||||
_objs.Clear();
|
||||
_disableObjs.Clear();
|
||||
_eventOnEnableChanged = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,22 +27,31 @@ namespace BITKit.Physics
|
||||
|
||||
var vertices = _mesh.vertices;
|
||||
|
||||
if (vertices.Length > 256) return false;
|
||||
if (vertices.Length > 2048) return false;
|
||||
|
||||
var minPos = new Vector3(64, 64, 64);
|
||||
var minDistance = 64f;
|
||||
|
||||
for (var index = 0; index < _mesh.triangles.Length; index+=3)
|
||||
{
|
||||
var x = vertices[_mesh.triangles[index]];
|
||||
|
||||
if (Vector3.Distance(x, _position) > minDistance)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var y = vertices[_mesh.triangles[index + 1]];
|
||||
var z = vertices[_mesh.triangles[index + 2]];
|
||||
|
||||
var pos = GeometryUtils.GetPosInTriangle(x, y, z, _position);
|
||||
|
||||
if (Vector3.Distance(pos, _position) < Vector3.Distance(minPos, _position))
|
||||
{
|
||||
minPos = pos;
|
||||
}
|
||||
var distance = Vector3.Distance(pos, _position);
|
||||
|
||||
if (!(distance < minDistance)) continue;
|
||||
|
||||
minPos = pos;
|
||||
minDistance = distance;
|
||||
}
|
||||
|
||||
position = minPos;
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1705803e58f488146b0c364b69f275ff
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "BITKit.Extensions.TranslucentImage",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:ff218ee40fe2b8648ab3234d56415557"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"LeTai_TranslucentImage"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4dea7f9c2d5c3d4abb7467736ee56df
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using LeTai.Asset.TranslucentImage;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class TranslucentService : MonoBehaviour
|
||||
{
|
||||
public static RenderTexture BlurredScreen;
|
||||
[SerializeField] private TranslucentImageSource source;
|
||||
[SerializeField] private RenderTexture blurredScreen;
|
||||
private void LateUpdate()
|
||||
{
|
||||
source.Request();
|
||||
BlurredScreen = blurredScreen = source.BlurredScreen;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14ba5b1e81092234d944bec5c7063bc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,34 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
|
||||
public class TranslucentVisualElement : VisualElement
|
||||
{
|
||||
public new class UxmlFactory : UxmlFactory<TranslucentVisualElement, UxmlTraits> { }
|
||||
public TranslucentVisualElement()
|
||||
{
|
||||
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
generateVisualContent += DrawCanvas;
|
||||
}
|
||||
|
||||
private void DrawCanvas(MeshGenerationContext obj)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnGeometryChanged(GeometryChangedEvent evt)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (BITAppForUnity.IsPlaying is false) return;
|
||||
#endif
|
||||
if (style.display.value is not DisplayStyle.Flex) return;
|
||||
style.backgroundImage = new StyleBackground(Background.FromRenderTexture(TranslucentService.BlurredScreen));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45ff73d2202441b44a5453c22ebf0dab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXTranslucentService : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image image;
|
||||
private float alpha;
|
||||
private void Start()
|
||||
{
|
||||
BITAppForUnity.AllowCursor.AddListener(OnCursor);
|
||||
destroyCancellationToken.Register(Dispose);
|
||||
}
|
||||
private void Dispose()
|
||||
{
|
||||
BITAppForUnity.AllowCursor.RemoveListener(OnCursor);
|
||||
}
|
||||
private void OnCursor(bool obj)
|
||||
{
|
||||
image.enabled = obj;
|
||||
if (obj) alpha = 0;
|
||||
}
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (BITAppForUnity.AllowCursor.Allow && alpha is not 1)
|
||||
{
|
||||
alpha = Mathf.Clamp01(alpha + Time.deltaTime*5);
|
||||
image.color = new Color(0, 0, 0, alpha);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c99210a06ff163b4ab4bfce7ebbccbe9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user