protected override void InternalOnSceneGUI()
        {
            var objectRotate = (BGCcCursorObjectRotate)cc;

            var cursor = objectRotate.Cursor;

            if (cursor == null)
            {
                return;
            }

            var math = cursor.Math;

            if (math == null || !math.IsCalculated(BGCurveBaseMath.Field.Tangent))
            {
                return;
            }

            var position = cursor.CalculatePosition();
            var tangent  = cursor.CalculateTangent();

            if (Vector3.SqrMagnitude(tangent) > 0.0001)
            {
                var handleSize = BGEditorUtility.GetHandleSize(position, BGPrivateField.Get <float>(ObjectRotate, "handlesScale"));
                BGEditorUtility.SwapHandlesColor(BGPrivateField.Get <Color>(ObjectRotate, "handlesColor"), () => { Handles.ArrowCap(0, position, Quaternion.LookRotation(tangent), handleSize); });
            }
        }
 private static void ShowTangent(Vector3 position, Vector3 tangent, float size)
 {
     if (tangent.sqrMagnitude > 0.0001f)
     {
         Handles.ArrowCap(0, position, Quaternion.LookRotation(tangent), BGEditorUtility.GetHandleSize(position, size));
     }
 }
        protected static void PreviewControl(BGCurveSettings settings, Vector3 position, Vector3 controlWorld)
        {
            var size = BGEditorUtility.GetHandleSize(position, ScalePreviewPoint * .8f);

            Handles.SphereCap(0, controlWorld, Quaternion.identity, size);
            Handles.DrawLine(position, controlWorld);
        }
예제 #4
0
        private static void ShowTangent(Vector3 position, Vector3 tangent, float size)
        {
            if (tangent.sqrMagnitude > 0.0001f)
            {
#if UNITY_5_6_OR_NEWER
                Handles.ArrowHandleCap(0, position, Quaternion.LookRotation(tangent), BGEditorUtility.GetHandleSize(position, size), EventType.Repaint);
#else
                Handles.ArrowCap(0, position, Quaternion.LookRotation(tangent), BGEditorUtility.GetHandleSize(position, size));
#endif
            }
        }
        protected static void PreviewControl(BGCurveSettings settings, Vector3 position, Vector3 controlWorld)
        {
            var size = BGEditorUtility.GetHandleSize(position, ScalePreviewPoint * .8f);

#if UNITY_5_6_OR_NEWER
            Handles.SphereHandleCap(0, controlWorld, Quaternion.identity, size, EventType.Repaint);
#else
            Handles.SphereCap(0, controlWorld, Quaternion.identity, size);
#endif
            Handles.DrawLine(position, controlWorld);
        }
        protected override void InternalOnSceneGUI()
        {
            var curve = ObjectRotate.Curve;

            if (curve == null || curve.PointsCount == 0)
            {
                return;
            }

            BGCcCursor cursor;

            try
            {
                cursor = ObjectRotate.Cursor;
            }
            catch (MissingReferenceException)
            {
                return;
            }

            if (cursor == null)
            {
                return;
            }

            var math = cursor.Math;

            if (math == null || !math.IsCalculated(BGCurveBaseMath.Field.Tangent))
            {
                return;
            }

            var position = cursor.CalculatePosition();

            //by field
            var result = Quaternion.identity;

            if (!ObjectRotate.TryToCalculateRotation(ref result))
            {
                return;
            }

            var handleSize = BGEditorUtility.GetHandleSize(position, BGPrivateField.Get <float>(ObjectRotate, "handlesScale"));

            BGEditorUtility.SwapHandlesColor(BGPrivateField.Get <Color>(ObjectRotate, "handlesColor"), () =>
            {
#if UNITY_5_6_OR_NEWER
                Handles.ArrowHandleCap(0, position, result, handleSize, EventType.Repaint);
#else
                Handles.ArrowCap(0, position, result, handleSize);
#endif
            });
        }
