Migrating and cleaning up

This commit is contained in:
Pascal Serrarens 2026-04-21 17:40:16 +02:00
parent b6630ad84e
commit 0ab2d2102d
2 changed files with 71 additions and 87 deletions

View File

@ -437,13 +437,6 @@ namespace NanoBrain {
subclusterInstance.defaultOutput.AddReceiver(nucleus); subclusterInstance.defaultOutput.AddReceiver(nucleus);
} }
private void EditCluster(Cluster subCluster) {
// May be used with storedPrefab...
Selection.activeObject = subCluster.prefab;
EditorGUIUtility.PingObject(subCluster.prefab);
_ = CreateEditor(subCluster.prefab);
}
private void ReimportCluster(Cluster subCluster) { private void ReimportCluster(Cluster subCluster) {
if (subCluster.siblingClusters == null || subCluster.siblingClusters.Length <= 0) { if (subCluster.siblingClusters == null || subCluster.siblingClusters.Length <= 0) {
Cluster reimportedCluster = new(subCluster.prefab, this.prefab); Cluster reimportedCluster = new(subCluster.prefab, this.prefab);

View File

@ -543,72 +543,10 @@ namespace NanoBrain {
fontStyle = FontStyle.Bold, fontStyle = FontStyle.Bold,
}; };
if (nucleus.parent is Cluster parentCluster && parentCluster != currentNucleus.parent) { if (nucleus.parent is Cluster parentCluster && parentCluster != currentNucleus.parent)
if (expandArray) { DrawCluster(parentCluster, position, color, size);
// Put array indices above elements else if (nucleus is Cluster cluster)
style.alignment = TextAnchor.LowerCenter; DrawCluster(cluster, position, color, size);
Vector3 labelPos1 = position + Vector3.down * (size + 5); // below disc
int colonPos1 = nucleus.name.IndexOf(":");
if (colonPos1 > 0) {
string extName = nucleus.name[(colonPos1 + 2)..];
Handles.Label(labelPos1, extName, style);
}
else
Handles.Label(labelPos1, "0", style);
}
else {
// draw the array size label
if (parentCluster.instanceCount > 1) {
if (color.grayscale > 0.5f)
style.normal.textColor = Color.black;
else
style.normal.textColor = Color.white;
Handles.Label(labelPosition, parentCluster.instanceCount.ToString(), style);
style.normal.textColor = Color.white;
}
else if (parentCluster.siblingClusters != null && parentCluster.siblingClusters.Length > 1) {
if (color.grayscale > 0.5f)
style.normal.textColor = Color.black;
else
style.normal.textColor = Color.white;
Handles.Label(labelPosition, parentCluster.siblingClusters.Length.ToString(), style);
style.normal.textColor = Color.white;
}
}
}
else if (nucleus is Cluster cluster) {
if (expandArray) {
// Put array indices above elements
style.alignment = TextAnchor.LowerCenter;
Vector3 labelPos1 = position + Vector3.down * (size + 5); // below disc
int colonPos1 = nucleus.name.IndexOf(":");
if (colonPos1 > 0) {
string extName = nucleus.name[(colonPos1 + 2)..];
Handles.Label(labelPos1, extName, style);
}
else
Handles.Label(labelPos1, "0", style);
}
else {
// draw the array size label
if (cluster.instanceCount > 1) {
if (color.grayscale > 0.5f)
style.normal.textColor = Color.black;
else
style.normal.textColor = Color.white;
Handles.Label(labelPosition, cluster.instanceCount.ToString(), style);
style.normal.textColor = Color.white;
}
else if (cluster.siblingClusters != null && cluster.siblingClusters.Length > 1) {
if (color.grayscale > 0.5f)
style.normal.textColor = Color.black;
else
style.normal.textColor = Color.white;
Handles.Label(labelPosition, cluster.siblingClusters.Length.ToString(), style);
style.normal.textColor = Color.white;
}
}
}
if (expandArray == false || nucleus != currentNucleus) { if (expandArray == false || nucleus != currentNucleus) {
// put name below nucleus // put name below nucleus
@ -645,12 +583,6 @@ namespace NanoBrain {
} }
} }
// Draw Cluster ring
if (nucleus.parent != currentNucleus.parent || nucleus is Cluster) {
Handles.color = Color.white;
Handles.DrawWireDisc(position, Vector3.forward, size + 5);
}
// Tooltip // Tooltip
Rect neuronRect = new(position.x - size, position.y - size, size * 2, size * 2); Rect neuronRect = new(position.x - size, position.y - size, size * 2, size * 2);
@ -672,6 +604,57 @@ namespace NanoBrain {
} }
} }
private void DrawCluster(Cluster cluster, Vector3 position, Color color, float size) {
GUIStyle labelTextStyle = new(EditorStyles.label) {
normal = { textColor = Color.white },
fontStyle = FontStyle.Bold,
};
if (expandArray) {
// Put array indices above the discs
labelTextStyle.alignment = TextAnchor.LowerCenter;
Vector3 labelPosition = position + Vector3.down * (size + 5); // below disc
// Strip the instance number in the name
int colonPos1 = cluster.name.IndexOf(":");
if (colonPos1 > 0) {
string extName = cluster.name[(colonPos1 + 2)..];
Handles.Label(labelPosition, extName, labelTextStyle);
}
else
Handles.Label(labelPosition, "0", labelTextStyle);
}
else {
// Put instance count inside the disc
labelTextStyle.alignment = TextAnchor.MiddleCenter;
Vector3 labelPosition = position + (Vector3.forward * 0.1f);
// Adjust text color based on disc color
if (color.grayscale > 0.5f)
labelTextStyle.normal.textColor = Color.black;
else
labelTextStyle.normal.textColor = Color.white;
if (cluster.instanceCount > 1) {
Handles.Label(labelPosition, cluster.instanceCount.ToString(), labelTextStyle);
labelTextStyle.normal.textColor = Color.white;
}
else if (cluster.siblingClusters != null && cluster.siblingClusters.Length > 1) {
Handles.Label(labelPosition, cluster.siblingClusters.Length.ToString(), labelTextStyle);
labelTextStyle.normal.textColor = Color.white;
}
}
// Draw a circle around the disc to indicate this is a Cluster
Handles.color = Color.white;
Handles.DrawWireDisc(position, Vector3.forward, size + 5);
}
protected void DrawEdge(Vector2 from, Vector2 to) {
Handles.color = Color.white;
Handles.DrawLine(from, to);
}
private void HandleMouseHover(Nucleus nucleus, Rect rect) { private void HandleMouseHover(Nucleus nucleus, Rect rect) {
GUIContent tooltip; GUIContent tooltip;
if (nucleus is Neuron neuron) { if (nucleus is Neuron neuron) {
@ -691,13 +674,19 @@ namespace NanoBrain {
GUI.Box(tooltipRect, tooltip); GUI.Box(tooltipRect, tooltip);
} }
private void HandleClicked(Nucleus nucleus) { protected void HandleClicked(Nucleus nucleus) {
if (nucleus == this.currentNucleus) { if (nucleus == this.currentNucleus) {
if (nucleus is Cluster) //is Receptor) // || nucleus is ClusterReceptor) if (Application.isPlaying) {
if (nucleus is Cluster)
expandArray = !expandArray; expandArray = !expandArray;
else else
expandArray = false; expandArray = false;
} }
else {
if (nucleus is Cluster cluster)
EditCluster(cluster);
}
}
else if (nucleus.parent != this.currentNucleus.parent) { else if (nucleus.parent != this.currentNucleus.parent) {
// We go to a different cluster // We go to a different cluster
// select the cluster, not the neuron in the cluster // select the cluster, not the neuron in the cluster
@ -712,9 +701,11 @@ namespace NanoBrain {
} }
} }
protected void DrawEdge(Vector2 from, Vector2 to) { protected void EditCluster(Cluster subCluster) {
Handles.color = Color.white; // May be used with storedPrefab...
Handles.DrawLine(from, to); Selection.activeObject = subCluster.prefab;
EditorGUIUtility.PingObject(subCluster.prefab);
_ = CreateEditor(subCluster.prefab);
} }
#endregion Graph #endregion Graph