Exemplo n.º 1
0
        public void OnSceneGUI()
        {
            var settings = BGPrivateField.GetSettings(Curve);

            AdjustMath(settings, Math);

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


            if (settings.HandlesSettings != null && settings.HandlesType == BGCurveSettings.HandlesTypeEnum.Configurable ||
                settings.ControlHandlesSettings != null && settings.ControlHandlesType == BGCurveSettings.HandlesTypeEnum.Configurable)
            {
                BGEditorUtility.ReloadSnapSettings();
            }


            OverlayMessage.OnSceneGui();

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

            // process all editors
            foreach (var editor in editors)
            {
                editor.OnSceneGui(frustum);
            }

            editorSelection.Process(Event.current);


            transformMonitor.CheckForChange();
        }
        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));
                }
            });
        }
Exemplo n.º 3
0
        public virtual void DrawCurve()
        {
            if (transformMonitor != null)
            {
                transformMonitor.Check();
            }

            var settings = BGPrivateField.GetSettings(Math.Curve);

            BGEditorUtility.SwapGizmosColor(settings.LineColor, () =>
            {
                //========================================  Draw section
                for (var i = 0; i < Math.SectionsCount; i++)
                {
                    DrawSection(Math[i]);
                }
            });


            //========================================  Draw spheres
            if (settings.ShowSpheres)
            {
                BGEditorUtility.SwapGizmosColor(settings.SphereColor, () =>
                {
                    BeforeDrawingSpheres(settings);
                    for (var i = 0; i < Math.Curve.PointsCount; i++)
                    {
                        DrawSphere(settings, Math.GetPosition(i), settings.SphereRadius);
                    }
                    AfterDrawingSpheres();
                });
            }
        }
Exemplo n.º 4
0
            protected override void AdditionalMenuItems()
            {
                Add(new MenuSeparator());

                //add before
                Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointInsertBefore123), "Insert a point before this point",
                                       () =>
                {
                    var curve    = point.Curve;
                    var settings = BGPrivateField.GetSettings(curve);
                    var index    = curve.IndexOf(point);
                    curve.AddPoint(BGNewPointPositionManager.InsertBefore(curve, index, settings.ControlType, settings.Sections), index);
                }));

                //add after
                Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointInsertAfter123), "Insert a point after this point",
                                       () =>
                {
                    var curve    = point.Curve;
                    var settings = BGPrivateField.GetSettings(curve);
                    var index    = curve.IndexOf(point);
                    curve.AddPoint(BGNewPointPositionManager.InsertAfter(curve, index, settings.ControlType, settings.Sections), index + 1);
                }));


                //add remove to selection
                addToSelectionItem = new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionAdd123), "Add this point to selection",
                                                        () => EditorSelection.Add(point));

                removeFromSelectionItem = new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionRemove123), "Remove this point from selection",
                                                             () => EditorSelection.Remove(point));

                Add(addToSelectionItem);
                Add(removeFromSelectionItem);
            }
        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); });
            }
        }
Exemplo n.º 6
0
 public virtual void OnSceneGUI()
 {
     if (!cc.SupportHandles || !BGPrivateField.GetShowHandles(cc))
     {
         return;
     }
     InternalOnSceneGUI();
 }
        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
            });
        }
Exemplo n.º 8
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);
            });
        }
Exemplo n.º 9
0
        private void InternalOnUndoRedo()
        {
            transformMonitor.CheckForChange();

            Curve.PrivateUpdateFieldsValuesIndexes();

            if (BGCurve.IsGoMode(Curve.PointsMode)) BGPrivateField.Invoke(Curve, BGCurve.MethodSetPointsNames);

            foreach (var editor in editors) editor.OnUndoRedo();

            if (Math != null) Math.Recalculate();

            Repaint();
            SceneView.RepaintAll();
        }
Exemplo n.º 10
0
 public CcData(Type type, bool single, BGCc.CcDescriptor ccDescriptor)
     : this(type, single, ccDescriptor.Name)
 {
     Description = ccDescriptor.Description;
     if (!string.IsNullOrEmpty(ccDescriptor.Icon))
     {
         var texture = BGPrivateField.Get <BGEditorIcon>(typeof(BGBinaryResources), ccDescriptor.Icon);
         if (texture != null)
         {
             Icon = texture;
         }
     }
     else if (!string.IsNullOrEmpty(ccDescriptor.Image))
     {
         Icon = BGEditorUtility.LoadCcTexture2D(ccDescriptor.Image);
     }
 }
Exemplo n.º 11
0
        public override void OnInspectorGUI()
        {
            //adjust math if needed
            AdjustMath(BGPrivateField.GetSettings(Curve), Math);

            //styles
            BGEditorUtility.Assign(ref stickerStyle, () => new GUIStyle("Label") {fontSize = 18, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState {textColor = Color.white}});

            serializedObject.Update();

            // =========== Header
            DrawLogo();

            // =========== lock view
            BGEditorUtility.Horizontal(() =>
            {
                var temp = BGCurveSettingsForEditor.LockView;
                BGCurveSettingsForEditor.LockView = BGEditorUtility.ButtonOnOff(ref temp, "Lock view", "Disable selection of any object in the scene, except points", LockViewActiveColor,
                    new GUIContent("Turn Off", "Click to turn this mode off"),
                    new GUIContent("Turn On", "Click to turn this mode on"));

                if (GUILayout.Button(BGBinaryResources.BGSettingsIcon123, GUILayout.MaxWidth(24), GUILayout.MaxHeight(24))) BGCurveSettingsForEditorWindow.Open(BGCurveSettingsForEditor.I);
            });

            //warning
            BGEditorUtility.HelpBox("You can not chose another objects in the scene, except points.", MessageType.Warning, BGCurveSettingsForEditor.LockView, () => GUILayout.Space(8));

            // =========== Tabs
            var currentTab = BGCurveSettingsForEditor.CurrentTab;
            if (currentTab < 0 || currentTab > headers.Length - 1) currentTab = 0;
            var newTab = GUILayout.Toolbar(currentTab, headers, GUILayout.Height(ToolBarHeight));
            //do not move this method(GUILayoutUtility.GetLastRect() is used) 
            ShowStickers();
            if (currentTab != newTab) GUI.FocusControl("");
            BGCurveSettingsForEditor.CurrentTab = newTab;
            editors[newTab].OnInspectorGui();

            if (!GUI.changed) return; // if no change- return

            foreach (var editor in editors) editor.OnApply();

            transformMonitor.CheckForChange();
        }
Exemplo n.º 12
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;
                        }
                    }
                }
            });
        }
Exemplo n.º 13
0
        public static void DrawGizmos(BGCurve curve, GizmoType gizmoType)
        {
            var playMode = EditorApplication.isPlaying;

            if (lastPlayMode != playMode)
            {
                lastPlayMode = playMode;

                foreach (var painterGizmo in curve2Painter)
                {
                    painterGizmo.Value.Dispose();
                }
                curve2Painter.Clear();
            }

            var settings = BGPrivateField.GetSettings(curve);

            if (!ComplyForDrawGizmos(curve, gizmoType, settings))
            {
                return;
            }

            if (CurrentCurve != null && curve.GetInstanceID() == CurrentCurve.GetInstanceID())
            {
                if (CurrentGizmoPainter != null)
                {
                    CurrentGizmoPainter.DrawCurve();
                }
            }
            else
            {
                //curve is not selected in hierarchy
                var painter = BGEditorUtility.Ensure(curve2Painter, curve, () => new BGCurvePainterGizmo(NewMath(curve, settings), true));
                AdjustMath(settings, painter.Math);
                if (curve.ForceChangedEventMode != BGCurve.ForceChangedEventModeEnum.Off && !Application.isPlaying)
                {
                    painter.Math.Recalculate();
                }
                painter.DrawCurve();
            }
        }
Exemplo n.º 14
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;
                    }
                });
            }
        }
Exemplo n.º 15
0
        public void OnSceneGUI()
        {
            var settings = BGPrivateField.GetSettings(Curve);

            AdjustMath(settings, Math);

            if (settings.HandlesSettings != null && settings.HandlesType == BGCurveSettings.HandlesTypeEnum.Configurable ||
                settings.ControlHandlesSettings != null && settings.ControlHandlesType == BGCurveSettings.HandlesTypeEnum.Configurable)
            {
                BGEditorUtility.ReloadSnapSettings();
            }

            OverlayMessage.OnSceneGui();

            // process all editors
            foreach (var editor in editors)
            {
                editor.OnSceneGui();
            }

            transformMonitor.Check();
        }
Exemplo n.º 16
0
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            var settings = BGPrivateField.GetSettings(Curve);

            BGEditorUtility.HelpBox("Curve UI is disabled in settings. All handles are disabled too.", MessageType.Warning, !settings.ShowCurve);

            BGEditorUtility.Assign(ref systemUi, () => new TableUi("System fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }));
            BGEditorUtility.Assign(ref customUi, () => new TableUi("Custom fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }));

            BGEditorUtility.Assign(ref systemFields, () => new[]
            {
                (SystemField) new SystemFieldPosition(settings),
                new SystemFieldControls(settings),
                new SystemFieldControlsType(settings),
            });

            //warnings
            BGEditorUtility.HelpBox("All handles for positions are disabled.", MessageType.Warning, settings.HandlesSettings.Disabled);
            BGEditorUtility.HelpBox("All handles for controls are disabled.", MessageType.Warning, settings.ControlHandlesSettings.Disabled);

            systemUi.Init();

            foreach (var field in systemFields)
            {
                field.Ui(systemUi);
            }

            //inform layout manager
            GUILayoutUtility.GetRect(systemUi.Width, systemUi.Height);

            customUi.Init();
            customUi.NextRow("Custom fields are not supported in this version.");

            GUILayoutUtility.GetRect(customUi.Width, customUi.Height);

            GUILayout.Space(4);
        }
Exemplo n.º 17
0
        public static void SwapVector2Labels(BGCurve.Mode2DEnum mode2D, Action action)
        {
            var needToSwap = mode2D != BGCurve.Mode2DEnum.Off && mode2D != BGCurve.Mode2DEnum.XY;

            GUIContent[] oldLabels = null;
            if (needToSwap)
            {
                oldLabels = BGPrivateField.Get <GUIContent[]>(typeof(EditorGUI), "s_XYLabels");
                GUIContent[] newLabels;
                switch (mode2D)
                {
                case BGCurve.Mode2DEnum.XZ:
                    newLabels = XZLabels;
                    break;

                case BGCurve.Mode2DEnum.YZ:
                    newLabels = YZLabels;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("mode2D", mode2D, null);
                }
                BGPrivateField.Set(typeof(EditorGUI), "s_XYLabels", newLabels);
            }

            try
            {
                action();
            }
            finally
            {
                if (needToSwap)
                {
                    BGPrivateField.Set(typeof(EditorGUI), "s_XYLabels", oldLabels);
                }
            }
        }
Exemplo n.º 18
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
            });
        }
Exemplo n.º 19
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);
                });
            }
Exemplo n.º 20
0
        public override void OnApply()
        {
            var curve    = Editor.Curve;
            var settings = Settings;

            // ==============================================    Closed
            if (curve.Closed != closedProperty.boolValue)
            {
                Curve.FireBeforeChange(BGCurve.EventClosed);
                serializedObject.ApplyModifiedProperties();
                Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Points, BGCurve.EventClosed));
            }

            if ((int)curve.ForceChangedEventMode != forceChangedEventModeProperty.enumValueIndex)
            {
                Curve.FireBeforeChange(BGCurve.EventForceUpdate);
                serializedObject.ApplyModifiedProperties();
                Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Curve, BGCurve.EventForceUpdate));
            }

            // ==============================================    Points store mode
            if ((int)Curve.PointsMode != pointsModeProperty.enumValueIndex)
            {
                var newPointsMode = (BGCurve.PointsModeEnum)pointsModeProperty.enumValueIndex;

                //ask for confirmation in case changes may affect something else
                if ((Curve.PointsMode == BGCurve.PointsModeEnum.Components) && !BGEditorUtility.Confirm("Convert Points",
                                                                                                        "Are you sure you want to convert points? All existing references to these points will be lost.", "Convert"))
                {
                    return;
                }

                if ((Curve.PointsMode == BGCurve.PointsModeEnum.GameObjectsNoTransform && newPointsMode != BGCurve.PointsModeEnum.GameObjectsTransform ||
                     Curve.PointsMode == BGCurve.PointsModeEnum.GameObjectsTransform && newPointsMode != BGCurve.PointsModeEnum.GameObjectsNoTransform) &&
                    !BGEditorUtility.Confirm("Convert Points", "Are you sure you want to convert points? All existing GameObjects for points will be deleted.", "Convert"))
                {
                    return;
                }

                editorSelection.Clear();

                //invoke convert
                BGPrivateField.Invoke(Curve, BGCurve.MethodConvertPoints, newPointsMode,
                                      BGCurveEditor.GetPointProvider(newPointsMode, Curve),
                                      BGCurveEditor.GetPointDestroyer(Curve.PointsMode, Curve));

                //this call is not required
                //                serializedObject.ApplyModifiedProperties();
            }

            // ==============================================    2D mode
            if ((int)curve.Mode2D != mode2DProperty.enumValueIndex)
            {
                Curve.FireBeforeChange(BGCurve.Event2D);
                serializedObject.ApplyModifiedProperties();

                var oldEventMode = Curve.EventMode;
                Curve.EventMode = BGCurve.EventModeEnum.NoEvents;

                //force points recalc
                Curve.Apply2D(Curve.Mode2D);

                if (BGEditorUtility.Confirm("Editor handles change", "Do you want to adjust configurable Editor handles (in Scene View) to chosen mode? This affects only current curve.", "Yes"))
                {
                    if (Curve.Mode2D != BGCurve.Mode2DEnum.Off)
                    {
                        Apply2D(settings.HandlesSettings);
                        Apply2D(settings.ControlHandlesSettings);
                    }
                    else
                    {
                        Apply3D(settings.HandlesSettings);
                        Apply3D(settings.ControlHandlesSettings);
                    }
                }

                Curve.EventMode = oldEventMode;

                Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Points, BGCurve.Event2D));
            }

            // ==============================================    Snapping
            if ((int)curve.SnapType != snapTypeProperty.enumValueIndex)
            {
                SnappingChanged(BGCurve.EventSnapType);
            }

            if ((int)curve.SnapAxis != snapAxisProperty.enumValueIndex)
            {
                SnappingChanged(BGCurve.EventSnapAxis);
            }

            if (Math.Abs((int)curve.SnapDistance - snapDistanceProperty.floatValue) > BGCurve.Epsilon)
            {
                SnappingChanged(BGCurve.EventSnapDistance);
            }

            if ((int)curve.SnapTriggerInteraction != snapTriggerInteractionProperty.enumValueIndex)
            {
                SnappingChanged(BGCurve.EventSnapTrigger);
            }

            if (curve.SnapToBackFaces != snapToBackFacesProperty.boolValue)
            {
                SnappingChanged(BGCurve.EventSnapBackfaces);
            }

            if (curve.SnapMonitoring != snapMonitoringProperty.boolValue)
            {
                SnappingChanged(BGCurve.EventSnapMonitoring);
            }

            // ==============================================    Event mode
            if ((int)curve.EventMode != eventModeProperty.enumValueIndex)
            {
                serializedObject.ApplyModifiedProperties();
            }

            // ==============================================    Control Type
            if ((int)settings.ControlType != controlTypeProperty.enumValueIndex)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
Exemplo n.º 21
0
        private void InspectorTopSection()
        {
            if (Curve.PointsCount == 0)
            {
                EditorGUILayout.HelpBox(
                    "1) Ctrl + LeftClick in scene view to add a point and snap it to  "
                    + "\r\n    a) 3D mode: mesh with collider"
                    + "\r\n    b) 2D mode: curve's 2D plane."
                    + "\r\n"
                    + "\r\n2) Ctrl + Shift + LeftClick in Scene View to add a point unconditionally at some distance, specified in the settings."
                    + "\r\n"
                    + "\r\n3) Hold control over existing point or selection to access Scene View menu"
                    + "\r\n"
                    + "\r\n4) Hold shift + drag to use rectangular selection in Scene View"
                    + "\r\n"
                    + "\r\n5) Ctrl + LeftClick over existing spline to insert a point"
                    , MessageType.Info);
            }


            try
            {
                // Curve's block
                BGEditorUtility.VerticalBox(() =>
                {
                    //closed
                    EditorGUILayout.PropertyField(closedProperty);


                    //point's store mode
                    BGEditorUtility.Horizontal(() =>
                    {
                        EditorGUILayout.PropertyField(pointsModeProperty);

                        BGEditorUtility.DisableGui(() =>
                        {
                            BGEditorUtility.Assign(ref syncContent, () => new GUIContent("Sync", "Sort points Game Objects and update names"));

                            if (!GUILayout.Button(syncContent))
                            {
                                return;
                            }

                            BGPrivateField.Invoke(Curve, BGCurve.MethodSetPointsNames);
                        }, !BGCurve.IsGoMode(Curve.PointsMode));
                    });


                    //2D mode
                    BGEditorUtility.Horizontal(() =>
                    {
                        EditorGUILayout.PropertyField(mode2DProperty);
                        BGEditorUtility.DisableGui(() =>
                        {
                            if (!GUILayout.Button("Apply", GUI.skin.button, GUILayout.Width(80)))
                            {
                                return;
                            }

                            Curve.FireBeforeChange(BGCurve.Event2D);
                            Curve.Apply2D(Curve.Mode2D);
                            Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Points, BGCurve.Event2D));
                        }, mode2DProperty.enumValueIndex == 0);
                    });

                    //snapping
                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.Horizontal(() =>
                        {
                            EditorGUILayout.PropertyField(snapTypeProperty);

                            BGEditorUtility.DisableGui(() =>
                            {
                                if (!GUILayout.Button("Apply", GUI.skin.button, GUILayout.Width(80)))
                                {
                                    return;
                                }

                                Curve.FireBeforeChange(BGCurve.EventSnapType);
                                Curve.ApplySnapping();
                                Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Snap, BGCurve.EventSnapType));
                            }, snapTypeProperty.enumValueIndex == 0);
                        });

                        if (snapTypeProperty.enumValueIndex == 0)
                        {
                            return;
                        }

                        EditorGUILayout.PropertyField(snapAxisProperty);
                        EditorGUILayout.PropertyField(snapDistanceProperty);
                        EditorGUILayout.PropertyField(snapTriggerInteractionProperty);
                        EditorGUILayout.PropertyField(snapToBackFacesProperty);

                        BGEditorUtility.LayerMaskField("Snap Layer Mask", Curve.SnapLayerMask, i =>
                        {
                            Curve.FireBeforeChange(BGCurve.EventSnapTrigger);
                            Curve.SnapLayerMask = i;
                            Curve.ApplySnapping();
                            Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Snap, BGCurve.EventSnapTrigger));
                        });

                        EditorGUILayout.PropertyField(snapMonitoringProperty);
                        if (Curve.SnapMonitoring && Curve.SnapType != BGCurve.SnapTypeEnum.Off)
                        {
                            EditorGUILayout.HelpBox("You enabled snap monitoring, which monitor environment every frame and snap to it. Be aware, this is a very costly function", MessageType.Warning);
                        }
                    });

                    //event mode
                    EditorGUILayout.PropertyField(eventModeProperty);

                    //force update
                    EditorGUILayout.PropertyField(forceChangedEventModeProperty);

                    //convert control type
                    BGEditorUtility.Horizontal(() =>
                    {
                        EditorGUILayout.PropertyField(controlTypeProperty);

                        if (!BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGConvertAll123, "Convert control types for all existing points ", 44))
                        {
                            return;
                        }

                        var settings = Settings;

                        foreach (var point in Curve.Points.Where(point => point.ControlType != settings.ControlType))
                        {
                            point.ControlType = settings.ControlType;
                        }
                    });
                });
            }
            catch (BGEditorUtility.ExitException)
            {
                GUIUtility.ExitGUI();
            }
        }
 public void Reset()
 {
     Changed  = false;
     settings = BGPrivateField.GetSettings(curve);
 }
Exemplo n.º 23
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;
        }
Exemplo n.º 24
0
 public static void DeletePoints(BGCurve curve, BGCurvePointI[] points)
 {
     BGPrivateField.Invoke(curve, BGCurve.MethodDeletePoint, new[] { typeof(BGCurvePointI[]), typeof(Action <BGCurvePointI>) }, points, GetPointDestroyer(curve.PointsMode, curve));
 }
Exemplo n.º 25
0
 public static void DeletePoint(BGCurve curve, int index)
 {
     BGPrivateField.Invoke(curve, BGCurve.MethodDeletePoint, new[] { typeof(int), typeof(Action <BGCurvePointI>) }, index, GetPointDestroyer(curve.PointsMode, curve));
 }
Exemplo n.º 26
0
 public static void AddPoint(BGCurve curve, BGCurvePoint point, int index)
 {
     BGPrivateField.Invoke(curve, BGCurve.MethodAddPoint, point, index, GetPointProvider(curve.PointsMode, curve));
 }
        public override void OnInspectorGui()
        {
            settings = SerializedObject.FindProperty("settings");
            var settingsObj = Settings;

            // Save & Load
            showSaveLoad = EditorGUILayout.Foldout(showSaveLoad, "Save and load settings");
            if (showSaveLoad)
            {
                BGEditorUtility.VerticalBox(() =>
                {
                    var path = BGCurveSettingsOperations.GetPath();

                    BGEditorUtility.HelpBox("Folder is not set", MessageType.Info, path == null, () =>
                    {
                        EditorGUILayout.LabelField("Folder", path);

                        BGEditorUtility.HelpBox("Folder is not found", MessageType.Warning, !BGCurveSettingsOperations.IsValid(path), () =>
                        {
                            // =================================  Load settings
                            var all = BGCurveSettingsOperations.GetAll();

                            BGEditorUtility.HelpBox("Folder does not have any settings", MessageType.Warning, all == null || all.Length == 0, () =>
                            {
                                BGEditorUtility.Horizontal(() =>
                                {
                                    var options = new List <GUIContent> {
                                        new GUIContent("")
                                    };
                                    options.AddRange(all.Select(setting => new GUIContent(setting)));
                                    var selected = EditorGUILayout.Popup(new GUIContent("Load", "Load a specified settings for current object"), 0, options.ToArray());
                                    if (selected > 0)
                                    {
                                        var newSettings = BGCurveSettingsOperations.Load(options[selected].text);
                                        if (newSettings != null)
                                        {
                                            BGPrivateField.SetSettings(Curve, newSettings);
                                            EditorUtility.SetDirty(Curve);
                                            lastOperation = options[selected].text + " was loaded";
                                        }
                                        else
                                        {
                                            lastOperation = "Unable to load a settings " + options[selected].text;
                                        }
                                    }

                                    if (GUILayout.Button(new GUIContent("Reload", "Reload settings from disk. This operation does not change settings for the curent object.")))
                                    {
                                        BGCurveSettingsOperations.Reload(BGCurveSettingsOperations.GetPath());
                                        lastOperation = "Settings was reloaded from disk";
                                    }
                                });
                            });

                            // =================================  Save settings
                            BGEditorUtility.Horizontal(() =>
                            {
                                newAssetName = EditorGUILayout.TextField(new GUIContent("Save", "Save current setting on disk"), newAssetName);
                                if (!GUILayout.Button(new GUIContent("Save", "Save current setting on disk")))
                                {
                                    return;
                                }

                                if (newAssetName == null || newAssetName.Trim().Equals(""))
                                {
                                    BGEditorUtility.Inform("Invalid asset name", "Please, enter the name for new asset");
                                }
                                else
                                {
                                    lastOperation = BGCurveSettingsOperations.Save(settingsObj, newAssetName) ? newAssetName + " was saved on disk" : "Unable to save " + newAssetName + " on disk";
                                }
                            });

                            BGEditorUtility.HelpBox(lastOperation, MessageType.Info, lastOperation != null);
                        });
                    });

                    BGEditorUtility.Horizontal(() =>
                    {
                        if (GUILayout.Button(new GUIContent("Save as default", "Save current settings as default for future curves")))
                        {
                            lastOperation = BGCurveSettingsOperations.SaveDefault(settingsObj) ? "Current settings was saved as default" : "Unable to save settings on disk as default";
                        }

                        if (GUILayout.Button(new GUIContent("Chose a folder", "Chose a folder where to store settings files")))
                        {
                            BGCurveSettingsOperations.ChoseDir();
                        }
                    });
                });
            }

            EditorGUILayout.HelpBox("All fields settings are under Fields tab", MessageType.Warning);

            BGEditorUtility.ChangeCheck(() =>
            {
                //Points
                BGEditorUtility.VerticalBox(() =>
                {
                    //Hide handles
                    EditorGUILayout.PropertyField(Find("hideHandles"));

                    EditorGUILayout.PropertyField(Find("newPointDistance"));
                    EditorGUILayout.PropertyField(Find("showPointMenu"));
                    EditorGUILayout.PropertyField(Find("restrictGizmoz"));
                    if (settingsObj.RestrictGizmozSettings.Valid && settingsObj.RestrictGizmozSettings.HasValue)
                    {
                        EditorGUILayout.HelpBox("Gizmos are shown for specified points only", MessageType.Warning);
                    }
                });

                var tangentProp = Find("showTangents");

                //curve
                BGEditorUtility.FadeGroup(showCurveProp, () =>
                {
//                    EditorGUILayout.PropertyField(Find("showCurveMode"));
                    EditorGUILayout.PropertyField(Find("showCurveOption"));
                    EditorGUILayout.PropertyField(Find("sections"));
                    EditorGUILayout.PropertyField(Find("vRay"));
                    EditorGUILayout.PropertyField(Find("lineColor"));

                    //tangents
                    BGEditorUtility.VerticalBox(() =>
                    {
                        EditorGUILayout.PropertyField(tangentProp);
                        if (settingsObj.ShowTangents)
                        {
                            BGEditorUtility.Indent(1, () =>
                            {
                                EditorGUILayout.PropertyField(Find("tangentsSize"));
                                EditorGUILayout.PropertyField(Find("tangentsPerSection"));
                                EditorGUILayout.PropertyField(Find("tangentsColor"));
                            });
                        }
                    });
                });
            }, () =>
            {
                //if any change
                SerializedObject.ApplyModifiedProperties();
                SceneView.RepaintAll();
            });
        }
