Exemplo n.º 1
0
        private void UpdatePointsTrackers()
        {
            if (pointTransformTrackers.Count > 0)
            {
                foreach (var tracker in pointTransformTrackers)
                {
                    tracker.Release();
                }
            }

            pointTransformTrackers.Clear();

            //for GameObjectsTransform mode
            if (Curve.PointsMode == BGCurve.PointsModeEnum.GameObjectsTransform)
            {
                Curve.ForEach((point, index, count) => pointTransformTrackers.Add(BGTransformMonitor.GetMonitor(((BGCurvePointGO)point).transform, transform => Curve.FireChange(null))));
            }

            //for points transforms
            Curve.ForEach((point, index, count) =>
            {
                if (point.PointTransform != null)
                {
                    pointTransformTrackers.Add(BGTransformMonitor.GetMonitor(point.PointTransform, transform => Curve.FireChange(null)));
                }
            });
        }
Exemplo n.º 2
0
        protected override void OnEnable()
        {
            pointReference = (BGCurveReferenceToPoint)target;

            var point = pointReference.Point;

            if (!IsValid(point))
            {
                //no need for it anymore
                DestroyImmediate(pointReference);
                return;
            }

            var allComponents = pointReference.GetComponents <BGCurveReferenceToPoint>();

            if (allComponents.Any(component => component != pointReference && component.Point == pointReference.Point))
            {
                DestroyImmediate(pointReference);
                return;
            }

            transformMonitor = BGTransformMonitor.GetMonitor(pointReference.transform, transform => point.Curve.FireChange(null));

            base.OnEnable();
        }
Exemplo n.º 3
0
 public BGCurvePainterGizmo(BGCurveBaseMath math, bool monitorTransform = false)
 {
     Math = math;
     if (monitorTransform)
     {
         transformMonitor = new BGTransformMonitor(math.Curve);
     }
 }
Exemplo n.º 4
0
 public void OnDestroy()
 {
     if (transformMonitor != null)
     {
         transformMonitor.Release();
     }
     transformMonitor = null;
     pointReference   = null;
 }
Exemplo n.º 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;
        }