Importing external JSON
This commit is contained in:
parent
da5a5492dd
commit
e27e5f476a
@ -47,28 +47,30 @@ namespace NanoBrain.Unity {
|
|||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
|
|
||||||
// Begin horizontal split
|
// Begin horizontal split
|
||||||
EditorGUILayout.BeginHorizontal();
|
// EditorGUILayout.BeginHorizontal();
|
||||||
|
|
||||||
// Left: fixed-width drawing area
|
// // Left: fixed-width drawing area
|
||||||
GUILayoutOption[] leftOptions = { GUILayout.Width(drawAreaWidth) };
|
// GUILayoutOption[] leftOptions = { GUILayout.Width(drawAreaWidth) };
|
||||||
Rect drawRect = GUILayoutUtility.GetRect(drawAreaWidth, 450f, leftOptions); // height adjustable
|
// Rect drawRect = GUILayoutUtility.GetRect(drawAreaWidth, 450f, leftOptions); // height adjustable
|
||||||
|
|
||||||
// add padding inside rect
|
// // add padding inside rect
|
||||||
Rect innerRect = new(drawRect.x + padding, drawRect.y + padding,
|
// Rect innerRect = new(drawRect.x + padding, drawRect.y + padding,
|
||||||
drawRect.width - padding * 2, drawRect.height - padding * 2);
|
// drawRect.width - padding * 2, drawRect.height - padding * 2);
|
||||||
|
|
||||||
view.Render(innerRect);
|
// view.Render(innerRect);
|
||||||
|
|
||||||
// Right: info panel (takes remaining width)
|
// Right: info panel (takes remaining width)
|
||||||
EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));
|
EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));
|
||||||
float prevLabelWidth = EditorGUIUtility.labelWidth;
|
float prevLabelWidth = EditorGUIUtility.labelWidth;
|
||||||
EditorGUIUtility.labelWidth = 100f; // smaller labels -> larger fields
|
EditorGUIUtility.labelWidth = 100f; // smaller labels -> larger fields
|
||||||
|
|
||||||
|
if (GUILayout.Button("Import"))
|
||||||
|
ImportJson();
|
||||||
InspectorHandler(serializedObject);
|
InspectorHandler(serializedObject);
|
||||||
|
|
||||||
EditorGUIUtility.labelWidth = prevLabelWidth;
|
EditorGUIUtility.labelWidth = prevLabelWidth;
|
||||||
EditorGUILayout.EndVertical(); // end right column
|
EditorGUILayout.EndVertical(); // end right column
|
||||||
EditorGUILayout.EndHorizontal(); // end split
|
// EditorGUILayout.EndHorizontal(); // end split
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck()) {
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
serializedObject.Update();
|
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
|
#region Inspector
|
||||||
|
|
||||||
private bool showSynapses = true;
|
private bool showSynapses = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user