Exemplo n.º 28
0
            public void Ui(BGTableView ui)
            {
                var cursor = 0;

                // ==========================   First row
                //number
                ui.NextColumn("" + index, "Field's index", GetWidth(ui, ref cursor));

                //name
                ui.NextColumn(rect =>
                {
                    BGEditorUtility.TextField(rect, field.FieldName, s =>
                    {
                        if (NameHasError(field.Curve, s))
                        {
                            return;
                        }
                        Change(() => field.FieldName = s);
                    }, true);
                }, GetWidth(ui, ref cursor));

                //type
                ui.NextColumn(field.Type.ToString(), "Field's Type", GetWidth(ui, ref cursor));

                //show in Points menu
                ui.NextColumn(rect => BGEditorUtility.BoolField(rect, BGPrivateField.GetShowInPointsMenu(field), b => Change(() => BGPrivateField.SetShowInPointsMenu(field, b))),
                              GetWidth(ui, ref cursor));

                //delete icon
                ui.NextColumn(rect =>
                {
                    if (!GUI.Button(rect, deleteIcon) || !BGEditorUtility.Confirm("Delete", "Are you sure you want to delete '" + field.FieldName + "' field?", "Delete"))
                    {
                        return;
                    }

                    BGPrivateField.Invoke(field.Curve, BGCurve.MethodDeleteField, field, (Action <BGCurvePointField>)Undo.DestroyObjectImmediate);

                    GUIUtility.ExitGUI();
                }, GetWidth(ui, ref cursor));

                //\r\n
                ui.NextRow();

                // ==========================   Second row
                //does not support
                if (!SupportHandles(field.Type))
                {
                    return;
                }

                ui.NextColumn("      Handles", "Field's index", 25);

                //handles type
                ui.NextColumn(
                    rect => BGEditorUtility.PopupField(rect, (HandlesType)BGPrivateField.GetHandlesType(field), Type2Handles[field.Type],
                                                       b => Change(() => BGPrivateField.SetHandlesType(field, (int)((HandlesType)b)))), 30);

                //Handles color
                ui.NextColumn(rect => BGEditorUtility.ColorField(rect, BGPrivateField.GetHandlesColor(field), b => Change(() => BGPrivateField.SetHandlesColor(field, b))), 30);

                //show handles in Scene View
                ui.NextColumn(rect => BGEditorUtility.BoolField(rect, BGPrivateField.GetShowHandles(field), b => Change(() => BGPrivateField.SetShowHandles(field, b))), 5);

                //empty column under delete button
                ui.NextColumn(rect => EditorGUI.LabelField(rect, ""), 10);

                //\r\n
                ui.NextRow();
            }
Exemplo n.º 29
0
        public override void OnInspectorGUI()
        {
            //adjust math if needed
            AdjustMath(BGPrivateField.GetSettings(Curve), Math);

            //styles
            BGEditorUtility.Assign(ref stickerStyle, () => new GUIStyle("Label")
            {
                fontSize = 18, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState {
                    textColor = Color.white
                }
            });
            BGEditorUtility.Assign(ref settingsTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSettingsIcon123));

            serializedObject.Update();

            // =========== Header
            DrawLogo();

            // =========== lock view
            BGEditorUtility.Horizontal(() =>
            {
                var temp = BGCurveSettingsForEditor.LockView;
                BGCurveSettingsForEditor.LockView = BGEditorUtility.ButtonOnOff(ref temp, "Lock view", "Disable selection of other objects in the scene", LockViewActiveColor,
                                                                                new GUIContent("Turn Off", "Click to turn this mode off"),
                                                                                new GUIContent("Turn On", "Click to turn this mode on"));

                if (BGEditorUtility.ButtonWithIcon(settingsTexture, "Open BGCurve Editor Settings", 24, 24))
                {
                    BGCurveSettingsForEditorWindow.Open();
                }
            });

            //warning
            BGEditorUtility.HelpBox("You can not chose another objects in the scene, except points.\r\n Use rectangular selection without pressing shift", MessageType.Warning,
                                    BGCurveSettingsForEditor.LockView, () => GUILayout.Space(8));

            // =========== Tabs
            if (BGCurveSettingsForEditor.CurrentTab < 0 || BGCurveSettingsForEditor.CurrentTab > headers.Length - 1)
            {
                BGCurveSettingsForEditor.CurrentTab = 0;
            }
            BGCurveSettingsForEditor.CurrentTab = GUILayout.Toolbar(BGCurveSettingsForEditor.CurrentTab, headers, GUILayout.Height(ToolBarHeight));
            //do not move this method(GUILayoutUtility.GetLastRect() is used)
            ShowStickers();
            editors[BGCurveSettingsForEditor.CurrentTab].OnInspectorGui();


            if (!GUI.changed)
            {
                return;               // if no change- return
            }
            foreach (var editor in editors)
            {
                editor.OnBeforeApply();
            }

            serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(Curve);

            foreach (var editor in editors)
            {
                editor.OnApply();
            }

            transformMonitor.Check();
        }
