funny spheres go brr
This commit is contained in:
parent
49799b8dbd
commit
66240db1ee
3 changed files with 5378 additions and 367 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,19 +1,29 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
[HideInInspector]
|
||||
public static GameManager instance;
|
||||
|
||||
[SerializeField]
|
||||
private Transform NodeParent;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject NodePrefab;
|
||||
|
||||
|
||||
[Header("Parameters")]
|
||||
[Range(0, 100)]
|
||||
public float maxConnectionLength;
|
||||
|
||||
|
||||
public List<Node> nodes = new List<Node>();
|
||||
private List<Node> nodes = new List<Node>();
|
||||
|
||||
[SerializeField]
|
||||
public List<Connection> connections = new List<Connection>();
|
||||
|
|
@ -25,17 +35,51 @@ public class GameManager : MonoBehaviour
|
|||
public bool allowed;
|
||||
}
|
||||
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
[ContextMenu("Generate Along Sphere")]
|
||||
void GenerateAlongSphere()
|
||||
{
|
||||
connections.Clear();
|
||||
nodes.Clear();
|
||||
|
||||
|
||||
int pointCount = 100;
|
||||
float radius = 20f;
|
||||
|
||||
float goldenRatio = (1f + Mathf.Sqrt(5f)) / 2f;
|
||||
float angleIncrement = 2f * Mathf.PI * goldenRatio;
|
||||
|
||||
for (int i = 0; i < pointCount; i++)
|
||||
{
|
||||
float t = (float)i / pointCount; // von 0 bis 1
|
||||
float inclination = Mathf.Acos(1f - 2f * t);
|
||||
float azimuth = angleIncrement * i;
|
||||
|
||||
float x = Mathf.Sin(inclination) * Mathf.Cos(azimuth);
|
||||
float y = Mathf.Sin(inclination) * Mathf.Sin(azimuth);
|
||||
float z = Mathf.Cos(inclination);
|
||||
|
||||
Vector3 pos = new Vector3(x, y, z) * radius;
|
||||
|
||||
var auto = Instantiate(NodePrefab, NodeParent);
|
||||
auto.transform.localPosition = pos;
|
||||
nodes.Add(auto.GetComponent<Node>());
|
||||
}
|
||||
}
|
||||
|
||||
[ContextMenu("Generate Connections")]
|
||||
void GenerateConnections()
|
||||
{
|
||||
connections.Clear();
|
||||
|
||||
foreach (Node nodeA in nodes)
|
||||
{
|
||||
if (nodeA == null) continue;
|
||||
foreach (Node nodeB in nodes)
|
||||
{
|
||||
if (nodeB == null) continue;
|
||||
bool conExists = false;
|
||||
if (nodeA == nodeB || Vector3.Distance(nodeA.transform.position, nodeB.transform.position) > maxConnectionLength)
|
||||
break;
|
||||
if (nodeA == nodeB || Math.Abs(Vector3.Distance(nodeA.transform.position, nodeB.transform.position)) > maxConnectionLength)
|
||||
continue;
|
||||
|
||||
foreach (Connection con in connections)
|
||||
{
|
||||
|
|
@ -51,12 +95,25 @@ public class GameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
foreach (Connection con in connections)
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
Debug.DrawLine(con.nodeA.transform.position, con.nodeB.transform.position, con.allowed ? Color.green : Color.red);
|
||||
if (connections == null) return;
|
||||
|
||||
// Linien respektieren den Z-Buffer
|
||||
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
|
||||
|
||||
foreach (var con in connections)
|
||||
{
|
||||
Handles.color = con.allowed ? Color.green : Color.red;
|
||||
Handles.DrawLine(con.nodeA.transform.position, con.nodeB.transform.position);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using UnityEngine;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class Node : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
|
|
@ -11,6 +12,7 @@ public class Node : MonoBehaviour
|
|||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
transform.localPosition = transform.localPosition.normalized * 20f;
|
||||
transform.forward = transform.position;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue