Starting with clusterinstance
This commit is contained in:
parent
b556aa62fc
commit
8b8e5fc33c
@ -73,6 +73,7 @@
|
|||||||
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Vector2Int.cs" />
|
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Vector2Int.cs" />
|
||||||
<Compile Include="Assets/Scenes/Boids/Scripts/SwarmControl.cs" />
|
<Compile Include="Assets/Scenes/Boids/Scripts/SwarmControl.cs" />
|
||||||
<Compile Include="Assets/NanoBrain/INucleus.cs" />
|
<Compile Include="Assets/NanoBrain/INucleus.cs" />
|
||||||
|
<Compile Include="Assets/NanoBrain/ClusterInstance.cs" />
|
||||||
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Spherical.cs" />
|
<Compile Include="Assets/NanoBrain/LinearAlgebra/src/Spherical.cs" />
|
||||||
<Compile Include="Assets/NanoBrain/LinearAlgebra/test/Vector3FloatTest.cs" />
|
<Compile Include="Assets/NanoBrain/LinearAlgebra/test/Vector3FloatTest.cs" />
|
||||||
<Compile Include="Assets/NanoBrain/LinearAlgebra/test/QuaternionTest.cs" />
|
<Compile Include="Assets/NanoBrain/LinearAlgebra/test/QuaternionTest.cs" />
|
||||||
|
|||||||
74
Assets/NanoBrain/ClusterInstance.cs
Normal file
74
Assets/NanoBrain/ClusterInstance.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
public class ClusterInstance {
|
||||||
|
// The ScriptableObject asset from which the runtime object has been created
|
||||||
|
public readonly Cluster asset;
|
||||||
|
|
||||||
|
public ClusterInstance parent;
|
||||||
|
|
||||||
|
public ClusterInstance(Cluster asset) {
|
||||||
|
this.asset = asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NucleusArray array;
|
||||||
|
|
||||||
|
#region Synapses
|
||||||
|
|
||||||
|
private Synapse[] _synapses = new Synapse[0];
|
||||||
|
public Synapse[] synapses => _synapses;
|
||||||
|
|
||||||
|
public void AddSynapse(IReceptor sendingNucleus) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Does this even exist already?
|
||||||
|
public void RemoveSynapse() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Synapses
|
||||||
|
|
||||||
|
#region Receivers
|
||||||
|
|
||||||
|
private INucleus[] _nucleiReceivers = new INucleus[0];
|
||||||
|
public INucleus[] nucleiReceivers => _nucleiReceivers;
|
||||||
|
|
||||||
|
public void AddReceiver(INucleus receivingNucleus) {
|
||||||
|
int newLength = this._nucleiReceivers.Length + 1;
|
||||||
|
INucleus[] newReceivers = new INucleus[newLength];
|
||||||
|
|
||||||
|
// Copy the existing receivers
|
||||||
|
for (int ix = 0; ix < this._nucleiReceivers.Length; ix++)
|
||||||
|
newReceivers[ix] = this._nucleiReceivers[ix];
|
||||||
|
// Add the new receivers
|
||||||
|
newReceivers[this._nucleiReceivers.Length] = receivingNucleus;
|
||||||
|
// Replace the receivers with the new receivers
|
||||||
|
this._nucleiReceivers = newReceivers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveReceiver(INucleus receivingNucleus) {
|
||||||
|
int newLength = this._nucleiReceivers.Length - 1;
|
||||||
|
if (newLength < 0)
|
||||||
|
// Array was empty, so we cannot remove anything
|
||||||
|
return;
|
||||||
|
|
||||||
|
INucleus[] newReceivers = new INucleus[newLength];
|
||||||
|
|
||||||
|
int newIx = 0;
|
||||||
|
// Copy all receivers except receivingNucleus
|
||||||
|
for (int ix = 0; ix < this._nucleiReceivers.Length; ix++) {
|
||||||
|
if (this._nucleiReceivers[ix] == receivingNucleus)
|
||||||
|
// skip the receiver we want to remote
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (newIx >= newLength)
|
||||||
|
// We want to copy more elements than expected
|
||||||
|
// the receivingNucleus is not found
|
||||||
|
// and the original array is returned
|
||||||
|
return;
|
||||||
|
newReceivers[newIx] = this._nucleiReceivers[ix];
|
||||||
|
newIx++;
|
||||||
|
}
|
||||||
|
this._nucleiReceivers = newReceivers;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Receivers
|
||||||
|
}
|
||||||
2
Assets/NanoBrain/ClusterInstance.cs.meta
Normal file
2
Assets/NanoBrain/ClusterInstance.cs.meta
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f13cdc4a175a9f379a00317ae68d8bea
|
||||||
Loading…
x
Reference in New Issue
Block a user