Fix clusterarray
This commit is contained in:
parent
4b72e6c712
commit
f309d4cec6
@ -1,46 +1,64 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class NucleusArray {
|
public class NucleusArray {
|
||||||
[SerializeReference]
|
[SerializeReference]
|
||||||
public INucleus[] nuclei;
|
private INucleus[] _nuclei;
|
||||||
public Cluster[] clusters;
|
private Cluster[] _clusters;
|
||||||
|
public IEnumerable<INucleus> nuclei {
|
||||||
|
get {
|
||||||
|
if (_nuclei == null)
|
||||||
|
return _clusters;
|
||||||
|
else if (_clusters == null)
|
||||||
|
return _nuclei;
|
||||||
|
else
|
||||||
|
return _nuclei.Concat(_clusters);
|
||||||
|
}
|
||||||
|
}
|
||||||
public string name;
|
public string name;
|
||||||
|
|
||||||
public NucleusArray(INucleus nucleus) {
|
public NucleusArray(INucleus nucleus) {
|
||||||
this.name = nucleus.name;
|
this.name = nucleus.name;
|
||||||
this.nuclei = new INucleus[1];
|
this._nuclei = new INucleus[1];
|
||||||
this.nuclei[0] = nucleus;
|
this._nuclei[0] = nucleus;
|
||||||
|
}
|
||||||
|
public NucleusArray(Cluster cluster) {
|
||||||
|
this.name = cluster.name;
|
||||||
|
this._clusters = new Cluster[1];
|
||||||
|
this._clusters[0] = cluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddNucleus() {
|
public void AddNucleus() {
|
||||||
if (this.nuclei.Length == 0) {
|
if (this._nuclei.Length == 0) {
|
||||||
Debug.LogError("Empty perceptoid array, cannot add");
|
Debug.LogError("Empty perceptoid array, cannot add");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int newLength = this.nuclei.Length + 1;
|
int newLength = this._nuclei.Length + 1;
|
||||||
INucleus[] newArray = new INucleus[newLength];
|
INucleus[] newArray = new INucleus[newLength];
|
||||||
|
|
||||||
for (int i = 0; i < this.nuclei.Length; i++)
|
for (int i = 0; i < this._nuclei.Length; i++)
|
||||||
newArray[i] = this.nuclei[i];
|
newArray[i] = this._nuclei[i];
|
||||||
newArray[newLength - 1] = this.nuclei[0].Clone();
|
newArray[newLength - 1] = this._nuclei[0].Clone();
|
||||||
|
|
||||||
this.nuclei = newArray;
|
this._nuclei = newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveNucleus() {
|
public void RemoveNucleus() {
|
||||||
int newLength = this.nuclei.Length - 1;
|
int newLength = this._nuclei.Length - 1;
|
||||||
if (newLength == 0) {
|
if (newLength == 0) {
|
||||||
Debug.LogWarning("Perceptoid array cannot be empty");
|
Debug.LogWarning("Perceptoid array cannot be empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
INucleus[] newPerceptei = new INucleus[newLength];
|
INucleus[] newPerceptei = new INucleus[newLength];
|
||||||
for (int i = 0; i < newLength; i++)
|
for (int i = 0; i < newLength; i++)
|
||||||
newPerceptei[i] = this.nuclei[i];
|
newPerceptei[i] = this._nuclei[i];
|
||||||
// Delete the last perception
|
// Delete the last perception
|
||||||
Neuron.Delete(this.nuclei[newLength]);
|
Neuron.Delete(this._nuclei[newLength]);
|
||||||
|
|
||||||
this.nuclei = newPerceptei;
|
this._nuclei = newPerceptei;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -231,7 +231,7 @@ public class ClusterInspector : Editor {
|
|||||||
maxValue = value;
|
maxValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float spacing = 400f / this.currentNucleus.array.nuclei.Length;
|
float spacing = 400f / this.currentNucleus.array.nuclei.Count();
|
||||||
float margin = 10 + spacing / 2;
|
float margin = 10 + spacing / 2;
|
||||||
float xMin = 150 - size;
|
float xMin = 150 - size;
|
||||||
float xMax = 150 + size;
|
float xMax = 150 + size;
|
||||||
@ -384,13 +384,13 @@ public class ClusterInspector : Editor {
|
|||||||
fontStyle = FontStyle.Bold,
|
fontStyle = FontStyle.Bold,
|
||||||
};
|
};
|
||||||
if (nucleus is INucleus neuron) {
|
if (nucleus is INucleus neuron) {
|
||||||
if (neuron.array == null || neuron.array.nuclei == null || neuron.array.nuclei.Length == 0)
|
if (neuron.array == null || neuron.array.nuclei == null || neuron.array.nuclei.Count() == 0)
|
||||||
neuron.array = new NucleusArray(neuron);
|
neuron.array = new NucleusArray(neuron);
|
||||||
|
|
||||||
if ((!expandArray || neuron.array.nuclei[0] != this.currentNucleus) && neuron.array.nuclei.Length > 1) {
|
if ((!expandArray || neuron.array.nuclei.First() != this.currentNucleus) && neuron.array.nuclei.Count() > 1) {
|
||||||
Handles.Label(labelPosition, neuron.array.nuclei.Length.ToString(), style);
|
Handles.Label(labelPosition, neuron.array.nuclei.Count().ToString(), style);
|
||||||
}
|
}
|
||||||
if (expandArray && neuron.array.nuclei[0] == this.currentNucleus) {
|
if (expandArray && neuron.array.nuclei.First() == this.currentNucleus) {
|
||||||
int arrayIx = 0;
|
int arrayIx = 0;
|
||||||
foreach (INucleus n in neuron.array.nuclei) {
|
foreach (INucleus n in neuron.array.nuclei) {
|
||||||
if (n == neuron)
|
if (n == neuron)
|
||||||
@ -497,10 +497,10 @@ public class ClusterInspector : Editor {
|
|||||||
neuroid.curvePreset = (Neuron.CurvePresets)EditorGUILayout.EnumPopup(neuroid.curvePreset, GUILayout.Width(100));
|
neuroid.curvePreset = (Neuron.CurvePresets)EditorGUILayout.EnumPopup(neuroid.curvePreset, GUILayout.Width(100));
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
if (neuroid.array == null || neuroid.array.nuclei == null || neuroid.array.nuclei.Length == 0)
|
if (neuroid.array == null || neuroid.array.nuclei == null || neuroid.array.nuclei.Count() == 0)
|
||||||
neuroid.array = new NucleusArray(neuroid);
|
neuroid.array = new NucleusArray(neuroid);
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
EditorGUILayout.IntField("Array size", neuroid.array.nuclei.Length);
|
EditorGUILayout.IntField("Array size", neuroid.array.nuclei.Count());
|
||||||
if (GUILayout.Button("Add"))
|
if (GUILayout.Button("Add"))
|
||||||
neuroid.array.AddNucleus();
|
neuroid.array.AddNucleus();
|
||||||
if (GUILayout.Button("Del"))
|
if (GUILayout.Button("Del"))
|
||||||
|
|||||||
@ -13,19 +13,19 @@ MonoBehaviour:
|
|||||||
m_Name: New Cluster
|
m_Name: New Cluster
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::Cluster
|
m_EditorClassIdentifier: Assembly-CSharp::Cluster
|
||||||
nuclei:
|
nuclei:
|
||||||
- rid: 2243601242842202217
|
- rid: 2243601242842202225
|
||||||
subClusters: []
|
subClusters: []
|
||||||
references:
|
references:
|
||||||
version: 2
|
version: 2
|
||||||
RefIds:
|
RefIds:
|
||||||
- rid: 2243601242842202217
|
- rid: 2243601242842202225
|
||||||
type: {class: Neuron, ns: , asm: Assembly-CSharp}
|
type: {class: Neuron, ns: , asm: Assembly-CSharp}
|
||||||
data:
|
data:
|
||||||
_name: Output
|
_name: Output
|
||||||
_synapses: []
|
_synapses: []
|
||||||
_receivers: []
|
_receivers: []
|
||||||
_array:
|
_array:
|
||||||
rid: 2243601242842202218
|
rid: 2243601242842202226
|
||||||
_curvePreset: 0
|
_curvePreset: 0
|
||||||
curve:
|
curve:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@ -53,10 +53,9 @@ MonoBehaviour:
|
|||||||
m_RotationOrder: 4
|
m_RotationOrder: 4
|
||||||
curveMax: 1
|
curveMax: 1
|
||||||
average: 0
|
average: 0
|
||||||
- rid: 2243601242842202218
|
- rid: 2243601242842202226
|
||||||
type: {class: NucleusArray, ns: , asm: Assembly-CSharp}
|
type: {class: NucleusArray, ns: , asm: Assembly-CSharp}
|
||||||
data:
|
data:
|
||||||
nuclei:
|
_nuclei:
|
||||||
- rid: 2243601242842202217
|
- rid: 2243601242842202225
|
||||||
clusters: []
|
|
||||||
name: Output
|
name: Output
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user