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,41 +1,85 @@
|
||||||
using UnityEngine;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity.VisualScripting;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
|
||||||
|
[ExecuteAlways]
|
||||||
public class GameManager : MonoBehaviour
|
public class GameManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public static GameManager instance;
|
public static GameManager instance;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private Transform NodeParent;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private GameObject NodePrefab;
|
||||||
|
|
||||||
|
|
||||||
[Header("Parameters")]
|
[Header("Parameters")]
|
||||||
[Range(0, 100)]
|
[Range(0, 100)]
|
||||||
public float maxConnectionLength;
|
public float maxConnectionLength;
|
||||||
|
|
||||||
|
|
||||||
public List<Node> nodes = new List<Node>();
|
private List<Node> nodes = new List<Node>();
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
public List<Connection> connections = new List<Connection>();
|
public List<Connection> connections = new List<Connection>();
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public struct Connection
|
public struct Connection
|
||||||
{
|
{
|
||||||
public Node nodeA, nodeB;
|
public Node nodeA, nodeB;
|
||||||
public bool allowed;
|
public bool allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
[ContextMenu("Generate Connections")]
|
||||||
void Start()
|
void GenerateConnections()
|
||||||
{
|
{
|
||||||
|
connections.Clear();
|
||||||
|
|
||||||
foreach (Node nodeA in nodes)
|
foreach (Node nodeA in nodes)
|
||||||
{
|
{
|
||||||
|
if (nodeA == null) continue;
|
||||||
foreach (Node nodeB in nodes)
|
foreach (Node nodeB in nodes)
|
||||||
{
|
{
|
||||||
|
if (nodeB == null) continue;
|
||||||
bool conExists = false;
|
bool conExists = false;
|
||||||
if (nodeA == nodeB || Vector3.Distance(nodeA.transform.position, nodeB.transform.position) > maxConnectionLength)
|
if (nodeA == nodeB || Math.Abs(Vector3.Distance(nodeA.transform.position, nodeB.transform.position)) > maxConnectionLength)
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
foreach (Connection con in connections)
|
foreach (Connection con in connections)
|
||||||
{
|
{
|
||||||
|
|
@ -45,18 +89,31 @@ public class GameManager : MonoBehaviour
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!conExists)
|
if (!conExists)
|
||||||
connections.Add(new Connection { nodeA = nodeA, nodeB = nodeB});
|
connections.Add(new Connection { nodeA = nodeA, nodeB = nodeB });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
void Update()
|
void Start()
|
||||||
{
|
{
|
||||||
foreach (Connection con in connections)
|
|
||||||
{
|
|
||||||
Debug.DrawLine(con.nodeA.transform.position, con.nodeB.transform.position, con.allowed ? Color.green : Color.red);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
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;
|
using UnityEngine;
|
||||||
|
|
||||||
|
[ExecuteAlways]
|
||||||
public class Node : MonoBehaviour
|
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
|
||||||
|
|
@ -11,6 +12,7 @@ public class Node : MonoBehaviour
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
transform.localPosition = transform.localPosition.normalized * 20f;
|
||||||
|
transform.forward = transform.position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue