1
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "BITKit.WorldNode.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:508392158bd966c4d9c21e19661a441d",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:01cf845b40a364e4cbaee058936fa4a3"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UNITY_EDITOR"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f93c330bf016d047a49b0c29307ef42
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.WorldNodes
|
||||
{
|
||||
public class WorldNodeServiceEditor : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/Scenes/WorldNode Window")]
|
||||
public static void Open()
|
||||
{
|
||||
GetWindow<WorldNodeServiceEditor>().Show();
|
||||
}
|
||||
private List<ValueTuple<IWorldNode,IWorldNode>> _connections = new();
|
||||
private List<ValueTuple<IWorldNode, IWorldNode>> _blockConnections = new();
|
||||
|
||||
private Label reportLabel;
|
||||
private Toggle drawBlocked;
|
||||
private void OnEnable()
|
||||
{
|
||||
var checkButton = rootVisualElement.Create<Button>();
|
||||
checkButton.text = "Check";
|
||||
checkButton.clicked += Rebuild;
|
||||
|
||||
drawBlocked = rootVisualElement.Create<Toggle>();
|
||||
|
||||
reportLabel = rootVisualElement.Create<Label>();
|
||||
|
||||
drawBlocked.label = "Draw Blocked Connections";
|
||||
|
||||
WorldNodeService.OnDrawGizmo += DrawGizmo;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
WorldNodeService.OnDrawGizmo -= DrawGizmo;
|
||||
}
|
||||
|
||||
private void Rebuild()
|
||||
{
|
||||
var watch = System.Diagnostics.Stopwatch.StartNew();
|
||||
_connections.Clear();
|
||||
_blockConnections.Clear();
|
||||
//这里会在WorldNodeService中获取节点的数组,然后获取所有两个节点之间的组合
|
||||
var nodes = WorldNodeService.WorldNodes;
|
||||
foreach (var t in nodes)
|
||||
{
|
||||
foreach (var t1 in nodes)
|
||||
{
|
||||
if(t1==t)continue;
|
||||
if(Physics.Linecast(t.Position, t1.Position, out var hit))
|
||||
{
|
||||
_blockConnections.Add((t, t1));
|
||||
}
|
||||
else
|
||||
{
|
||||
_connections.Add((t, t1));
|
||||
}
|
||||
}
|
||||
}
|
||||
watch.Stop();
|
||||
reportLabel.text = $"Connections: {_connections.Count}";
|
||||
reportLabel.text += $"\nBlockConnections: {_blockConnections.Count}";
|
||||
reportLabel.text += $"\nTime: {watch.ElapsedMilliseconds}ms\tcompleted at {DateTime.Now:HH:mm:ss}";
|
||||
}
|
||||
private void DrawGizmo()
|
||||
{
|
||||
foreach (var x in WorldNodeService.WorldNodes)
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere(x.Position, 0.1f);
|
||||
}
|
||||
|
||||
foreach (var (x, y) in _connections)
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawLine(x.Position, y.Position);
|
||||
}
|
||||
|
||||
|
||||
if (drawBlocked.value)
|
||||
{
|
||||
foreach (var (x, y) in _blockConnections)
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawLine(x.Position, y.Position);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b8483d77837cd64ba3bf1212b7fd8fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user