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_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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
@ -96,7 +69,10 @@ public class GameManager : MonoBehaviour
|
|||
public void GenerateConnections()
|
||||
{
|
||||
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;
|
||||
|
|
@ -185,22 +140,49 @@ public class GameManagerEditor : Editor
|
|||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
GameManager gm = (GameManager)target;
|
||||
GUILayout.BeginHorizontal();
|
||||
GameManager gm = (GameManager)target;
|
||||
|
||||
if (GUILayout.Button("Generate Sphere"))
|
||||
gm.GenerateAlongSphere();
|
||||
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);
|
||||
|
||||
if (GUILayout.Button("Generate Connections"))
|
||||
gm.GenerateConnections();
|
||||
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();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (GUILayout.Button("Generate"))
|
||||
if (GUILayout.Button("Generate Both"))
|
||||
{
|
||||
gm.GenerateAlongSphere();
|
||||
gm.GenerateConnections();
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,15 @@ public class Node : MonoBehaviour
|
|||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.localPosition = transform.localPosition.normalized * 20f;
|
||||
transform.forward = transform.position;
|
||||
{
|
||||
transform.localPosition = transform.localPosition.normalized * 20f;
|
||||
transform.forward = transform.position;
|
||||
|
||||
switch (Owner)
|
||||
{
|
||||
case 0:
|
||||
|
|
@ -28,5 +29,10 @@ public class Node : MonoBehaviour
|
|||
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
|
||||
- _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: []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue