Beispiel #1
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));
                        });
                    });

                    //event mode
                    EditorGUILayout.PropertyField(eventModeProperty);

                    //force update
                    EditorGUILayout.PropertyField(forceChangedEventModeProperty);

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

                        if (!BGEditorUtility.ButtonWithIcon(convertAll2D, "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();
            }
        }
        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;
        }
        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();
            }
        }
Beispiel #4
0
        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.type != EventType.Repaint)
            {
                SceneView.RepaintAll();
            }
        }
        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 #6
0
 public virtual Texture2D GetLinkTexture(int level)
 {
     BGEditorUtility.Assign(ref linkTexture, () => BGEditorUtility.Texture1X1(Color.black));
     return(linkTexture);
 }
Beispiel #7
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);
        }
Beispiel #8
0
        public virtual Rect OnInspectorGui()
        {
            var level = Level;

            var myRect = new Rect();

            BGEditorUtility.Vertical(() =>
            {
                BGEditorUtility.Horizontal(() =>
                {
                    if (level > 0 && tree.Configuration.HorizontalSpace > 0)
                    {
                        GUILayout.Space(tree.Configuration.HorizontalSpace * level);
                    }

                    BGEditorUtility.Vertical(() => { OnInspectorGuiInternal(level); });

                    myRect = GUILayoutUtility.GetLastRect();
                });
            });

            if (Event.current.type == EventType.Repaint)
            {
                Rect = myRect;
            }

            if (children == null || children.Count == 0 || Collapsed)
            {
                return(myRect);
            }


            //Children
            var texture = tree.GetLinkTexture(level);

            var linkStartX = myRect.x + tree.Configuration.HorizontalLinkOffset;

            var childRect = new Rect();

            var linkSize = tree.Configuration.LinkLineSize;

            if (postActions != null)
            {
                postActions.Clear();
            }
            foreach (var child in children)
            {
                if (tree.Configuration.VerticalSpace > 0)
                {
                    GUILayout.Space(tree.Configuration.VerticalSpace);
                }

                childRect = child.OnInspectorGui();

                //horizontal link
                var linkWidth = childRect.x - linkStartX;

                if (!(linkWidth > 0))
                {
                    continue;
                }

                //child Y Center
                var childCenterY = childRect.y + childRect.size.y * .5f;

                //link
                var horizontalLink = new Rect(
                    linkStartX,
                    childCenterY - linkSize * .5f,
                    linkWidth,
                    linkSize);

                GUI.DrawTexture(horizontalLink, texture, ScaleMode.StretchToFill);

                //icon
                var iconSize = tree.Configuration.ExpandCollapseIconSize;
                if (iconSize > 0 && child.HasChildren)
                {
                    BGEditorUtility.Assign(ref buttonStyle, () => new GUIStyle("Button")
                    {
                        margin  = new RectOffset(),
                        padding = new RectOffset(),
                        border  = new RectOffset()
                    });

                    postActions = postActions ?? new List <Action>();
                    var childRef = child;
                    postActions.Add(() =>
                    {
                        var iconSizeHalf = iconSize * .5f;
                        if (GUI.Button(new Rect(
                                           linkStartX - iconSizeHalf + linkSize * .5f,
                                           childCenterY - iconSizeHalf + linkSize * .5f,
                                           iconSize,
                                           iconSize),
                                       childRef.Collapsed ? tree.CollapsedIconTexture : tree.ExpandedIconTexture, buttonStyle))
                        {
                            childRef.Collapsed = !childRef.Collapsed;
                        }
                    });
                }
            }

            if (linkStartX < childRect.x)
            {
                //vertical link
                GUI.DrawTexture(new Rect(
                                    linkStartX,
                                    myRect.yMax,
                                    linkSize,
                                    childRect.center.y - myRect.yMax
                                    ), texture, ScaleMode.StretchToFill);
            }


            if (postActions != null && postActions.Count > 0)
            {
                foreach (var postAction in postActions)
                {
                    postAction();
                }
            }

            return(myRect);
        }
Beispiel #9
0
                //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 #10
