diff --git a/Editor/ClusterInspector.cs b/Editor/ClusterInspector.cs index a6668b9..15fe536 100644 --- a/Editor/ClusterInspector.cs +++ b/Editor/ClusterInspector.cs @@ -437,13 +437,6 @@ namespace NanoBrain { 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) { if (subCluster.siblingClusters == null || subCluster.siblingClusters.Length <= 0) { Cluster reimportedCluster = new(subCluster.prefab, this.prefab); diff --git a/Editor/ClusterViewer.cs b/Editor/ClusterViewer.cs index 34a9c11..b42a41b 100644 --- a/Editor/ClusterViewer.cs +++ b/Editor/ClusterViewer.cs @@ -543,72 +543,10 @@ namespace NanoBrain { fontStyle = FontStyle.Bold, }; - if (nucleus.parent is Cluster parentCluster && parentCluster != currentNucleus.parent) { - 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 (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 (nucleus.parent is Cluster parentCluster && parentCluster != currentNucleus.parent) + DrawCluster(parentCluster, position, color, size); + else if (nucleus is Cluster cluster) + DrawCluster(cluster, position, color, size); if (expandArray == false || nucleus != currentNucleus) { // 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 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) { GUIContent tooltip; if (nucleus is Neuron neuron) { @@ -691,12 +674,18 @@ namespace NanoBrain { GUI.Box(tooltipRect, tooltip); } - private void HandleClicked(Nucleus nucleus) { + protected void HandleClicked(Nucleus nucleus) { if (nucleus == this.currentNucleus) { - if (nucleus is Cluster) //is Receptor) // || nucleus is ClusterReceptor) - expandArray = !expandArray; - else - expandArray = false; + if (Application.isPlaying) { + if (nucleus is Cluster) + expandArray = !expandArray; + else + expandArray = false; + } + else { + if (nucleus is Cluster cluster) + EditCluster(cluster); + } } else if (nucleus.parent != this.currentNucleus.parent) { // We go to a different cluster @@ -712,9 +701,11 @@ namespace NanoBrain { } } - protected void DrawEdge(Vector2 from, Vector2 to) { - Handles.color = Color.white; - Handles.DrawLine(from, to); + protected void EditCluster(Cluster subCluster) { + // May be used with storedPrefab... + Selection.activeObject = subCluster.prefab; + EditorGUIUtility.PingObject(subCluster.prefab); + _ = CreateEditor(subCluster.prefab); } #endregion Graph