public static void display(float imagesize = 64, AXNodeGraphEditorWindow editor = null) { //Debug.Log("imagesise="+imagesize); // called from an OnGUI //imagesize = 64; scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUIStyle.none, GUIStyle.none); EditorGUILayout.BeginVertical(); string[] itemStrings = null; // Select menu item list if (editor.OutputParameterBeingDragged == null) { if (editor.model != null && editor.model.selectedPOs.Count > 1) { //if (editor.model.selectedPOs[0].is2D()) // itemStrings = ArchimatixEngine.nodeStringsFrom2DMultiSelect; //else itemStrings = ArchimatixEngine.nodeStringsFromMultiSelect; } else { itemStrings = ArchimatixEngine.nodeStrings; } } else if (editor.OutputParameterBeingDragged.parametricObject.is2D()) { itemStrings = ArchimatixEngine.nodeStringsFrom2DOutput; } else if (editor.OutputParameterBeingDragged.parametricObject.is3D()) { if (editor.OutputParameterBeingDragged.Type == AXParameter.DataType.Spline) { itemStrings = ArchimatixEngine.nodeStringsFrom2DOutput; } else { itemStrings = ArchimatixEngine.nodeStringsFrom3DOutput; } } else if (editor.OutputParameterBeingDragged.parametricObject.generator is RepeaterTool) { itemStrings = ArchimatixEngine.nodeStringsFromRepeaterTool; } /* * if (Library.last2DItem != null) * { * if (GUILayout.Button(new GUIContent(Library.last2DItem.icon, Library.last2DItem.po.Name), new GUILayoutOption[] {GUILayout.Width(imagesize), GUILayout.Height(imagesize)})) * { * * } * } */ List <string> stringList = null; if (itemStrings != null) { stringList = itemStrings.ToList(); } if (stringList != null) { stringList.AddRange(Archimatix.customNodeNames); } // Build Menu string poName; if (stringList != null) { for (int i = 0; i < stringList.Count; i++) { string nodeName = stringList[i]; Texture2D nodeIcon = null; if (ArchimatixEngine.nodeIcons.ContainsKey(nodeName)) { nodeIcon = ArchimatixEngine.nodeIcons[nodeName]; } else { if (ArchimatixEngine.nodeIcons.ContainsKey("CustomNode")) { nodeIcon = ArchimatixEngine.nodeIcons["CustomNode"]; } else { continue; } } if (nodeIcon != null) { if (GUILayout.Button(new GUIContent(nodeIcon, nodeName), new GUILayoutOption[] { GUILayout.Width(imagesize), GUILayout.Height(imagesize) })) { //if (editor.DraggingOutputParameter != null) //{ AXModel model = AXEditorUtilities.getOrMakeSelectedModel(); Undo.RegisterCompleteObjectUndo(model, "Node Menu Selection"); AXParametricObject mostRecentPO = model.recentlySelectedPO; int index = nodeName.IndexOf("_"); poName = (index > 0) ? nodeName.Substring(0, index) : nodeName; // Support multi-select operation List <AXParametricObject> selectedPOs = new List <AXParametricObject>(); if (model.selectedPOs.Count > 0) { selectedPOs.AddRange(model.selectedPOs); } // ADD NEW PO TO MODEL (only this new po is selected after this) AXParametricObject po = AXEditorUtilities.addNodeToCurrentModel(poName, false); if (po == null || po.generator == null) { return; } float max_x = -AXGeometryTools.Utilities.IntPointPrecision; if (poName == "FreeCurve") { ArchimatixEngine.sceneViewState = ArchimatixEngine.SceneViewState.AddPoint; } // DRAGGING A PARAMETER? THEN RIG'R UP! if (editor.OutputParameterBeingDragged != null) { AXParametricObject draggingPO = editor.OutputParameterBeingDragged.parametricObject; AXParameter new_input_p = null; switch (nodeName) { case "Instance2D": case "ShapeOffsetter": po.getParameter("Input Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); if (po.geometryControls != null) { po.geometryControls.isOpen = true; } break; case "ShapeDistributor": List <AXParameter> deps = new List <AXParameter>(); for (int dd = 0; dd < editor.OutputParameterBeingDragged.Dependents.Count; dd++) { deps.Add(editor.OutputParameterBeingDragged.Dependents[dd]); } for (int dd = 0; dd < deps.Count; dd++) { deps[dd].makeDependentOn(po.getParameter("Output Shape")); } po.getParameter("Input Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); if (po.geometryControls != null) { po.geometryControls.isOpen = true; } break; case "ShapeMerger": po.generator.getInputShape().addInput().makeDependentOn(editor.OutputParameterBeingDragged); if (editor.OutputParameterBeingDragged.axis != Axis.NONE) { po.intValue("Axis", (int)editor.OutputParameterBeingDragged.axis); } else { po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); } break; case "PlanRepeater2D": case "PlanRepeater2D_Corner": po.getParameter("Corner Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "PlanRepeater_Corner": po.getParameter("Corner Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "PairRepeater2D": case "RadialRepeater2D": case "RadialRepeater2D_Node": case "LinearRepeater2D": case "LinearRepeater2D_Node": case "GridRepeater2D": case "GridRepeater2D_Node": po.getParameter("Node Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "RadialRepeater2D_Cell": case "LinearRepeater2D_Cell": case "GridRepeater2D_Cell": po.getParameter("Cell Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "Grouper": //po.addInputMesh().makeDependentOn(editor.OutputParameterBeingDragged); po.addGroupee(editor.OutputParameterBeingDragged.parametricObject); break; case "PlanRepeater2D_Plan": case "Polygon_Plan": case "Extrude_Plan": case "PlanSweep_Plan": case "PlanRepeater_Plan": case "PlanDeformer_Plan": // SYNC AXES if (editor.OutputParameterBeingDragged.axis != Axis.NONE) { po.intValue("Axis", (int)editor.OutputParameterBeingDragged.axis); } else { po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); } if (nodeName == "Extrude_Plan" && po.intValue("Axis") != (int)Axis.Y) { po.floatValue("Bevel", 0); } // INSERT SHAPE_DISTRIBUTOR? new_input_p = po.getParameter("Plan", "Input Shape"); //if (draggingPO.is2D() && !(draggingPO.generator is ShapeDistributor) && editor.OutputParameterBeingDragged.Dependents != null && editor.OutputParameterBeingDragged.Dependents.Count > 0) // model.insertShapeDistributor(editor.OutputParameterBeingDragged, new_input_p); //else new_input_p.makeDependentOn(editor.OutputParameterBeingDragged); // the output of the new node should match the shapestate of the input if (po.generator.P_Output != null) { po.generator.P_Output.shapeState = new_input_p.shapeState; } AXNodeGraphEditorWindow.repaintIfOpen(); break; case "Lathe_Section": case "PlanSweep_Section": case "PlanRepeater_Section": //po.getParameter("Section").makeDependentOn(editor.OutputParameterBeingDragged); // INSERT SHAPE_DISTRIBUTOR? new_input_p = po.getParameter("Section"); if (draggingPO.is2D() && !(draggingPO.generator is ShapeDistributor) && draggingPO.hasDependents()) { model.insertShapeDistributor(editor.OutputParameterBeingDragged, new_input_p); } else { new_input_p.makeDependentOn(editor.OutputParameterBeingDragged); } // the output of the new node should match the shapestate of the input //if (po.generator.P_Output != null) //Debug.Log(new_input_p.Name+" "+new_input_p.shapeState + " :=: " +editor.OutputParameterBeingDragged.Name + " " + editor.OutputParameterBeingDragged.shapeState); AXNodeGraphEditorWindow.repaintIfOpen(); break; case "NoiseDeformer": case "ShearDeformer": case "TwistDeformer": case "DomicalDeformer": case "TaperDeformer": case "InflateDeformer": case "PlanDeformer": po.getParameter("Input Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; //case "PlanDeformer_Plan": case "PairRepeater": case "StepRepeater": case "RadialStepRepeater": po.getParameter("Node Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater_Node": AXParameter nodeMesh_p = po.getParameter("Node Mesh"); nodeMesh_p.makeDependentOn(editor.OutputParameterBeingDragged); // if the src is very long in x, assume you want to repeat in Z if (editor.OutputParameterBeingDragged.parametricObject.bounds.size.x > (6 * editor.OutputParameterBeingDragged.parametricObject.bounds.size.z)) { po.initiateRipple_setBoolParameterValueByName("zAxis", true); } break; case "LinearRepeater_Cell": case "PlanRepeater_Cell": po.getParameter("Cell Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater_Span": po.getParameter("Bay SpanU").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater": po.getParameter("RepeaterU").makeDependentOn(editor.OutputParameterBeingDragged); break; case "FloorRepeater": po.getParameter("Floor Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "RadialRepeater": case "RadialRepeater_Node": case "GridRepeater_Node": case "PlanRepeater_Node": po.getParameter("Node Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "RadialRepeater_Span": case "GridRepeater_Span": po.getParameter("Bay SpanU", "SpanU Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "GridRepeater_Cell": po.getParameter("Cell Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "ShapeRepeater_Plan": AXEditorUtilities.addNodeToCurrentModel("ShapeRepeater").getParameter("Plan").makeDependentOn(editor.OutputParameterBeingDragged); break; default: AXEditorUtilities.addNodeToCurrentModel(nodeName); break; } if (editor.OutputParameterBeingDragged.parametricObject != null) { mostRecentPO = editor.OutputParameterBeingDragged.parametricObject; //po.rect = editor.OutputParameterBeingDragged.parametricObject.rect; //po.rect.x += 325; } /* * else * { * po.rect.x = (model.focusPointInGraphEditor.x)+100;// + UnityEngine.Random.Range(-100, 300); * po.rect.y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0); * } */ } // NO DRAGGING - CONNECT ALL MULTI_SELECTED else if (selectedPOs != null && selectedPOs.Count > 0) { switch (nodeName) { case "ShapeMerger": AXShape shp = po.generator.getInputShape(); for (int j = 0; j < selectedPOs.Count; j++) { AXParametricObject poo = selectedPOs [j]; if (j == 0) { po.intValue("Axis", selectedPOs [j].intValue("Axis")); } max_x = Mathf.Max(max_x, poo.rect.x); if (poo.is2D()) { AXParameter out_p = poo.generator.getPreferredOutputParameter(); if (out_p != null) { shp.addInput().makeDependentOn(out_p); } } } po.rect.x = max_x + 250; break; case "Grouper": //Debug.Log("selectedPOs="+selectedPOs.Count); //if (model.currentWorkingGroupPO != null && ! selectedPOs.Contains(model.currentWorkingGroupPO)) //{ po.addGroupees(selectedPOs); Rect r = AXUtilities.getBoundaryRectFromPOs(selectedPOs); po.rect.x = r.center.x - po.rect.width / 2; po.rect.y = r.center.y - po.rect.height / 2; //} //po.rect.x = max_x+250; break; case "Channeler": //Debug.Log("selectedPOs="+selectedPOs.Count); //if (model.currentWorkingGroupPO != null && ! selectedPOs.Contains(model.currentWorkingGroupPO)) //{ foreach (AXParametricObject selpo in selectedPOs) { AXParameter inputer = po.addInputMesh(); inputer.makeDependentOn(selpo.generator.P_Output); } Rect cr = AXUtilities.getBoundaryRectFromPOs(selectedPOs); po.rect.x = cr.center.x - po.rect.width / 2; po.rect.y = cr.center.y - po.rect.height / 2; //} //po.rect.x = max_x+250; break; } } else { switch (nodeName) { case "ShapeMerger": po.assertInputControls(); //po.generator.getInputShape().addInput(); break; } } editor.OutputParameterBeingDragged = null; model.autobuild(); po.generator.adjustWorldMatrices(); if (mostRecentPO != null) { po.rect = mostRecentPO.rect; po.rect.x += (mostRecentPO.rect.width + 50); } else { po.rect.x = (model.focusPointInGraphEditor.x) + 100; // + UnityEngine.Random.Range(-100, 300); po.rect.y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0); } po.rect.height = 700; //AXNodeGraphEditorWindow.zoomToRectIfOpen(po.rect); //model.beginPanningToRect(po.rect); } } } } //GUILayout.Label (GUI.tooltip); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); /* Not sure why I was doing this - it took up a huge amount of CPU! * * * editor.Repaint(); * SceneView sv = SceneView.lastActiveSceneView; * if (sv != null) * sv.Repaint(); * */ }
public static void processEventCommand(Event e, AXModel model) { if (e.type == EventType.ValidateCommand) { e.Use(); } //Debug.Log("-> processEventCommand 1: PROCESS COMMAND "+e.commandName); var view = SceneView.lastActiveSceneView; string focusedControlName = GUI.GetNameOfFocusedControl(); if (model != null) { // intercept this command and use for po's switch (e.commandName) { case "UndoRedoPerformed": //Debug.Log ("UndoRedoPerformed"); model.cleanGraph(); model.autobuild(); for (int i = 0; i < model.selectedPOs.Count; i++) { model.selectedPOs[i].generator.adjustWorldMatrices(); } // SCENEVIEW if (SceneView.lastActiveSceneView != null) { SceneView.lastActiveSceneView.Repaint(); } //model.setRenderMode( AXModel.RenderMode.GameObjects ); model.cacheThumbnails("AXGeometryTools.Utilities::processEventCommand::UndoRedoPerformed"); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } break; case "SelectAll": Debug.Log("SelectAll"); model.selectAll(); e.Use(); break; case "Copy": //Debug.Log ("COPY ..."+ GUI.GetNameOfFocusedControl()); //Debug.Log ("buf: " + EditorGUIUtility.systemCopyBuffer); //Debug.Log("-"+focusedControlName+"-"); //Debug.Log((string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_"))); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { if (model.selectedPOs.Count > 0) { EditorGUIUtility.systemCopyBuffer = LibraryEditor.poWithSubNodes_2_JSON(model.selectedPOs[0], true); } if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; case "Paste": //Debug.Log ("PASTE"); //Debug.Log(GUI.GetNameOfFocusedControl()); //if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) //{ Undo.RegisterCompleteObjectUndo(model, "Paste"); string focusedControlNameBeforePaste = GUI.GetNameOfFocusedControl(); if (string.IsNullOrEmpty(focusedControlNameBeforePaste) || !focusedControlNameBeforePaste.Contains("_Text_")) { //model.deselectAll(); Library.pasteParametricObjectFromString(EditorGUIUtility.systemCopyBuffer); model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } model.autobuild(); break; case "Duplicate": Undo.RegisterCompleteObjectUndo(model, "Duplicate"); //Debug.Log ("Duplicate Command"); if (model.selectedPOs.Count > 0) { AXParametricObject selectedPO = model.selectedPOs[0]; instancePO(selectedPO); } model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } break; case "Cut": Undo.RegisterCompleteObjectUndo(model, "Cut"); //EditorGUIUtility.systemCopyBuffer = JSONSerializersAX.allSelectedPOsAsJson(model); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { if (model.selectedPOs.Count > 0) { EditorGUIUtility.systemCopyBuffer = LibraryEditor.poWithSubNodes_2_JSON(model.selectedPOs[0], true); } if (e.shift) { model.deleteSelectedPOsAndInputs(); } else { model.deleteSelectedPOs(); } model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; case "SoftDelete": case "Delete": //Debug.Log("DELETE"); // see if it is a selected point on a curve //if (ArchimatixEngine /* * FreeCurve selectedFreeCurve = null; * * if ( model.selectedPOs != null && model.selectedPOs.Count == 1 && model.selectedPOs[0] != null && model.selectedPOs[0].generator != null && model.selectedPOs[0].generator is FreeCurve) * { * selectedFreeCurve = (FreeCurve) model.selectedPOs[0].generator; * } * * if (selectedFreeCurve != null && selectedFreeCurve.selectedIndices != null && selectedFreeCurve.selectedIndices.Count > 0) * { * // delete points * selectedFreeCurve.deleteSelected(); * } */ // SELECTED POINTS TO DELETE? //Debug.Log("focusedControlName="+focusedControlName); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { bool foundSelectedPoints = false; if (model.activeFreeCurves.Count > 0) { for (int i = 0; i < model.activeFreeCurves.Count; i++) { FreeCurve gener = (FreeCurve)model.activeFreeCurves[i].generator; //Debug.Log("gener.hasSelectedPoints()="+gener.hasSelectedPoints()); if (gener.hasSelectedPoints()) { foundSelectedPoints = true; gener.deleteSelected(); } } } //Debug.Log("foundSelectedPoints="+foundSelectedPoints); if (foundSelectedPoints) { ArchimatixEngine.mouseIsDownOnHandle = false; } else if (e.shift) { Undo.RegisterCompleteObjectUndo(model, "Delete Nodes"); model.deleteSelectedPOsAndInputs(); } // [S.Darkwell: changed else to this else if to fix bug: "Fix pressing Delete key without Node selected still registers undo event" https://archimatixbeta.slack.com/files/s.darkwell/F1DJRQ3LL/fix_pressing_delete_key_without_node_selected_still_registers_undo_event.cs - 2016.06.02] else if (model.selectedPOs.Count > 0) { Undo.RegisterCompleteObjectUndo(model, "Delete Node"); model.deleteSelectedPOs(); } else if (model.selectedParameterInputRelation != null) { Undo.RegisterCompleteObjectUndo(model, "Delete Dependancy"); model.selectedParameterInputRelation.makeIndependent(); model.selectedParameterInputRelation = null; } else if (model.selectedRelationInGraph != null) { Undo.RegisterCompleteObjectUndo(model, "Delete Relation"); model.unrelate(model.selectedRelationInGraph); model.selectedRelationInGraph = null; } //Debug.Log("*********************************** DELETE"); model.remapMaterialTools(); model.autobuild(); //Debug.Log("caching here G"); model.cacheThumbnails(); e.Use(); } break; case "FrameSelected": if (view != null) { float framePadding = 400; if (model.selectedPOs == null || model.selectedPOs.Count == 0) { //model.selectAll(); model.selectAllVisibleInGroup(model.currentWorkingGroupPO); Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); model.deselectAll(); } else if (model.selectedPOs.Count > 1) { Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); } else { //frame first po AXParametricObject currPO = model.cycleSelectedPO; // model.selectedPOs[0]; if (currPO == null) { currPO = model.mostRecentlySelectedPO; } if (currPO == null && model.selectedPOs != null && model.selectedPOs.Count > 0) { currPO = model.selectedPOs[0]; } if (currPO == null) { currPO = model.selectFirstHeadPO(); } if (currPO != null) { Matrix4x4 m = model.transform.localToWorldMatrix * currPO.worldDisplayMatrix; // * currPO.getLocalMatrix(); if (m.isIdentity) { m = currPO.generator.localMatrix; } Vector3 position = m.MultiplyPoint(currPO.bounds.center); if (currPO.bounds.size.magnitude > .005 && currPO.bounds.size.magnitude < 10000) { view.LookAt(position, view.camera.transform.rotation, currPO.bounds.size.magnitude * 1.01f); } else { //Debug.Log("FrameSelected - select ParametricObjectObject bounds not good: "+currPO.bounds.size.magnitude); } //if (currPO.grouper != null ) //{ AXNodeGraphEditorWindow.displayGroupIfOpen(currPO.grouper); //} //model.beginPanningToPoint(currPO.rect.center); AXNodeGraphEditorWindow.zoomToRectIfOpen(currPO.rect); } } if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; } } // EDITOR WINDOW ArchimatixEngine.repaintGraphEditorIfExistsAndOpen(); // SCENEVIEW if (view != null) { view.Repaint(); } lastCommand = e.commandName; }
// return the height of this gui area public static void OnGUI(Rect headerRect, AXNodeGraphEditorWindow editor) { Event e = Event.current; AXModel model = editor.model; // DO HEADER MENU BAR -- MODEL MENU GUILayout.BeginArea(headerRect); GUILayout.BeginHorizontal(); GUIStyle labelstyle = new GUIStyle(GUI.skin.label); labelstyle.alignment = TextAnchor.LowerLeft; labelstyle.fixedWidth = 150; GUILayout.Space(5); if (GUILayout.Button("2D")) { ArchimatixEngine.openLibrary2D(); } if (GUILayout.Button("3D")) { ArchimatixEngine.openLibrary3D(); } // NEW MODEL GUILayout.Space(10); if (GUILayout.Button("▼")) { AXModel[] allModels = ArchimatixUtils.getAllModels(); GenericMenu menu = new GenericMenu(); //menu.AddSeparator("Library ..."); if (allModels != null && allModels.Length > 0) { for (int i = 0; i < allModels.Length; i++) { AXModel m = allModels [i]; menu.AddItem(new GUIContent(m.gameObject.name), false, () => { Selection.activeGameObject = m.gameObject; ArchimatixEngine.currentModel = m; }); } } menu.AddSeparator(""); menu.AddItem(new GUIContent("New Model"), false, () => { AXEditorUtilities.createNewModel(); }); menu.ShowAsContext(); } Color bgc = GUI.backgroundColor; GUI.backgroundColor = Color.clear; if (model != null) { // SELECTED MODEL if (GUILayout.Button(model.name)) { model.currentWorkingGroupPO = null; model.selectAllVisibleInGroup(null); float framePadding = 50; Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); } if (model.currentWorkingGroupPO != null) { if (model.currentWorkingGroupPO.grouper != null) { // Make breadcrumb trail List <AXParametricObject> crumbs = new List <AXParametricObject>(); AXParametricObject cursor = model.currentWorkingGroupPO; while (cursor.grouper != null) { crumbs.Add(cursor.grouper); cursor = cursor.grouper; } crumbs.Reverse(); // model button frames for (int i = 0; i < crumbs.Count; i++) { if (GUILayout.Button("> " + crumbs[i].Name)) { model.currentWorkingGroupPO = crumbs[i]; Rect grouperCanvasRect = model.currentWorkingGroupPO.getBoundsRect(); editor.zoomToRect(grouperCanvasRect); } } } GUILayout.Button("> " + model.currentWorkingGroupPO.Name); } } GUILayout.FlexibleSpace(); if (model != null) { Color buildBG = Color.Lerp(Color.cyan, Color.white, .8f); string buildLabel = "Rebuild"; if (model.buildStatus == AXModel.BuildStatus.Generated) { buildBG = Color.red; buildLabel = "Build"; } GUI.backgroundColor = buildBG; if (GUILayout.Button(buildLabel)) { model.build(); } GUI.backgroundColor = Color.cyan; if (model.generatedGameObjects != null && model.generatedGameObjects.transform.childCount == 0) { GUI.enabled = false; } if (GUILayout.Button("Stamp")) { model.stamp(); } if (GUILayout.Button("Prefab")) { string startDir = Application.dataPath; string path = EditorUtility.SaveFilePanel( "Save Prefab", startDir, ("" + model.name), "prefab"); if (!string.IsNullOrEmpty(path)) { AXPrefabWindow.makePrefab(model, path, editor); } } GUI.enabled = true; GUILayout.Space(4); } GUILayout.EndHorizontal(); GUILayout.EndArea(); GUI.backgroundColor = bgc; }
// return the height of this gui area public static void OnGUI(AXParameterAlias pa) { AXParameter p = pa.parameter; //Event e = Event.current; // if (Event.current.type == EventType.KeyUp) // { // if (p != null && ! GUI.GetNameOfFocusedControl().Contains("logicTextArea_") ) // { // p.parametricObject.model.autobuildDelayed(1000); // } // } //Color oldBackgroundColor = GUI.backgroundColor; if (p == null || p.parametricObject == null) { return; } //Color defcolor = GUI.color; GUILayout.BeginHorizontal(); // FOLDOUT GUIStyle toggleStyle = new GUIStyle(EditorStyles.foldout); toggleStyle.fixedWidth = 50; pa.isEditing = EditorGUILayout.Foldout(pa.isEditing, GUIContent.none); //Debug.Log(pa.isEditing); // SLIDER AND NUMBER FIELD GUIStyle textfieldStyle = new GUIStyle(GUI.skin.textField); textfieldStyle.fixedWidth = 150; GUIStyle labelWrap = new GUIStyle(GUI.skin.label); labelWrap.stretchWidth = true; labelWrap.wordWrap = true; labelWrap.fontSize = 9; labelWrap.fixedWidth = 150; if (pa.isEditing) { GUILayout.BeginVertical(); pa.alias = GUILayout.TextField(pa.alias, textfieldStyle); GUILayout.Label("You can edit the alias without altering the source parameter.", labelWrap); GUILayout.Label("Actual: ", labelWrap); if (GUILayout.Button(pa.parameter.parametricObject.Name + "." + pa.parameter.Name)) { pa.parameter.parametricObject.model.selectPO(pa.parameter.parametricObject); pa.parameter.ParentNode.isOpen = true; float framePadding = 200; Rect allRect = AXUtilities.getBoundaryRectFromPOs(pa.parameter.parametricObject.model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); } GUILayout.Space(15); GUILayout.EndVertical(); } else { string nameString = pa.alias; switch (p.Type) { case AXParameter.DataType.Float: // FLOAT SLIDER if (p.PType != AXParameter.ParameterType.DerivedValue) { // VALIDATE INPUT - IF INVALID >> LOSE FOCUS AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_Text_" + p.Name); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Text_" + p.Guid + "_" + p.Name); p.val = EditorGUILayout.FloatField(nameString, p.val); if (EditorGUI.EndChangeCheck()) { //Debug.Log(val); Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.Parent.initiateRipple_setFloatValueFromGUIChange(p.Name, p.val); p.parametricObject.model.isAltered(27); p.parametricObject.generator.adjustWorldMatrices(); } } else { GUILayout.Label(p.Name); GUILayout.Label("" + p.val); } break; case AXParameter.DataType.Int: { // INT SLIDER // VALIDATE INPUT - IF INVALID >> LOSE FOCUS /* * if (Event.current.type == EventType.KeyDown) * { * if(Event.current.keyCode != KeyCode.None && !AXEditorUtilities.isValidIntFieldKeyCode(Event.current.keyCode) && GUI.GetNameOfFocusedControl() == ("IntField_" + p.Name)) * { * Event.current.Use(); * GUI.FocusControl("dummy_label"); * } * } */ AXEditorUtilities.assertIntFieldKeyCodeValidity("IntField_" + p.Name); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("IntField_" + p.Guid + "_" + p.Name); p.intval = EditorGUILayout.IntField(nameString, p.intval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.initiateRipple_setIntValueFromGUIChange(p.intval); p.parametricObject.model.isAltered(28); p.parametricObject.generator.adjustWorldMatrices(); } break; } case AXParameter.DataType.Bool: { EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("BoolToggle_" + p.Guid + "_" + p.Name); p.boolval = EditorGUILayout.Toggle(nameString, p.boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.parametricObject.initiateRipple_setBoolParameterValueByName(p.Name, p.boolval); p.parametricObject.model.autobuild(); p.parametricObject.generator.adjustWorldMatrices(); } break; } case AXParameter.DataType.String: if (p.Parent.isEditing) { GUILayout.Label(nameString); } else { GUILayout.Label(nameString); } break; case AXParameter.DataType.Option: { // OPTION POPUP string[] options = ArchimatixUtils.getMenuOptions(p.Name); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("OptionPopup_" + p.Guid + "_" + p.Name); p.intval = EditorGUILayout.Popup( nameString, p.intval, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.parametricObject.model.autobuild(); if (p.PType == AXParameter.ParameterType.PositionControl) { p.parametricObject.generator.adjustWorldMatrices(); } } break; } case AXParameter.DataType.CustomOption: { // OPTION POPUP string[] options = p.optionLabels.ToArray(); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("CustomOptionPopup_" + p.Guid + "_" + p.Name); p.intval = EditorGUILayout.Popup( nameString, p.intval, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); if (p.PType == AXParameter.ParameterType.PositionControl) { p.parametricObject.generator.adjustWorldMatrices(); } p.parametricObject.model.autobuild(); } break; } case AXParameter.DataType.Spline: { GUILayout.Label(pa.alias); break; } } // END switch (Type) } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //GUI.backgroundColor = oldBackgroundColor; //GUI.color = defcolor; }
// Maintain a AXHandle.GUID // and any other runtime preferences public static void OnGUI(AXHandleRuntimeAlias rth) { AXHandle handle = rth.handle; if (handle == null) { return; } //Event e = Event.current; GUILayout.BeginHorizontal(); // FOLDOUT GUIStyle toggleStyle = new GUIStyle(EditorStyles.foldout); toggleStyle.fixedWidth = 50; rth.isEditing = EditorGUILayout.Foldout(rth.isEditing, GUIContent.none); //Debug.Log(pa.isEditing); // SLIDER AND NUMBER FIELD GUIStyle textfieldStyle = new GUIStyle(GUI.skin.textField); textfieldStyle.fixedWidth = 150; GUIStyle labelWrap = new GUIStyle(GUI.skin.label); labelWrap.stretchWidth = true; labelWrap.wordWrap = true; labelWrap.fontSize = 9; labelWrap.fixedWidth = 150; if (rth.isEditing) { GUILayout.BeginVertical(); rth.alias = GUILayout.TextField(rth.alias, textfieldStyle); GUILayout.Label("You can edit the alias without altering the source handle.", labelWrap); GUILayout.Label("Actual: ", labelWrap); if (GUILayout.Button(handle.parametricObject.Name + "." + handle.Name)) { handle.parametricObject.model.selectPO(handle.parametricObject); //handle.ParentNode.isOpen = true; float framePadding = 200; Rect allRect = AXUtilities.getBoundaryRectFromPOs(handle.parametricObject.model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); } GUILayout.Space(15); GUILayout.EndVertical(); } else { GUILayout.Label(rth.alias); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } // OnGUI()