Exemple #1
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();
        }
Exemple #2
0
 public void OnDestroy()
 {
     if (transformMonitor != null)
     {
         transformMonitor.Release();
     }
     transformMonitor = null;
     pointReference   = null;
 }
        internal void OnInspectorGui(BGCurvePointI point, int index, BGCurveSettings settings)
        {
            var mode2D = point.Curve.Mode2D;


            //point transform
            if (point.Curve.PointsMode != BGCurve.PointsModeEnum.Inlined && point.PointTransform != null)
            {
                var referenceToPoint = BGCurveReferenceToPoint.GetReferenceToPoint(point);
                if (referenceToPoint == null)
                {
                    point.PointTransform.gameObject.AddComponent <BGCurveReferenceToPoint>().Point = point;
                }
            }

            BGEditorUtility.HorizontalBox(() =>
            {
                if (editorSelection != null)
                {
                    editorSelection.InspectorSelectionRect(point);
                }

                BGEditorUtility.VerticalBox(() =>
                {
                    BGEditorUtility.SwapLabelWidth(60, () =>
                    {
                        if (!settings.ShowPointPosition && !settings.ShowPointControlType)
                        {
                            BGEditorUtility.Horizontal(() =>
                            {
                                //nothing to show- only label
                                EditorGUILayout.LabelField("Point " + index);
                                PointButtons(point, index, settings);
                            });
                            BGEditorUtility.StartIndent(1);
                        }
                        else
                        {
                            //control type
                            if (settings.ShowPointControlType)
                            {
                                BGEditorUtility.Horizontal(() =>
                                {
                                    point.ControlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Point " + index, point.ControlType);
                                    PointButtons(point, index, settings);
                                });
                                BGEditorUtility.StartIndent(1);
                            }

                            //position
                            if (settings.ShowPointPosition)
                            {
                                if (!settings.ShowPointControlType)
                                {
                                    BGEditorUtility.Horizontal(() =>
                                    {
                                        PositionField("Point " + index, point, mode2D, index);
                                        PointButtons(point, index, settings);
                                    });
                                    BGEditorUtility.StartIndent(1);
                                }
                                else
                                {
                                    PositionField("Pos", point, mode2D, index);
                                }
                            }
                        }
                    });

                    // control positions
                    if (point.ControlType != BGCurvePoint.ControlTypeEnum.Absent && settings.ShowPointControlPositions)
                    {
                        // 1st
                        ControlField(point, mode2D, 1);

                        // 2nd
                        ControlField(point, mode2D, 2);
                    }

                    //transform
                    if (settings.ShowTransformField)
                    {
                        BGEditorUtility.ComponentField("Transform", point.PointTransform, transform =>
                        {
                            if (transform != null)
                            {
                                Undo.RecordObject(transform, "Object moved");

                                if (point.Curve.PointsMode != BGCurve.PointsModeEnum.Inlined)
                                {
                                    Undo.AddComponent <BGCurveReferenceToPoint>(transform.gameObject).Point = point;
                                }
                            }

                            if (point.PointTransform != null)
                            {
                                var referenceToPoint = BGCurveReferenceToPoint.GetReferenceToPoint(point);
                                if (referenceToPoint != null)
                                {
                                    Undo.DestroyObjectImmediate(referenceToPoint);
                                }
                            }

                            point.PointTransform = transform;
                        });
                    }


                    //fields
                    if (point.Curve.FieldsCount > 0)
                    {
                        ShowFields(point);
                    }

                    BGEditorUtility.EndIndent(1);
                });
            });
        }
Exemple #4
0
 public static void DrawGizmos(BGCurveReferenceToPoint point, GizmoType gizmoType)
 {
     BGCurveEditor.DrawGizmos(point.Point.Curve, gizmoType);
 }