From e477ce4814432e35353c4fa4281d101a6efbf75d Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 12 Jan 2026 16:06:12 +0100 Subject: [PATCH] (re)added nucleus arrays --- Assembly-CSharp.csproj | 2 +- Assets/NanoBrain/Cluster.cs | 10 +- Assets/NanoBrain/INucleus.cs | 6 +- Assets/NanoBrain/Neuroid.cs | 22 +++ Assets/NanoBrain/Nucleus.cs | 106 +++++++-------- Assets/NanoBrain/NucleusArray.cs | 45 +++++++ ...pteiArray.cs.meta => NucleusArray.cs.meta} | 0 Assets/NanoBrain/PercepteiArray.cs | 61 --------- Assets/NanoBrain/Perceptoid.cs | 2 + Assets/NanoBrain/Receptor.cs | 56 ++++---- Assets/NanoBrain/Synapse.cs | 36 ++--- .../VisualEditor/Editor/BrainPickerWindow.cs | 10 +- .../VisualEditor/Editor/ClusterInspector.cs | 125 +++++------------- .../VisualEditor/Editor/NanoBrainInspector.cs | 7 +- Assets/NanoBrain/VisualEditor/NanoBrain.cs | 8 +- 15 files changed, 223 insertions(+), 273 deletions(-) create mode 100644 Assets/NanoBrain/NucleusArray.cs rename Assets/NanoBrain/{PercepteiArray.cs.meta => NucleusArray.cs.meta} (100%) delete mode 100644 Assets/NanoBrain/PercepteiArray.cs diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index d59c742..891c3d0 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -62,7 +62,6 @@ - @@ -83,6 +82,7 @@ + diff --git a/Assets/NanoBrain/Cluster.cs b/Assets/NanoBrain/Cluster.cs index 2216d32..a148a00 100644 --- a/Assets/NanoBrain/Cluster.cs +++ b/Assets/NanoBrain/Cluster.cs @@ -21,6 +21,13 @@ public class Cluster : ScriptableObject, INucleus { private readonly List _synapses = new(); public List synapses => _synapses; + public NucleusArray array { get; set; } + + public INucleus Clone() { + Cluster clone = CreateInstance(); + // Lots to add here... + return clone; + } // Call this function to ensure that there is at least one nucleus // This is an invariant and should be ensured before the nucleus is used @@ -42,9 +49,10 @@ public class Cluster : ScriptableObject, INucleus { get => output.receivers; } - public void AddSynapse(IReceptor sender) { + public Synapse AddSynapse(IReceptor sender) { Synapse synapse = new(sender, 1.0f); synapses.Add(synapse); + return synapse; } public void GarbageCollection() { diff --git a/Assets/NanoBrain/INucleus.cs b/Assets/NanoBrain/INucleus.cs index 45c0acd..535caca 100644 --- a/Assets/NanoBrain/INucleus.cs +++ b/Assets/NanoBrain/INucleus.cs @@ -10,7 +10,9 @@ public interface INucleus : IReceptor { // Senders public List synapses { get; } - public void AddSynapse(IReceptor sender); + public Synapse AddSynapse(IReceptor sender); + + public NucleusArray array { get; set; } #endregion static struct @@ -21,6 +23,8 @@ public interface INucleus : IReceptor { public void IncreaseAge(); #endregion dynamic state + + public INucleus Clone(); } public interface IReceptor { diff --git a/Assets/NanoBrain/Neuroid.cs b/Assets/NanoBrain/Neuroid.cs index 9e56de1..f14a788 100644 --- a/Assets/NanoBrain/Neuroid.cs +++ b/Assets/NanoBrain/Neuroid.cs @@ -16,6 +16,28 @@ public class Neuroid : Nucleus { public Neuroid(string name) : base(name) { } + public override INucleus Clone() { + Neuroid clone = new(this.name) { + cluster = this.cluster, + array = this.array, + curve = this.curve, + curvePreset = this.curvePreset, + curveMax = this.curveMax, + average = this.average + }; + if (clone.cluster != null) + clone.cluster.nuclei.Add(clone); + + foreach (Synapse synapse in this.synapses) { + Synapse clonedSynapse = clone.AddSynapse(synapse.nucleus); + clonedSynapse.weight = synapse.weight; + } + foreach (INucleus receiver in this.receivers) { + clone.AddReceiver(receiver); + } + return clone; + } + public void SetWeight(Neuroid input, float weight) { this.SetWeight((Nucleus)input, weight); } diff --git a/Assets/NanoBrain/Nucleus.cs b/Assets/NanoBrain/Nucleus.cs index 41ac085..01f0693 100644 --- a/Assets/NanoBrain/Nucleus.cs +++ b/Assets/NanoBrain/Nucleus.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using UnityEngine; -using UnityEditor; [Serializable] public class Nucleus : INucleus { @@ -23,6 +22,7 @@ public class Nucleus : INucleus { private List _receivers = new(); public List receivers => _receivers; + public NucleusArray array { get; set; } #region Serialization [SerializeField] @@ -67,31 +67,31 @@ public class Nucleus : INucleus { } } - public virtual void Rebuild(NanoBrain brain) { - if (this.synapses != null) { - foreach (Synapse synapse in synapses) - synapse.Rebuild(brain); - } - // foreach (INucleus receiver in receivers.ToArray()) { - // if (receiver.Rebuild(brain) == false) { - // Debug.Log("Rebuilding failed, removing receiver."); - // receivers.Remove(receiver); - // } - // } - } + // public virtual void Rebuild(NanoBrain brain) { + // if (this.synapses != null) { + // foreach (Synapse synapse in synapses) + // synapse.Rebuild(brain); + // } + // // foreach (INucleus receiver in receivers.ToArray()) { + // // if (receiver.Rebuild(brain) == false) { + // // Debug.Log("Rebuilding failed, removing receiver."); + // // receivers.Remove(receiver); + // // } + // // } + // } - public static Nucleus RebuildType(NanoBrain brain, Nucleus nucleus) { - if (string.IsNullOrEmpty(nucleus.nucleusType) == false) { - Type nucleusType = Type.GetType(nucleus.nucleusType); - if (nucleusType != null) { - object[] args = new object[] { brain, nucleus.name }; - Nucleus rebuiltNucleus = (Nucleus)Activator.CreateInstance(nucleusType, args); - rebuiltNucleus.Deserialize(nucleus); - return rebuiltNucleus; - } - } - return nucleus; - } + // public static Nucleus RebuildType(NanoBrain brain, Nucleus nucleus) { + // if (string.IsNullOrEmpty(nucleus.nucleusType) == false) { + // Type nucleusType = Type.GetType(nucleus.nucleusType); + // if (nucleusType != null) { + // object[] args = new object[] { brain, nucleus.name }; + // Nucleus rebuiltNucleus = (Nucleus)Activator.CreateInstance(nucleusType, args); + // rebuiltNucleus.Deserialize(nucleus); + // return rebuiltNucleus; + // } + // } + // return nucleus; + // } public virtual void Deserialize(Nucleus nucleus) { } @@ -133,10 +133,29 @@ public class Nucleus : INucleus { this.id = this.GetHashCode(); } + public virtual INucleus Clone() { + Nucleus clone = new(this.name) { + cluster = this.cluster, + array = this.array, + curve = this.curve, + curvePreset = this.curvePreset, + curveMax = this.curveMax + }; + if (clone.cluster != null) + clone.cluster.nuclei.Add(clone); + + foreach (Synapse synapse in this.synapses) { + Synapse clonedSynapse = clone.AddSynapse(synapse.nucleus); + clonedSynapse.weight = synapse.weight; + } + foreach (INucleus receiver in this.receivers) { + clone.AddReceiver(receiver); + } + return clone; + } + public virtual void AddReceiver(INucleus receivingNucleus) { - // this.receivers.Add(new Receiver(receivingNucleus)); this.receivers.Add(receivingNucleus); - //receivingNucleus.SetWeight(this, 1.0f); receivingNucleus.AddSynapse(this); } @@ -182,9 +201,10 @@ public class Nucleus : INucleus { return false; } - public void AddSynapse(IReceptor sendingNucleus) { + public Synapse AddSynapse(IReceptor sendingNucleus) { Synapse synapse = new(sendingNucleus, 1.0f); this.synapses.Add(synapse); + return synapse; } public void SetWeight(Nucleus nucleus, float weight) { foreach (Synapse synapse in synapses) { @@ -211,32 +231,4 @@ public class Nucleus : INucleus { receiver.UpdateState(); } -} - -// [Serializable] -// public class Receiver { -// [NonSerialized] -// public INucleus nucleus; -// //public int nucleusId; - -// public Receiver(INucleus nucleus) { -// this.nucleus = nucleus; -// //this.nucleusId = nucleus.id; -// } - -// public bool Rebuild(NanoBrain brain) { -// if (brain == null) { -// return false; -// } - -// // Use SerializedReference instead? -// // foreach (Nucleus nucleus in brain.nuclei) { -// // if (nucleus.id == this.nucleusId) { -// // this.nucleus = nucleus; -// // return true; -// // } -// // } -// //Debug.LogWarning($"Receiver deserialization error: could not find nucleus with id {this.nucleusId}"); -// return false; -// } -// } \ No newline at end of file +} \ No newline at end of file diff --git a/Assets/NanoBrain/NucleusArray.cs b/Assets/NanoBrain/NucleusArray.cs new file mode 100644 index 0000000..db34958 --- /dev/null +++ b/Assets/NanoBrain/NucleusArray.cs @@ -0,0 +1,45 @@ + +using UnityEngine; + +[System.Serializable] +public class NucleusArray { + [SerializeReference] + public INucleus[] nuclei; + public string name; + + public NucleusArray(INucleus nucleus) { + this.name = nucleus.name; + this.nuclei = new INucleus[1]; + this.nuclei[0] = nucleus; + } + + public void AddNucleus() { + if (this.nuclei.Length == 0) { + Debug.LogError("Empty perceptoid array, cannot add"); + return; + } + int newLength = this.nuclei.Length + 1; + INucleus[] newArray = new INucleus[newLength]; + + for (int i = 0; i < this.nuclei.Length; i++) + newArray[i] = this.nuclei[i]; + newArray[newLength - 1] = this.nuclei[0].Clone(); + + this.nuclei = newArray; + } + + public void RemoveNucleus() { + int newLength = this.nuclei.Length - 1; + if (newLength == 0) { + Debug.LogWarning("Perceptoid array cannot be empty"); + return; + } + INucleus[] newPerceptei = new INucleus[newLength]; + for (int i = 0; i < newLength; i++) + newPerceptei[i++] = this.nuclei[i]; + // Delete the last perception + Nucleus.Delete(this.nuclei[newLength]); + + this.nuclei = newPerceptei; + } +} \ No newline at end of file diff --git a/Assets/NanoBrain/PercepteiArray.cs.meta b/Assets/NanoBrain/NucleusArray.cs.meta similarity index 100% rename from Assets/NanoBrain/PercepteiArray.cs.meta rename to Assets/NanoBrain/NucleusArray.cs.meta diff --git a/Assets/NanoBrain/PercepteiArray.cs b/Assets/NanoBrain/PercepteiArray.cs deleted file mode 100644 index a46f2d0..0000000 --- a/Assets/NanoBrain/PercepteiArray.cs +++ /dev/null @@ -1,61 +0,0 @@ -using UnityEngine; - -[System.Serializable] -public class PercepteiArray { - [SerializeReference] - public Perceptoid[] perceptei; - public string name; - - // public PercepteiArray(NanoBrain brain, int thingType, string baseName, uint count) { - // this.name = baseName; - // this.perceptei = new Perceptoid[count]; - // for (uint i = 0; i < count; i++) { - // this.perceptei[i] = new Perceptoid(brain, thingType, $"{baseName}[{i}]") { - // array = this - // }; - // } - // } - public PercepteiArray(Perceptoid perceptoid) { - this.name = perceptoid.baseName; - this.perceptei = new Perceptoid[1]; - this.perceptei[0] = perceptoid; - } - - public void AddPerceptoid() { - if (this.perceptei.Length == 0) { - Debug.LogError("Empty perceptoid array, cannot add"); - return; - } - int newLength = this.perceptei.Length + 1; - Perceptoid[] newPerceptei = new Perceptoid[newLength]; - - for (int i = 0; i < this.perceptei.Length; i++) - newPerceptei[i] = this.perceptei[i]; - newPerceptei[newLength - 1] = new Perceptoid(this); - - this.perceptei = newPerceptei; - } - - public void RemovePerceptoid() { - int newLength = this.perceptei.Length - 1; - if (newLength == 0) { - Debug.LogWarning("Perceptoid array cannot be empty"); - return; - } - Perceptoid[] newPerceptei = new Perceptoid[newLength]; - for (int i = 0; i < newLength; i++) - newPerceptei[i++] = this.perceptei[i]; - // Delete the last perception - Nucleus.Delete(this.perceptei[newLength]); - - this.perceptei = newPerceptei; - } -} - -// public class ArrayPerceptoid : Perceptoid { -// public PercepteiArray array; - -// public ArrayPerceptoid(NanoBrain brain, int thingType, string name = "sensor") : base(brain, thingType, name) { -// } - -// } \ No newline at end of file diff --git a/Assets/NanoBrain/Perceptoid.cs b/Assets/NanoBrain/Perceptoid.cs index b30847e..447a3d7 100644 --- a/Assets/NanoBrain/Perceptoid.cs +++ b/Assets/NanoBrain/Perceptoid.cs @@ -1,3 +1,4 @@ +/* using UnityEngine; [System.Serializable] @@ -101,3 +102,4 @@ public class Perceptoid : Neuroid { } } +*/ \ No newline at end of file diff --git a/Assets/NanoBrain/Receptor.cs b/Assets/NanoBrain/Receptor.cs index dcd3c28..39f1699 100644 --- a/Assets/NanoBrain/Receptor.cs +++ b/Assets/NanoBrain/Receptor.cs @@ -10,18 +10,12 @@ public class Receptor : IReceptor { set => _name = value; } - public Cluster cluster; - //public INucleus nucleus; - - //[SerializeField] [SerializeReference] private List _receivers = new(); public List receivers => _receivers; public virtual void AddReceiver(INucleus receivingNucleus) { - //this.receivers.Add(new Receiver(receivingNucleus)); this.receivers.Add(receivingNucleus); - //receivingNucleus.SetWeight(this, 1.0f); receivingNucleus.AddSynapse(this); } @@ -35,18 +29,18 @@ public class Receptor : IReceptor { /// /// The list of perceptoid which can process stimuli from this receptor /// - public List perceptei = new(); + //public List perceptei = new(); - private int _thingType = 0; - public int thingType { - get { return _thingType; } - set { - _thingType = value; - foreach (Perceptoid perceptoid in perceptei) { - perceptoid.thingType = _thingType; - } - } - } + // private int _thingType = 0; + // public int thingType { + // get { return _thingType; } + // set { + // _thingType = value; + // foreach (Perceptoid perceptoid in perceptei) { + // perceptoid.thingType = _thingType; + // } + // } + // } public Vector3 localPosition; public float distanceResolution = 0.1f; public float directionResolution = 5; @@ -59,26 +53,24 @@ public class Receptor : IReceptor { } - public Receptor(NanoBrain brain, int thingType) { - this.thingType = thingType; - //this.perceptei.Add(perceptoid); - brain.receptors.Add(this); - } + // public Receptor(NanoBrain brain, int thingType) { + // this.thingType = thingType; + // brain.receptors.Add(this); + // } public Receptor(Cluster cluster, INucleus nucleus) { - this.cluster = cluster; - //nucleus.AddSynapse(this); + //this.cluster = cluster; this.AddReceiver(nucleus); } - public static Receptor GetReceptor(NanoBrain brain, int thingType) { - foreach (Receptor receptor in brain.receptors) { - if (thingType == 0 || receptor.thingType == thingType) - return receptor; - } - Receptor newReceptor = new(brain, thingType); - return newReceptor; - } + // public static Receptor GetReceptor(NanoBrain brain, int thingType) { + // foreach (Receptor receptor in brain.receptors) { + // if (thingType == 0 || receptor.thingType == thingType) + // return receptor; + // } + // Receptor newReceptor = new(brain, thingType); + // return newReceptor; + // } public static Receptor CreateReceptor(Cluster cluster, string nucleusName) { if (cluster == null) diff --git a/Assets/NanoBrain/Synapse.cs b/Assets/NanoBrain/Synapse.cs index 7bcdfde..ef42fb5 100644 --- a/Assets/NanoBrain/Synapse.cs +++ b/Assets/NanoBrain/Synapse.cs @@ -29,25 +29,25 @@ public class Synapse { this.weight = weight; } - public void Rebuild(NanoBrain brain) { - // if (brain == null) { - // return; - // } + // public void Rebuild(NanoBrain brain) { + // // if (brain == null) { + // // return; + // // } - // foreach (Nucleus nucleus in brain.nuclei) { - // if (nucleus.id == this.nucleusId) { - // this.nucleus = nucleus; - // return; - // } - // } - // foreach (Perceptoid perceptoid in brain.perceptei) { - // if (perceptoid.id == this.nucleusId) { - // this.nucleus = perceptoid; - // return; - // } - // } - // Debug.LogError($"Synapse deserialization error: could not find nucleus with id {this.nucleusId}"); - } + // // foreach (Nucleus nucleus in brain.nuclei) { + // // if (nucleus.id == this.nucleusId) { + // // this.nucleus = nucleus; + // // return; + // // } + // // } + // // foreach (Perceptoid perceptoid in brain.perceptei) { + // // if (perceptoid.id == this.nucleusId) { + // // this.nucleus = perceptoid; + // // return; + // // } + // // } + // // Debug.LogError($"Synapse deserialization error: could not find nucleus with id {this.nucleusId}"); + // } // public AnimationCurve GenerateCurve() { // switch (this.curvePreset) { diff --git a/Assets/NanoBrain/VisualEditor/Editor/BrainPickerWindow.cs b/Assets/NanoBrain/VisualEditor/Editor/BrainPickerWindow.cs index d80c282..6e7a849 100644 --- a/Assets/NanoBrain/VisualEditor/Editor/BrainPickerWindow.cs +++ b/Assets/NanoBrain/VisualEditor/Editor/BrainPickerWindow.cs @@ -6,11 +6,11 @@ using System.Linq; public class BrainPickerWindow : EditorWindow { private Vector2 scroll; - private NanoBrain[] items = new NanoBrain[0]; - private Action onPicked; + private Cluster[] items = new Cluster[0]; + private Action onPicked; private string search = ""; - public static void ShowPicker(Action onPicked, string title = "Select NanoBrain") + public static void ShowPicker(Action onPicked, string title = "Select NanoBrain") { var w = CreateInstance(); w.titleContent = new GUIContent(title); @@ -26,7 +26,7 @@ public class BrainPickerWindow : EditorWindow { var guids = AssetDatabase.FindAssets("t:NanoBrain"); items = guids - .Select(g => AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(g))) + .Select(g => AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(g))) .Where(b => b != null) .OrderBy(b => b.name) .ToArray(); @@ -52,7 +52,7 @@ public class BrainPickerWindow : EditorWindow continue; EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField(EditorGUIUtility.ObjectContent(it, typeof(NanoBrain)), GUILayout.Height(20)); + EditorGUILayout.LabelField(EditorGUIUtility.ObjectContent(it, typeof(Cluster)), GUILayout.Height(20)); if (GUILayout.Button("Select", GUILayout.Width(70))) { onPicked?.Invoke(it); diff --git a/Assets/NanoBrain/VisualEditor/Editor/ClusterInspector.cs b/Assets/NanoBrain/VisualEditor/Editor/ClusterInspector.cs index b3a443b..1d7ae17 100644 --- a/Assets/NanoBrain/VisualEditor/Editor/ClusterInspector.cs +++ b/Assets/NanoBrain/VisualEditor/Editor/ClusterInspector.cs @@ -271,25 +271,14 @@ public class ClusterInspector : Editor { float margin = 10 + spacing / 2; int row = 0; - List drawnArrays = new(); + List drawnArrays = new(); foreach (Synapse synapse in nucleus.synapses) { Vector3 pos = new(250, margin + row * spacing, 0.0f); Handles.color = Color.white; Handles.DrawLine(parentPos, pos); - // if (synapse.nucleus is Perceptoid perceptoid && perceptoid.array != null) { - // // if (drawnArrays.Contains(perceptoid.array)) - // // // We already drawn this array - // // continue; - - // drawnArrays.Add(perceptoid.array); - // DrawArray(perceptoid.array, pos, size); - // } - // else { - if (synapse.nucleus != null) DrawNucleus(synapse.nucleus, pos, maxValue, size); row++; - // } } } @@ -315,12 +304,12 @@ public class ClusterInspector : Editor { normal = { textColor = Color.white }, fontStyle = FontStyle.Bold, }; - if (nucleus is Perceptoid perceptoid) { - if (perceptoid.array == null || perceptoid.array.perceptei == null || perceptoid.array.perceptei.Length == 0) - perceptoid.array = new PercepteiArray(perceptoid); + if (nucleus is Nucleus perceptoid) { + if (perceptoid.array == null || perceptoid.array.nuclei == null || perceptoid.array.nuclei.Length == 0) + perceptoid.array = new NucleusArray(perceptoid); - if (perceptoid.array.perceptei.Length > 1) { - Handles.Label(labelPosition, perceptoid.array.perceptei.Length.ToString(), style); + if (perceptoid.array.nuclei.Length > 1) { + Handles.Label(labelPosition, perceptoid.array.nuclei.Length.ToString(), style); } } @@ -344,46 +333,15 @@ public class ClusterInspector : Editor { } } - private void DrawArray(PercepteiArray array, Vector3 position, float size) { - Vector3 offset = new(size / 4, size / 4, 0); - Handles.color = Color.black; - Handles.DrawSolidDisc(position, Vector3.forward, size); - - GUIStyle style = new(EditorStyles.label) { - alignment = TextAnchor.UpperCenter, - normal = { textColor = Color.white }, - fontStyle = FontStyle.Bold - }; - Handles.Label(position, array.perceptei.Length.ToString(), style); - Vector3 labelPos = position - Vector3.down * (size + 0.2f); // below disc along up axis - Handles.Label(labelPos, array.name, style); - - // To do: add HandleClick (see above) to expand the array - } - private void HandleMouseHover(IReceptor nucleus, Rect rect) { GUIContent tooltip; - if (nucleus is Perceptoid perceptoid) { - if (perceptoid.receptor != null) { - tooltip = new( - $"{perceptoid.name}" + - $"\nType {perceptoid.receptor.thingType}" + - $" Thing {perceptoid.thingId}" + - $"\nValue: {nucleus.outputValue}"); - } - else { - tooltip = new( - $"{perceptoid.name}" + - $"\nThing {perceptoid.thingId}" + - $"\nValue: {nucleus.outputValue}"); - } - } - else if (nucleus is INucleus n) { + if (nucleus is INucleus n) { tooltip = new( $"{nucleus.name}" + $"\nsynapse count {n.synapses.Count}" + $"\nValue: {nucleus.outputValue}"); - } else { + } + else { tooltip = new( $"{nucleus.name}" + $"\nValue: {nucleus.outputValue}"); @@ -400,8 +358,8 @@ public class ClusterInspector : Editor { private void HandleClicked(IReceptor nucleus) { if (nucleus is INucleus n) { - this.currentNucleus = n; - BuildLayers(); + this.currentNucleus = n; + BuildLayers(); } } @@ -424,29 +382,30 @@ public class ClusterInspector : Editor { return; this.currentNucleus.name = EditorGUILayout.TextField(this.currentNucleus.name); - if (this.currentNucleus is Perceptoid perceptoid) { - perceptoid.receptor.thingType = EditorGUILayout.IntField("Thing Type", perceptoid.receptor.thingType); + if (this.currentNucleus is Nucleus perceptoid) { + // perceptoid.receptor.thingType = EditorGUILayout.IntField("Thing Type", perceptoid.receptor.thingType); - if (perceptoid.array == null || perceptoid.array.perceptei == null || perceptoid.array.perceptei.Length == 0) - perceptoid.array = new PercepteiArray(perceptoid); + if (perceptoid.array == null || perceptoid.array.nuclei == null || perceptoid.array.nuclei.Length == 0) + perceptoid.array = new NucleusArray(perceptoid); EditorGUILayout.BeginHorizontal(); - EditorGUILayout.IntField("Array size", perceptoid.array.perceptei.Length); + EditorGUILayout.IntField("Array size", perceptoid.array.nuclei.Length); if (GUILayout.Button("Add")) - perceptoid.array.AddPerceptoid(); + perceptoid.array.AddNucleus(); if (GUILayout.Button("Del")) - perceptoid.array.RemovePerceptoid(); - EditorGUILayout.EndHorizontal(); - } - else if (this.currentNucleus is Nucleus neuroid) { - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField("Activation Curve", GUILayout.Width(150)); - if (neuroid.curveMax > 0) - EditorGUILayout.CurveField(neuroid.curve, Color.cyan, new Rect(0, 0, 1, neuroid.curveMax)); - else - EditorGUILayout.CurveField(neuroid.curve, Color.cyan, new Rect(0, neuroid.curveMax, 1, -neuroid.curveMax)); - neuroid.curvePreset = (Neuroid.CurvePresets)EditorGUILayout.EnumPopup(neuroid.curvePreset, GUILayout.Width(100)); + perceptoid.array.RemoveNucleus(); EditorGUILayout.EndHorizontal(); } + else + if (this.currentNucleus is Nucleus neuroid) { + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("Activation Curve", GUILayout.Width(150)); + if (neuroid.curveMax > 0) + EditorGUILayout.CurveField(neuroid.curve, Color.cyan, new Rect(0, 0, 1, neuroid.curveMax)); + else + EditorGUILayout.CurveField(neuroid.curve, Color.cyan, new Rect(0, neuroid.curveMax, 1, -neuroid.curveMax)); + neuroid.curvePreset = (Neuroid.CurvePresets)EditorGUILayout.EnumPopup(neuroid.curvePreset, GUILayout.Width(100)); + EditorGUILayout.EndHorizontal(); + } if (Application.isPlaying) EditorGUILayout.FloatField("Output", this.currentNucleus.outputValue.magnitude); @@ -465,14 +424,6 @@ public class ClusterInspector : Editor { else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(synapse.nucleus.name); - // if (synapse.nucleus is Perceptoid perceptoid) { - // if (perceptoid.array == null || perceptoid.array.perceptei == null || perceptoid.array.perceptei.Length == 0) { - // perceptoid.array = new PercepteiArray(perceptoid); - // } - // EditorGUILayout.IntField(perceptoid.array.perceptei.Length); - // if (GUILayout.Button("Add")) - // perceptoid.array.AddPerceptoid(); - // } if (GUILayout.Button("Disconnect")) synapse.nucleus.RemoveReceiver(this.currentNucleus); EditorGUILayout.EndHorizontal(); @@ -491,8 +442,6 @@ public class ClusterInspector : Editor { ConnectNucleus(cluster, this.currentNucleus); if (GUILayout.Button("Add Input Neuron")) AddInputNeuron(this.currentNucleus); - // if (GUILayout.Button("Add Input Perceptoid")) - // AddPerceptoid(this.currentNucleus); if (GUILayout.Button("Add Input Cluster")) AddCluster(this.currentNucleus); @@ -501,7 +450,6 @@ public class ClusterInspector : Editor { if (GUILayout.Button("Delete this neuron")) DeleteNeuron(this.currentNucleus); - //DisconnectNucleus(this.currentNucleus); if (this.gameObject != null) { Vector3 worldVector = this.gameObject.transform.TransformVector(this.currentNucleus.outputValue); @@ -534,19 +482,12 @@ public class ClusterInspector : Editor { BuildLayers(); } - // protected virtual void AddPerceptoid(INucleus nucleus) { - // Perceptoid newPerceptoid = new(this.brain, 0, "New Perceptoid"); - // newPerceptoid.AddReceiver(nucleus); - // this.currentNucleus = newPerceptoid; - // BuildLayers(); - // } - protected virtual void AddCluster(INucleus nucleus) { BrainPickerWindow.ShowPicker(brain => OnClusterPicked(nucleus, brain), "Select Cluster"); } - private void OnClusterPicked(INucleus nucleus, NanoBrain brain) { - NanoBrain brainInstance = Instantiate(brain); + private void OnClusterPicked(INucleus nucleus, Cluster brain) { + Cluster brainInstance = Instantiate(brain); brainInstance.AddReceiver(nucleus); } @@ -555,7 +496,7 @@ public class ClusterInspector : Editor { if (cluster == null) return; - IEnumerable synapseNuclei = this.currentNucleus.synapses.Select(synapse => synapse.nucleus != null ? synapse.nucleus.name: ""); + IEnumerable synapseNuclei = this.currentNucleus.synapses.Select(synapse => synapse.nucleus != null ? synapse.nucleus.name : ""); //IEnumerable perceptei = this.currentNucleus.brain.perceptei.Select(i => i.name).Except(synapseNuclei); IEnumerable nuclei = cluster.nuclei.Select(i => i.name).Except(synapseNuclei); //string[] names = perceptei.Concat(nuclei).ToArray(); @@ -572,7 +513,7 @@ public class ClusterInspector : Editor { // n.AddReceiver(this.currentNucleus); // } INucleus n = cluster.nuclei[selectedIndex]; - n.AddReceiver(this.currentNucleus); + n.AddReceiver(this.currentNucleus); } } diff --git a/Assets/NanoBrain/VisualEditor/Editor/NanoBrainInspector.cs b/Assets/NanoBrain/VisualEditor/Editor/NanoBrainInspector.cs index c8cc316..447fa70 100644 --- a/Assets/NanoBrain/VisualEditor/Editor/NanoBrainInspector.cs +++ b/Assets/NanoBrain/VisualEditor/Editor/NanoBrainInspector.cs @@ -1,3 +1,4 @@ +/* using System.Collections.Generic; using System.Linq; using UnityEditor; @@ -364,7 +365,7 @@ public class NanoBrainInspector : Editor { if (perceptoid.receptor != null) { tooltip = new( $"{perceptoid.name}" + - $"\nType {perceptoid.receptor.thingType}" + + // $"\nType {perceptoid.receptor.thingType}" + $" Thing {perceptoid.thingId}" + $"\nValue: {nucleus.outputValue}"); } @@ -423,7 +424,7 @@ public class NanoBrainInspector : Editor { this.currentNucleus.name = EditorGUILayout.TextField(this.currentNucleus.name); if (this.currentNucleus is Perceptoid perceptoid) { - perceptoid.receptor.thingType = EditorGUILayout.IntField("Thing Type", perceptoid.receptor.thingType); + // perceptoid.receptor.thingType = EditorGUILayout.IntField("Thing Type", perceptoid.receptor.thingType); if (perceptoid.array == null || perceptoid.array.perceptei == null || perceptoid.array.perceptei.Length == 0) perceptoid.array = new PercepteiArray(perceptoid); @@ -615,6 +616,7 @@ public class NeuroidLayer { } */ +/* public class GraphNodeWrapper : ScriptableObject { // expose fields that map to GraphNode //public string title; @@ -640,3 +642,4 @@ public class GraphNodeWrapper : ScriptableObject { } } } +*/ \ No newline at end of file diff --git a/Assets/NanoBrain/VisualEditor/NanoBrain.cs b/Assets/NanoBrain/VisualEditor/NanoBrain.cs index e9b5a8b..d786da6 100644 --- a/Assets/NanoBrain/VisualEditor/NanoBrain.cs +++ b/Assets/NanoBrain/VisualEditor/NanoBrain.cs @@ -1,3 +1,4 @@ +/* using System; using System.Collections.Generic; using UnityEngine; @@ -58,7 +59,7 @@ public class NanoBrain : ScriptableObject, ISerializationCallbackReceiver { this.cluster.GarbageCollection(); } - /* + public void GarbageCollection() { HashSet visitedNuclei = new(); MarkNuclei(visitedNuclei, this.output); @@ -96,5 +97,6 @@ public class NanoBrain : ScriptableObject, ISerializationCallbackReceiver { nucleus.receivers.RemoveAll(receiver => visitedReceivers.Contains(receiver) == false); } } - */ -} \ No newline at end of file + +} +*/ \ No newline at end of file