public PointsContainer(BGCurveEditorPointsSelection selection) { this.selection = selection; Curve = selection.curve; // var animationCurve = new AnimationCurve(); }
protected AbstractMenu(BGSceneViewOverlay overlay, BGCurveEditorPointsSelection editorSelection, string title) : base(title) { EditorSelection = editorSelection; Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGControlAbsent123), "Convert point control to Absent", () => { SetControl(BGCurvePoint.ControlTypeEnum.Absent); })); Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGControlBezierSymmetrical123), "Convert point control to Bezier Symmetrical", () => { SetControl(BGCurvePoint.ControlTypeEnum.BezierSymmetrical); })); Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGControlBezierIndependent123), "Convert point control to Bezier Independent", () => { SetControl(BGCurvePoint.ControlTypeEnum.BezierIndependant); })); AdditionalMenuItems(); Add(new LockMenuItem(() => { BGCurveSettingsForEditor.LockView = !BGCurveSettingsForEditor.LockView; EditorUtility.SetDirty(overlay.Editor.Curve); })); Add(new MenuSeparator()); Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointDelete123), "Delete a point", Delete)); }
public BGCurveEditorFields(BGCurveEditor editor, SerializedObject curveObject, BGCurveEditorPointsSelection editorSelection) : base(editor, curveObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGFields123)) { this.editorSelection = editorSelection; addIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123); deleteIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123); }
public BGRectangularSelection(BGCurveEditor editor, BGCurveEditorPointsSelection selection) { this.editor = editor; this.selection = selection; curve = editor.Curve; borderHorizontal = CreateBorder(false); borderVertical = CreateBorder(true); }
public BGCurveEditorPoint(BGCurveEditorPoints editor, BGCurveEditorPointsSelection editorSelection) { this.editor = editor; this.editorSelection = editorSelection; //textures deleteTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123); addBeforeTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123); moveUpTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMoveUp123); moveDownTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMoveDown123); maskTexture = BGEditorUtility.Texture1X1(new Color(1, 0, 0, .15f)); }
public BGCurveEditorPoint(Func <BGCurveBaseMath> mathProvider, BGCurveEditorPointsSelection editorSelection) { this.mathProvider = mathProvider; this.editorSelection = editorSelection; //textures deleteTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123); addBeforeTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123); moveUpTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMoveUp123); moveDownTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMoveDown123); copyTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCopy123); pasteTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPaste123); }
public BGSceneViewOverlay(BGCurveEditorPoints editor, BGCurveEditorPointsSelection editorSelection) { Editor = editor; actions = new SceneAction[] { new BGSceneViewOverlayMenuSelection(this, editorSelection), new BGSceneViewOverlayMenuPoint(this, editorSelection), new BGSceneViewOverlayPointAddAtDistance(this), new BGSceneViewOverlayPointAddSnap3D(this), new BGSceneViewOverlayPointAddSnap2D(this) }; }
public BGCurveEditorPoints(BGCurveEditor editor, SerializedObject serializedObject, BGCurveEditorPointsSelection editorSelection) : base(editor, serializedObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPoints123)) { this.serializedObject = serializedObject; this.editorSelection = editorSelection; //textures convertAll2D = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGConvertAll123); addPointIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123); //point editorPoint = new BGCurveEditorPoint(() => Editor.Math, editorSelection); //closed or not closedProperty = serializedObject.FindProperty("closed"); //how points are stored pointsModeProperty = serializedObject.FindProperty("pointsMode"); //2d mode mode2DProperty = serializedObject.FindProperty("mode2D"); //snapping snapTypeProperty = serializedObject.FindProperty("snapType"); snapAxisProperty = serializedObject.FindProperty("snapAxis"); snapDistanceProperty = serializedObject.FindProperty("snapDistance"); snapTriggerInteractionProperty = serializedObject.FindProperty("snapTriggerInteraction"); snapToBackFacesProperty = serializedObject.FindProperty("snapToBackFaces"); snapMonitoringProperty = serializedObject.FindProperty("snapMonitoring"); //force update forceChangedEventModeProperty = serializedObject.FindProperty("forceChangedEventMode"); //event type eventModeProperty = serializedObject.FindProperty("eventMode"); //settings controlTypeProperty = serializedObject.FindProperty("settings").FindPropertyRelative("controlType"); //Context menu overlay = new BGSceneViewOverlay(this, editorSelection); //for GameObjects points which use transforms UpdatePointsTrackers(); }
public BGCurveEditorPoints(BGCurveEditor editor, SerializedObject curveObject) : base(editor, curveObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPoints123)) { //textures convertAll2D = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGConvertAll123); addPointIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123); //selection editorSelection = new BGCurveEditorPointsSelection(Curve, this); //point editorPoint = new BGCurveEditorPoint(this, editorSelection); //closed or not closedProperty = curveObject.FindProperty("closed"); //2d mode mode2DProperty = curveObject.FindProperty("mode2D"); //settings controlTypeProperty = curveObject.FindProperty("settings").FindPropertyRelative("controlType"); //Context menu overlay = new BGSceneViewOverlay(this, editorSelection); }
protected BGSceneViewOverlayMenu(BGSceneViewOverlay overlay, BGCurveEditorPointsSelection editorSelection) : base(overlay) { this.editorSelection = editorSelection; pointSelectedTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointSelected123); }
public PointMenu(BGSceneViewOverlay overlay, BGCurveEditorPointsSelection editorSelection) : base(overlay, editorSelection, "Point menu") { }
public BGSceneViewOverlayMenuPoint(BGSceneViewOverlay overlay, BGCurveEditorPointsSelection editorSelection) : base(overlay, editorSelection) { menu = new PointMenu(overlay, editorSelection); }
public static void OnSceneGui(Plane[] frustum, BGCurve curve, BGCurveSettings settings, BGCurveEditorPointsSelection editorSelection) { Array.Resize(ref visiblePoints, curve.PointsCount); curve.ForEach((point, i, count) => visiblePoints[i] = GeometryUtility.TestPlanesAABB(frustum, new Bounds(point.PositionWorld, Vector3.one))); var fieldsCount = curve.FieldsCount; var fields = curve.Fields; var showPointsNumbers = settings.ShowLabels; var fieldsWithHandlesCount = 0; var fieldsWithLabelCount = 0; if (fieldsCount > 0) { fieldsWithHandlesCount = fields.Count(FieldWithHandlesPredicate); if (fieldsWithHandlesCount > 0) { Array.Resize(ref handlesColor, fieldsWithHandlesCount); var cursor = 0; for (var i = 0; i < fieldsCount; i++) { var f = fields[i]; if (!FieldWithHandlesPredicate(f)) { continue; } if (FieldWithLabelPredicate(f)) { fieldsWithLabelCount++; } handlesColor[cursor++] = BGPrivateField.GetHandlesColor(f); } } } // nothing to show if (!showPointsNumbers && fieldsWithHandlesCount == 0) { return; } if (fieldsWithHandlesCount > 0) { //not a label curve.ForEach((point, i, length) => { if (!visiblePoints[i] || !settings.RestrictGizmozSettings.IsShowing(i)) { return; } var pos = point.PositionWorld; var quanterionShown = false; var fieldCursor = 0; for (var j = 0; j < fields.Length; j++) { var field = fields[j]; var handlesType = (HandlesType)BGPrivateField.GetHandlesType(field); if (handlesType == 0) { continue; } if (handlesType == HandlesType.Label) { fieldCursor++; continue; } var color = handlesColor[fieldCursor++]; switch (handlesType) { case HandlesType.DistanceFromPoint: BGEditorUtility.SwapHandlesColor(color, () => { #if UNITY_5_6_OR_NEWER Handles.CircleHandleCap(0, pos, Quaternion.LookRotation(SceneView.currentDrawingSceneView.camera.transform.position - pos), point.GetField <float>(field.FieldName), EventType.Repaint); #else Handles.CircleCap(0, pos, Quaternion.LookRotation(SceneView.currentDrawingSceneView.camera.transform.position - pos), point.GetField <float>(field.FieldName)); #endif } ); break; case HandlesType.BoundsAroundPoint: Bounds bounds; switch (field.Type) { case BGCurvePointField.TypeEnum.Bounds: bounds = point.GetField <Bounds>(field.FieldName); bounds.center = pos; break; default: //vector3 var vector3 = point.GetField <Vector3>(field.FieldName); bounds = new Bounds(pos, vector3); break; } BGEditorUtility.DrawBound(bounds, new Color(color.r, color.g, color.b, 0.05f), color); break; case HandlesType.Bounds: var boundsValue = point.GetField <Bounds>(field.FieldName); if (boundsValue.extents != Vector3.zero) { BGEditorUtility.DrawBound(boundsValue, new Color(color.r, color.g, color.b, 0.05f), color); BGEditorUtility.SwapHandlesColor(color, () => Handles.DrawDottedLine(boundsValue.center, pos, 4)); } break; case HandlesType.Direction: var vector3Value = point.GetField <Vector3>(field.FieldName); if (vector3Value != Vector3.zero) { BGEditorUtility.SwapHandlesColor(color, () => { #if UNITY_5_6_OR_NEWER Handles.ArrowHandleCap(0, pos, Quaternion.LookRotation(vector3Value), vector3Value.magnitude, EventType.Repaint); #else Handles.ArrowCap(0, pos, Quaternion.LookRotation(vector3Value), vector3Value.magnitude); #endif }); } break; case HandlesType.Rotation: if (quanterionShown) { break; } quanterionShown = true; var quaternionValue = point.GetField <Quaternion>(field.FieldName); if (quaternionValue.x < BGCurve.Epsilon && quaternionValue.y < BGCurve.Epsilon && quaternionValue.z < BGCurve.Epsilon && quaternionValue.w < BGCurve.Epsilon) { quaternionValue = Quaternion.identity; } var newValue = Handles.RotationHandle(quaternionValue, pos); point.SetField(field.FieldName, newValue); BGEditorUtility.SwapHandlesColor(color, () => { var rotated = newValue * Vector3.forward * BGEditorUtility.GetHandleSize(pos, 2); var toPos = pos + rotated; #if UNITY_5_6_OR_NEWER Handles.ArrowHandleCap(0, toPos, newValue, 1, EventType.Repaint); #else Handles.ArrowCap(0, toPos, newValue, 1); #endif Handles.DrawDottedLine(pos, toPos, 10); }); break; case HandlesType.Link: switch (field.Type) { case BGCurvePointField.TypeEnum.GameObject: var go = point.GetField <GameObject>(field.FieldName); if (go != null) { BGEditorUtility.SwapHandlesColor(color, () => Handles.DrawDottedLine(go.transform.position, pos, 4)); } break; case BGCurvePointField.TypeEnum.BGCurve: var bgCurve = point.GetField <BGCurve>(field.FieldName); if (bgCurve != null) { BGEditorUtility.SwapHandlesColor(color, () => Handles.DrawDottedLine(bgCurve.transform.position, pos, 4)); } break; case BGCurvePointField.TypeEnum.BGCurvePointComponent: var pointComponent = point.GetField <BGCurvePointComponent>(field.FieldName); if (pointComponent != null) { BGEditorUtility.SwapHandlesColor(color, () => Handles.DrawDottedLine(pointComponent.PositionWorld, pos, 4)); } break; case BGCurvePointField.TypeEnum.BGCurvePointGO: var pointGO = point.GetField <BGCurvePointGO>(field.FieldName); if (pointGO != null) { BGEditorUtility.SwapHandlesColor(color, () => Handles.DrawDottedLine(pointGO.PositionWorld, pos, 4)); } break; } break; } } }); } // nothing more to show if (!showPointsNumbers && fieldsWithLabelCount == 0) { return; } //=============================== Labels //styles var labelColor = settings.LabelColor; var selectedColor = settings.LabelColorSelected; var backColor = BGCurveSettingsForEditor.I.Get <Color32>(BGCurveSettingsForEditor.ColorForLabelBackgroundKey); if (labelStyle == null || labelStyle.normal.textColor != labelColor || labelStyle.normal.background == null || latestLabelBackColor.r != backColor.r || latestLabelBackColor.g != backColor.g || latestLabelBackColor.b != backColor.b || latestLabelBackColor.a != backColor.a) { latestLabelBackColor = backColor; labelStyle = new GUIStyle("Label") { richText = true, border = new RectOffset(2, 2, 2, 2), clipping = TextClipping.Overflow, wordWrap = false, normal = { background = BGEditorUtility.TextureWithBorder(8, 1, backColor, new Color32(backColor.r, backColor.g, backColor.b, 255)), textColor = labelColor } }; selectedlabelStyle = new GUIStyle(labelStyle) { normal = { background = BGEditorUtility.TextureWithBorder(8, 1, new Color(selectedColor.r, selectedColor.g, selectedColor.b, .1f), selectedColor), textColor = selectedColor } }; } curve.ForEach((point, i, length) => { if (!visiblePoints[i]) { return; } var pos = point.PositionWorld; var style = !editorSelection.Contains(point) ? labelStyle : selectedlabelStyle; var text = ""; //point numbers and pos if (showPointsNumbers) { text += "# : " + i + "\r\n"; if (settings.ShowPositions) { text += "P : " + pos + "\r\n"; } } //fields if (fieldsWithLabelCount > 0) { for (var j = 0; j < fieldsCount; j++) { var field = fields[j]; if (!FieldWithHandlesPredicate(field) || !FieldWithLabelPredicate(field)) { continue; } text += BGEditorUtility.ColorIt(field.FieldName + " : " + point.GetField(field.FieldName, BGCurvePoint.FieldTypes.GetType(field.Type)), BGEditorUtility.ToHex(BGPrivateField.GetHandlesColor(field))) + "\r\n"; } } var normalized = (SceneView.currentDrawingSceneView.camera.transform.position - pos).normalized; var handleSize = BGEditorUtility.GetHandleSize(pos, .25f); var shiftLeft = -Vector3.Cross(normalized, Vector3.up); var shiftBottom = Vector3.Cross(normalized, Vector3.right) * .3f; Handles.Label(pos + handleSize * shiftLeft + handleSize * shiftBottom, text.Substring(0, text.Length - 2), style); }); }
public BGCurveEditorFields(BGCurveEditor editor, SerializedObject curveObject, BGCurveEditorPointsSelection editorSelection) : base(editor, curveObject) { this.editorSelection = editorSelection; }
protected BGSceneViewOverlayMenu(BGSceneViewOverlay overlay, BGCurveEditorPointsSelection editorSelection) : base(overlay) { this.editorSelection = editorSelection; }
public BGCurveEditorPoint(Func <BGCurveBaseMath> mathProvider, BGCurveEditorPointsSelection editorSelection) { this.mathProvider = mathProvider; this.editorSelection = editorSelection; }
protected void OnEnable() { Curve = (BGCurve)target; //wth if (Curve == null) { return; } CurrentCurve = Curve; transformMonitor = BGTransformMonitor.GetMonitor(Curve); var settings = BGPrivateField.GetSettings(Curve); //painter and math if (curve2Painter.ContainsKey(Curve)) { curve2Painter[Curve].Dispose(); curve2Painter.Remove(Curve); } Math = NewMath(Curve, settings); CurrentGizmoPainter = new BGCurvePainterGizmo(Math); AllCurves = FindObjectsOfType <BGCurve>(); //overlay BGEditorUtility.Assign(ref OverlayMessage, () => new BGOverlayMessage()); //probably we do not need it for play mode.. probably if (!Application.isPlaying) { //they are not persistent Curve.ImmediateChangeEvents = true; Curve.BeforeChange += BeforeCurveChange; Curve.Changed += CurveChanged; } if (!settings.Existing) { //newly created settings.Existing = true; var defaultSettings = BGCurveSettingsOperations.LoadDefault(); if (defaultSettings != null) { BGPrivateField.SetSettings(Curve, defaultSettings); } } //load textures BGEditorUtility.Assign(ref headerTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCurveLogo123)); stickerTextureOk = BGEditorUtility.Texture1X1(new Color32(46, 143, 168, 255)); stickerTextureError = BGEditorUtility.Texture1X1(new Color32(255, 0, 0, 255)); stickerTextureWarning = BGEditorUtility.Texture1X1(new Color32(255, 206, 92, 255)); stickerTextureActive = BGEditorUtility.Texture1X1(new Color32(44, 160, 90, 255)); //selection editorSelection = new BGCurveEditorPointsSelection(Curve, this); // editors editors = new BGCurveEditorTab[] { new BGCurveEditorPoints(this, serializedObject, editorSelection), new BGCurveEditorComponents(this, serializedObject), new BGCurveEditorFields(this, serializedObject, editorSelection), new BGCurveEditorSettings(this, serializedObject) }; headers = editors.Select(editor => editor.Header2D).ToArray(); foreach (var editor in editors) { editor.OnEnable(); } //do it every frame EditorApplication.update -= OverlayMessage.Check; EditorApplication.update += OverlayMessage.Check; Undo.undoRedoPerformed -= InternalOnUndoRedo; Undo.undoRedoPerformed += InternalOnUndoRedo; }