예제 #7
0
        protected override void InternalOnSceneGUI()
        {
            var cursor = (BGCcCursor)cc;

            var position = cursor.CalculatePosition();

            var handleSize = BGEditorUtility.GetHandleSize(position, BGPrivateField.Get <float>(cursor, "handlesScale"));

            BGEditorUtility.SwapHandlesColor(BGPrivateField.Get <Color>(cursor, "handlesColor"), () =>
            {
                Handles.ArrowCap(0, position + Vector3.up * handleSize * 1.2f, Quaternion.LookRotation(Vector3.down), handleSize);
                Handles.SphereCap(0, position, Quaternion.LookRotation(Vector3.down), handleSize * .15f);
            });
        }
        // preview
        protected void Preview(Vector3 position, BGCurve curve, ref float toLast, ref float toFirst)
        {
            var settings = overlay.Editor.Settings;

            //show point
            BGEditorUtility.SwapHandlesColor(settings.SphereColor, () =>
            {
#if UNITY_5_6_OR_NEWER
                Handles.SphereHandleCap(0, position, Quaternion.identity, BGEditorUtility.GetHandleSize(position, ScalePreviewPoint), EventType.Repaint);
#else
                Handles.SphereCap(0, position, Quaternion.identity, BGEditorUtility.GetHandleSize(position, ScalePreviewPoint));
#endif
            });

            //create a point
            var newPoint = CreatePointForPreview(position, curve, out toLast, out toFirst, settings);

            //show controls
            if (newPoint.ControlType != BGCurvePoint.ControlTypeEnum.Absent)
            {
                PreviewControls(settings, position, newPoint.ControlFirstWorld, newPoint.ControlSecondWorld);
            }

            if (curve.PointsCount == 0)
            {
                return;
            }

            if (VisualizingSections)
            {
                BGEditorUtility.SwapHandlesColor(BGCurveSettingsForEditor.I.Get <Color32>(BGCurveSettingsForEditor.ColorForNewSectionPreviewKey), () =>
                {
                    // last To new
                    DrawSection(curve[curve.PointsCount - 1], newPoint, settings.Sections);

                    AdditionalPreview(newPoint);

                    // new To zero
                    if (curve.Closed)
                    {
                        DrawSection(newPoint, curve[0], settings.Sections);
                    }
                });
            }
        }
예제 #9
0
        internal Vector3 Handle(int number, BGCurveSettings.HandlesTypeEnum type, Vector3 position, Quaternion rotation, BGCurveSettings.SettingsForHandles handlesSettings)
        {
            switch (type)
            {
            case BGCurveSettings.HandlesTypeEnum.FreeMove:
                position = Handles.FreeMoveHandle(position, rotation, BGEditorUtility.GetHandleSize(position, .2f), Vector3.zero, Handles.CircleCap);
                break;

            case BGCurveSettings.HandlesTypeEnum.Standard:
                position = Handles.PositionHandle(position, rotation);
                break;

            case BGCurveSettings.HandlesTypeEnum.Configurable:
                position = BGEditorUtility.ControlHandleCustom(number, position, rotation, handlesSettings);
                break;
            }
            return(position);
        }
예제 #10
0
        protected override void InternalOnSceneGUI()
        {
            var mathCc = Math;

            if (mathCc == null || mathCc.Math == null || mathCc.Math.SectionsCount == 0)
            {
                return;
            }

            if (mathCc.Curve.ForceChangedEventMode != BGCurve.ForceChangedEventModeEnum.Off)
            {
                mathCc.Recalculate();
            }

            var math = mathCc.Math;

            var sphereScale = BGPrivateField.Get <float>(mathCc, "spheresScale");

            BGEditorUtility.SwapHandlesColor(BGPrivateField.Get <Color>(mathCc, "spheresColor"), () =>
            {
                var count = BGPrivateField.Get <int>(mathCc, "spheresCount");

                for (var i = 0; i < math.SectionsCount; i++)
                {
                    var section = math[i];
                    var points  = section.Points;
                    for (var j = 0; j < points.Count; j++)
                    {
                        var pos = points[j].Position;
#if UNITY_5_6_OR_NEWER
                        Handles.SphereHandleCap(0, pos, Quaternion.identity, sphereScale * BGEditorUtility.GetHandleSize(pos, .07f), EventType.Repaint);
#else
                        Handles.SphereCap(0, pos, Quaternion.identity, sphereScale * BGEditorUtility.GetHandleSize(pos, .07f));
#endif
                        if (count-- <= 0)
                        {
                            return;
                        }
                    }
                }
            });
        }
