Importing external JSON
This commit is contained in:
parent
da5a5492dd
commit
e27e5f476a
@ -47,28 +47,30 @@ namespace NanoBrain.Unity {
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
// Begin horizontal split
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
|
||||
// Left: fixed-width drawing area
|
||||
GUILayoutOption[] leftOptions = { GUILayout.Width(drawAreaWidth) };
|
||||
Rect drawRect = GUILayoutUtility.GetRect(drawAreaWidth, 450f, leftOptions); // height adjustable
|
||||
// // Left: fixed-width drawing area
|
||||
// GUILayoutOption[] leftOptions = { GUILayout.Width(drawAreaWidth) };
|
||||
// Rect drawRect = GUILayoutUtility.GetRect(drawAreaWidth, 450f, leftOptions); // height adjustable
|
||||
|
||||
// add padding inside rect
|
||||
Rect innerRect = new(drawRect.x + padding, drawRect.y + padding,
|
||||
drawRect.width - padding * 2, drawRect.height - padding * 2);
|
||||
// // add padding inside rect
|
||||
// Rect innerRect = new(drawRect.x + padding, drawRect.y + padding,
|
||||
// drawRect.width - padding * 2, drawRect.height - padding * 2);
|
||||
|
||||
view.Render(innerRect);
|
||||
// view.Render(innerRect);
|
||||
|
||||
// Right: info panel (takes remaining width)
|
||||
EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));
|
||||
float prevLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 100f; // smaller labels -> larger fields
|
||||
|
||||
if (GUILayout.Button("Import"))
|
||||
ImportJson();
|
||||
InspectorHandler(serializedObject);
|
||||
|
||||
EditorGUIUtility.labelWidth = prevLabelWidth;
|
||||
EditorGUILayout.EndVertical(); // end right column
|
||||
EditorGUILayout.EndHorizontal(); // end split
|
||||
// EditorGUILayout.EndHorizontal(); // end split
|
||||
|
||||
if (EditorGUI.EndChangeCheck()) {
|
||||
serializedObject.Update();
|
||||
@ -82,6 +84,35 @@ namespace NanoBrain.Unity {
|
||||
|
||||
}
|
||||
|
||||
protected void ImportJson() {
|
||||
string path = EditorUtility.OpenFilePanel(
|
||||
"Import JSON",
|
||||
"",
|
||||
"json"
|
||||
);
|
||||
|
||||
if (!string.IsNullOrEmpty(path) && System.IO.File.Exists(path)) {
|
||||
ClusterData newClusterData = Cluster.Import(path);
|
||||
clusterPrefab.cluster = new(newClusterData) {
|
||||
name = clusterPrefab.name
|
||||
};
|
||||
clusterPrefab.cluster.Cleanup();
|
||||
|
||||
view.currentCluster = clusterPrefab.cluster;
|
||||
view.currentNucleus = clusterPrefab.cluster.defaultOutput;
|
||||
view.selectedOutput = view.currentNucleus;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasPreviewGUI() => true;
|
||||
|
||||
public override void OnPreviewGUI(Rect r, GUIStyle background) {
|
||||
base.OnPreviewGUI(r, background);
|
||||
GUI.Label(r, "welcome");
|
||||
view.Render(r);
|
||||
}
|
||||
|
||||
#region Inspector
|
||||
|
||||
private bool showSynapses = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user