feat: connection editing via line renderer

This commit is contained in:
LordDemonix 2025-09-16 16:50:21 +02:00
parent c43d897626
commit 606c210005
5 changed files with 1407 additions and 70764 deletions

File diff suppressed because it is too large Load diff

View file

@ -121,7 +121,7 @@ GameObject:
m_Layer: 0
m_Name: Point
m_TagString: Untagged
m_Icon: {fileID: 3443629218296621865, guid: 0000000000000000d000000000000000, type: 0}
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
@ -153,3 +153,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3}
m_Name:
m_EditorClassIdentifier:
Owner: -1

View file

@ -11,58 +11,31 @@ using static UnityEngine.GraphicsBuffer;
[ExecuteAlways]
public class GameManager : MonoBehaviour
{
[HideInInspector]
public static GameManager instance;
public Transform ConnectionParent;
public Transform NodeParent;
public GameObject NodePrefab;
[HideInInspector] public static GameManager instance;
[Header("Node Generation")]
[Range(0, 20)]
public float maxConnectionLength = 6;
[Range(0, 1000)]
public int nodeCount = 100;
[Range(0, 100)]
public float hoverRadius = 50;
[Space]
[Range(0,10)]
public int editorConnectionAllowedWidth = 3;
public Color editorConnectionAllowedColor = Color.white;
[Space]
[Range(0, 10)]
public int editorConnectionHoveredWidth = 2;
public Color editorConnectionHoveredColor = Color.gray;
[Space]
[Range(0,10)]
public int editorConnectionForbiddenWidth = 1;
public Color editorConnectionForbiddenColor = Color.black;
private List<Node> nodes = new List<Node>();
[HideInInspector] public float maxConnectionLength = 6;
[HideInInspector] public int nodeCount = 100;
[HideInInspector] public int hoverRadius = 50;
[SerializeField]
public List<Connection> connections = new List<Connection>();
[HideInInspector] public List<Connection> connections = new List<Connection>();
[HideInInspector] public List<Node> nodes = new List<Node>();
[Serializable]
public class Connection
{
public Node nodeA, nodeB;
public bool allowed;
public bool allowed = true;
public bool hovered = false;
public LineRenderer lineRenderer;
~Connection()
{
DestroyImmediate(lineRenderer.transform.parent);
}
}
public void GenerateAlongSphere()
{
connections.Clear();
@ -97,6 +70,9 @@ public class GameManager : MonoBehaviour
{
connections.Clear();
foreach (LineRenderer line in ConnectionParent.GetComponentsInChildren<LineRenderer>())
DestroyImmediate(line.gameObject);
foreach (Node nodeA in nodes)
{
if (nodeA == null) continue;
@ -117,8 +93,8 @@ public class GameManager : MonoBehaviour
}
if (!conExists)
{
var dummy = Instantiate(new GameObject(), transform);
dummy.name = "Dummy";
var dummy = new GameObject("dummy");
dummy.transform.SetParent(ConnectionParent);
var newCon = new Connection
{
nodeA = nodeA,
@ -137,37 +113,16 @@ public class GameManager : MonoBehaviour
}
}
#if UNITY_EDITOR
void OnDrawGizmos()
{
if (connections == null) return;
// Linien respektieren den Z-Buffer
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
foreach (var con in connections)
{
if(!con.allowed) continue;
Handles.color = Color.red;
Handles.DrawLine(con.nodeA.transform.position, con.nodeB.transform.position);
}
}
#endif
private void Update()
{
foreach (var con in connections)
{
if (!con.allowed)
{
con.lineRenderer.enabled = false;
continue;
}
con.lineRenderer.enabled = true;
con.lineRenderer.startColor = con.nodeA.transform.GetChild(0).GetComponent<Renderer>().material.color;
con.lineRenderer.endColor = con.nodeB.transform.GetChild(0).GetComponent<Renderer>().material.color;
con.lineRenderer.startWidth = 0.3f;
con.lineRenderer.endWidth = 0.3f;
float width = (con.hovered ? 0.6f : 0.3f) * (con.allowed ? 1f : 0.3f);
con.lineRenderer.startColor = con.allowed ? con.nodeA.transform.GetChild(0).GetComponent<Renderer>().sharedMaterial.color : new Color(0.2f, 0.2f, 0.2f);
con.lineRenderer.endColor = con.allowed ? con.nodeB.transform.GetChild(0).GetComponent<Renderer>().sharedMaterial.color : new Color(0.2f, 0.2f, 0.2f);
con.lineRenderer.startWidth = width;
con.lineRenderer.endWidth = width;
con.lineRenderer.SetGreatCircleArc(con.nodeA.transform.position, con.nodeB.transform.position, 5, 20.5f);
con.lineRenderer.enabled = true;
@ -186,21 +141,48 @@ public class GameManagerEditor : Editor
DrawDefaultInspector();
GameManager gm = (GameManager)target;
GUILayout.BeginHorizontal();
if (GUILayout.Button("Generate Sphere"))
gm.GenerateAlongSphere();
if (GUILayout.Button("Generate Connections"))
gm.GenerateConnections();
GUILayout.EndHorizontal();
if (GUILayout.Button("Generate"))
GUILayout.Label("Generation Parameters", EditorStyles.boldLabel);
EditorGUI.BeginChangeCheck();
gm.nodeCount = EditorGUILayout.IntSlider("Node Count", gm.nodeCount, 0, 200);
gm.maxConnectionLength = EditorGUILayout.Slider("Max Connection Length", gm.maxConnectionLength, 0, 100);
if (EditorGUI.EndChangeCheck())
{
gm.GenerateAlongSphere();
gm.GenerateConnections();
SceneView.RepaintAll();
}
GUILayout.Space(10);
GUILayout.Label("Connection Gizmos", EditorStyles.boldLabel);
gm.hoverRadius = EditorGUILayout.IntSlider("Hover Radius", gm.hoverRadius, 0, 100);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Generate Nodes"))
{
gm.GenerateAlongSphere();
SceneView.RepaintAll();
}
if (GUILayout.Button("Generate Connections"))
{
gm.GenerateConnections();
SceneView.RepaintAll();
}
if (GUILayout.Button("Generate Both"))
{
gm.GenerateAlongSphere();
gm.GenerateConnections();
SceneView.RepaintAll();
}
GUILayout.EndHorizontal();
}
private void OnSceneGUI()
{
@ -221,6 +203,8 @@ public class GameManagerEditor : Editor
// Hover-Ermittlung
for (int i = 0; i < gm.connections.Count; i++)
{
gm.connections[i].hovered = false;
var con = gm.connections[i];
Vector3 a = cam.WorldToScreenPoint(con.nodeA.transform.position);
Vector3 b = cam.WorldToScreenPoint(con.nodeB.transform.position);
@ -238,8 +222,14 @@ public class GameManagerEditor : Editor
}
}
if(closestIdx >= 0)
gm.connections[closestIdx].hovered = true;
// Klick-Behandlung
Event e = Event.current;
if (e.type == EventType.MouseDown && e.button == 0 && closestIdx >= 0)
{
clickedConIdx = closestIdx;
@ -256,15 +246,6 @@ public class GameManagerEditor : Editor
clickedConIdx = -1;
}
// Zeichnen
for (int i = 0; i < gm.connections.Count; i++)
{
var con = gm.connections[i];
Handles.color = (i == closestIdx && !con.allowed) ? gm.editorConnectionHoveredColor : con.allowed ? gm.editorConnectionAllowedColor : gm.editorConnectionForbiddenColor;
float thickness = (i == closestIdx) ? gm.editorConnectionHoveredWidth : con.allowed ? gm.editorConnectionAllowedWidth : gm.editorConnectionForbiddenWidth;
Handles.DrawLine(con.nodeA.transform.position, con.nodeB.transform.position, thickness);
}
// SceneView kontinuierlich aktualisieren
SceneView.RepaintAll();
}

View file

@ -18,6 +18,7 @@ public class Node : MonoBehaviour
{
transform.localPosition = transform.localPosition.normalized * 20f;
transform.forward = transform.position;
switch (Owner)
{
case 0:
@ -29,4 +30,9 @@ public class Node : MonoBehaviour
}
}
private void OnMouseDown()
{
Owner = Owner >= 1 ? -1 : Owner + 1;
}
}

View file

@ -117,8 +117,8 @@ Material:
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.21032429, g: 1, b: 0, a: 1}
- _Color: {r: 0.21032426, g: 1, b: 0, a: 1}
- _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []