public void OnEnable() { availableModels = new Model[0]; inputSourceSelectionIndices = new Dictionary <int, int>().WithDefaultValue(0); optionSelectionIndices = new Dictionary <int, int>().WithDefaultValue(0); inputWidths = new Dictionary <int, int>().WithDefaultValue(640); inputHeights = new Dictionary <int, int>().WithDefaultValue(480); maxWidths = new Dictionary <int, int>().WithDefaultValue(1); maxHeights = new Dictionary <int, int>().WithDefaultValue(1); inputWindows = new Dictionary <int, RunwayPreviewWindow>(); inputData = new Dictionary <string, object>().WithDefaultValue(null); isWindowEnabled = true; logoTexture = Resources.Load("Icons/Logo") as Texture2D; horizontalStyle = new GUIStyle(); horizontalStyle.margin = new RectOffset(10, 10, 0, 0); justifyCenterTextStyle = new GUIStyle(); justifyCenterTextStyle.alignment = TextAnchor.MiddleCenter; boldTextStyle = new GUIStyle(); boldTextStyle.alignment = TextAnchor.MiddleCenter; boldTextStyle.fontStyle = FontStyle.Bold; sectionTitleStyle = new GUIStyle(); sectionTitleStyle.fontStyle = FontStyle.Bold; sectionTitleStyle.margin = new RectOffset(20, 0, 0, 0);; this.StartCoroutine(CheckIfRunwayRunning()); this.StartCoroutine(UpdateRunningSession()); if (RunwayInput1Window.IsOpen) { inputWindows[0] = GetWindow <RunwayInput1Window>(); } if (RunwayInput2Window.IsOpen) { inputWindows[1] = GetWindow <RunwayInput2Window>(); } if (RunwayOutputWindow.IsOpen) { outputWindow = GetWindow <RunwayOutputWindow>(); } }
void RenderInputsAndOutputs() { Field[] inputs = getFilteredModels()[selectedModelIndex].commands[0].inputs; Field[] outputs = getFilteredModels()[selectedModelIndex].commands[0].outputs; GUILayout.Space(10); GUILayout.Label("INPUT", sectionTitleStyle); GUILayout.Space(5); GUILayout.BeginHorizontal("box"); GUILayout.BeginVertical(); for (int i = 0; i < inputs.Length; i++) { GUILayout.Space(5); Field input = inputs[i]; GUILayout.BeginVertical(); if (input.type.Equals("image") || input.type.Equals("segmentation")) { GUILayout.BeginHorizontal(horizontalStyle); GUILayout.FlexibleSpace(); GUILayout.Label(RunwayUtils.FormatFieldName(input.name), boldTextStyle); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(5); } if (input.type.Equals("image")) { RenderImageInput(input, i); } else if (input.type.Equals("segmentation")) { RenderSegmentationInput(input, i); } else if (input.type.Equals("text")) { GUILayout.BeginHorizontal(horizontalStyle); GUILayout.Label(System.String.Format("{0}:", RunwayUtils.FormatFieldName(input.name))); GUILayout.FlexibleSpace(); inputData[input.name] = EditorGUILayout.TextField(inputData[input.name] as string, GUILayout.MaxWidth(250)); GUILayout.EndHorizontal(); } else if (input.type.Equals("category")) { GUILayout.BeginHorizontal(horizontalStyle); GUILayout.Label(System.String.Format("{0}:", RunwayUtils.FormatFieldName(input.name))); GUILayout.FlexibleSpace(); inputData[input.name] = RunwayUtils.Dropdown(inputData[input.name] as string, input.oneOf); GUILayout.EndHorizontal(); } else if (input.type.Equals("number")) { GUILayout.BeginHorizontal(horizontalStyle); GUILayout.Label(System.String.Format("{0}:", RunwayUtils.FormatFieldName(input.name))); GUILayout.FlexibleSpace(); if (RunwayUtils.IsAnInteger(input.step)) { if (input.hasMin && input.hasMax && input.hasStep) { int value = inputData[input.name] is int?(int)inputData[input.name] : (int)Convert.ToSingle(input.defaultValue); inputData[input.name] = EditorGUILayout.IntSlider(value, (int)input.min, (int)input.max); } else { int value = inputData[input.name] is int?(int)inputData[input.name] : (int)Convert.ToSingle(input.defaultValue); inputData[input.name] = EditorGUILayout.IntField(value); } } else { if (input.hasMin && input.hasMax && input.hasStep) { float value = inputData[input.name] is float?(float)inputData[input.name] : (float)Convert.ToSingle(input.defaultValue); inputData[input.name] = EditorGUILayout.Slider(value, input.min, input.max); } else { float value = inputData[input.name] is float?(float)inputData[input.name] : Convert.ToSingle(input.defaultValue); inputData[input.name] = EditorGUILayout.FloatField(value); } } GUILayout.EndHorizontal(); } else if (input.type.Equals("boolean")) { GUILayout.BeginHorizontal(horizontalStyle); GUILayout.Label(System.String.Format("{0}:", RunwayUtils.FormatFieldName(input.name))); bool value = inputData[input.name] is bool?(bool)inputData[input.name] : false; GUILayout.FlexibleSpace(); inputData[input.name] = EditorGUILayout.Toggle(value, GUILayout.Width(20)); GUILayout.EndHorizontal(); } GUILayout.Space(5); GUILayout.EndVertical(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.Label("OUTPUT", sectionTitleStyle); GUILayout.Space(5); GUILayout.BeginHorizontal("box"); GUILayout.BeginVertical(); GUILayout.Space(5); GUILayout.BeginHorizontal(horizontalStyle); GUILayout.FlexibleSpace(); if (this.lastOutput) { RenderTextureInfo(this.lastOutput); } else { RenderNotAvailable(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Preview")) { outputWindow = GetWindow <RunwayOutputWindow>(false, "Runway - Model Output", true); } GUILayout.Space(5); if (this.lastOutput && GUILayout.Button("Save")) { string path = EditorUtility.SaveFilePanel("Save as PNG", "", "ModelOutput.png", "png"); byte[] data = RunwayUtils.TextureToPNG(this.lastOutput); File.WriteAllBytes(path, data); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (lastOutput != null && outputWindow != null) { outputWindow.texture = lastOutput; outputWindow.Repaint(); } }