Cluster instances deserialization
This commit is contained in:
parent
85017861b5
commit
90f8065a39
@ -186,7 +186,7 @@ namespace NanoBrain.Unity {
|
||||
protected void ClusterInspector(Cluster cluster, ref bool anythingChanged) {
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
int instanceCount = cluster.instanceCount;
|
||||
int instanceCount = (int)cluster.instanceCount;
|
||||
if (instanceCount <= 1) {
|
||||
if (cluster.instances != null && cluster.instances.Length > 1)
|
||||
instanceCount = cluster.instances.Count();
|
||||
|
||||
@ -63,7 +63,7 @@ namespace NanoBrain {
|
||||
/// </summary>
|
||||
/// A cluster is a multi-clsuter when there is more than one instance.
|
||||
[SerializeField]
|
||||
public int instanceCount = 1;
|
||||
public uint instanceCount = 1;
|
||||
/// <summary>
|
||||
/// The mapping from things to cluster instances
|
||||
/// </summary>
|
||||
@ -89,7 +89,7 @@ namespace NanoBrain {
|
||||
/// </summary>
|
||||
/// <param name="prefab">The prefab to use</param>
|
||||
/// <param name="parent">The cluster in which this new cluster will be placed</param>
|
||||
public Cluster(ClusterPrefab prefab, Cluster parent) {
|
||||
public Cluster(ClusterPrefab prefab, Cluster parent, uint instanceCount = 1) {
|
||||
this.prefab = prefab;
|
||||
this.version = prefab.version;
|
||||
this.name = prefab.name;
|
||||
@ -97,6 +97,27 @@ namespace NanoBrain {
|
||||
this.parent = parent;
|
||||
this.parent?.nuclei.Add(this);
|
||||
ClonePrefab();
|
||||
|
||||
if (instanceCount > 1) {
|
||||
Debug.Log($" InstanceCount = {instanceCount}");
|
||||
List<Cluster> siblings = new() { this };
|
||||
for (int instanceIx = 1; instanceIx < instanceCount; instanceIx++) {
|
||||
// Create another sibling
|
||||
Cluster sibling = new(prefab, this) {
|
||||
name = $"{this.baseName}: {instanceIx}",
|
||||
parent = this.parent,
|
||||
instanceCount = this.instanceCount,
|
||||
};
|
||||
siblings.Add(sibling);
|
||||
CopyAllExternalReceivers(this, sibling, this);
|
||||
}
|
||||
Cluster[] siblingClusters = siblings.ToArray();
|
||||
foreach (Cluster sibling in siblings) {
|
||||
sibling.instanceCount = instanceCount;
|
||||
sibling.instances = siblingClusters;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -158,7 +179,12 @@ namespace NanoBrain {
|
||||
if (extPrefab == null)
|
||||
Debug.LogError($"Could not find cluster Resource {synapseData.clusterName}");
|
||||
else {
|
||||
Cluster extCluster = new Cluster(extPrefab, this);
|
||||
uint instanceCount = 1;
|
||||
foreach (ExternalClusterData externalCluster in clusterData.clusters) {
|
||||
if (externalCluster.name == synapseData.clusterName)
|
||||
instanceCount = externalCluster.instanceCount;
|
||||
}
|
||||
Cluster extCluster = new Cluster(extPrefab, this, instanceCount);
|
||||
Neuron extNeuron = extCluster.GetNeuron(synapseData.neuronName);
|
||||
extNeuron.AddReceiver(receiver);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user