public void DrawToolbar() { if (Screen.width < minWidth) { scale = (float)Screen.width / minWidth; } else { scale = 1f; } SplineEditorGUI.SetScale(scale); DreamteckEditorGUI.SetScale(scale); minWidth = 770; //if (InMirrorMode()) Mirror(Mathf.RoundToInt(44 * scale)); //else if(InMergeMode()) Merge(Mathf.RoundToInt(44 * scale)); //else { //switch (tool) //{ // case PointTool.Create: // if (computer.is2D) Create2DToolbar(Mathf.RoundToInt(44 * scale)); // else CreateToolbar(Mathf.RoundToInt(44 * scale)); // break; // case PointTool.NormalEdit: Normals(Mathf.RoundToInt(44 * scale)); break; // case PointTool.Move: Translate(Mathf.RoundToInt(44 * scale)); break; // case PointTool.Scale: Scale(Mathf.RoundToInt(44 * scale)); break; // case PointTool.Rotate: Rotate(Mathf.RoundToInt(44 * scale)); break; //} } Main(); }
public override void DrawInspector() { HandleEditModeToggle(); base.DrawInspector(); if (editMode) { EditorGUILayout.Space(); DrawToolMenu(); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); if (currentModule != null) { currentModule.DrawInspector(); } DreamteckEditorGUI.DrawSeparator(); PointPanel(); if (EditorGUI.EndChangeCheck()) { ResetCurrentModule(); } } else { if (GUILayout.Button("Edit")) { editMode = true; } } }
private void Merge(int verticalOffset) { if (computer.hasMorph && !MorphWindow.editShapeMode) { return; } Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale); if (barRect.Contains(Event.current.mousePosition)) { mouseHoversToolbar = true; } GUI.color = new Color(1f, 1f, 1f, 0.3f); GUI.Box(barRect, "", SplineEditorGUI.whiteBox); GUI.color = SplineEditorGUI.activeColor; DreamteckEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Merge endpoints", true); mergeEditor.mergeEndpoints = GUI.Toggle(new Rect(130 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), mergeEditor.mergeEndpoints, ""); int mergeSide = (int)mergeEditor.mergeSide; DreamteckEditorGUI.Label(new Rect(120 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Merge side", true); bool hover = SplineEditorGUI.DropDown(new Rect(250, verticalOffset + 5 * scale, 100 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Start", "End" }, true, ref mergeSide); mergeEditor.mergeSide = (SplineComputerMergeEditor.MergeSide)mergeSide; if (hover) { mouseHoversToolbar = true; } }
private void Create2DToolbar(int verticalOffset) { Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale); if (barRect.Contains(Event.current.mousePosition)) { mouseHoversToolbar = true; } GUI.color = new Color(1f, 1f, 1f, 0.3f); GUI.Box(barRect, "", SplineEditorGUI.whiteBox); GUI.color = SplineEditorGUI.activeColor; DreamteckEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 105 * scale, 25 * scale), "Place method:", true); bool hover = SplineEditorGUI.DropDown(new Rect(110 * scale, verticalOffset + 5 * scale, 130 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Free", "Insert" }, true, ref createPointMode2D); if (hover) { mouseHoversToolbar = true; } DreamteckEditorGUI.Label(new Rect(230 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Add Node", true); createNodeOnCreatePoint = GUI.Toggle(new Rect(320 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), createNodeOnCreatePoint, ""); minWidth = 790; if (createPointMode != 1) { DreamteckEditorGUI.Label(new Rect(325 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Append:", true); if (SplineEditorGUI.DropDown(new Rect(405 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "End", "Beginning" }, true, ref appendMode)) { mouseHoversToolbar = true; } minWidth = 1100; } }
private void Translate(int verticalOffset) { if (computer.hasMorph && !MorphWindow.editShapeMode) { return; } Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale); if (barRect.Contains(Event.current.mousePosition)) { mouseHoversToolbar = true; } GUI.color = new Color(1f, 1f, 1f, 0.3f); GUI.Box(barRect, "", SplineEditorGUI.whiteBox); GUI.color = SplineEditorGUI.activeColor; DreamteckEditorGUI.Label(new Rect(110 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Grid snap", true); positionEditor.snap = GUI.Toggle(new Rect(200 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), positionEditor.snap, ""); if (positionEditor.snap) { DreamteckEditorGUI.Label(new Rect(220 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Grid size:", true); positionEditor.snapGridSize = SplineEditorGUI.FloatField(new Rect(300 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), positionEditor.snapGridSize); positionEditor.snapGridSize = SplineEditorGUI.FloatDrag(new Rect(220 * scale, verticalOffset + 5 * scale, 80 * scale, 25 * scale), positionEditor.snapGridSize); if (positionEditor.snapGridSize < 0.001f) { positionEditor.snapGridSize = 0.001f; } } EditSpaceMenu(verticalOffset); }
private void Mirror(int verticalOffset) { if (computer.hasMorph && !MorphWindow.editShapeMode) { return; } Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale); if (barRect.Contains(Event.current.mousePosition)) { mouseHoversToolbar = true; } GUI.color = new Color(1f, 1f, 1f, 0.3f); GUI.Box(barRect, "", SplineEditorGUI.whiteBox); GUI.color = SplineEditorGUI.activeColor; if (SplineEditorGUI.Button(new Rect(5 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), "Cancel")) { ExitMirrorMode(); } if (SplineEditorGUI.Button(new Rect(115 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), "Save")) { SaveMirror(); } DreamteckEditorGUI.Label(new Rect(215 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), "Axis", true); int axis = (int)mirrorEditor.axis; bool hover = SplineEditorGUI.DropDown(new Rect(270 * scale, verticalOffset + 5 * scale, 60 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "X", "Y", "Z" }, true, ref axis); mirrorEditor.axis = (SplinePointMirrorEditor.Axis)axis; if (hover) { mouseHoversToolbar = true; } DreamteckEditorGUI.Label(new Rect(315 * scale, verticalOffset + 5 * scale, 60 * scale, 25 * scale), "Flip", true); mirrorEditor.flip = GUI.Toggle(new Rect(380 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), mirrorEditor.flip, ""); DreamteckEditorGUI.Label(new Rect(390 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Weld Distance", true); mirrorEditor.weldDistance = SplineEditorGUI.FloatField(new Rect(525 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), mirrorEditor.weldDistance); mirrorEditor.weldDistance = SplineEditorGUI.FloatDrag(new Rect(390 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), mirrorEditor.weldDistance); if (mirrorEditor.weldDistance < 0f) { mirrorEditor.weldDistance = 0f; } DreamteckEditorGUI.Label(new Rect(570 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Center X:", true); mirrorEditor.center.x = SplineEditorGUI.FloatField(new Rect(700 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), mirrorEditor.center.x); DreamteckEditorGUI.Label(new Rect(720 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), "Y:", true); mirrorEditor.center.y = SplineEditorGUI.FloatField(new Rect(770 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), mirrorEditor.center.y); DreamteckEditorGUI.Label(new Rect(790 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), "Z:", true); mirrorEditor.center.z = SplineEditorGUI.FloatField(new Rect(840 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), mirrorEditor.center.z); }
void OnSceneGUI(SceneView sceneView) { Handles.BeginGUI(); for (int i = 0; i < pointIndices.Count; i++) { Vector2 screenPosition = HandleUtility.WorldToGUIPoint(currentComputer.GetPoint(pointIndices[i]).position); screenPosition.y -= 25f; string pointName = "P" + pointIndices[i]; DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + pointName.Length * 4, screenPosition.y, 120, 25), pointName); } Handles.EndGUI(); }
protected virtual void ColorGUI() { RandomPathGenerator generator = (RandomPathGenerator)target; EditorGUILayout.BeginHorizontal(); generator.useColors = EditorGUILayout.Toggle(generator.useColors, GUILayout.Width(20)); GUILayout.Label("Use Colors", EditorStyles.boldLabel); EditorGUILayout.EndHorizontal(); if (generator.useColors) { generator.minColor = DreamteckEditorGUI.GradientField("Min.", generator.minColor); generator.maxColor = DreamteckEditorGUI.GradientField("Max.", generator.maxColor); } }
public void DrawToolbar() { if (Screen.width < minWidth) { scale = (float)Screen.width / minWidth; } else { scale = 1f; } SplineEditorGUI.SetScale(scale); DreamteckEditorGUI.SetScale(scale); mouseHoversToolbar = false; minWidth = 770; if (InMirrorMode()) { Mirror(Mathf.RoundToInt(44 * scale)); } else if (InMergeMode()) { Merge(Mathf.RoundToInt(44 * scale)); } else { switch (tool) { case PointTool.Create: if (computer.is2D) { Create2DToolbar(Mathf.RoundToInt(44 * scale)); } else { CreateToolbar(Mathf.RoundToInt(44 * scale)); } break; case PointTool.NormalEdit: Normals(Mathf.RoundToInt(44 * scale)); break; case PointTool.Move: Translate(Mathf.RoundToInt(44 * scale)); break; case PointTool.Scale: Scale(Mathf.RoundToInt(44 * scale)); break; case PointTool.Rotate: Rotate(Mathf.RoundToInt(44 * scale)); break; } } Main(); }
public override void DrawInspector() { base.DrawInspector(); DrawToolMenu(); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); if (currentModule != null) { currentModule.DrawInspector(); } DreamteckEditorGUI.DrawSeparator(); PointPanel(); if (EditorGUI.EndChangeCheck()) { RefreshCurrentModule(); } }
public override void DrawInspector() { editSpace = (EditSpace)EditorGUILayout.EnumPopup("Edit Space", editSpace); surfaceMode = EditorGUILayout.Toggle("Move On Surface", surfaceMode); if (surfaceMode) { surfaceLayerMask = DreamteckEditorGUI.LayermaskField("Surface Mask", surfaceLayerMask); surfaceOffset = EditorGUILayout.FloatField("Surface Offset", surfaceOffset); } snap = EditorGUILayout.Toggle("Snap to Grid", snap); if (snap) { snapGridSize = EditorGUILayout.FloatField("Grid Size", snapGridSize); if (snapGridSize < 0.0001f) { snapGridSize = 0.0001f; } } }
private void Scale(int verticalOffset) { if (computer.hasMorph && !MorphWindow.editShapeMode) { return; } Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale); if (barRect.Contains(Event.current.mousePosition)) { mouseHoversToolbar = true; } GUI.color = new Color(1f, 1f, 1f, 0.3f); GUI.Box(barRect, "", SplineEditorGUI.whiteBox); GUI.color = SplineEditorGUI.activeColor; EditSpaceMenu(verticalOffset); DreamteckEditorGUI.Label(new Rect(120 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Scale sizes", true); scaleEditor.scaleSize = GUI.Toggle(new Rect(210 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), scaleEditor.scaleSize, ""); DreamteckEditorGUI.Label(new Rect(235 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Scale tangents", true); scaleEditor.scaleTangents = GUI.Toggle(new Rect(355 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), scaleEditor.scaleTangents, ""); }
public override void DrawInspector() { placementMode = (PlacementMode)EditorGUILayout.EnumPopup("Placement Mode", placementMode); if (placementMode != PlacementMode.Insert) { normalMode = (NormalMode)EditorGUILayout.EnumPopup("Normal Mode", normalMode); appendMode = (AppendMode)EditorGUILayout.EnumPopup("Append To", appendMode); } string offsetLabel = "Grid Offset"; if (placementMode == PlacementMode.CameraPlane) { offsetLabel = "Far Plane"; } if (placementMode == PlacementMode.Surface) { offsetLabel = "Surface Offset"; } offset = EditorGUILayout.FloatField(offsetLabel, offset); if (placementMode == PlacementMode.Surface) { surfaceLayerMask = DreamteckEditorGUI.LayermaskField("Surface Mask", surfaceLayerMask); } }
public override void DrawScene() { HandleEditModeToggle(); if (!editMode) { return; } base.DrawScene(); Event e = Event.current; if (Tools.current != Tool.None) { lastEditorTool = Tools.current; Tools.current = Tool.None; } int controlID = GUIUtility.GetControlID(FocusType.Passive); if (e.GetTypeForControl(controlID) == EventType.Layout) { HandleUtility.AddDefaultControl(controlID); } if (eventModule.mouseLeftDown) { lastClickPoint = e.mousePosition; } EditorGUI.BeginChangeCheck(); mainModule.DrawScene(); if (currentModule != null) { currentModule.DrawScene(); if (currentModule is CreatePointModule) { if (eventModule.mouseLeftDown && eventModule.mouseRight) { GUIUtility.hotControl = -1; ToggleModule(0); } } } if (eventModule.mouseLeftDown) { emptyClick = GUIUtility.hotControl == 0; } if (emptyClick) { if (eventModule.mouseLeft && !mainModule.isDragging && Vector2.Distance(lastClickPoint, e.mousePosition) >= mainModule.minimumRectSize && !eventModule.alt) { mainModule.StartDrag(lastClickPoint); emptyClick = false; } } if (eventModule.mouseLeftUp) { if (mainModule.isDragging) { mainModule.FinishDrag(); } else { if (emptyClick) { if (selectedPoints.Count > 0) { mainModule.ClearSelection(); } else if (editMode) { if (Time.realtimeSinceStartup - lastEmptyClickTime <= 0.3f) { editMode = false; } else { editLabelAlpha = 1f; editLabelPosition = e.mousePosition; lastEmptyClickTime = Time.realtimeSinceStartup; } } } } } if (!eventModule.mouseRight && !eventModule.mouseLeft && e.type == EventType.KeyDown && !e.control) { switch (e.keyCode) { case KeyCode.Q: if (module == 0) { ToggleModule(1); } else { ToggleModule(0); } e.Use(); break; case KeyCode.W: ToggleModule(2); e.Use(); break; case KeyCode.E: ToggleModule(3); e.Use(); break; case KeyCode.R: ToggleModule(4); e.Use(); break; case KeyCode.T: ToggleModule(5); e.Use(); break; case KeyCode.Y: ToggleModule(6); e.Use(); break; } } if (editLabelAlpha > 0f) { Handles.BeginGUI(); GUI.contentColor = new Color(1f, 1f, 1f, editLabelAlpha); DreamteckEditorGUI.Label(new Rect(editLabelPosition, new Vector2(140, 50)), "Click Again To Exit"); Handles.EndGUI(); editLabelAlpha = Mathf.MoveTowards(editLabelAlpha, 0f, Time.deltaTime * 0.05f); Repaint(); } }
void RenderConnections() { Node node = (Node)target; Node.Connection[] connections = node.GetConnections(); scroll = EditorGUILayout.BeginScrollView(scroll, GUI.skin.box, GUILayout.Width(EditorGUIUtility.currentViewWidth - 30), GUILayout.Height(Mathf.Min(75 + connections.Length * 20, 200))); EditorGUILayout.LabelField("Connections"); EditorGUILayout.Space(); if (connections.Length > 0) { for (int i = 0; i < connections.Length; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(connections[i].computer.name + " at point " + (connections[i].pointIndex + 1)); if (GUILayout.Button("Select", GUILayout.Width(70))) { Selection.activeGameObject = connections[i].computer.gameObject; } if (SplineEditorGUI.EditorLayoutSelectableButton(new GUIContent("Swap Tangents"), connections[i].computer.type == Spline.Type.Bezier, connections[i].invertTangents)) { connections[i].invertTangents = !connections[i].invertTangents; node.UpdateConnectedComputers(); SceneView.RepaintAll(); } if (GUILayout.Button("x", GUILayout.Width(20))) { Undo.RecordObject(node, "Remove connection"); Undo.RecordObject(connections[i].computer, "Remove node"); node.RemoveConnection(connections[i].computer, connections[i].pointIndex); } EditorGUILayout.EndHorizontal(); } } else { EditorGUILayout.HelpBox("Drag & Drop SplineComputers here to link their points.", MessageType.Info); } EditorGUILayout.EndScrollView(); Rect rect = GUILayoutUtility.GetLastRect(); SplineComputer[] addComps; SplineComputer lastComp = addComp; bool dragged = DreamteckEditorGUI.DropArea <SplineComputer>(rect, out addComps); if (dragged && addComps.Length > 0) { SelectComputer(addComps[0]); } if (lastComp != addComp) { SceneView.RepaintAll(); } node.transformNormals = EditorGUILayout.Toggle("Transform Normals", node.transformNormals); node.transformSize = EditorGUILayout.Toggle("Transform Size", node.transformSize); node.transformTangents = EditorGUILayout.Toggle("Transform Tangents", node.transformTangents); EditorGUI.BeginChangeCheck(); if (connections.Length > 1) { node.type = (Node.Type)EditorGUILayout.EnumPopup("Node type", node.type); } if (EditorGUI.EndChangeCheck()) { SceneView.RepaintAll(); node.UpdateConnectedComputers(); } }
private void Main() { Rect barRect = new Rect(0f, 0f, Screen.width, 45 * scale); if (barRect.Contains(Event.current.mousePosition)) { mouseHoversToolbar = true; } GUI.color = new Color(1f, 1f, 1f, 0.3f); GUI.Box(barRect, "", SplineEditorGUI.whiteBox); GUI.color = SplineEditorGUI.activeColor; if (computer.hasMorph && !MorphWindow.editShapeMode) { DreamteckEditorGUI.Label(new Rect(Screen.width / 2f - 200f, 10, 400, 30), "Editing unavailable outside of morph states."); return; } if (computer.hasMorph) { if (tool == PointTool.Create || tool == PointTool.Delete) { tool = PointTool.None; } } else { if (SplineEditorGUI.BigButton(new Rect(5 * scale, 5 * scale, 35 * scale, 35 * scale), addButtonContent, true, tool == PointTool.Create)) { ToggleCreateTool(); } if (SplineEditorGUI.BigButton(new Rect(45 * scale, 5 * scale, 35 * scale, 35 * scale), removeButtonContent, computer.pointCount > 0, tool == PointTool.Delete)) { if (tool != PointTool.Delete) { tool = PointTool.Delete; } else { tool = PointTool.None; } } if (SplineEditorGUI.BigButton(new Rect(85 * scale, 5 * scale, 35 * scale, 35 * scale), presetButtonContent, true, presetWindow != null)) { if (presetWindow == null) { presetWindow = EditorWindow.GetWindow <PresetsWindow>(true); presetWindow.Init(this, Vector2.zero, new Vector2(350, 20 * 22)); } } } if (SplineEditorGUI.BigButton(new Rect(150 * scale, 5 * scale, 35 * scale, 35 * scale), moveButtonContent, true, tool == PointTool.Move)) { if (tool != PointTool.Move) { ToggleMoveTool(); } else { tool = PointTool.None; } } if (SplineEditorGUI.BigButton(new Rect(190 * scale, 5 * scale, 35 * scale, 35 * scale), rotateButtonContent, true, tool == PointTool.Rotate)) { if (tool != PointTool.Rotate) { ToggleRotateTool(); } else { tool = PointTool.None; } } if (SplineEditorGUI.BigButton(new Rect(230 * scale, 5 * scale, 35 * scale, 35 * scale), scaleButtonContent, true, tool == PointTool.Scale)) { if (tool != PointTool.Scale) { ToggleScaleTool(); } else { tool = PointTool.None; } } if (SplineEditorGUI.BigButton(new Rect(270 * scale, 5 * scale, 35 * scale, 35 * scale), normalsButtonContent, !computer.is2D, tool == PointTool.NormalEdit)) { if (tool != PointTool.NormalEdit) { tool = PointTool.NormalEdit; } else { tool = PointTool.None; } } if (SplineEditorGUI.BigButton(new Rect(330 * scale, 5 * scale, 35 * scale, 35 * scale), mirrorButtonContent, computer.pointCount > 0 || InMirrorMode(), InMirrorMode())) { if (InMirrorMode()) { ExitMirrorMode(); } else { EnterMirrorMode(); } } if (SplineEditorGUI.BigButton(new Rect(370 * scale, 5 * scale, 35 * scale, 35 * scale), mergeButtonContent, computer.pointCount > 0 && !computer.isClosed, InMergeMode())) { if (InMergeMode()) { ExitMergeMode(); } else { EnterMergeMode(); } } if (SplineEditorGUI.BigButton(new Rect(410 * scale, 5 * scale, 35 * scale, 35 * scale), splitButtonContent, computer.pointCount > 0 && !computer.isClosed, InSplitMode())) { if (InSplitMode()) { ExitSplitMode(); } else { EnterSplitMode(); } } int operation = 0; float operationsPosition = Screen.width - (190 * scale + 100); #if UNITY_EDITOR_OSX operationsPosition = 430 * scale; #endif bool hover = SplineEditorGUI.DropDown(new Rect(operationsPosition, 10 * scale, 150 * scale, 25 * scale), SplineEditorGUI.defaultButton, operations, HasSelection(), ref operation); if (hover) { mouseHoversToolbar = true; } if (selectedPointsCount > 0) { switch (operation) { case 1: CenterSelection(); break; case 2: MoveTransformToSelection(); break; case 3: FlatSelection(0); break; case 4: FlatSelection(1); break; case 5: FlatSelection(2); break; case 6: MirrorSelection(0); break; case 7: MirrorSelection(1); break; case 8: MirrorSelection(2); break; case 9: DistributeEvenly(); break; case 10: EditorWindow.GetWindow <RelaxWindow>(true).Init(this, new Vector2(250, 90)); break; } } GUI.color = SplineEditorGUI.activeColor; ((SplineComputer)target).editorPathColor = EditorGUI.ColorField(new Rect(operationsPosition + 160 * scale, 13 * scale, 40 * scale, 20 * scale), ((SplineComputer)target).editorPathColor); }
private void CreateToolbar(int verticalOffset) { Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale); if (barRect.Contains(Event.current.mousePosition)) { mouseHoversToolbar = true; } GUI.color = new Color(1f, 1f, 1f, 0.3f); GUI.Box(barRect, "", SplineEditorGUI.whiteBox); GUI.color = SplineEditorGUI.activeColor; DreamteckEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 105 * scale, 25 * scale), "Place method:", true); bool hover = SplineEditorGUI.DropDown(new Rect(110 * scale, verticalOffset + 5 * scale, 130 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Camera Plane", "Insert", "Surface", "X Plane", "Y Plane", "Z Plane" }, true, ref createPointMode); if (hover) { mouseHoversToolbar = true; } DreamteckEditorGUI.Label(new Rect(220 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), "Normal:", true); hover = SplineEditorGUI.DropDown(new Rect(320 * scale, verticalOffset + 5 * scale, 160 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Auto", "Look at Camera", "Align with Camera", "Calculate", "Left", "Right", "Up", "Down", "Forward", "Back" }, true, ref createNormalMode); if (hover) { mouseHoversToolbar = true; } DreamteckEditorGUI.Label(new Rect(800 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Add Node", true); createNodeOnCreatePoint = GUI.Toggle(new Rect(890 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), createNodeOnCreatePoint, ""); bool showNormalField = false; if (createPointMode >= 3 && createPointMode <= 5) { DreamteckEditorGUI.Label(new Rect(500 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Grid offset:", true); showNormalField = true; } else if (createPointMode == 2) { DreamteckEditorGUI.Label(new Rect(480 * scale, verticalOffset + 5 * scale, 100 * scale, 30 * scale), "Normal offset:", true); showNormalField = true; if (SplineEditorGUI.Button(new Rect(925 * scale, verticalOffset * scale + 5, 95 * scale, 25 * scale), "LayerMask")) { LayermaskWindow maskWindow = EditorWindow.GetWindow <LayermaskWindow>(true); maskWindow.position = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 10, 10); maskWindow.Init(this, new Vector2(150, 30), new Vector2(150, 30)); } } else if (createPointMode == 0) { DreamteckEditorGUI.Label(new Rect(500 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Far plane:", true); showNormalField = true; } if (showNormalField) { createPointOffset = SplineEditorGUI.FloatField(new Rect(580 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), createPointOffset); createPointOffset = SplineEditorGUI.FloatDrag(new Rect(500 * scale, verticalOffset + 5 * scale, 80 * scale, 25 * scale), createPointOffset); if (createPointOffset < 0f && createPointMode < 3) { createPointOffset = 0f; } } minWidth = 790; if (createPointMode != 1) { DreamteckEditorGUI.Label(new Rect(625 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Append:", true); if (SplineEditorGUI.DropDown(new Rect(705 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "End", "Beginning" }, true, ref appendMode)) { mouseHoversToolbar = true; } minWidth = 1100; } }
void OnSceneGUI() { #if DREAMTECK_SPLINES for (int i = 0; i < splines.Length; i++) { if (splines[i] != null) { DSSplineDrawer.DrawSplineComputer(splines[i]); } } #endif if (Application.isPlaying) { for (int i = 0; i < sceneSegments.Length; i++) { if (sceneSegments[i].drawCustomPaths) { LevelSegmentDebug.DrawCustomPaths(sceneSegments[i]); } if (sceneSegments[i].drawGeneratedSpline) { LevelSegmentDebug.DrawGeneratedSpline(sceneSegments[i]); } if (sceneSegments[i].drawGeneratedSamples) { LevelSegmentDebug.DrawGeneratedSamples(sceneSegments[i]); } } } else { for (int i = 0; i < sceneSegments.Length; i++) { if (sceneSegments[i].drawCustomPaths) { LevelSegmentDebug.DrawCustomPaths(sceneSegments[i]); } if (sceneSegments[i].type == LevelSegment.Type.Custom) { continue; } if (sceneSegments[i].drawBounds) { LevelSegmentDebug.DrawBounds(sceneSegments[i]); } } if (sceneSegments.Length == 1 && selectedProperties.Count > 0) { Handles.BeginGUI(); for (int i = 0; i < selectedProperties.Count; i++) { Vector2 screenPosition = HandleUtility.WorldToGUIPoint(sceneSegments[0].objectProperties[selectedProperties[i]].transform.transform.position); DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + sceneSegments[0].objectProperties[selectedProperties[i]].transform.transform.name.Length * 4, screenPosition.y, 120, 25), sceneSegments[0].objectProperties[selectedProperties[i]].transform.transform.name); } Handles.EndGUI(); } } if (pathEditor != null) { pathEditor.DrawScene(); } for (int i = 0; i < sceneSegments.Length; i++) { if (!sceneSegments[i].drawEntranceAndExit) { continue; } if (sceneSegments[i].type == LevelSegment.Type.Custom) { if (sceneSegments[i].customEntrance != null) { float handleSize = HandleUtility.GetHandleSize(sceneSegments[i].customEntrance.position); Handles.color = ForeverPrefs.entranceColor; Handles.DrawSolidDisc(sceneSegments[i].customEntrance.position, Camera.current.transform.position - sceneSegments[i].customEntrance.position, handleSize * 0.1f); Handles.ArrowHandleCap(0, sceneSegments[i].customEntrance.position, sceneSegments[i].customEntrance.rotation, handleSize * 0.5f, EventType.Repaint); Handles.Label(sceneSegments[i].customEntrance.position + Camera.current.transform.up * handleSize * 0.3f, "Entrance"); } if (sceneSegments[i].customExit != null) { Handles.color = ForeverPrefs.exitColor; float handleSize = HandleUtility.GetHandleSize(sceneSegments[i].customExit.position); Handles.DrawSolidDisc(sceneSegments[i].customExit.position, Camera.current.transform.position - sceneSegments[i].customExit.position, handleSize * 0.1f); Handles.ArrowHandleCap(0, sceneSegments[i].customExit.position, sceneSegments[i].customExit.rotation, handleSize * 0.5f, EventType.Repaint); Handles.Label(sceneSegments[i].customExit.position + Camera.current.transform.up * HandleUtility.GetHandleSize(sceneSegments[i].customExit.position) * 0.3f, "Exit"); } } } }
public override void DrawScene() { base.DrawScene(); if (drawComputer) { for (int i = 0; i < splines.Length; i++) { DSSplineDrawer.DrawSplineComputer(splines[i]); } } if (drawConnectedComputers) { for (int i = 0; i < splines.Length; i++) { List <SplineComputer> computers = splines[i].GetConnectedComputers(); for (int j = 1; j < computers.Count; j++) { DSSplineDrawer.DrawSplineComputer(computers[j], 0.0, 1.0, 0.5f); } } } if (pathEditor.currentModule == null) { switch (transformTool) { case 1: for (int i = 0; i < splines.Length; i++) { Vector3 position = splines[i].transform.position; position = Handles.PositionHandle(position, splines[i].transform.rotation); if (position != splines[i].transform.position) { RecordUndo("Move spline computer"); Undo.RecordObject(splines[i].transform, "Move spline computer"); splines[i].transform.position = position; splines[i].SetPoints(pathEditor.points); pathEditor.Refresh(); } } break; case 2: for (int i = 0; i < splines.Length; i++) { Quaternion rotation = splines[i].transform.rotation; rotation = Handles.RotationHandle(rotation, splines[i].transform.position); if (rotation != splines[i].transform.rotation) { RecordUndo("Rotate spline computer"); Undo.RecordObject(splines[i].transform, "Rotate spline computer"); splines[i].transform.rotation = rotation; splines[i].SetPoints(pathEditor.points); pathEditor.Refresh(); } } break; case 3: for (int i = 0; i < splines.Length; i++) { Vector3 scale = splines[i].transform.localScale; scale = Handles.ScaleHandle(scale, splines[i].transform.position, splines[i].transform.rotation, HandleUtility.GetHandleSize(splines[i].transform.position)); if (scale != splines[i].transform.localScale) { RecordUndo("Scale spline computer"); Undo.RecordObject(splines[i].transform, "Scale spline computer"); splines[i].transform.localScale = scale; splines[i].SetPoints(pathEditor.points); pathEditor.Refresh(); } } break; } if (transformTool > 0) { for (int i = 0; i < splines.Length; i++) { Vector2 screenPosition = HandleUtility.WorldToGUIPoint(splines[i].transform.position); screenPosition.y += 20f; Handles.BeginGUI(); DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + splines[i].name.Length * 4, screenPosition.y, 120, 25), splines[i].name); Handles.EndGUI(); } } } if (module >= 0 && module < modules.Length) { modules[module].DrawScene(); } }
public override void DrawInspector() { base.DrawInspector(); if (spline == null) { return; } SplineEditorGUI.SetHighlightColors(SplinePrefs.highlightColor, SplinePrefs.highlightContentColor); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUI.BeginChangeCheck(); operationsToolbar.SetContent(0, new GUIContent(spline.isClosed ? "Break" : "Close")); operationsToolbar.SetContent(1, new GUIContent("Reverse")); operationsToolbar.SetContent(2, new GUIContent(spline.is2D ? "3D Mode" : "2D Mode")); operationsToolbar.Draw(ref operation); //operation = GUILayout.Toolbar(operation, new string[] { , "Reverse", text2D }, GUILayout.Width(220f)); if (EditorGUI.EndChangeCheck()) { PerformOperation(); } EditorGUI.BeginChangeCheck(); if (splines.Length == 1) { int mod = module; utilityToolbar.Draw(ref mod); if (EditorGUI.EndChangeCheck()) { ToggleModule(mod); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (module >= 0 && module < modules.Length) { modules[module].DrawInspector(); } EditorGUILayout.Space(); DreamteckEditorGUI.DrawSeparator(); EditorGUILayout.Space(); serializedObject.Update(); SerializedProperty splineProperty = serializedObject.FindProperty("spline"); SerializedProperty sampleRate = serializedObject.FindProperty("spline").FindPropertyRelative("sampleRate"); SerializedProperty type = serializedObject.FindProperty("spline").FindPropertyRelative("type"); SerializedProperty linearAverageDirection = splineProperty.FindPropertyRelative("linearAverageDirection"); SerializedProperty space = serializedObject.FindProperty("_space"); SerializedProperty sampleMode = serializedObject.FindProperty("_sampleMode"); SerializedProperty optimizeAngleThreshold = serializedObject.FindProperty("_optimizeAngleThreshold"); SerializedProperty updateMode = serializedObject.FindProperty("updateMode"); SerializedProperty rebuildOnAwake = serializedObject.FindProperty("rebuildOnAwake"); SerializedProperty multithreaded = serializedObject.FindProperty("multithreaded"); SerializedProperty customNormalInterpolation = splineProperty.FindPropertyRelative("customNormalInterpolation"); SerializedProperty customValueInterpolation = splineProperty.FindPropertyRelative("customValueInterpolation"); EditorGUI.BeginChangeCheck(); Spline.Type lastType = (Spline.Type)type.intValue; EditorGUILayout.PropertyField(type); if (lastType == Spline.Type.CatmullRom && type.intValue == (int)Spline.Type.Bezier) { if (EditorUtility.DisplayDialog("Hermite to Bezier", "Would you like to retain the Catmull Rom shape in Bezier mode?", "Yes", "No")) { for (int i = 0; i < splines.Length; i++) { splines[i].CatToBezierTangents(); } serializedObject.Update(); pathEditor.Refresh(); } } if (spline.type == Spline.Type.Linear) { EditorGUILayout.PropertyField(linearAverageDirection); } int lastSpace = space.intValue; EditorGUILayout.PropertyField(space, new GUIContent("Space")); EditorGUILayout.PropertyField(sampleMode, new GUIContent("Sample Mode")); if (sampleMode.intValue == (int)SplineComputer.SampleMode.Optimized) { EditorGUILayout.PropertyField(optimizeAngleThreshold); } EditorGUILayout.PropertyField(updateMode); if (updateMode.intValue == (int)SplineComputer.UpdateMode.None && Application.isPlaying) { if (GUILayout.Button("Rebuild")) { for (int i = 0; i < splines.Length; i++) { splines[i].RebuildImmediate(true, true); } } } if (spline.type != Spline.Type.Linear) { EditorGUILayout.PropertyField(sampleRate, new GUIContent("Sample Rate")); } EditorGUILayout.PropertyField(rebuildOnAwake); EditorGUILayout.PropertyField(multithreaded); EditorGUI.indentLevel++; bool curveUpdate = false; interpolationFoldout = EditorGUILayout.Foldout(interpolationFoldout, "Point Value Interpolation"); if (interpolationFoldout) { if (customValueInterpolation.animationCurveValue == null || customValueInterpolation.animationCurveValue.keys.Length == 0) { if (GUILayout.Button("Size & Color Interpolation")) { AnimationCurve curve = new AnimationCurve(); curve.AddKey(new Keyframe(0, 0, 0, 0)); curve.AddKey(new Keyframe(1, 1, 0, 0)); for (int i = 0; i < splines.Length; i++) { splines[i].customValueInterpolation = curve; } serializedObject.Update(); curveUpdate = true; } } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(customValueInterpolation, new GUIContent("Size & Color Interpolation")); if (GUILayout.Button("x", GUILayout.MaxWidth(25))) { customValueInterpolation.animationCurveValue = null; for (int i = 0; i < splines.Length; i++) { splines[i].customValueInterpolation = null; } serializedObject.Update(); curveUpdate = true; } EditorGUILayout.EndHorizontal(); } if (customNormalInterpolation.animationCurveValue == null || customNormalInterpolation.animationCurveValue.keys.Length == 0) { if (GUILayout.Button("Normal Interpolation")) { AnimationCurve curve = new AnimationCurve(); curve.AddKey(new Keyframe(0, 0)); curve.AddKey(new Keyframe(1, 1)); for (int i = 0; i < splines.Length; i++) { splines[i].customNormalInterpolation = curve; } serializedObject.Update(); curveUpdate = true; } } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(customNormalInterpolation, new GUIContent("Normal Interpolation")); if (GUILayout.Button("x", GUILayout.MaxWidth(25))) { customNormalInterpolation.animationCurveValue = null; for (int i = 0; i < splines.Length; i++) { splines[i].customNormalInterpolation = null; } serializedObject.Update(); curveUpdate = true; } EditorGUILayout.EndHorizontal(); } } EditorGUI.indentLevel--; if (EditorGUI.EndChangeCheck() || curveUpdate) { if (sampleRate.intValue < 2) { sampleRate.intValue = 2; } if (lastSpace != space.intValue) { for (int i = 0; i < splines.Length; i++) { splines[i].space = (SplineComputer.Space)space.intValue; } serializedObject.Update(); if (splines.Length == 1) { pathEditor.Refresh(); } } serializedObject.ApplyModifiedProperties(); for (int i = 0; i < splines.Length; i++) { splines[i].Rebuild(true); } } if (pathEditor.currentModule != null) { transformTool = 0; } EditorGUILayout.BeginHorizontal(); GUILayout.Label("Edit Transform"); GUILayout.FlexibleSpace(); int lastTool = transformTool; transformToolbar.Draw(ref transformTool); if (lastTool != transformTool && transformTool > 0) { pathEditor.UntoggleCurrentModule(); } EditorGUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); Node node = (Node)target; if (nodes.Length == 1) { if (addComp != null) { string[] pointNames = new string[availablePoints.Length]; for (int i = 0; i < pointNames.Length; i++) { pointNames[i] = "Point " + (availablePoints[i] + 1); } if (availablePoints.Length > 0) { addPoint = EditorGUILayout.Popup("Link point", addPoint, pointNames); } else { EditorGUILayout.LabelField("No Points Available"); } if (GUILayout.Button("Cancel")) { addComp = null; addPoint = 0; } if (addPoint >= 0 && availablePoints.Length > addPoint) { if (node.HasConnection(addComp, availablePoints[addPoint])) { EditorGUILayout.HelpBox("Connection already exists (" + addComp.name + "," + availablePoints[addPoint], MessageType.Error); } else if (GUILayout.Button("Link")) { AddConnection(addComp, availablePoints[addPoint]); } } } else { SplineEditorGUI.BeginContainerBox(ref connectionsOpen, "Connections"); if (connectionsOpen) { ConnectionsGUI(); } SplineEditorGUI.EndContainerBox(); Rect rect = GUILayoutUtility.GetLastRect(); SplineComputer[] addComps; SplineComputer lastComp = addComp; bool dragged = DreamteckEditorGUI.DropArea <SplineComputer>(rect, out addComps); if (dragged && addComps.Length > 0) { SelectComputer(addComps[0]); } if (lastComp != addComp) { SceneView.RepaintAll(); } } } else { EditorGUILayout.HelpBox("Connection UI not available when multiple Nodes are selected.", MessageType.Info); } SplineEditorGUI.BeginContainerBox(ref settingsOpen, "Settings"); if (settingsOpen) { SettingsGUI(); } SplineEditorGUI.EndContainerBox(); }
protected override void OnSceneGUI() { base.OnSceneGUI(); ObjectBender bender = (ObjectBender)target; if (selected.Count > 0) { Handles.BeginGUI(); for (int i = 0; i < selected.Count; i++) { Vector2 screenPosition = HandleUtility.WorldToGUIPoint(bender.bendProperties[selected[i]].transform.transform.position); DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + bender.bendProperties[selected[i]].transform.transform.name.Length * 4, screenPosition.y, 120, 25), bender.bendProperties[selected[i]].transform.transform.name); } Handles.EndGUI(); } for (int i = 0; i < bender.bendProperties.Length; i++) { if (bender.bendProperties[i].bendSpline && bender.bendProperties[i].splineComputer != null) { DSSplineDrawer.DrawSplineComputer(bender.bendProperties[i].splineComputer, 0.0, 1.0, 0.2f); } } //Draw bounds if (bender.bend) { return; } TS_Bounds bound = bender.GetBounds(); Vector3 a = bender.transform.TransformPoint(bound.min); Vector3 b = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.min.y, bound.min.z)); Vector3 c = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.min.y, bound.max.z)); Vector3 d = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.min.y, bound.max.z)); Vector3 e = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.max.y, bound.min.z)); Vector3 f = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.max.y, bound.min.z)); Vector3 g = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.max.y, bound.max.z)); Vector3 h = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.max.y, bound.max.z)); Handles.color = Color.gray; Handles.DrawLine(a, b); Handles.DrawLine(b, c); Handles.DrawLine(c, d); Handles.DrawLine(d, a); Handles.DrawLine(e, f); Handles.DrawLine(f, g); Handles.DrawLine(g, h); Handles.DrawLine(h, e); Handles.DrawLine(a, e); Handles.DrawLine(b, f); Handles.DrawLine(c, g); Handles.DrawLine(d, h); Vector3 r = bender.transform.right; Vector3 fr = bender.transform.forward; switch (bender.axis) { case ObjectBender.Axis.Z: Handles.color = Color.blue; Handles.DrawLine(r + b, r + c); break; case ObjectBender.Axis.X: Handles.color = Color.red; Handles.DrawLine(b - fr, a - fr); break; case ObjectBender.Axis.Y: Handles.color = Color.green; Handles.DrawLine(b - fr + r, f - fr + r); break; } }
public void DrawInspector() { Spline spline = path.spline; if (spline == null) { return; } path.Transform(); EditorGUILayout.BeginVertical(); bool bezier = path.spline.type == Spline.Type.Bezier; bezier = EditorGUILayout.Toggle("Bezier", bezier); path.spline.type = bezier ? Spline.Type.Bezier : Spline.Type.Linear; path.seamlessEnds = EditorGUILayout.Toggle("Seamless Ends", path.seamlessEnds); path.spline.sampleRate = EditorGUILayout.IntField("Precision", path.spline.sampleRate); string[] options = new string[spline.points.Length + 1]; for (int i = 0; i < options.Length - 1; i++) { options[i + 1] = "Point " + (i + 1); } options[0] = "- None -"; EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); selectedPoint = EditorGUILayout.Popup("Select Point", selectedPoint + 1, options) - 1; if (selectedPoint > 0 && spline.points.Length > 2 && modifyWindow == null) { if (GUILayout.Button("X", GUILayout.Width(20))) { ArrayUtility.Remove(ref spline.points, spline.points[selectedPoint]); selectedPoint--; } } EditorGUILayout.EndHorizontal(); if (selectedPoint >= 0 && selectedPoint < spline.points.Length) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if (tool == PathTool.Move) { GUI.backgroundColor = ForeverPrefs.highlightColor; } else { GUI.backgroundColor = Color.white; } if (GUILayout.Button("Move", EditorStyles.miniButtonLeft)) { tool = PathTool.Move; } if (tool == PathTool.Surface) { GUI.backgroundColor = ForeverPrefs.highlightColor; } else { GUI.backgroundColor = Color.white; } if (GUILayout.Button("Surface", EditorStyles.miniButtonMid)) { tool = PathTool.Surface; } if (tool == PathTool.Normal) { GUI.backgroundColor = ForeverPrefs.highlightColor; } else { GUI.backgroundColor = Color.white; } if (GUILayout.Button("Normals", EditorStyles.miniButtonRight)) { tool = PathTool.Normal; } EditorGUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; if (tool == PathTool.Surface) { surfaceLayermask = DreamteckEditorGUI.LayermaskField("Layer Mask", surfaceLayermask); } EditorGUILayout.Space(); SplinePoint avgPoint = spline.points[selectedPoint]; avgPoint.SetPosition(EditorGUILayout.Vector3Field("Position", avgPoint.position)); if (spline.type == Spline.Type.Bezier) { EditorGUILayout.Space(); avgPoint.type = (SplinePoint.Type)EditorGUILayout.EnumPopup("Tangents Type", avgPoint.type); avgPoint.SetTangent2Position(EditorGUILayout.Vector3Field("Front Tangent", avgPoint.tangent2)); avgPoint.SetTangentPosition(EditorGUILayout.Vector3Field("Back Tangent", avgPoint.tangent)); EditorGUILayout.Space(); } else { avgPoint.tangent = avgPoint.position; avgPoint.tangent2 = avgPoint.position; } avgPoint.normal = EditorGUILayout.Vector3Field("Normal", avgPoint.normal); avgPoint.normal.Normalize(); EditorGUIUtility.labelWidth = 0f; avgPoint.size = EditorGUILayout.FloatField("Size", avgPoint.size); avgPoint.color = EditorGUILayout.ColorField("Color", avgPoint.color); Undo.RecordObject(segment, "Edit Path " + path.name); spline.points[selectedPoint] = avgPoint; if (GUI.changed) { path.InverseTransform(); } } if (modifyWindow == null) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Insert Point", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("At Start")) { SplineSample result = spline.Evaluate(DMath.Lerp(0.0, 1.0 / (spline.points.Length - 1), 0.5)); float tangentLength = Mathf.Lerp(Vector3.Distance(spline.points[0].position, spline.points[0].tangent), Vector3.Distance(spline.points[1].position, spline.points[1].tangent), 0.5f); ArrayUtility.Insert(ref spline.points, 1, new SplinePoint(result.position, result.position - result.forward * tangentLength, result.up, result.size, result.color)); path.InverseTransform(); selectedPoint = 1; } if (GUILayout.Button("At End")) { SplineSample result = spline.Evaluate(DMath.Lerp((double)(spline.points.Length - 2) / (spline.points.Length - 1), 1.0, 0.5)); float tangentLength = Mathf.Lerp(Vector3.Distance(spline.points[spline.points.Length - 2].position, spline.points[spline.points.Length - 2].tangent), Vector3.Distance(spline.points[spline.points.Length - 1].position, spline.points[spline.points.Length - 1].tangent), 0.5f); ArrayUtility.Insert(ref spline.points, spline.points.Length - 2, new SplinePoint(result.position, result.position - result.forward * tangentLength, result.up, result.size, result.color)); path.InverseTransform(); selectedPoint = spline.points.Length - 2; } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Modify Path")) { modifyWindow = EditorWindow.GetWindow <ModifyWindow>(true); modifyWindow.Init(this); } } EditorGUILayout.EndVertical(); }
public static bool Slider(SplineUser user, ref double percent, Color color, string text = "", SplineSliderGizmo gizmo = SplineSliderGizmo.Rectangle, float buttonSize = 1f) { Camera cam = SceneView.currentDrawingSceneView.camera; SplineResult result = user.Evaluate(percent); float size = HandleUtility.GetHandleSize(result.position); Handles.color = new Color(color.r, color.g, color.b, 0.4f); Handles.DrawSolidDisc(result.position, cam.transform.position - result.position, size * 0.2f * buttonSize); Handles.color = Color.white; if ((color.r + color.g + color.b + color.a) / 4f >= 0.9f) { Handles.color = Color.black; } Vector3 center = result.position; Vector2 screenPosition = HandleUtility.WorldToGUIPoint(center); screenPosition.y += 20f; Vector3 localPos = cam.transform.InverseTransformPoint(center); if (text != "" && localPos.z > 0f) { Handles.BeginGUI(); DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + text.Length * 4, screenPosition.y, 120, 25), text); Handles.EndGUI(); } bool buttonClick = SliderButton(center, false, Color.white, 0.3f); Vector3 lookAtCamera = (cam.transform.position - result.position).normalized; Vector3 right = Vector3.Cross(lookAtCamera, result.direction).normalized *size * 0.1f * buttonSize; Vector3 front = Vector3.forward; switch (gizmo) { case SplineSliderGizmo.BackwardTriangle: center += result.direction * size * 0.06f * buttonSize; front = center - result.direction * size * 0.2f * buttonSize; Handles.DrawLine(center + right, front); Handles.DrawLine(front, center - right); Handles.DrawLine(center - right, center + right); break; case SplineSliderGizmo.ForwardTriangle: center -= result.direction * size * 0.06f * buttonSize; front = center + result.direction * size * 0.2f * buttonSize; Handles.DrawLine(center + right, front); Handles.DrawLine(front, center - right); Handles.DrawLine(center - right, center + right); break; case SplineSliderGizmo.DualArrow: center += result.direction * size * 0.025f * buttonSize; front = center + result.direction * size * 0.17f * buttonSize; Handles.DrawLine(center + right, front); Handles.DrawLine(front, center - right); Handles.DrawLine(center - right, center + right); center -= result.direction * size * 0.05f * buttonSize; front = center - result.direction * size * 0.17f * buttonSize; Handles.DrawLine(center + right, front); Handles.DrawLine(front, center - right); Handles.DrawLine(center - right, center + right); break; case SplineSliderGizmo.Rectangle: break; case SplineSliderGizmo.Circle: Handles.DrawWireDisc(center, lookAtCamera, 0.13f * size * buttonSize); break; } Vector3 lastPos = result.position; Handles.color = Color.clear; #if UNITY_5_5_OR_NEWER result.position = Handles.FreeMoveHandle(result.position, Quaternion.LookRotation(cam.transform.position - result.position), size * 0.2f * buttonSize, Vector3.zero, Handles.CircleHandleCap); #else result.position = Handles.FreeMoveHandle(result.position, Quaternion.LookRotation(cam.transform.position - result.position), size * 0.2f * buttonSize, Vector3.zero, Handles.CircleCap); #endif if (result.position != lastPos) { percent = user.Project(result.position).percent; } Handles.color = Color.white; return(buttonClick); }