예제 #11
0
        // OnSceneGui
        public void Scene(Quaternion rotation)
        {
            if (lastCurveCount != curve.PointsCount)
            {
                lastCurveCount = curve.PointsCount;
                OnUndoRedo();
            }

            if (!HasSelected())
            {
                return;
            }

            BGEditorUtility.Assign(ref settings, () => BGPrivateField.GetSettings(curve));

            //group operation for selected points
            var text    = "     Selected [" + points.Count + "]";
            var average = GetAveragePosition();

            Handles.Label(average + BGEditorUtility.GetHandleSize(average) * Vector3.up * .25f, text, new GUIStyle("Label")
            {
                normal = new GUIStyleState {
                    textColor = settings.LabelColorSelected
                }
            });

            var newAverage = BGEditorUtility.Handle(-10, settings.HandlesType, average, rotation, settings.HandlesSettings);

            if (BGEditorUtility.AnyChange(average, newAverage))
            {
                curve.Transaction(() =>
                {
                    var delta = newAverage - average;
                    foreach (var selectedPoint in points)
                    {
                        selectedPoint.PositionWorld += delta;
                    }
                });
            }
        }
예제 #12
0
        protected override void InternalOnSceneGUI()
        {
            var cursor = Cursor;

            if (cursor == null)
            {
                return;
            }

            var position = cursor.CalculatePosition();

            var handleSize = BGEditorUtility.GetHandleSize(position, BGPrivateField.Get <float>(cursor, "handlesScale"));

            BGEditorUtility.SwapHandlesColor(BGPrivateField.Get <Color>(cursor, "handlesColor"), () =>
            {
#if UNITY_5_6_OR_NEWER
                Handles.ArrowHandleCap(0, position + Vector3.up * handleSize * 1.2f, Quaternion.LookRotation(Vector3.down), handleSize, EventType.Repaint);
                Handles.SphereHandleCap(0, position, Quaternion.LookRotation(Vector3.down), handleSize * .15f, EventType.Repaint);
#else
                Handles.ArrowCap(0, position + Vector3.up * handleSize * 1.2f, Quaternion.LookRotation(Vector3.down), handleSize);
                Handles.SphereCap(0, position, Quaternion.LookRotation(Vector3.down), handleSize * .15f);
#endif
            });
        }
예제 #13
0
            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);
                });
            }
        protected override void InternalOnSceneGUI()
        {
            var splitter = Splitter;

            if (splitter == null)
            {
                return;
            }

            var positions = splitter.Positions;

            if (positions == null || positions.Count == 0)
            {
                return;
            }

            var sphereScale = BGPrivateField.Get <float>(splitter, "spheresScale");

            BGEditorUtility.SwapHandlesColor(BGPrivateField.Get <Color>(splitter, "spheresColor"), () =>
            {
                var count = Mathf.Min(positions.Count, BGPrivateField.Get <int>(splitter, "spheresCount"));

                var localToWorldMatrix = splitter.transform.localToWorldMatrix;
                for (var i = 0; i < count; i++)
                {
                    var position = positions[i];
                    if (splitter.UseLocal)
                    {
                        position = localToWorldMatrix.MultiplyPoint(position);
                    }

                    Handles.SphereCap(0, position, Quaternion.identity, sphereScale * BGEditorUtility.GetHandleSize(position, .07f));
                }
            });
        }
        // preview
        protected void Preview(Vector3 position, BGCurve curve, ref float toLast, ref float toFirst)
        {
            var settings = overlay.Editor.Settings;

            //show point
            BGEditorUtility.SwapHandlesColor(settings.SphereColor, () => Handles.SphereCap(0, position, Quaternion.identity, BGEditorUtility.GetHandleSize(position, ScalePreviewPoint)));

            //create a point
            var newPoint = BGNewPointPositionManager.CreatePoint(position, curve, settings.ControlType, settings.Sections, out toLast, out toFirst, false);

            //show controls
            if (newPoint.ControlType != BGCurvePoint.ControlTypeEnum.Absent)
            {
                PreviewControls(settings, position, newPoint.ControlFirstWorld, newPoint.ControlSecondWorld);
            }

            if (curve.PointsCount == 0)
            {
                return;
            }

            BGEditorUtility.SwapHandlesColor(BGCurveSettingsForEditor.ColorForNewSectionPreview, () =>
            {
                // last To new
                DrawSection(curve[curve.PointsCount - 1], newPoint, settings.Sections);

                AdditionalPreview(newPoint);

                // new To zero
                if (curve.Closed)
                {
                    DrawSection(newPoint, curve[0], settings.Sections);
                }
            });
        }