upgrade
This commit is contained in:
parent
dfbcd03756
commit
6df4649c64
|
@ -28,6 +28,7 @@ namespace BITKit
|
|||
[System.Serializable]
|
||||
public record AppSettings
|
||||
{
|
||||
public bool AllowInitialize = true;
|
||||
public List<string> whiteList = new();
|
||||
public List<string> blackList = new()
|
||||
{
|
||||
|
@ -133,9 +134,14 @@ namespace BITKit
|
|||
CancellationTokenSource = new CancellationTokenSource();
|
||||
AppName = appName;
|
||||
ThreadHelper.LogCurrentThread();
|
||||
|
||||
if (settings is not null && settings.AllowInitialize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await Init();
|
||||
}
|
||||
static async Task Init()
|
||||
private static async Task Init()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -13,6 +13,7 @@ MonoBehaviour:
|
|||
m_Name: AppSettings
|
||||
m_EditorClassIdentifier:
|
||||
appSettings:
|
||||
AllowInitialize: 1
|
||||
whiteList: []
|
||||
blackList:
|
||||
- System
|
||||
|
|
Binary file not shown.
|
@ -39,7 +39,7 @@ namespace BITKit.Sensors
|
|||
return _sensorImplementation.Execute();
|
||||
}
|
||||
}
|
||||
public abstract class Sensor : BITBehavior, ISensor
|
||||
public abstract class Sensor : MonoBehaviour, ISensor
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public LayerMask detectLayer;
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:508392158bd966c4d9c21e19661a441d",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
namespace BITKit.Sensors.Editors
|
||||
{
|
||||
/* [CustomEditor(typeof(Sensor), true)]
|
||||
public class SensorInspecer : Editor
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
VisualElement container = new();
|
||||
InspectorElement.FillDefaultInspector(container, serializedObject, this);
|
||||
|
||||
var sensor = serializedObject.targetObject as Sensor;
|
||||
|
||||
VisualElement listElement = new();
|
||||
Refresh();
|
||||
Button button = new(() =>
|
||||
{
|
||||
sensor.Excute();
|
||||
Refresh();
|
||||
});
|
||||
button.text = "Test";
|
||||
|
||||
container.Add(listElement);
|
||||
container.Add(button);
|
||||
return container;
|
||||
|
||||
void Refresh()
|
||||
{
|
||||
listElement.Clear();
|
||||
listElement.Add(new Label("Detected:"));
|
||||
sensor.detecteds.ForEach(x =>
|
||||
{
|
||||
var objectFiled = new ObjectField();
|
||||
objectFiled.objectType = typeof(Transform);
|
||||
objectFiled.value = x;
|
||||
listElement.Add(objectFiled);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
|
@ -1,10 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
#if UNITY_EDITOR
|
||||
using System.CodeDom;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
#endif
|
||||
namespace BITKit.Sensors
|
||||
{
|
||||
public class TriggerSensor : MonoBehaviour, ISensor
|
||||
|
@ -12,28 +17,35 @@ namespace BITKit.Sensors
|
|||
[Header(Constant.Header.Settings)] [SerializeField]
|
||||
private List<GameObject> ignores = new();
|
||||
|
||||
[SerializeField] private Optional<LayerMask> detectedLayer;
|
||||
[SerializeField] private bool allowStatic;
|
||||
|
||||
[Header(Constant.Header.Events)] public UnityEvent<Collider> onDetected = new();
|
||||
public UnityEvent<Collider> onLost = new();
|
||||
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
// ReSharper disable once FieldCanBeMadeReadOnly.Local
|
||||
private List<Collider> detected = new();
|
||||
|
||||
private Queue<Collider> triggerEnterQueue=new();
|
||||
private Queue<Collider> triggerExitQueue=new();
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider _collider)
|
||||
{
|
||||
if (_collider.gameObject.isStatic) return;
|
||||
if (IsValid(_collider) is false) return;
|
||||
if (detected.Contains(_collider)) return;
|
||||
detected.Add(_collider);
|
||||
onDetected.Invoke(_collider);
|
||||
triggerEnterQueue.Enqueue(_collider);
|
||||
|
||||
// if (IsValid(_collider) is false) return;
|
||||
// if (detected.Contains(_collider)) return;
|
||||
// detected.Add(_collider);
|
||||
// onDetected.Invoke(_collider);
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider _collider)
|
||||
{
|
||||
if (_collider.gameObject.isStatic) return;
|
||||
if (IsValid(_collider) is false) return;
|
||||
if (!detected.Remove(_collider)) return;
|
||||
onLost.Invoke(_collider);
|
||||
triggerExitQueue.Enqueue(_collider);
|
||||
// if (IsValid(_collider) is false) return;
|
||||
// if (!detected.Remove(_collider)) return;
|
||||
// onLost.Invoke(_collider);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
|
@ -55,7 +67,13 @@ namespace BITKit.Sensors
|
|||
|
||||
public IEnumerable<Transform> Get() => detected.Select(x => x.transform).ToArray();
|
||||
|
||||
public bool IsValid(Collider _collider) => ignores.Contains(_collider.gameObject) is false;
|
||||
//public bool IsValid(Collider _collider) => ignores.Contains(_collider.gameObject) is false;
|
||||
public bool IsValid(Collider _collider)
|
||||
{
|
||||
if(allowStatic is false && _collider.gameObject.isStatic) return false;
|
||||
if (ignores.Contains(_collider.gameObject)) return false;
|
||||
return !detectedLayer.Allow || detectedLayer.Value.Includes(_collider.gameObject.layer);
|
||||
}
|
||||
|
||||
public float GetDistance()
|
||||
{
|
||||
|
@ -66,5 +84,51 @@ namespace BITKit.Sensors
|
|||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
while (triggerEnterQueue.TryDequeue(out var _collider))
|
||||
{
|
||||
if (IsValid(_collider) is false) return;
|
||||
if (triggerExitQueue.Contains(_collider) || detected.Contains(_collider))continue;
|
||||
detected.Add(_collider);
|
||||
}
|
||||
while (triggerExitQueue.TryDequeue(out var _collider))
|
||||
{
|
||||
if (IsValid(_collider) is false) return;
|
||||
detected.Remove(_collider);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(TriggerSensor))]
|
||||
public class TriggerSensorInspector:BITInspector<TriggerSensor>
|
||||
{
|
||||
private VisualElement detectedContainer;
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
FillDefaultInspector();
|
||||
|
||||
detectedContainer = root.Create<VisualElement>();
|
||||
|
||||
return root;
|
||||
}
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (detectedContainer is null) return;
|
||||
detectedContainer.Clear();
|
||||
foreach (var x in agent.Get())
|
||||
{
|
||||
|
||||
ObjectField objectField = new()
|
||||
{
|
||||
objectType = x.GetType(),
|
||||
value = x,
|
||||
};
|
||||
objectField.SetEnabled(false);
|
||||
detectedContainer.Add(objectField);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -20,4 +20,6 @@ namespace BITKit.UX
|
|||
public const string ContextListView = "context-listview";
|
||||
public const string Inspector = "inspector-container";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -17,6 +17,14 @@ namespace BITKit
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
public class BITEditorUtils
|
||||
{
|
||||
public const string InspectorPath = "Assets/BITKit/Unity/Common/UX/BITInspector.uss";
|
||||
#if UNITY_EDITOR
|
||||
public static StyleSheet InspectorStyleSheet => AssetDatabase.LoadAssetAtPath<StyleSheet>(InspectorPath);
|
||||
#endif
|
||||
}
|
||||
public class ServerRpcAttribute : System.Attribute
|
||||
{
|
||||
|
||||
|
@ -79,7 +87,7 @@ namespace BITKit
|
|||
void OnEnable()
|
||||
{
|
||||
//StyleSheet css = Addressables.LoadAssetAsync<StyleSheet>(ussName).WaitForCompletion();
|
||||
StyleSheet css = AssetDatabase.LoadAssetAtPath<StyleSheet>($"Assets/BITKit/Unity/Common/UX/BITInspector.uss");
|
||||
StyleSheet css = AssetDatabase.LoadAssetAtPath<StyleSheet>(BITEditorUtils.InspectorPath);
|
||||
|
||||
root.root.styleSheets.Add(css);
|
||||
|
||||
|
|
|
@ -7,4 +7,4 @@ ScriptedImporter:
|
|||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {instanceID: 0}
|
||||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class BITEditorForUnity : EditorWindow
|
||||
{
|
||||
private Slider _timeScaleSlider;
|
||||
private Button _resetTimeScaleButton;
|
||||
|
||||
[MenuItem("Tools/Common Editor")]
|
||||
private static void OpenEditor()
|
||||
{
|
||||
var window = GetWindow<BITEditorForUnity>();
|
||||
window.titleContent = new GUIContent("BIT Editor");
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
rootVisualElement.styleSheets.Add(BITEditorUtils.InspectorStyleSheet);
|
||||
|
||||
_timeScaleSlider = new Slider()
|
||||
{
|
||||
label = "TimeScale",
|
||||
showInputField = true,
|
||||
value = Time.timeScale
|
||||
};
|
||||
_timeScaleSlider.RegisterValueChangedCallback(x => { Time.timeScale = x.newValue; });
|
||||
|
||||
_resetTimeScaleButton = new Button()
|
||||
{
|
||||
text = "Reset TimeScale",
|
||||
};
|
||||
_resetTimeScaleButton.clicked += () =>
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
_timeScaleSlider.value = 1;
|
||||
};
|
||||
|
||||
rootVisualElement.Add(_timeScaleSlider);
|
||||
rootVisualElement.Add(_resetTimeScaleButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4af8b62f1e9db2045a42831c3cb3ab77
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue