breakpoint

before update unity version
This commit is contained in:
CortexCore
2024-03-04 18:45:21 +08:00
parent e2fbb14dd5
commit 9ad58a2ff4
5423 changed files with 14757 additions and 653 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Cysharp.Threading.Tasks;
#if UNITY_EDITOR
@@ -41,6 +42,9 @@ namespace BITKit.Sensors
public IEnumerable<Transform> Get() =>CurrentTarget is not null ? new[] { CurrentTarget }:Enumerable.Empty<Transform>();
bool ISensor.AutoUpdate => autoUpdate;
internal StringBuilder reportBuilder;
internal DoubleBuffer<string> report=new();
public bool IsValid(Collider _collider)
{
@@ -79,44 +83,76 @@ namespace BITKit.Sensors
}
public async UniTask Execute()
{
updateCount++;
timeoutCancellationTokenSource?.Cancel();
timeoutCancellationTokenSource = new CancellationTokenSource();
await sensor.Execute();
Profiler.BeginSample("Release Detected Buffer");
var newDetected = sensor.Get();
Profiler.EndSample();
// ReSharper disable once PossibleMultipleEnumeration
if (newDetected.Contains(CurrentTarget))
try
{
if (optionalRetargetInterval.Allow && optionalRetargetInterval.Value.AllowUpdate)
_currentPosition = transform.position;
updateCount++;
timeoutCancellationTokenSource?.Cancel();
timeoutCancellationTokenSource = new CancellationTokenSource();
await sensor.Execute();
reportBuilder?.AppendLine($"-----BEGIN------{updateCount}");
Profiler.BeginSample("Release Detected Buffer");
var newDetected = sensor.Get();
if (reportBuilder is not null)
{
reportBuilder.AppendLine($"Detected:{newDetected.Count()}");
foreach (var x in newDetected)
{
reportBuilder.AppendLine(x.name);
}
reportBuilder.AppendLine();
}
Profiler.EndSample();
// ReSharper disable once PossibleMultipleEnumeration
if (newDetected.Contains(CurrentTarget))
{
if (optionalRetargetInterval.Allow && optionalRetargetInterval.Value.AllowUpdate)
{
reportBuilder?.AppendLine("Retarget Interval Catch,Search New Target");
}
else
{
reportBuilder?.AppendLine("Current Target Detected,Keep Target");
return;
}
}
Profiler.BeginSample("Filter Detected");
foreach (var x in newDetected.OrderBy(KeySelector))
{
if(IsValid(x.GetComponent<Collider>()) is false)continue;
CurrentTarget = x;
reportBuilder?.AppendLine($"New Target:{x.name},Is oder by distance");
break;
}
Profiler.EndSample();
reportBuilder?.AppendLine($"-----Complete------{updateCount}");
if(reportBuilder is not null)
{
report.Release(reportBuilder.ToString());
reportBuilder.Clear();
}
else
{
return;
report.Clear();
}
}
Profiler.BeginSample("Filter Detected");
// // ReSharper disable once PossibleMultipleEnumeration
// CurrentTarget = newDetected
// .Where(_transform => IsValid(_transform.GetComponent<Collider>()))
// .OrderBy(_transform => Vector3.Distance(currentPosition, _transform.position))
// .FirstOrDefault();
foreach (var x in newDetected.OrderBy(KeySelector))
catch (Exception e)
{
if(IsValid(x.GetComponent<Collider>()) is false)continue;
CurrentTarget = x;
break;
BIT4Log.LogException(e);
}
Profiler.EndSample();
}
private float KeySelector(Transform x)
{
return Vector3.Distance(_currentPosition, x.position);
var distance = Vector3.Distance(_currentPosition, x.position);
reportBuilder?.AppendLine($"Distance:{distance}@{x.name}");
return distance;
}
void IAction.Execute()
{
@@ -142,6 +178,7 @@ namespace BITKit.Sensors
public class SmartTargetSensorInspector:BITInspector<SmartTargetSensor>
{
private ObjectField _objectField;
private Label _reportLabel;
public override VisualElement CreateInspectorGUI()
{
FillDefaultInspector();
@@ -154,15 +191,36 @@ namespace BITKit.Sensors
_objectField.SetEnabled(false);
_reportLabel = root.Create<Label>();
_reportLabel.text = "Waiting agent report";
return root;
}
protected override void OnEnabled()
{
base.OnEnabled();
agent.reportBuilder = new();
}
protected override void OnDisabled()
{
base.OnDisabled();
agent.reportBuilder = null;
}
protected override void OnUpdate()
{
if (_objectField is not null)
{
_objectField.value = agent.CurrentTarget;
}
if (agent.reportBuilder is not null && _reportLabel is not null && agent.report.TryGetRelease(out var value))
{
_reportLabel.text = value;
}
}
}
#endif