Fix resizing neuron array
This commit is contained in:
parent
b3823ac2e6
commit
3a67652578
@ -20,7 +20,12 @@ public class Nucleus : INucleus {
|
||||
private List<INucleus> _receivers = new();
|
||||
public List<INucleus> receivers => _receivers;
|
||||
|
||||
public NucleusArray array { get; set; }
|
||||
[SerializeReference]
|
||||
private NucleusArray _array;
|
||||
public NucleusArray array {
|
||||
get { return _array; }
|
||||
set { _array = value; }
|
||||
}
|
||||
|
||||
#region Serialization
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ public class NucleusArray {
|
||||
}
|
||||
INucleus[] newPerceptei = new INucleus[newLength];
|
||||
for (int i = 0; i < newLength; i++)
|
||||
newPerceptei[i++] = this.nuclei[i];
|
||||
newPerceptei[i] = this.nuclei[i];
|
||||
// Delete the last perception
|
||||
Nucleus.Delete(this.nuclei[newLength]);
|
||||
|
||||
|
||||
@ -258,8 +258,15 @@ public class ClusterInspector : Editor {
|
||||
// Determine the maximum value in this layer
|
||||
// This is used to 'scale' the output value colors of the nuclei
|
||||
float maxValue = 0;
|
||||
foreach (Synapse receiver in nucleus.synapses) {
|
||||
if (receiver.nucleus is Neuroid neuroid) {
|
||||
int neuronCount = 0;
|
||||
List<NucleusArray> drawnArrays = new();
|
||||
foreach (Synapse synapse in nucleus.synapses) {
|
||||
if (synapse.nucleus is Neuroid neuroid) {
|
||||
if (drawnArrays.Contains(neuroid.array))
|
||||
continue;
|
||||
drawnArrays.Add(neuroid.array);
|
||||
neuronCount++;
|
||||
|
||||
float value = neuroid.outputValue.magnitude;
|
||||
if (value > maxValue)
|
||||
maxValue = value;
|
||||
@ -267,12 +274,17 @@ public class ClusterInspector : Editor {
|
||||
}
|
||||
|
||||
// Determine the spacing of the nuclei in the layer
|
||||
float spacing = 400f / nodeCount;
|
||||
float spacing = 400f / neuronCount; //nodeCount;
|
||||
float margin = 10 + spacing / 2;
|
||||
|
||||
int row = 0;
|
||||
List<NucleusArray> drawnArrays = new();
|
||||
drawnArrays = new();
|
||||
foreach (Synapse synapse in nucleus.synapses) {
|
||||
if (synapse.nucleus is Neuroid neuroid) {
|
||||
if (drawnArrays.Contains(neuroid.array))
|
||||
continue;
|
||||
drawnArrays.Add(neuroid.array);
|
||||
}
|
||||
Vector3 pos = new(250, margin + row * spacing, 0.0f);
|
||||
Handles.color = Color.white;
|
||||
Handles.DrawLine(parentPos, pos);
|
||||
@ -382,30 +394,26 @@ public class ClusterInspector : Editor {
|
||||
return;
|
||||
|
||||
this.currentNucleus.name = EditorGUILayout.TextField(this.currentNucleus.name);
|
||||
if (this.currentNucleus is Nucleus perceptoid) {
|
||||
// perceptoid.receptor.thingType = EditorGUILayout.IntField("Thing Type", perceptoid.receptor.thingType);
|
||||
|
||||
if (perceptoid.array == null || perceptoid.array.nuclei == null || perceptoid.array.nuclei.Length == 0)
|
||||
perceptoid.array = new NucleusArray(perceptoid);
|
||||
if (this.currentNucleus is Nucleus neuroid) {
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.IntField("Array size", perceptoid.array.nuclei.Length);
|
||||
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 (neuroid.array == null || neuroid.array.nuclei == null || neuroid.array.nuclei.Length == 0)
|
||||
neuroid.array = new NucleusArray(neuroid);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.IntField("Array size", neuroid.array.nuclei.Length);
|
||||
if (GUILayout.Button("Add"))
|
||||
perceptoid.array.AddNucleus();
|
||||
neuroid.array.AddNucleus();
|
||||
if (GUILayout.Button("Del"))
|
||||
perceptoid.array.RemoveNucleus();
|
||||
neuroid.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);
|
||||
|
||||
60
Assets/Scenes/Boids/New Cluster.asset
Normal file
60
Assets/Scenes/Boids/New Cluster.asset
Normal file
@ -0,0 +1,60 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 60a957541c24c57e78018c202ebb1d9b, type: 3}
|
||||
m_Name: New Cluster
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Cluster
|
||||
nuclei:
|
||||
- rid: 2243601034565648587
|
||||
references:
|
||||
version: 2
|
||||
RefIds:
|
||||
- rid: 2243601034565648587
|
||||
type: {class: Neuroid, ns: , asm: Assembly-CSharp}
|
||||
data:
|
||||
_name: Output
|
||||
_synapses: []
|
||||
_receivers: []
|
||||
_array:
|
||||
rid: 2243601034565648588
|
||||
_curvePreset: 0
|
||||
curve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0
|
||||
outSlope: 1
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
- serializedVersion: 3
|
||||
time: 1000
|
||||
value: 1000
|
||||
inSlope: 1
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
curveMax: 1
|
||||
average: 0
|
||||
- rid: 2243601034565648588
|
||||
type: {class: NucleusArray, ns: , asm: Assembly-CSharp}
|
||||
data:
|
||||
nuclei:
|
||||
- rid: 2243601034565648587
|
||||
name: Output
|
||||
8
Assets/Scenes/Boids/New Cluster.asset.meta
Normal file
8
Assets/Scenes/Boids/New Cluster.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83e4ef8976534236989bcb1a9342dbf8
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user