public override void OnInspectorGUI() { InteractivePrimitive primitive = ((InteractivePrimitive)target); if (primitive.hasSubdivisions) { EditorGUI.BeginChangeCheck(); int subs = primitive.GetSubdivisions(); subs = EditorGUILayout.IntField("Subdivisions", subs); if (EditorGUI.EndChangeCheck()) { primitive.SetSubdivisions((int)Mathf.Clamp(subs, primitive.MinSubdivisions, primitive.MaxSubdivisions)); primitive.SetMeshDimensions(primitive.baseStart, primitive.baseEnd, primitive.height); primitive.ToMesh(); primitive.OnFinishDragSizing(); } } }
public void OnSceneGUI() { // For the pretty screenshots // DrawBounds(); // EditorUtility.SetSelectedWireframeHidden(t.renderer, true); if (!t.sizing) { return; } if (dragState != DragState.None) { DrawBounds(); } // Force the control id focus int controlID = GUIUtility.GetControlID(FocusType.Passive); HandleUtility.AddDefaultControl(controlID); Event e = Event.current; if (e.modifiers != (EventModifiers)0 || Tools.current == Tool.View) { return; } switch (e.type) { case EventType.MouseDown: Vector3 pivot = SceneView.lastActiveSceneView.pivot; plane = new Plane(Vector3.up, pivot); /** * First contact - set the base to the mouse intersect */ if (dragState == DragState.None) { Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); if (!InteractivePrimitivesMath.MousePositionOnPlane(ray, plane, ref baseStart)) { Debug.LogWarning("Could not find origin plane."); t.sizing = false; t.OnFinishDragSizing(); } baseEnd = baseStart; height = .01f; ((InteractivePrimitive)target).GetComponent <Renderer>().enabled = true; dragState = DragState.Base; } break; case EventType.MouseDrag: if (dragState == DragState.Base) { Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); InteractivePrimitivesMath.MousePositionOnPlane(ray, plane, ref baseEnd); } break; case EventType.MouseUp: case EventType.Ignore: { if (dragState == DragState.Base) { if (t.baseOnly) { t.sizing = false; t.OnFinishDragSizing(); return; } else { dragState = DragState.Height; } } else { if (dragState == DragState.Height) { // Complete ((InteractivePrimitive)t).sizing = false; ((InteractivePrimitive)t).OnFinishDragSizing(); return; } } } break; } switch (dragState) { case DragState.None: return; case DragState.Base: break; case DragState.Height: Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); Vector3 closestPointLine1, closestPointLine2; if (InteractivePrimitivesMath.ClosestPointsOnTwoLines(out closestPointLine1, out closestPointLine2, ray.GetPoint(0f), ray.direction, baseEnd, Vector3.up)) { height = Vector3.Distance(baseEnd, closestPointLine2); } break; } t.SetMeshDimensions(baseStart, baseEnd, height); }