From 49799b8dbd07b7b4c76a8c3f0e674ab2ebc9ac94 Mon Sep 17 00:00:00 2001 From: LordDemonix Date: Mon, 15 Sep 2025 23:01:07 +0200 Subject: [PATCH] feat: added connections --- Assets/Earth/EarthScene.unity | 111 +++++++++++++++++++++++++++++ Assets/Prefabs/Point.prefab | 13 ++++ Assets/Scripts/GameManager.cs | 62 ++++++++++++++++ Assets/Scripts/GameManager.cs.meta | 2 + Assets/Scripts/Node.cs | 16 +++++ Assets/Scripts/Node.cs.meta | 2 + 6 files changed, 206 insertions(+) create mode 100644 Assets/Scripts/GameManager.cs create mode 100644 Assets/Scripts/GameManager.cs.meta create mode 100644 Assets/Scripts/Node.cs create mode 100644 Assets/Scripts/Node.cs.meta diff --git a/Assets/Earth/EarthScene.unity b/Assets/Earth/EarthScene.unity index 34c9dd8..4284f02 100644 --- a/Assets/Earth/EarthScene.unity +++ b/Assets/Earth/EarthScene.unity @@ -633,6 +633,61 @@ Transform: m_Children: [] m_Father: {fileID: 1249182055} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &952215032 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 952215034} + - component: {fileID: 952215033} + m_Layer: 0 + m_Name: GameManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &952215033 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 952215032} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d9a8ed1dbf611654e914bd61e5a99aac, type: 3} + m_Name: + m_EditorClassIdentifier: + maxConnectionLength: 6 + nodes: + - {fileID: 8318396349631803076} + - {fileID: 2030518901} + - {fileID: 1781135855} + - {fileID: 1929610336} + - {fileID: 1380013025} + connections: + - nodeA: {fileID: 2030518901} + nodeB: {fileID: 1380013025} + allowed: 0 +--- !u!4 &952215034 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 952215032} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.54042053, y: 0.5476823, z: -0.84545517} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1038807940 PrefabInstance: m_ObjectHideFlags: 0 @@ -803,6 +858,28 @@ Transform: m_CorrespondingSourceObject: {fileID: 7965170655419664431, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} m_PrefabInstance: {fileID: 1380013023} m_PrefabAsset: {fileID: 0} +--- !u!114 &1380013025 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 6619618649642168463, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} + m_PrefabInstance: {fileID: 1380013023} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &1781135855 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 6619618649642168463, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} + m_PrefabInstance: {fileID: 1038807940} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1858015877 GameObject: m_ObjectHideFlags: 0 @@ -986,6 +1063,17 @@ Transform: m_CorrespondingSourceObject: {fileID: 7965170655419664431, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} m_PrefabInstance: {fileID: 1929610334} m_PrefabAsset: {fileID: 0} +--- !u!114 &1929610336 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 6619618649642168463, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} + m_PrefabInstance: {fileID: 1929610334} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &2030518899 PrefabInstance: m_ObjectHideFlags: 0 @@ -1048,6 +1136,17 @@ Transform: m_CorrespondingSourceObject: {fileID: 7965170655419664431, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} m_PrefabInstance: {fileID: 2030518899} m_PrefabAsset: {fileID: 0} +--- !u!114 &2030518901 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 6619618649642168463, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} + m_PrefabInstance: {fileID: 2030518899} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!114 &114306062090195993 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1134,10 +1233,22 @@ Transform: m_CorrespondingSourceObject: {fileID: 7965170655419664431, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} m_PrefabInstance: {fileID: 8318396349631803074} m_PrefabAsset: {fileID: 0} +--- !u!114 &8318396349631803076 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 6619618649642168463, guid: 6fa1678ce2080e44ca5b11723d197651, type: 3} + m_PrefabInstance: {fileID: 8318396349631803074} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 m_Roots: + - {fileID: 952215034} - {fileID: 1858015879} - {fileID: 1249182055} - {fileID: 510780377} diff --git a/Assets/Prefabs/Point.prefab b/Assets/Prefabs/Point.prefab index d765df5..3eac059 100644 --- a/Assets/Prefabs/Point.prefab +++ b/Assets/Prefabs/Point.prefab @@ -9,6 +9,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 7965170655419664431} + - component: {fileID: 6619618649642168463} m_Layer: 0 m_Name: Point m_TagString: Untagged @@ -31,3 +32,15 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6619618649642168463 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6039747573752144155} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 041c65d606731c44cb794dc7d95e72dd, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs new file mode 100644 index 0000000..a1fc838 --- /dev/null +++ b/Assets/Scripts/GameManager.cs @@ -0,0 +1,62 @@ +using UnityEngine; +using System.Collections.Generic; +using System; + +public class GameManager : MonoBehaviour +{ + [HideInInspector] + public static GameManager instance; + + + [Header("Parameters")] + [Range(0, 100)] + public float maxConnectionLength; + + + public List nodes = new List(); + + [SerializeField] + public List connections = new List(); + + [Serializable] + public struct Connection + { + public Node nodeA, nodeB; + public bool allowed; + } + + + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start() + { + foreach (Node nodeA in nodes) + { + foreach (Node nodeB in nodes) + { + bool conExists = false; + if (nodeA == nodeB || Vector3.Distance(nodeA.transform.position, nodeB.transform.position) > maxConnectionLength) + break; + + foreach (Connection con in connections) + { + if ((con.nodeA == nodeA && con.nodeB == nodeB) || (con.nodeA == nodeB && con.nodeB == nodeA)) + { + conExists = true; + break; + } + } + if(!conExists) + connections.Add(new Connection { nodeA = nodeA, nodeB = nodeB}); + } + } + } + + // Update is called once per frame + void Update() + { + foreach (Connection con in connections) + { + Debug.DrawLine(con.nodeA.transform.position, con.nodeB.transform.position, con.allowed ? Color.green : Color.red); + } + } +} diff --git a/Assets/Scripts/GameManager.cs.meta b/Assets/Scripts/GameManager.cs.meta new file mode 100644 index 0000000..38dac4a --- /dev/null +++ b/Assets/Scripts/GameManager.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: d9a8ed1dbf611654e914bd61e5a99aac \ No newline at end of file diff --git a/Assets/Scripts/Node.cs b/Assets/Scripts/Node.cs new file mode 100644 index 0000000..8906c80 --- /dev/null +++ b/Assets/Scripts/Node.cs @@ -0,0 +1,16 @@ +using UnityEngine; + +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() + { + + } +} diff --git a/Assets/Scripts/Node.cs.meta b/Assets/Scripts/Node.cs.meta new file mode 100644 index 0000000..7a9250e --- /dev/null +++ b/Assets/Scripts/Node.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 041c65d606731c44cb794dc7d95e72dd \ No newline at end of file