This commit is contained in:
Pascal Serrarens 2026-02-11 12:42:13 +01:00
parent c1bf54a1cc
commit f40d1ea4ae
3 changed files with 24 additions and 57 deletions

View File

@ -19,16 +19,15 @@ public class ClusterInspector : Editor {
public override VisualElement CreateInspectorGUI() { public override VisualElement CreateInspectorGUI() {
ClusterPrefab prefab = target as ClusterPrefab; ClusterPrefab prefab = target as ClusterPrefab;
string path = AssetDatabase.GetAssetPath(prefab); // or known path // string path = AssetDatabase.GetAssetPath(prefab); // or known path
Debug.Log($"{path}"); // Debug.Log($"{path}");
ClusterPrefab currentWrapper = AssetDatabase.LoadAssetAtPath<ClusterPrefab>(path); // ClusterPrefab currentWrapper = AssetDatabase.LoadAssetAtPath<ClusterPrefab>(path);
if (currentWrapper == null) // if (currentWrapper == null)
Debug.LogError("CreateInspectorGUI: Cluster Prefab is not found on disk"); // Debug.LogError("CreateInspectorGUI: Cluster Prefab is not found on disk");
if (prefab != null) if (prefab != null)
prefab.EnsureInitialization(); prefab.EnsureInitialization();
serializedObject.Update(); serializedObject.Update();
VisualElement root = new(); VisualElement root = new();
@ -176,20 +175,13 @@ public class ClusterInspector : Editor {
return; return;
} }
// if (currentWrapper != null)
// DestroyImmediate(currentWrapper);
// currentWrapper = CreateInstance<ClusterWrapper>().Init(this.currentNucleus, prefab);
string path = AssetDatabase.GetAssetPath(this.prefab); // or known path string path = AssetDatabase.GetAssetPath(this.prefab); // or known path
this.prefabAsset = AssetDatabase.LoadAssetAtPath<ClusterPrefab>(path); this.prefabAsset = AssetDatabase.LoadAssetAtPath<ClusterPrefab>(path);
if (this.prefabAsset == null) { if (this.prefabAsset == null) {
// create and save if it doesn't exist // create in memory save if it doesn't exist
this.prefabAsset = CreateInstance<ClusterPrefab>(); this.prefabAsset = CreateInstance<ClusterPrefab>();
// AssetDatabase.CreateAsset(currentWrapper, "Assets/ClusterPrefab.asset");
// AssetDatabase.SaveAssets();
Debug.LogError("Cluster Prefab is not found on disk"); Debug.LogError("Cluster Prefab is not found on disk");
} }
//currentWrapper.Init(this.currentNucleus, prefab);
DrawInspector(inspectorContainer); DrawInspector(inspectorContainer);
} }
@ -579,7 +571,7 @@ public class ClusterInspector : Editor {
showSynapses = EditorGUILayout.BeginFoldoutHeaderGroup(showSynapses, "Synapses"); showSynapses = EditorGUILayout.BeginFoldoutHeaderGroup(showSynapses, "Synapses");
if (showSynapses) { if (showSynapses) {
ConnectNucleus(this.prefab, this.currentNucleus); anythingChanged = ConnectNucleus(this.prefab, this.currentNucleus);
AddSynapse(this.prefab, this.currentNucleus); AddSynapse(this.prefab, this.currentNucleus);
EditorGUILayout.Space(); EditorGUILayout.Space();
@ -627,7 +619,7 @@ public class ClusterInspector : Editor {
EditorGUILayout.EndFoldoutHeaderGroup(); EditorGUILayout.EndFoldoutHeaderGroup();
// Activation // Activation
EditorGUILayout.Space(); EditorGUILayout.Space();
showActivation = EditorGUILayout.BeginFoldoutHeaderGroup(showActivation, "Activation"); showActivation = EditorGUILayout.BeginFoldoutHeaderGroup(showActivation, "Activation");
if (showActivation) { if (showActivation) {
@ -809,9 +801,9 @@ public class ClusterInspector : Editor {
} }
// Connect to another nucleus in the same cluster // 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) if (cluster == null)
return; return false;
IEnumerable<Nucleus> synapseNuclei = this.currentNucleus.synapses IEnumerable<Nucleus> synapseNuclei = this.currentNucleus.synapses
.Where(synapse => synapse.nucleus != null) .Where(synapse => synapse.nucleus != null)
@ -824,10 +816,12 @@ public class ClusterInspector : Editor {
string[] names = nucleiNames.ToArray(); string[] names = nucleiNames.ToArray();
int selectedIndex = -1; int selectedIndex = -1;
selectedIndex = EditorGUILayout.Popup("Connect", selectedIndex, names); selectedIndex = EditorGUILayout.Popup("Connect", selectedIndex, names);
if (selectedIndex >= 0) { if (selectedIndex < 0)
Nucleus receptor = nuclei.ElementAt(selectedIndex); return false;
receptor.AddReceiver(this.currentNucleus);
} Nucleus receptor = nuclei.ElementAt(selectedIndex);
receptor.AddReceiver(this.currentNucleus);
return true;
} }
protected virtual void AddSynapse(ClusterPrefab cluster, Nucleus nucleus) { protected virtual void AddSynapse(ClusterPrefab cluster, Nucleus nucleus) {
@ -865,29 +859,3 @@ public class NeuroidLayer {
public int ix = 0; public int ix = 0;
public List<Nucleus> neuroids = new(); public List<Nucleus> 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
// }
// }
// }

View File

@ -17,11 +17,10 @@ public class Neuron : Nucleus {
public Neuron(ClusterPrefab parent, string name) { public Neuron(ClusterPrefab parent, string name) {
this.cluster = parent; this.cluster = parent;
this.name = name; this.name = name;
if (this.cluster != null) { if (this.cluster != null)
this.cluster.nuclei.Add(this); this.cluster.nuclei.Add(this);
} else
// else Debug.LogError("No prefab when adding neuron to prefab");
// Debug.LogError("No neuroid network");
} }
#region Serialization #region Serialization

View File

@ -13,19 +13,19 @@ public class NucleusArray {
return _nuclei; return _nuclei;
} }
} }
public string name; //public string name;
public NucleusArray(Nucleus nucleus) { public NucleusArray(Nucleus nucleus) {
this.name = nucleus.name; //this.name = nucleus.name;
this._nuclei = new Nucleus[1]; this._nuclei = new Nucleus[1];
this._nuclei[0] = nucleus; this._nuclei[0] = nucleus;
} }
public NucleusArray(ClusterPrefab cluster) { public NucleusArray(ClusterPrefab cluster) {
this.name = cluster.name; //this.name = cluster.name;
this._nuclei = new Nucleus[0]; this._nuclei = new Nucleus[0];
} }
public NucleusArray(int size, string name) { public NucleusArray(int size, string name) {
this.name = name; //this.name = name;
this._nuclei = new Nucleus[size]; this._nuclei = new Nucleus[size];
} }