From f40d1ea4ae800a2d34c6cd37e33eb954fd1ca35f Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 11 Feb 2026 12:42:13 +0100 Subject: [PATCH] Fixes --- Editor/ClusterInspector.cs | 64 ++++++++++---------------------------- Neuron.cs | 9 +++--- NucleusArray.cs | 8 ++--- 3 files changed, 24 insertions(+), 57 deletions(-) diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index b52cba9..6d94ed5 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -19,16 +19,15 @@ public class ClusterInspector : Editor { public override VisualElement CreateInspectorGUI() { ClusterPrefab prefab = target as ClusterPrefab; - string path = AssetDatabase.GetAssetPath(prefab); // or known path - Debug.Log($"{path}"); - ClusterPrefab currentWrapper = AssetDatabase.LoadAssetAtPath(path); - if (currentWrapper == null) - Debug.LogError("CreateInspectorGUI: Cluster Prefab is not found on disk"); + // string path = AssetDatabase.GetAssetPath(prefab); // or known path + // Debug.Log($"{path}"); + // ClusterPrefab currentWrapper = AssetDatabase.LoadAssetAtPath(path); + // if (currentWrapper == null) + // Debug.LogError("CreateInspectorGUI: Cluster Prefab is not found on disk"); if (prefab != null) prefab.EnsureInitialization(); - serializedObject.Update(); VisualElement root = new(); @@ -176,20 +175,13 @@ public class ClusterInspector : Editor { return; } - // if (currentWrapper != null) - // DestroyImmediate(currentWrapper); - // currentWrapper = CreateInstance().Init(this.currentNucleus, prefab); - string path = AssetDatabase.GetAssetPath(this.prefab); // or known path this.prefabAsset = AssetDatabase.LoadAssetAtPath(path); if (this.prefabAsset == null) { - // create and save if it doesn't exist + // create in memory save if it doesn't exist this.prefabAsset = CreateInstance(); - // AssetDatabase.CreateAsset(currentWrapper, "Assets/ClusterPrefab.asset"); - // AssetDatabase.SaveAssets(); Debug.LogError("Cluster Prefab is not found on disk"); } - //currentWrapper.Init(this.currentNucleus, prefab); DrawInspector(inspectorContainer); } @@ -579,7 +571,7 @@ public class ClusterInspector : Editor { showSynapses = EditorGUILayout.BeginFoldoutHeaderGroup(showSynapses, "Synapses"); if (showSynapses) { - ConnectNucleus(this.prefab, this.currentNucleus); + anythingChanged = ConnectNucleus(this.prefab, this.currentNucleus); AddSynapse(this.prefab, this.currentNucleus); EditorGUILayout.Space(); @@ -627,7 +619,7 @@ public class ClusterInspector : Editor { EditorGUILayout.EndFoldoutHeaderGroup(); // Activation - + EditorGUILayout.Space(); showActivation = EditorGUILayout.BeginFoldoutHeaderGroup(showActivation, "Activation"); if (showActivation) { @@ -809,9 +801,9 @@ public class ClusterInspector : Editor { } // Connect to another nucleus in the same cluster - protected virtual void ConnectNucleus(ClusterPrefab cluster, Nucleus nucleus) { + protected virtual bool ConnectNucleus(ClusterPrefab cluster, Nucleus nucleus) { if (cluster == null) - return; + return false; IEnumerable synapseNuclei = this.currentNucleus.synapses .Where(synapse => synapse.nucleus != null) @@ -824,10 +816,12 @@ public class ClusterInspector : Editor { string[] names = nucleiNames.ToArray(); int selectedIndex = -1; selectedIndex = EditorGUILayout.Popup("Connect", selectedIndex, names); - if (selectedIndex >= 0) { - Nucleus receptor = nuclei.ElementAt(selectedIndex); - receptor.AddReceiver(this.currentNucleus); - } + if (selectedIndex < 0) + return false; + + Nucleus receptor = nuclei.ElementAt(selectedIndex); + receptor.AddReceiver(this.currentNucleus); + return true; } protected virtual void AddSynapse(ClusterPrefab cluster, Nucleus nucleus) { @@ -865,29 +859,3 @@ public class NeuroidLayer { public int ix = 0; public List neuroids = new(); } - -// public class ClusterWrapper : ScriptableObject { -// // expose fields that map to GraphNode -// //public string title; -// public Vector2 position; -// Nucleus node; -// ClusterPrefab graph; // needed to write back and mark dirty - -// public ClusterWrapper Init(Nucleus node, ClusterPrefab graphAsset) { -// this.node = node; -// this.graph = graphAsset; -// //this.title = " A " + node.name; -// //position = node.position; -// return this; -// } -// void OnValidate() { -// if (node != null) { -// //node.name = title; -// //node.position = position; -// #if UNITY_EDITOR -// if (graph != null) -// UnityEditor.EditorUtility.SetDirty(graph); -// #endif -// } -// } -// } \ No newline at end of file diff --git a/Neuron.cs b/Neuron.cs index 53865d4..089a862 100644 --- a/Neuron.cs +++ b/Neuron.cs @@ -17,11 +17,10 @@ public class Neuron : Nucleus { public Neuron(ClusterPrefab parent, string name) { this.cluster = parent; this.name = name; - if (this.cluster != null) { - this.cluster.nuclei.Add(this); - } - // else - // Debug.LogError("No neuroid network"); + if (this.cluster != null) + this.cluster.nuclei.Add(this); + else + Debug.LogError("No prefab when adding neuron to prefab"); } #region Serialization diff --git a/NucleusArray.cs b/NucleusArray.cs index c4141b4..30c77be 100644 --- a/NucleusArray.cs +++ b/NucleusArray.cs @@ -13,19 +13,19 @@ public class NucleusArray { return _nuclei; } } - public string name; + //public string name; public NucleusArray(Nucleus nucleus) { - this.name = nucleus.name; + //this.name = nucleus.name; this._nuclei = new Nucleus[1]; this._nuclei[0] = nucleus; } public NucleusArray(ClusterPrefab cluster) { - this.name = cluster.name; + //this.name = cluster.name; this._nuclei = new Nucleus[0]; } public NucleusArray(int size, string name) { - this.name = name; + //this.name = name; this._nuclei = new Nucleus[size]; }