49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Passer/NanoBrain")]
|
|
public class NanoBrainObj : ScriptableObject, ISerializationCallbackReceiver {
|
|
|
|
public string title;
|
|
public int count;
|
|
public Color color = Color.white;
|
|
public Texture2D texture;
|
|
|
|
public List<Nucleus> nuclei = new();
|
|
|
|
// This is probably always the first element in the nuclei list...
|
|
[System.NonSerialized]
|
|
public Nucleus root;
|
|
public int rootId;
|
|
|
|
public Perception perception;
|
|
|
|
public NanoBrainObj() {
|
|
this.root = new(this, "Root");
|
|
this.perception = new Perception(this);
|
|
}
|
|
|
|
public Neuroid AddNeuron(string name) {
|
|
Neuroid neuroid = new(this, name);
|
|
return neuroid;
|
|
}
|
|
|
|
public void UpdateNuclei() {
|
|
foreach (Neuroid neuroid in nuclei) {
|
|
neuroid.stale++;
|
|
if (neuroid.isSleeping)
|
|
neuroid.outputValue = Vector3.zero;
|
|
}
|
|
}
|
|
|
|
public void OnBeforeSerialize() {
|
|
this.rootId = root.id;
|
|
}
|
|
public void OnAfterDeserialize() {
|
|
foreach (Nucleus nucleus in nuclei) {
|
|
if (this.rootId == nucleus.id)
|
|
this.root = nucleus;
|
|
nucleus.Rebuild(this);
|
|
}
|
|
}
|
|
} |