Fix adding/removing cluster outputs
This commit is contained in:
parent
805b0f8489
commit
fc8caa8a29
@ -70,24 +70,7 @@ namespace NanoBrain {
|
|||||||
|
|
||||||
// In a Prefab editor, no instance exists but we need it for the ClusterViewer.
|
// In a Prefab editor, no instance exists but we need it for the ClusterViewer.
|
||||||
// So we create a temporary instance
|
// So we create a temporary instance
|
||||||
Cluster cluster = new(prefab);
|
this.currentCluster = new(prefab);
|
||||||
this.currentCluster = cluster;
|
|
||||||
|
|
||||||
Button addButton = new(() => OnAddClusterOutput()) {
|
|
||||||
text = "Add"
|
|
||||||
};
|
|
||||||
topMenuContainer?.Add(addButton);
|
|
||||||
|
|
||||||
Add(topMenuContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnAddClusterOutput() {
|
|
||||||
Nucleus newOutput = new Neuron(this.prefab, "New Output");
|
|
||||||
this.prefab.RefreshOutputs();
|
|
||||||
// outputsPopup.choices = this.prefab.outputs.Select(output => output.name).ToList();
|
|
||||||
// outputsPopup.value = newOutput.name;
|
|
||||||
|
|
||||||
this.currentNucleus = newOutput;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetGraph(GameObject gameObject, VisualElement inspectorContainer) {
|
public void SetGraph(GameObject gameObject, VisualElement inspectorContainer) {
|
||||||
@ -151,33 +134,37 @@ namespace NanoBrain {
|
|||||||
if (serializedObject == null || serializedObject.targetObject == null)
|
if (serializedObject == null || serializedObject.targetObject == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.currentNucleus == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
|
|
||||||
GUIStyle headerStyle = new(EditorStyles.boldLabel) {
|
|
||||||
alignment = TextAnchor.MiddleLeft,
|
|
||||||
margin = new RectOffset(10, 0, 4, 4)
|
|
||||||
};
|
|
||||||
GUIStyle boldTextFieldStyle = new(EditorStyles.textField) {
|
GUIStyle boldTextFieldStyle = new(EditorStyles.textField) {
|
||||||
fontStyle = FontStyle.Bold
|
fontStyle = FontStyle.Bold
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (this.currentNucleus == null) {
|
||||||
|
OutputsInspector(ref anythingChanged);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
GUIStyle headerStyle = new(EditorStyles.boldLabel) {
|
||||||
|
alignment = TextAnchor.MiddleLeft,
|
||||||
|
margin = new RectOffset(10, 0, 4, 4)
|
||||||
|
};
|
||||||
// Nucleus type
|
// Nucleus type
|
||||||
string nucleusType = this.currentNucleus.GetType().Name;
|
string nucleusType = this.currentNucleus.GetType().Name;
|
||||||
GUILayout.Label(nucleusType, headerStyle);
|
GUILayout.Label(nucleusType, headerStyle);
|
||||||
|
|
||||||
// Nucleus name
|
// Nucleus name
|
||||||
if (this.currentNucleus is Cluster parentCluster) {
|
Cluster cluster = this.currentNucleus as Cluster;
|
||||||
|
if (cluster != null) {
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
if (GUILayout.Button(this.currentNucleus.parent.name))
|
if (GUILayout.Button(this.currentNucleus.parent.name))
|
||||||
OnClusterClick(parentCluster);
|
OnClusterClick(cluster);
|
||||||
EditorGUI.BeginDisabledGroup(true);
|
EditorGUI.BeginDisabledGroup(true);
|
||||||
EditorGUILayout.TextField(this.currentNucleus.name, boldTextFieldStyle);
|
EditorGUILayout.TextField(this.currentNucleus.name, boldTextFieldStyle);
|
||||||
EditorGUI.EndDisabledGroup();
|
EditorGUI.EndDisabledGroup();
|
||||||
if (GUILayout.Button("Reimport"))
|
if (GUILayout.Button("Reimport"))
|
||||||
ReimportCluster(parentCluster);
|
ReimportCluster(cluster);
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -206,7 +193,7 @@ namespace NanoBrain {
|
|||||||
if (this.currentNucleus is MemoryCell memory)
|
if (this.currentNucleus is MemoryCell memory)
|
||||||
MemoryCellInspector(memory, ref anythingChanged);
|
MemoryCellInspector(memory, ref anythingChanged);
|
||||||
// Cluster
|
// Cluster
|
||||||
else if (this.currentNucleus is Cluster cluster)
|
else if (cluster != null) //(this.currentNucleus is Cluster cluster)
|
||||||
ClusterInspector(cluster, ref anythingChanged);
|
ClusterInspector(cluster, ref anythingChanged);
|
||||||
// Other
|
// Other
|
||||||
else
|
else
|
||||||
@ -214,6 +201,7 @@ namespace NanoBrain {
|
|||||||
|
|
||||||
if (GUILayout.Button("Delete"))
|
if (GUILayout.Button("Delete"))
|
||||||
DeleteNucleus(this.currentNucleus);
|
DeleteNucleus(this.currentNucleus);
|
||||||
|
}
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
if (anythingChanged) {
|
if (anythingChanged) {
|
||||||
@ -222,6 +210,24 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void OutputsInspector(ref bool anythingChanged) {
|
||||||
|
GUIStyle headerStyle = new(EditorStyles.boldLabel) {
|
||||||
|
alignment = TextAnchor.MiddleLeft,
|
||||||
|
margin = new RectOffset(10, 0, 4, 4)
|
||||||
|
};
|
||||||
|
GUILayout.Label("Outputs", headerStyle);
|
||||||
|
|
||||||
|
bool connecting = GUILayout.Button("Add Output Neuron");
|
||||||
|
if (connecting) {
|
||||||
|
Nucleus newOutput = new Neuron(this.prefab, "New Output");
|
||||||
|
// Regenerate the temporary clsuter instance
|
||||||
|
// See also the constructor
|
||||||
|
this.currentCluster = new (this.prefab);
|
||||||
|
this.currentNucleus = newOutput;
|
||||||
|
this.selectedOutput = this.currentNucleus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void MemoryCellInspector(MemoryCell memoryCell, ref bool anythingChanged) {
|
protected void MemoryCellInspector(MemoryCell memoryCell, ref bool anythingChanged) {
|
||||||
memoryCell.staticMemory = EditorGUILayout.Toggle("Static Memory", memoryCell.staticMemory);
|
memoryCell.staticMemory = EditorGUILayout.Toggle("Static Memory", memoryCell.staticMemory);
|
||||||
NucleusInspector(memoryCell, ref anythingChanged);
|
NucleusInspector(memoryCell, ref anythingChanged);
|
||||||
@ -430,15 +436,6 @@ namespace NanoBrain {
|
|||||||
case Nucleus.Type.Cluster:
|
case Nucleus.Type.Cluster:
|
||||||
AddClusterInput(nucleus);
|
AddClusterInput(nucleus);
|
||||||
break;
|
break;
|
||||||
// case Nucleus.Type.Receptor:
|
|
||||||
// AddReceptorInput(nucleus);
|
|
||||||
// break;
|
|
||||||
// case Nucleus.Type.ClusterReceptor:
|
|
||||||
// AddClusterReceptorInput(nucleus);
|
|
||||||
// break;
|
|
||||||
// case Nucleus.Type.ClusterArray:
|
|
||||||
// AddClusterArrayInput(nucleus);
|
|
||||||
// break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -535,15 +532,12 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.prefab.nuclei.Remove(nucleus);
|
this.currentCluster.DeleteNucleus(nucleus);//clusterNuclei.Remove(nucleus);
|
||||||
|
|
||||||
// if (outputsPopup.value == nucleus.name) {
|
// this.prefab.nuclei.Remove(nucleus);
|
||||||
// this.prefab.RefreshOutputs();
|
// Neuron.Delete(nucleus);
|
||||||
// // outputsPopup.choices = this.prefab.outputs.Select(output => output.name).ToList();
|
this.prefab.RefreshOutputs();
|
||||||
// // outputsPopup.index = 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
Neuron.Delete(nucleus);
|
|
||||||
|
|
||||||
this.currentNucleus = this.prefab.output;
|
this.currentNucleus = this.prefab.output;
|
||||||
this.selectedOutput = this.currentNucleus;
|
this.selectedOutput = this.currentNucleus;
|
||||||
|
|||||||
@ -528,10 +528,6 @@ namespace NanoBrain {
|
|||||||
|
|
||||||
#endregion ClusterArray
|
#endregion ClusterArray
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//public Dictionary<string, Nucleus> nucleiDict = new();
|
|
||||||
|
|
||||||
public List<Nucleus> _inputs = null;
|
public List<Nucleus> _inputs = null;
|
||||||
public virtual List<Nucleus> inputs {
|
public virtual List<Nucleus> inputs {
|
||||||
get {
|
get {
|
||||||
@ -643,6 +639,9 @@ namespace NanoBrain {
|
|||||||
return this._outputs;
|
return this._outputs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void RefreshOutputs() {
|
||||||
|
this._outputs = null;
|
||||||
|
}
|
||||||
|
|
||||||
public bool TryGetNucleus(string nucleusName, out Nucleus foundNucleus) {
|
public bool TryGetNucleus(string nucleusName, out Nucleus foundNucleus) {
|
||||||
foreach (Nucleus receptor in this.clusterNuclei) {
|
foreach (Nucleus receptor in this.clusterNuclei) {
|
||||||
@ -685,6 +684,22 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool DeleteNucleus(Nucleus nucleus) {
|
||||||
|
if (this.clusterNuclei.Contains(nucleus) == false) {
|
||||||
|
// Try to find the nucleus by name
|
||||||
|
if (TryGetNucleus(nucleus.name, out nucleus) == false)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Neuron.Delete(nucleus);
|
||||||
|
int nucleusIx = this.clusterNuclei.IndexOf(nucleus);
|
||||||
|
this.clusterNuclei.Remove(nucleus);
|
||||||
|
this.prefab.nuclei.RemoveAt(nucleusIx);
|
||||||
|
RefreshOutputs();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#region Receivers
|
#region Receivers
|
||||||
|
|
||||||
public virtual List<Nucleus> CollectReceivers() {
|
public virtual List<Nucleus> CollectReceivers() {
|
||||||
|
|||||||
@ -33,8 +33,10 @@ namespace NanoBrain {
|
|||||||
public Neuron(ClusterPrefab prefab, string name) {
|
public Neuron(ClusterPrefab prefab, string name) {
|
||||||
this.clusterPrefab = prefab;
|
this.clusterPrefab = prefab;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if (this.clusterPrefab != null)
|
if (this.clusterPrefab != null) {
|
||||||
this.clusterPrefab.nuclei.Add(this);
|
this.clusterPrefab.nuclei.Add(this);
|
||||||
|
this.clusterPrefab.RefreshOutputs();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Debug.LogError("No prefab when adding neuron to prefab");
|
Debug.LogError("No prefab when adding neuron to prefab");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user