feat: connection editing via line renderer
This commit is contained in:
parent
c43d897626
commit
606c210005
5 changed files with 1407 additions and 70764 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -121,7 +121,7 @@ GameObject:
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Point
|
m_Name: Point
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 3443629218296621865, guid: 0000000000000000d000000000000000, type: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 1
|
m_IsActive: 1
|
||||||
|
|
@ -153,3 +153,4 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3}
|
m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
Owner: -1
|
||||||
|
|
|
||||||
|
|
@ -11,58 +11,31 @@ using static UnityEngine.GraphicsBuffer;
|
||||||
[ExecuteAlways]
|
[ExecuteAlways]
|
||||||
public class GameManager : MonoBehaviour
|
public class GameManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
[HideInInspector]
|
public Transform ConnectionParent;
|
||||||
public static GameManager instance;
|
|
||||||
|
|
||||||
public Transform NodeParent;
|
public Transform NodeParent;
|
||||||
public GameObject NodePrefab;
|
public GameObject NodePrefab;
|
||||||
|
|
||||||
|
[HideInInspector] public static GameManager instance;
|
||||||
|
|
||||||
[Header("Node Generation")]
|
[HideInInspector] public float maxConnectionLength = 6;
|
||||||
|
[HideInInspector] public int nodeCount = 100;
|
||||||
[Range(0, 20)]
|
[HideInInspector] public int hoverRadius = 50;
|
||||||
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>();
|
|
||||||
|
|
||||||
[SerializeField]
|
[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]
|
[Serializable]
|
||||||
public class Connection
|
public class Connection
|
||||||
{
|
{
|
||||||
public Node nodeA, nodeB;
|
public Node nodeA, nodeB;
|
||||||
public bool allowed;
|
public bool allowed = true;
|
||||||
|
public bool hovered = false;
|
||||||
public LineRenderer lineRenderer;
|
public LineRenderer lineRenderer;
|
||||||
|
|
||||||
~Connection()
|
|
||||||
{
|
|
||||||
DestroyImmediate(lineRenderer.transform.parent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void GenerateAlongSphere()
|
public void GenerateAlongSphere()
|
||||||
{
|
{
|
||||||
connections.Clear();
|
connections.Clear();
|
||||||
|
|
@ -96,7 +69,10 @@ public class GameManager : MonoBehaviour
|
||||||
public void GenerateConnections()
|
public void GenerateConnections()
|
||||||
{
|
{
|
||||||
connections.Clear();
|
connections.Clear();
|
||||||
|
|
||||||
|
foreach (LineRenderer line in ConnectionParent.GetComponentsInChildren<LineRenderer>())
|
||||||
|
DestroyImmediate(line.gameObject);
|
||||||
|
|
||||||
foreach (Node nodeA in nodes)
|
foreach (Node nodeA in nodes)
|
||||||
{
|
{
|
||||||
if (nodeA == null) continue;
|
if (nodeA == null) continue;
|
||||||
|
|
@ -117,8 +93,8 @@ public class GameManager : MonoBehaviour
|
||||||
}
|
}
|
||||||
if (!conExists)
|
if (!conExists)
|
||||||
{
|
{
|
||||||
var dummy = Instantiate(new GameObject(), transform);
|
var dummy = new GameObject("dummy");
|
||||||
dummy.name = "Dummy";
|
dummy.transform.SetParent(ConnectionParent);
|
||||||
var newCon = new Connection
|
var newCon = new Connection
|
||||||
{
|
{
|
||||||
nodeA = nodeA,
|
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()
|
private void Update()
|
||||||
{
|
{
|
||||||
foreach (var con in connections)
|
foreach (var con in connections)
|
||||||
{
|
{
|
||||||
if (!con.allowed)
|
float width = (con.hovered ? 0.6f : 0.3f) * (con.allowed ? 1f : 0.3f);
|
||||||
{
|
|
||||||
con.lineRenderer.enabled = false;
|
con.lineRenderer.startColor = con.allowed ? con.nodeA.transform.GetChild(0).GetComponent<Renderer>().sharedMaterial.color : new Color(0.2f, 0.2f, 0.2f);
|
||||||
continue;
|
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.enabled = true;
|
con.lineRenderer.endWidth = width;
|
||||||
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;
|
|
||||||
|
|
||||||
con.lineRenderer.SetGreatCircleArc(con.nodeA.transform.position, con.nodeB.transform.position, 5, 20.5f);
|
con.lineRenderer.SetGreatCircleArc(con.nodeA.transform.position, con.nodeB.transform.position, 5, 20.5f);
|
||||||
con.lineRenderer.enabled = true;
|
con.lineRenderer.enabled = true;
|
||||||
|
|
@ -185,22 +140,49 @@ public class GameManagerEditor : Editor
|
||||||
{
|
{
|
||||||
DrawDefaultInspector();
|
DrawDefaultInspector();
|
||||||
|
|
||||||
GameManager gm = (GameManager)target;
|
GameManager gm = (GameManager)target;
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
|
|
||||||
if (GUILayout.Button("Generate Sphere"))
|
GUILayout.Label("Generation Parameters", EditorStyles.boldLabel);
|
||||||
gm.GenerateAlongSphere();
|
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);
|
||||||
|
|
||||||
if (GUILayout.Button("Generate Connections"))
|
gm.hoverRadius = EditorGUILayout.IntSlider("Hover Radius", gm.hoverRadius, 0, 100);
|
||||||
gm.GenerateConnections();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GUILayout.BeginHorizontal();
|
||||||
|
|
||||||
|
if (GUILayout.Button("Generate Nodes"))
|
||||||
|
{
|
||||||
|
gm.GenerateAlongSphere();
|
||||||
|
SceneView.RepaintAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GUILayout.Button("Generate Connections"))
|
||||||
|
{
|
||||||
|
gm.GenerateConnections();
|
||||||
|
SceneView.RepaintAll();
|
||||||
|
}
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
if (GUILayout.Button("Generate Both"))
|
||||||
|
|
||||||
if (GUILayout.Button("Generate"))
|
|
||||||
{
|
{
|
||||||
gm.GenerateAlongSphere();
|
gm.GenerateAlongSphere();
|
||||||
gm.GenerateConnections();
|
gm.GenerateConnections();
|
||||||
|
SceneView.RepaintAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
private void OnSceneGUI()
|
private void OnSceneGUI()
|
||||||
{
|
{
|
||||||
|
|
@ -221,6 +203,8 @@ public class GameManagerEditor : Editor
|
||||||
// Hover-Ermittlung
|
// Hover-Ermittlung
|
||||||
for (int i = 0; i < gm.connections.Count; i++)
|
for (int i = 0; i < gm.connections.Count; i++)
|
||||||
{
|
{
|
||||||
|
gm.connections[i].hovered = false;
|
||||||
|
|
||||||
var con = gm.connections[i];
|
var con = gm.connections[i];
|
||||||
Vector3 a = cam.WorldToScreenPoint(con.nodeA.transform.position);
|
Vector3 a = cam.WorldToScreenPoint(con.nodeA.transform.position);
|
||||||
Vector3 b = cam.WorldToScreenPoint(con.nodeB.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
|
// Klick-Behandlung
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
|
|
||||||
|
|
||||||
if (e.type == EventType.MouseDown && e.button == 0 && closestIdx >= 0)
|
if (e.type == EventType.MouseDown && e.button == 0 && closestIdx >= 0)
|
||||||
{
|
{
|
||||||
clickedConIdx = closestIdx;
|
clickedConIdx = closestIdx;
|
||||||
|
|
@ -256,15 +246,6 @@ public class GameManagerEditor : Editor
|
||||||
clickedConIdx = -1;
|
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 kontinuierlich aktualisieren
|
||||||
SceneView.RepaintAll();
|
SceneView.RepaintAll();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,15 @@ public class Node : MonoBehaviour
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
transform.localPosition = transform.localPosition.normalized * 20f;
|
transform.localPosition = transform.localPosition.normalized * 20f;
|
||||||
transform.forward = transform.position;
|
transform.forward = transform.position;
|
||||||
|
|
||||||
switch (Owner)
|
switch (Owner)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -28,5 +29,10 @@ public class Node : MonoBehaviour
|
||||||
transform.GetChild(0).GetComponent<Renderer>().sharedMaterial.color = Color.gray; break;
|
transform.GetChild(0).GetComponent<Renderer>().sharedMaterial.color = Color.gray; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMouseDown()
|
||||||
|
{
|
||||||
|
Owner = Owner >= 1 ? -1 : Owner + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,8 @@ Material:
|
||||||
- _WorkflowMode: 1
|
- _WorkflowMode: 1
|
||||||
- _ZWrite: 1
|
- _ZWrite: 1
|
||||||
m_Colors:
|
m_Colors:
|
||||||
- _BaseColor: {r: 0.21032429, g: 1, b: 0, a: 1}
|
- _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||||
- _Color: {r: 0.21032426, g: 1, b: 0, a: 1}
|
- _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||||
m_BuildTextureStacks: []
|
m_BuildTextureStacks: []
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue