private static void AssighStyles()
 {
     BGEditorUtility.Assign(ref nameStyle, () => new GUIStyle("Label")
     {
         alignment = TextAnchor.MiddleCenter,
         clipping  = TextClipping.Clip,
         wordWrap  = true,
         fontStyle = FontStyle.Bold,
         normal    =
         {
             textColor  = Color.black,
             background = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGBoxWithBorder123)
         }
     });
     BGEditorUtility.Assign(ref disabledStyle, () => new GUIStyle("Label")
     {
         alignment = TextAnchor.MiddleCenter,
         normal    =
         {
             textColor  = Color.red,
             background = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGBoxWithBorder123)
         }
     });
     BGEditorUtility.Assign(ref filterStyle, () => new GUIStyle("Label")
     {
         fontStyle = FontStyle.Bold,
         normal    =
         {
             textColor = Color.red
         }
     });
     BGEditorUtility.Assign(ref headerImage, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCurveComponents123));
     BGEditorUtility.Assign(ref boxWithBorderImage, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGBoxWithBorder123));
 }
Beispiel #2
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);
            }
                internal CcNode(Tree tree, BGCc cc) : base(tree)
                {
                    Cc         = cc;
                    descriptor = cc.Descriptor;

                    var editor = UnityEditor.Editor.CreateEditor(cc);

                    if (!(editor is BGCcEditor))
                    {
                        throw new BGCc.CcException("Unable to init an Editor for " + cc.GetType() + ": editor does not extend from BGCcEditor.");
                    }

                    ccEditor = (BGCcEditor)editor;
                    ccEditor.ChangedParent += ChangedParent;
//                    UnityEditor.Editor.CreateCachedEditor(cc, null, ref ccEditor);

                    onSceneGuiMethod = ccEditor.GetType().GetMethod("OnSceneGUI", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

                    enabledTexture    = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGTickYes123);
                    disabledTexture   = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGTickNo123);
                    helpTexture       = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHelp123);
                    deleteTexture     = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123);
                    addTexture        = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);
                    changeNameTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCcEditName123);

                    parentType = cc.GetParentClass();
                }
            protected AbstractMenu(BGSceneViewOverlay overlay, BGCurveEditorPointsSelection editorSelection, string title)
                : base(title)
            {
                EditorSelection = editorSelection;

                Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGControlAbsent123), "Convert point control to Absent",
                                       () => { SetControl(BGCurvePoint.ControlTypeEnum.Absent); }));

                Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGControlBezierSymmetrical123), "Convert point control to Bezier Symmetrical",
                                       () => { SetControl(BGCurvePoint.ControlTypeEnum.BezierSymmetrical); }));

                Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGControlBezierIndependent123), "Convert point control to Bezier Independent",
                                       () => { SetControl(BGCurvePoint.ControlTypeEnum.BezierIndependant); }));


                AdditionalMenuItems();


                Add(new LockMenuItem(() =>
                {
                    BGCurveSettingsForEditor.LockView = !BGCurveSettingsForEditor.LockView;
                    EditorUtility.SetDirty(overlay.Editor.Curve);
                }));

                Add(new MenuSeparator());

                Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointDelete123), "Delete a point", Delete));
            }
Beispiel #5
0
        public BGCurveEditorFields(BGCurveEditor editor, SerializedObject curveObject, BGCurveEditorPointsSelection editorSelection)
            : base(editor, curveObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGFields123))
        {
            this.editorSelection = editorSelection;

            addIcon    = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);
            deleteIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123);
        }
Beispiel #6
0
 public BGPopupMenu(string title)
 {
     this.title = title;
     menuItemBackgroundTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMenuItemBackground123);
     backTexture     = BGEditorUtility.Texture1X1(new Color32(46, 144, 168, 80));
     selectedTexture = BGEditorUtility.Texture1X1(new Color32(0, 255, 0, 100));
     currentTexture  = BGEditorUtility.Texture1X1(new Color32(200, 200, 200, 200));
 }
        public BGCurveEditorSettings(BGCurveEditor editor, SerializedObject serializedObject)
            : base(editor, serializedObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSettings123))
        {
            //anim props
            showCurveProp = new BGEditorUtility.BoolAnimatedProperty(editor, serializedObject.FindProperty("settings"), "showCurve");
//            showControlHandlesProp = new BGEUtil.BoolAnimatedProperty(editor, settings, "showControlHandles");
//            showLablesProp = new BGEUtil.BoolAnimatedProperty(editor, settings, "showLabels");
//            showSpheresProp = new BGEUtil.BoolAnimatedProperty(editor, settings, "showSpheres");
        }
Beispiel #8
0
 protected override void AdditionalMenuItems()
 {
     Add(new MenuSeparator());
     Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionRemove123), "Remove this point from selection",
                            () =>
     {
         EditorSelection.Clear();
         EditorUtility.SetDirty(Overlay.Editor.Curve);
     }));
 }
Beispiel #9
0
        internal static void Open(BGCurve curve, Action <Type> action, Type dependsOnType = null)
        {
            BGCcAddWindow.action = action;

            noImage = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCcNoImage123);

            tree = new Tree(curve, dependsOnType);

            instance = BGEditorUtility.ShowPopupWindow <BGCcAddWindow>(WindowSize);
        }
        public BGCurveEditorPoint(BGCurveEditorPoints editor, BGCurveEditorPointsSelection editorSelection)
        {
            this.editor          = editor;
            this.editorSelection = editorSelection;

            //textures
            deleteTexture    = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123);
            addBeforeTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);
            moveUpTexture    = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMoveUp123);
            moveDownTexture  = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMoveDown123);
            maskTexture      = BGEditorUtility.Texture1X1(new Color(1, 0, 0, .15f));
        }
Beispiel #11
0
 private static GUIStyle GetStyle(BGEditorUtility.Image background)
 {
     return(new GUIStyle("Label")
     {
         padding = new RectOffset(2, 2, 2, 2),
         border = new RectOffset(2, 2, 2, 2),
         normal = new GUIStyleState
         {
             background = BGEditorUtility.LoadTexture2D(background)
         }
     });
 }
Beispiel #12
0
        public BGCurveEditorPointsSelection(BGCurve curve, BGCurveEditor editor)
        {
            this.curve         = curve;
            selectionRectangle = new BGRectangularSelection(editor, this);

            tickNoTexture      = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGTickNo123);
            tickYesTexture     = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGTickYes123);
            deleteTexture      = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123);
            selectAllTexture   = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectAll123);
            deselectAllTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDeSelectAll123);
            convertAllTexture  = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGConvertAll123);
            pointsContainer    = new PointsContainer(this);
        }
Beispiel #13
0
        public BGCurveEditorPoint(Func <BGCurveBaseMath> mathProvider, BGCurveEditorPointsSelection editorSelection)
        {
            this.mathProvider    = mathProvider;
            this.editorSelection = editorSelection;

            //textures
            deleteTexture    = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123);
            addBeforeTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);
            moveUpTexture    = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMoveUp123);
            moveDownTexture  = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGMoveDown123);
            copyTexture      = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCopy123);
            pasteTexture     = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPaste123);
        }
                //true if exit gui pass
                public override void OnInspectorGuiInternal(int level)
                {
                    BGEditorUtility.Assign(ref okStyle, () => new GUIStyle("Label")
                    {
                        normal = { textColor = new Color32(66, 166, 33, 255) }, fontStyle = FontStyle.Bold
                    });
                    BGEditorUtility.Assign(ref errorStyle, () => new GUIStyle("Label")
                    {
                        normal = { textColor = new Color32(166, 66, 33, 255) }, fontStyle = FontStyle.Bold
                    });
                    BGEditorUtility.Assign(ref headerBoxStyle, () => new GUIStyle {
                        padding = new RectOffset(4, 4, 4, 4)
                    });
                    BGEditorUtility.Assign(ref headerFoldoutStyle, () => new GUIStyle(EditorStyles.foldout)
                    {
                        fontStyle = FontStyle.Bold, clipping = TextClipping.Clip
                    });
                    BGEditorUtility.Assign(ref headerFoldoutStyleDisabled, () => new GUIStyle(headerFoldoutStyle)
                    {
                        normal = { textColor = Color.gray }
                    });

                    var color = MyTree.GetColor(level, Collapsed, () => Color.white);

                    color.a = ConnectorLineAlpha;

                    //colored box
                    BGEditorUtility.SwapGuiColor(color, () => EditorGUILayout.BeginVertical(BGEditorUtility.Assign(ref coloredBoxStyle, () => new GUIStyle("Box")
                    {
                        padding = new RectOffset(),
                        margin  = new RectOffset(),
                        border  = new RectOffset(4, 4, 4, 4),
                        normal  = { background = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGBoxWhite123) }
                    })));

                    //header
                    HeaderUi(level, !String.IsNullOrEmpty(Cc.Error));


                    if (!Collapsed)
                    {
                        BGEditorUtility.VerticalBox(() =>
                        {
                            //show inspector
                            ccEditor.OnInspectorGUI();
                        });
                    }

                    //do not remove it (EditorGUILayout.BeginVertical is a little higher- colored box)
                    EditorGUILayout.EndVertical();
                }
Beispiel #15
0
        static BGStartUp()
        {
            CurveIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHierarchyIcon123, critical: false);
            if (CurveIcon != null)
            {
                CurveWarningIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHierarchyWarningIcon123);
                CurveErrorIcon   = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHierarchyErrorIcon123);

                CurveSelectedIcon        = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHierarchySelectedIcon123);
                CurveWarningSelectedIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHierarchyWarningSelectedIcon123);
                CurveErrorSelectedIcon   = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHierarchyErrorSelectedIcon123);
                EditorApplication.hierarchyWindowItemOnGUI += ShowIcon;
            }
        }
        protected virtual void OnEnable()
        {
            point = Point;

            pointEditor = new BGCurveEditorPoint(() => null, null);

            if (curveEditor != null)
            {
                curveEditor.OnDestroy();
            }

            curveEditor = (BGCurveEditor)CreateEditor(point.Curve);

            pointSelectedTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointSelected123);

            PointSelected = true;
        }
        public BGCurveEditorPoints(BGCurveEditor editor, SerializedObject serializedObject, BGCurveEditorPointsSelection editorSelection)
            : base(editor, serializedObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPoints123))
        {
            this.serializedObject = serializedObject;
            this.editorSelection  = editorSelection;

            //textures
            convertAll2D = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGConvertAll123);
            addPointIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);

            //point
            editorPoint = new BGCurveEditorPoint(() => Editor.Math, editorSelection);

            //closed or not
            closedProperty = serializedObject.FindProperty("closed");

            //how points are stored
            pointsModeProperty = serializedObject.FindProperty("pointsMode");

            //2d mode
            mode2DProperty = serializedObject.FindProperty("mode2D");

            //snapping
            snapTypeProperty               = serializedObject.FindProperty("snapType");
            snapAxisProperty               = serializedObject.FindProperty("snapAxis");
            snapDistanceProperty           = serializedObject.FindProperty("snapDistance");
            snapTriggerInteractionProperty = serializedObject.FindProperty("snapTriggerInteraction");
            snapToBackFacesProperty        = serializedObject.FindProperty("snapToBackFaces");
            snapMonitoringProperty         = serializedObject.FindProperty("snapMonitoring");

            //force update
            forceChangedEventModeProperty = serializedObject.FindProperty("forceChangedEventMode");

            //event type
            eventModeProperty = serializedObject.FindProperty("eventMode");

            //settings
            controlTypeProperty = serializedObject.FindProperty("settings").FindPropertyRelative("controlType");

            //Context menu
            overlay = new BGSceneViewOverlay(this, editorSelection);

            //for GameObjects points which use transforms
            UpdatePointsTrackers();
        }
Beispiel #18
0
        public BGCcTreeView(BGCurve curve, Type dependsOnType, bool ignoreExcludeFromMenuAttribute, Action <string> messageAction, Action <Type> typeWasChosenAction)
            : base(new Config(0, (int)(IconSize * .9f), (int)(IconSize * .5f), 2, 16))
        {
            Curve              = curve;
            DependsOnType      = dependsOnType;
            this.messageAction = messageAction;

            noImage = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCcNoImage123);


            //-------------  load all BGCc subclasses
            var typesList = GetAllSubTypes(typeof(BGCc), ignoreExcludeFromMenuAttribute ? null : typeof(BGCc.CcExcludeFromMenu));

            foreach (var node in from type in typesList
                     let descriptor = BGCc.GetDescriptor(type)
                                      let single = BGCc.IsSingle(type)
                                                   select new CcNode(this, descriptor != null ? new CcData(type, single, descriptor) : new CcData(type, single, type.Name), typeWasChosenAction))
            {
                try
                {
                    node.CcData.ParentType = BGCc.GetParentClass(node.CcData.Type);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    continue;
                }
                type2Node[node.CcData.Type] = node;
            }

            foreach (var node in type2Node.Values)
            {
                if (!node.Processed)
                {
                    node.ProcessStructure();
                }
            }
        }
        public BGCurveEditorPoints(BGCurveEditor editor, SerializedObject curveObject) : base(editor, curveObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPoints123))
        {
            //textures
            convertAll2D = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGConvertAll123);
            addPointIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);

            //selection
            editorSelection = new BGCurveEditorPointsSelection(Curve, this);

            //point
            editorPoint = new BGCurveEditorPoint(this, editorSelection);

            //closed or not
            closedProperty = curveObject.FindProperty("closed");

            //2d mode
            mode2DProperty = curveObject.FindProperty("mode2D");

            //settings
            controlTypeProperty = curveObject.FindProperty("settings").FindPropertyRelative("controlType");

            //Context menu
            overlay = new BGSceneViewOverlay(this, editorSelection);
        }
 protected BGSceneViewOverlayMenu(BGSceneViewOverlay overlay, BGCurveEditorPointsSelection editorSelection)
     : base(overlay)
 {
     this.editorSelection = editorSelection;
     pointSelectedTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointSelected123);
 }
Beispiel #21
0
 public BGCurveEditorFields(BGCurveEditor editor, SerializedObject curveObject) : base(editor, curveObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGFields123))
 {
 }
 public BGCurveEditorComponents(BGCurveEditor editor, SerializedObject curveObject)
     : base(editor, curveObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGComponents123))
 {
     tree = new Tree(Curve);
 }
Beispiel #23
0
        public void Process(Event currentEvent)
        {
            if (!On && currentEvent.control)
            {
                On = true;
            }

            if (!On)
            {
                return;
            }

            if (On && !currentEvent.control)
            {
                On = false;
            }

            if (currentEvent.type == EventType.mouseUp)
            {
                BGEditorUtility.Release(ref EventCanceller);
            }

            if (currentEvent.shift && !currentEvent.control)
            {
                return;
            }

            if (!BGEditorUtility.IsMouseInsideSceneView())
            {
                return;
            }

            BGEditorUtility.Assign(ref style, () => new GUIStyle("Label")
            {
                padding   = new RectOffset(4, 4, 4, 4),
                border    = new RectOffset(4, 4, 4, 4),
                fontStyle = FontStyle.Bold,
                richText  = true,
                normal    = new GUIStyleState
                {
                    textColor  = Color.white,
                    background = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGBoxWithBorder123)
                }
            });


            foreach (var action in actions)
            {
                var    position = Vector3.zero;
                string message  = null;

                if (!action.Seize(currentEvent, ref position, ref message))
                {
                    continue;
                }

                if (message != null)
                {
                    Message(action, position, message);
                }
                break;
            }

            if (currentEvent.control && currentEvent.type != EventType.Repaint)
            {
                SceneView.RepaintAll();
            }
        }
        public void Process(Event currentEvent)
        {
            if (currentEvent.type == EventType.mouseUp)
            {
                BGEditorUtility.Release(ref EventCanceller);
            }

            if (currentEvent.shift && !currentEvent.control)
            {
                return;
            }

            Vector3 mousePosition = Event.current.mousePosition;

            var pixelHeight = SceneView.currentDrawingSceneView.camera.pixelHeight;
            var pixelWidth  = SceneView.currentDrawingSceneView.camera.pixelWidth;

            mousePosition.y = pixelHeight - mousePosition.y;
            if (mousePosition.x < 0 || mousePosition.y < 0 || mousePosition.x > pixelWidth || mousePosition.y > pixelHeight)
            {
                return;
            }


            BGEditorUtility.Assign(ref style, () => new GUIStyle("Label")
            {
                padding   = new RectOffset(4, 4, 4, 4),
                border    = new RectOffset(4, 4, 4, 4),
                fontStyle = FontStyle.Bold,
                richText  = true,
                normal    = new GUIStyleState
                {
                    textColor  = Color.white,
                    background = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGBoxWithBorder123)
                }
            });


            foreach (var action in actions)
            {
                var    position = Vector3.zero;
                string message  = null;

                var seized = action.Seize(currentEvent, ref position, ref message);
                if (!seized)
                {
                    continue;
                }

                if (message != null)
                {
                    Message(action, position, message);
                }
                break;
            }

            if (currentEvent.control && currentEvent.type != EventType.Repaint)
            {
                SceneView.RepaintAll();
            }
        }
Beispiel #25
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;
        }
Beispiel #26
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 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(settingsTexture, 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();
        }
