// ================================================================================ Scene
        public override void OnSceneGui()
        {
            var settings = Settings;

            var rotation = Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : Curve.transform.rotation;

            if (Curve.PointsCount != 0 && settings.VRay)
            {
                painter = painter ?? new BGCurvePainterHandles(Editor.Math);
                painter.DrawCurve();
            }

            editorPoint.OnSceneGUIStart(settings);

            var frustum = GeometryUtility.CalculateFrustumPlanes(SceneView.currentDrawingSceneView.camera);

            Curve.ForEach((point, index, count) => editorPoint.OnSceneGUI(point, index, settings, rotation, frustum));

            //tangents
            if (settings.ShowCurve && settings.ShowTangents && Editor.Math.SectionsCount > 0 && Editor.Math.IsCalculated(BGCurveBaseMath.Field.Tangent))
            {
                BGEditorUtility.SwapHandlesColor(settings.TangentsColor, () =>
                {
                    var math          = Editor.Math;
                    var sectionsCount = math.SectionsCount;
                    var sections      = math.SectionInfos;

                    for (var i = 0; i < sectionsCount; i++)
                    {
                        var section = sections[i];
                        var points  = section.Points;
                        ShowTangent(points[0].Position, points[0].Tangent, settings.TangentsSize);
                        if (settings.TangentsPerSection > 1)
                        {
                            var sectionLength = section.Distance;
                            var part          = sectionLength / settings.TangentsPerSection;
                            for (var j = 1; j < settings.TangentsPerSection; j++)
                            {
                                var distanceWithinSection = part * j;
                                Vector3 position;
                                Vector3 tangent;
                                section.CalcByDistance(distanceWithinSection, out position, out tangent, true, true);
                                ShowTangent(position, tangent, settings.TangentsSize);
                            }
                        }
                    }
                });
            }


            editorSelection.Scene(rotation);

            var currentEvent = Event.current;

            overlay.Process(currentEvent);

            editorSelection.Process(currentEvent);
        }
        // ================================================================================ Scene
        public override void OnSceneGui(Plane[] frustum)
        {
            var settings = Settings;

            var curveRotation = GetRotation(Curve.transform);

            if (settings.VRay && settings.ShowCurve && Curve.PointsCount != 0)
            {
                painter = painter ?? new BGCurvePainterHandles(Editor.Math);
                painter.DrawCurve();
            }

            Curve.ForEach((point, index, count) => editorPoint.OnSceneGUI(point, index, settings, curveRotation, frustum));

            //tangents
            if (settings.ShowCurve && settings.ShowTangents && Editor.Math.SectionsCount > 0 && Editor.Math.IsCalculated(BGCurveBaseMath.Field.Tangent))
            {
                BGEditorUtility.SwapHandlesColor(settings.TangentsColor, () =>
                {
                    var math          = Editor.Math;
                    var sectionsCount = math.SectionsCount;
                    var sections      = math.SectionInfos;

                    for (var i = 0; i < sectionsCount; i++)
                    {
                        if (!settings.RestrictGizmozSettings.IsShowing(i))
                        {
                            continue;
                        }
                        var section = sections[i];
                        var points  = section.Points;
                        ShowTangent(points[0].Position, points[0].Tangent, settings.TangentsSize);
                        if (settings.TangentsPerSection > 1)
                        {
                            var sectionLength = section.Distance;
                            var part          = sectionLength / settings.TangentsPerSection;
                            for (var j = 1; j < settings.TangentsPerSection; j++)
                            {
                                var distanceWithinSection = part * j;
                                Vector3 position;
                                Vector3 tangent;
                                section.CalcByDistance(distanceWithinSection, out position, out tangent, true, true);
                                ShowTangent(position, tangent, settings.TangentsSize);
                            }
                        }
                    }
                });
            }


            editorSelection.Scene(curveRotation);

            overlay.Process(Event.current);

            CheckPointsTransforms();
        }
        private void Dispose()
        {
//            CurrentCurve = null;
            CurrentGizmoPainter = null;
            AllCurves = null;
            Undo.undoRedoPerformed -= InternalOnUndoRedo;

            if (Math != null) Math.Dispose();
            Math = null;
        }
Exemple #4
0
        private void Dispose()
        {
//            CurrentCurve = null;
            if (CurrentGizmoPainter != null && CurrentGizmoPainter.Math.Curve == Curve)
            {
                CurrentGizmoPainter = null;
            }
            AllCurves = null;
            Undo.undoRedoPerformed -= InternalOnUndoRedo;

            if (Math != null)
            {
                Math.Dispose();
            }
            Math = null;
        }
Exemple #5
0
        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;
        }