NanoBrain-unitypackage/NanoBrain.cs

43 lines
1.5 KiB
C#

using System;
using UnityEngine;
public class NanoBrain : MonoBehaviour {
public ClusterPrefab defaultBrain;
[NonSerialized]
private Cluster brainInstance;
public Cluster brain {
get {
if (brainInstance == null && defaultBrain != null) {
brainInstance = new Cluster(defaultBrain) {
name = defaultBrain.name + " (Instance)"
};
}
// SwarmControl sc = FindFirstObjectByType<SwarmControl>();
// if (sc != null) {
// UpdateWeight(brainInstance, "Containment", sc.containmentForce);
// UpdateWeight(brainInstance, "Cohesion", sc.cohesionForce);
// UpdateWeight(brainInstance, "Separation", sc.separationForce);
// UpdateWeight(brainInstance, "Alignment", sc.alignmentForce);
// }
return brainInstance;
}
}
// public void Awake() {
// brainInstance = new Cluster(defaultBrain);
// }
public static void UpdateWeight(Cluster brain, string name, float weight) {
INucleus root = brain.output;
foreach (Synapse synapse in root.synapses) {
if (synapse.nucleus.name == name) {
if (synapse.weight != weight) {
synapse.weight = weight;
// Debug.Log($"Updated weight for {name}");
}
}
}
}
}