Beispiel #27
0
        public void OnGui(Event currentEvent)
        {
            if (!Active)
            {
                return;
            }

            var mousePosition = currentEvent.mousePosition;

            if (onTransition == null && !targetRect.Contains(mousePosition))
            {
                Active = false;
                SceneView.RepaintAll();
                return;
            }

            BGEditorUtility.Assign(ref titleStyle, () => new GUIStyle("Label")
            {
                fontStyle = FontStyle.Bold,
                alignment = TextAnchor.MiddleCenter,
                normal    =
                {
                    textColor  = Color.white,
                    background = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGBoxWithBorder123)
                },
            });

            BGEditorUtility.HandlesGui(() =>
            {
                if (onTransition != null && !onTransition.Tick())
                {
                    //animating transition
                    GUI.DrawTexture(new Rect(Vector2.Lerp(Point2DPosition, targetRect.position, onTransition.Ratio), targetRect.size * onTransition.Ratio), backTexture, ScaleMode.StretchToFill);
                }
                else
                {
                    //ready
                    onTransition = null;

                    GUI.DrawTexture(targetRect, backTexture, ScaleMode.StretchToFill);
                    GUI.Label(new Rect(targetRect)
                    {
                        height = HeaderHeight
                    }, title, titleStyle);

                    ActiveItem = null;
                    var cursor = targetRect.x;

                    foreach (var item in items.Where(item => !item.Disabled))
                    {
                        var itemRect = new Rect(cursor, targetRect.y + HeaderHeight, item.Size.x, item.Size.y);
                        var selected = itemRect.Contains(mousePosition);

                        //if not separator
                        if (selected && item.Description != null)
                        {
                            ActiveItem = item;

                            if (!currentEvent.control && item is MenuItemButton)
                            {
                                ((MenuItemButton)item).Action();
                            }
                        }

                        //icon
                        if (item.Icon != null)
                        {
                            GUI.DrawTexture(itemRect, menuItemBackgroundTexture, ScaleMode.StretchToFill);

                            if (selected)
                            {
                                GUI.DrawTexture(itemRect, selectedTexture, ScaleMode.StretchToFill);
                            }

                            GUI.DrawTexture(itemRect, item.Icon, ScaleMode.StretchToFill);
                        }

                        if (item.Current)
                        {
                            GUI.DrawTexture(itemRect, currentTexture, ScaleMode.StretchToFill);
                        }

                        cursor += itemRect.width;
                    }
                }
            });

            if (!currentEvent.control)
            {
                Active = false;
            }
        }
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            BGEditorUtility.Assign(ref whiteTexture, () => BGEditorUtility.Texture1X1(Color.white));
            BGEditorUtility.Assign(ref collapseTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCollapseAll123));
            BGEditorUtility.Assign(ref expandTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGExpandAll123));
            BGEditorUtility.Assign(ref addTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123));
            BGEditorUtility.Assign(ref deleteTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123));
            BGEditorUtility.Assign(ref onTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGOn123));
            BGEditorUtility.Assign(ref offTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGOff123));


            components = Curve.GetComponents <BGCc>();
            var length = components.Length;

            tree.Refresh(components);

            if (tree.InitException != null)
            {
                EditorGUILayout.HelpBox("There was an error initializing editors for component's Tree View: " + tree.InitException.Message +
                                        "\r\n\r\nYou still can use default Unity's editors for components below.", MessageType.Error);
                return;
            }


            var hasError   = HasError;
            var hasWarning = HasWarning;

            BGEditorUtility.HorizontalBox(() =>
            {
                EditorGUILayout.LabelField("Components: " + length + " (" + (hasError ? "Error" : "Ok") + ")");

                GUILayout.FlexibleSpace();

                if (BGEditorUtility.ButtonWithIcon(customEditorsOn ? onTexture : offTexture, "Use custom UI for components (colored tree) and hide standard unity editors for components"))
                {
                    customEditorsOn = !customEditorsOn;
                    tree.Refresh(null, true);
                }
                EditorGUILayout.Separator();

                if (length > 0)
                {
                    if (BGEditorUtility.ButtonWithIcon(collapseTexture, "Collapse all components"))
                    {
                        tree.ExpandCollapseAll(true);
                    }
                    EditorGUILayout.Separator();

                    if (BGEditorUtility.ButtonWithIcon(expandTexture, "Expand all components"))
                    {
                        tree.ExpandCollapseAll(false);
                    }
                    EditorGUILayout.Separator();


                    if (BGEditorUtility.ButtonWithIcon(deleteTexture, "Delete all components") &&
                        BGEditorUtility.Confirm("Delete", "Are you sure you want to delete " + length + " component(s)?", "Delete"))
                    {
                        tree.Delete();
                    }
                    EditorGUILayout.Separator();
                }

                if (BGEditorUtility.ButtonWithIcon(addTexture, "Add new component"))
                {
                    BGCcAddWindow.Open(Curve, type => AddComponent(Curve, type));
                }
            });

            if (length > 0)
            {
                if (hasWarning || hasError)
                {
                    for (var i = 0; i < components.Length; i++)
                    {
                        var component = components[i];

                        var name = (component.Descriptor != null ? component.Descriptor.Name + " " : "") + component.CcName;

                        var error = component.Error;
                        if (!string.IsNullOrEmpty(error))
                        {
                            BGEditorUtility.HelpBox("Component error [" + name + "]: " + error, MessageType.Error);
                        }

                        var warning = component.Warning;
                        if (!string.IsNullOrEmpty(warning))
                        {
                            BGEditorUtility.HelpBox("Component warning [" + name + "]: " + warning, MessageType.Warning);
                        }
                    }
                }
                else
                {
                    BGEditorUtility.HelpBox("No warnings or errors", MessageType.Info);
                }

                tree.OnInspectorGui();
            }
            else
            {
                EditorGUILayout.HelpBox(
                    "Hit the Plus icon to add a component"
                    + "\r\n"
                    + "\r\n"
                    + "Components allows to add functionality without any scripting."
                    , MessageType.Info);
            }


            if (hasError ^ HasError || hasWarning ^ HasWarning)
            {
                EditorApplication.RepaintHierarchyWindow();
            }
        }