0
        // ================================================================================ 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));
            BGEditorUtility.Assign(ref handlesOnTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHandlesOn123));
            BGEditorUtility.Assign(ref handlesOffTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHandlesOff123));


            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();

                // turn on/off handles
                if (BGEditorUtility.ButtonWithIcon(BGCurveSettingsForEditor.CcInspectorHandlesOff ? handlesOffTexture : handlesOnTexture, "Turn on/off handles settings in Inspector"))
                {
                    BGCurveSettingsForEditor.CcInspectorHandlesOff = !BGCurveSettingsForEditor.CcInspectorHandlesOff;
                }
                EditorGUILayout.Separator();

                // turn on/off colored tree
                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)
                {
                    // collapse/expand
                    if (BGEditorUtility.ButtonWithIcon(collapseTexture, "Collapse all components"))
                    {
                        tree.ExpandCollapseAll(true);
                    }
                    EditorGUILayout.Separator();
                    if (BGEditorUtility.ButtonWithIcon(expandTexture, "Expand all components"))
                    {
                        tree.ExpandCollapseAll(false);
                    }
                    EditorGUILayout.Separator();


                    // delete all Ccs
                    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();
                }

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


            if (length > 0)
            {
                // warnings/errors
                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 GUI
                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();
            }
        }
        protected override void InternalOnInspectorGUI()
        {
            base.InternalOnInspectorGUI();

            // reusable labels
            BGEditorUtility.Assign(ref rotationFieldContent,
                                   () => new GUIContent("Rotation Field", "Rotation field to take a rotation from. Each point will have it's own rotation. Should be a Quaternion field."));
            BGEditorUtility.Assign(ref revolutionsFieldContent,
                                   () => new GUIContent("Revolutions Field", "Field to store additional revolutions around tangent. It should be an int field."));
            BGEditorUtility.Assign(ref clockwiseFieldContent,
                                   () => new GUIContent("Revolutions Clockwise Field", "Field to store if the rotation around tangent should be clockwise. It should be a bool field."));
//            BGEditorUtility.Assign(ref customUpFieldContent,
//                () => new GUIContent("Custom up Vector", "Field to store custom up vector. It should be a Vector3 field."));


            //type of the rotation 1) tangent (without field) 2) by field's values
            BGEditorUtility.VerticalBox(() =>
            {
                BGEditorUtility.CustomField(rotationFieldContent, cc.Curve, ObjectRotate.RotationField, BGCurvePointField.TypeEnum.Quaternion, field => ObjectRotate.RotationField = field);

                if (ObjectRotate.RotationField != null)
                {
                    //============================== field is used

                    BGEditorUtility.VerticalBox(() =>
                    {
                        // additional revolutions
                        BGEditorUtility.CustomField(revolutionsFieldContent, cc.Curve, ObjectRotate.RevolutionsAroundTangentField, BGCurvePointField.TypeEnum.Int,
                                                    field => ObjectRotate.RevolutionsAroundTangentField = field);
                        if (ObjectRotate.RevolutionsAroundTangentField == null)
                        {
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("revolutionsAroundTangent"));
                        }

                        // clockwise?
                        BGEditorUtility.CustomField(clockwiseFieldContent, cc.Curve, ObjectRotate.RevolutionsClockwiseField,
                                                    BGCurvePointField.TypeEnum.Bool, field => ObjectRotate.RevolutionsClockwiseField = field);

                        if (ObjectRotate.RevolutionsClockwiseField == null)
                        {
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("revolutionsClockwise"));
                        }
                    });
                }
                else
                {
                    //============================== no field- tangent is used
                    BGEditorUtility.VerticalBox(() =>
                    {
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("upMode"));
                        switch (ObjectRotate.UpMode)
                        {
                        case BGCcCursorObjectRotate.RotationUpEnum.WorldCustom:
                        case BGCcCursorObjectRotate.RotationUpEnum.LocalCustom:
                        case BGCcCursorObjectRotate.RotationUpEnum.TargetParentUpCustom:
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("upCustom"));
                            break;
//                            case BGCcCursorObjectRotate.RotationUpEnum.CustomField:
//                                EditorGUILayout.PropertyField(serializedObject.FindProperty("upCustomField"));
//                                break;
                        }
                    });
                }
            });


            //interpolation
            BGEditorUtility.VerticalBox(() =>
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("rotationInterpolation"));

                switch (ObjectRotate.RotationInterpolation)
                {
                case BGCcCursorObjectRotate.RotationInterpolationEnum.Lerp:
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("lerpSpeed"));
                    break;

                case BGCcCursorObjectRotate.RotationInterpolationEnum.Slerp:
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("slerpSpeed"));
                    break;
                }
            });

            EditorGUILayout.PropertyField(serializedObject.FindProperty("offsetAngle"));
        }
Beispiel #12
0
            public override void OnInspectorGuiInternal(int level)
            {
                const int offset = 2;

                if (singleAndAdded)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button("", GUILayout.Height(IconSize + offset * 2)))
                {
                    action(ccData.Type);
                    instance.Close();
                }
                if (singleAndAdded)
                {
                    GUI.enabled = true;
                }

                // Draw on top of the button (no more Layout stuff)
                var buttonRect = GUILayoutUtility.GetLastRect();


                var iconRect = new Rect(buttonRect.x + offset, buttonRect.y + offset, IconSize, IconSize);

                GUI.DrawTexture(iconRect, ccData.Icon);

/*
 *              //already added
 *              if (singleAndAdded) GUI.DrawTexture(new Rect(iconRect) {x = iconRect.xMax + offset, width = offset*8},
 *                      BGEUtil.Assign(ref addIcon, () => BGEUtil.LoadTexture2D(BGEUtil.Image.BGCcAdded123)));
 */
                if (singleAndAdded)
                {
                    var oldMatrix = GUI.matrix;
                    BGEditorUtility.Assign(ref addedStyle, () => new GUIStyle("Box")
                    {
                        fontSize  = 14,
                        fontStyle = FontStyle.Bold,
                        normal    = { textColor = Color.red, background = BGEditorUtility.Texture1X1(new Color(1, 0, 0, .2f)) }
                    });
                    var content    = new GUIContent("added");
                    var labelSize  = addedStyle.CalcSize(content);
                    var pivotPoint = new Vector2(iconRect.xMax, iconRect.center.y) + new Vector2(labelSize.y * .5f, 0);
                    GUIUtility.RotateAroundPivot(-90, pivotPoint);
                    GUI.Label(new Rect(pivotPoint - labelSize * .5f, labelSize), content, addedStyle);
                    GUI.matrix = oldMatrix;
                }


                //name
                var nameStartX = iconRect.xMax + offset * 12;
                var nameRect   = new Rect(nameStartX, iconRect.y, buttonRect.width - nameStartX, IconSize / 3f);

                EditorGUI.LabelField(nameRect, ccData.Name, BGEditorUtility.Assign(ref nameStyle, () => new GUIStyle("Label")
                {
                    fontStyle = FontStyle.Bold
                }));

                //description
                var descriptionRect = new Rect(nameStartX, nameRect.yMax + offset, nameRect.width, IconSize * 2 / 3f);

                EditorGUI.LabelField(descriptionRect, ccData.Description, BGEditorUtility.Assign(ref descriptionStyle, () => new GUIStyle("Label")
                {
                    wordWrap = true
                }));
            }