(re)added nucleus arrays

This commit is contained in:
Pascal Serrarens 2026-01-12 16:06:12 +01:00
parent 90350b625b
commit e477ce4814
15 changed files with 223 additions and 273 deletions

View File

@ -62,7 +62,6 @@
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Vector2Float.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/test/SwingTwistTest.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Vector3Int.cs" />
<Compile Include="Assets/NanoBrain/PercepteiArray.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Vector3Float.cs" />
<Compile Include="Assets/NanoBrain/Receptor.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Matrix.cs" />
@ -83,6 +82,7 @@
<Compile Include="Assets/NanoBrain/LinearAlgebra/test/Vector3IntTest.cs" />
<Compile Include="Assets/NanoBrain/Neuroid.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Angle.cs" />
<Compile Include="Assets/NanoBrain/NucleusArray.cs" />
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Float.cs" />
<Compile Include="Assets/NanoBrain/Nucleus.cs" />
</ItemGroup>

View File

@ -21,6 +21,13 @@ public class Cluster : ScriptableObject, INucleus {
private readonly List<Synapse> _synapses = new();
public List<Synapse> synapses => _synapses;
public NucleusArray array { get; set; }
public INucleus Clone() {
Cluster clone = CreateInstance<Cluster>();
// 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() {

View File

@ -10,7 +10,9 @@ public interface INucleus : IReceptor {
// Senders
public List<Synapse> 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 {

View File

@ -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);
}

View File

@ -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<INucleus> _receivers = new();
public List<INucleus> 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;
// }
// }
}

View File

@ -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;
}
}

View File

@ -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) {
// }
// }

View File

@ -1,3 +1,4 @@
/*
using UnityEngine;
[System.Serializable]
@ -101,3 +102,4 @@ public class Perceptoid : Neuroid {
}
}
*/

View File

@ -10,18 +10,12 @@ public class Receptor : IReceptor {
set => _name = value;
}
public Cluster cluster;
//public INucleus nucleus;
//[SerializeField]
[SerializeReference]
private List<INucleus> _receivers = new();
public List<INucleus> 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 {
/// <summary>
/// The list of perceptoid which can process stimuli from this receptor
/// </summary>
public List<Perceptoid> perceptei = new();
//public List<Perceptoid> 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)

View File

@ -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) {

View File

@ -6,11 +6,11 @@ using System.Linq;
public class BrainPickerWindow : EditorWindow
{
private Vector2 scroll;
private NanoBrain[] items = new NanoBrain[0];
private Action<NanoBrain> onPicked;
private Cluster[] items = new Cluster[0];
private Action<Cluster> onPicked;
private string search = "";
public static void ShowPicker(Action<NanoBrain> onPicked, string title = "Select NanoBrain")
public static void ShowPicker(Action<Cluster> onPicked, string title = "Select NanoBrain")
{
var w = CreateInstance<BrainPickerWindow>();
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<NanoBrain>(AssetDatabase.GUIDToAssetPath(g)))
.Select(g => AssetDatabase.LoadAssetAtPath<Cluster>(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);

View File

@ -271,25 +271,14 @@ public class ClusterInspector : Editor {
float margin = 10 + spacing / 2;
int row = 0;
List<PercepteiArray> drawnArrays = new();
List<NucleusArray> 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<string> synapseNuclei = this.currentNucleus.synapses.Select(synapse => synapse.nucleus != null ? synapse.nucleus.name: "");
IEnumerable<string> synapseNuclei = this.currentNucleus.synapses.Select(synapse => synapse.nucleus != null ? synapse.nucleus.name : "");
//IEnumerable<string> perceptei = this.currentNucleus.brain.perceptei.Select(i => i.name).Except(synapseNuclei);
IEnumerable<string> 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);
}
}

View File

@ -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 {
}
}
}
*/

View File

@ -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<INucleus> visitedNuclei = new();
MarkNuclei(visitedNuclei, this.output);
@ -96,5 +97,6 @@ public class NanoBrain : ScriptableObject, ISerializationCallbackReceiver {
nucleus.receivers.RemoveAll(receiver => visitedReceivers.Contains(receiver) == false);
}
}
*/
}
}
*/