Exemplo n.º 30
0
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            var settings = BGPrivateField.GetSettings(Curve);

            BGEditorUtility.HelpBox("Curve UI is disabled in settings. All handles are disabled too.", MessageType.Warning, !settings.ShowCurve);

            // Custom fields
            var warning = "";

            BGEditorUtility.Assign(ref customUi, () => new BGTableView("Custom fields", new[] { "#", "Name", "Type", "?", "Delete" }, new[] { 5, 40, 40, 5, 10 }, () =>
            {
                //add row
                customUi.NextColumn(rect => EditorGUI.LabelField(rect, "Name"), 12);
                customUi.NextColumn(rect => newFieldName = EditorGUI.TextField(rect, newFieldName), 28);
                customUi.NextColumn(rect => BGEditorUtility.PopupField(rect, newFieldType, @enum => newFieldType = (BGCurvePointField.TypeEnum)@enum), 50);
                customUi.NextColumn(rect =>
                {
                    if (!GUI.Button(rect, BGBinaryResources.BGAdd123))
                    {
                        return;
                    }

                    if (NameHasError(Curve, newFieldName))
                    {
                        return;
                    }

                    BGPrivateField.Invoke(Curve, BGCurve.MethodAddField, newFieldName, newFieldType, (Func <BGCurvePointField>)(() => Undo.AddComponent <BGCurvePointField>(Curve.gameObject)));
                    GUIUtility.hotControl = 0;
                    GUIUtility.ExitGUI();
                }, 10);

                customUi.NextRow();

                if (customFields == null || customFields.Length == 0)
                {
                    customUi.NextRow("Name should be 16 chars max, starts with a letter and contain English chars and numbers only.");
                }
                else
                {
                    //header
                    customUi.DrawHeaders();

                    //fields
                    var quaternionWithHandlesCount = 0;

                    BGEditorUtility.ChangeCheck(() =>
                    {
                        foreach (var customField in customFields)
                        {
                            if (customField.Field.Type == BGCurvePointField.TypeEnum.Quaternion && BGPrivateField.GetHandlesType(customField.Field) != 0)
                            {
                                quaternionWithHandlesCount++;
                            }
                            customField.Ui(customUi);
                        }
                    }, SceneView.RepaintAll);

                    if (quaternionWithHandlesCount > 1)
                    {
                        warning = "You have more than one Quaternion field with Handles enabled. Only first field will be shown in Scene View";
                    }
                    //footer
                    customUi.NextRow("?- Show in Points Menu/Scene View");
                }
            }));

            // System fields
            BGEditorUtility.Assign(ref systemUi, () => new BGTableView("System fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }, () =>
            {
                BGEditorUtility.ChangeCheck(() =>
                {
                    foreach (var field in systemFields)
                    {
                        field.Ui(systemUi);
                    }
                }, SceneView.RepaintAll);
            }));

            BGEditorUtility.Assign(ref systemFields, () => new[]
            {
                (SystemField) new SystemFieldPosition(settings),
                new SystemFieldControls(settings),
                new SystemFieldControlsType(settings),
                new SystemFieldTransform(settings),
            });

            var fields    = Curve.Fields;
            var hasFields = fields != null && fields.Length > 0;

            if (hasFields && (customFields == null || customFields.Length != fields.Length) || !hasFields && customFields != null && customFields.Length != fields.Length)
            {
                customFields = new PointField[fields.Length];

                for (var i = 0; i < fields.Length; i++)
                {
                    customFields[i] = new PointField(fields[i], i, BGBinaryResources.BGDelete123);
                }
            }


            //warnings
            BGEditorUtility.HelpBox("All handles for positions are disabled.", MessageType.Warning, settings.HandlesSettings.Disabled);
            BGEditorUtility.HelpBox("All handles for controls are disabled.", MessageType.Warning, settings.ControlHandlesSettings.Disabled);

            //====================== Custom fields
            customUi.OnGui();

            //warnings
            BGEditorUtility.HelpBox(warning, MessageType.Warning, warning.Length > 0);

            //====================== System fields
            systemUi.OnGui();
            GUILayout.Space(4);
        }