Пример #1
0
        public static object RangeRealDrawer(object obj, InvokeWrapper wrapper, GUISkin skin)
        {
            var      value      = wrapper.Get <RangeReal>(obj);
            GUIStyle labelStyle = skin.label;

            if (value.Min > value.Max)
            {
                if (m_rangeRealInvalidStyle == null)
                {
                    m_rangeRealInvalidStyle = new GUIStyle(skin.label);
                    m_rangeRealInvalidStyle.normal.background = GUI.CreateColoredTexture(4, 4, Color.Lerp(UnityEngine.GUI.color, Color.red, 0.75f));
                }
                labelStyle = m_rangeRealInvalidStyle;
            }

            RangeRealResult result = new RangeRealResult()
            {
                Min        = value.Min,
                MinChanged = false,
                Max        = value.Max,
                MaxChanged = false
            };

            using (new GUILayout.HorizontalScope(labelStyle)) {
                GUILayout.Label(MakeLabel(wrapper.Member), skin.label);
                result.Min              = EditorGUILayout.FloatField("", value.Min, skin.textField, GUILayout.MaxWidth(64));
                result.MinChanged       = UnityEngine.GUI.changed;
                UnityEngine.GUI.changed = false;
                result.Max              = EditorGUILayout.FloatField("", value.Max, skin.textField, GUILayout.MaxWidth(64));
                result.MaxChanged       = UnityEngine.GUI.changed;
                UnityEngine.GUI.changed = result.MinChanged || result.MaxChanged;
            }

            if (labelStyle == m_rangeRealInvalidStyle)
            {
                GUI.WarningLabel("Invalid range, Min > Max: (" + value.Min + " > " + value.Max + ")", skin);
            }

            return(result);
        }
Пример #2
0
        private void RouteGUI()
        {
            var      skin             = InspectorEditor.Skin;
            GUIStyle invalidNodeStyle = new GUIStyle(skin.label);

            invalidNodeStyle.normal.background = GUI.CreateColoredTexture(4, 4, Color.Lerp(UnityEngine.GUI.color, Color.red, 0.75f));

            bool  addNewPressed       = false;
            bool  insertBeforePressed = false;
            bool  insertAfterPressed  = false;
            bool  erasePressed        = false;
            NodeT listOpNode          = null;

            Undo.RecordObject(Route, "Route changed");

            GUI.Separator();

            if (GUI.Foldout(EditorData.Instance.GetData(Parent, "Route", (entry) => { entry.Bool = true; }), GUI.MakeLabel("Route", true), skin))
            {
                GUI.Separator();

                Route <NodeT> .ValidatedRoute validatedRoute = Route.GetValidated();
                foreach (var validatedNode in validatedRoute)
                {
                    var node = validatedNode.Node;
                    using (new GUI.Indent(12)) {
                        if (validatedNode.Valid)
                        {
                            GUILayout.BeginVertical();
                        }
                        else
                        {
                            GUILayout.BeginVertical(invalidNodeStyle);
                        }

                        if (GUI.Foldout(GetFoldoutData(node),
                                        GUI.MakeLabel(GetNodeTypeString(node) + " | " + SelectGameObjectDropdownMenuTool.GetGUIContent(node.Parent).text,
                                                      !validatedNode.Valid,
                                                      validatedNode.ErrorString),
                                        skin,
                                        newState =>
                        {
                            Selected = newState ? node : null;
                            EditorUtility.SetDirty(Parent);
                        }))
                        {
                            OnPreFrameGUI(node, skin);

                            GUI.HandleFrame(node, 12);

                            OnPostFrameGUI(node, skin);

                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.FlexibleSpace();

                                using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.1f))) {
                                    insertBeforePressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementBefore.ToString(),
                                                                                         16,
                                                                                         false,
                                                                                         "Insert a new node before this node"),
                                                                           skin.button,
                                                                           GUILayout.Width(20),
                                                                           GUILayout.Height(16)) || insertBeforePressed;
                                    insertAfterPressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementAfter.ToString(),
                                                                                        16,
                                                                                        false,
                                                                                        "Insert a new node after this node"),
                                                                          skin.button,
                                                                          GUILayout.Width(20),
                                                                          GUILayout.Height(16)) || insertAfterPressed;
                                }
                                using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.red, 0.1f)))
                                    erasePressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString(),
                                                                                  16,
                                                                                  false,
                                                                                  "Erase this node"),
                                                                    skin.button,
                                                                    GUILayout.Width(20),
                                                                    GUILayout.Height(16)) || erasePressed;

                                if (listOpNode == null && (insertBeforePressed || insertAfterPressed || erasePressed))
                                {
                                    listOpNode = node;
                                }
                            }
                            GUILayout.EndHorizontal();
                        }

                        GUILayout.EndVertical();

                        GUI.Separator();
                    }

                    if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) &&
                        Event.current.type == EventType.MouseDown &&
                        Event.current.button == 0)
                    {
                        Selected = node;
                    }
                }

                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();

                    using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.1f)))
                        addNewPressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementAfter.ToString(),
                                                                       16,
                                                                       false,
                                                                       "Add new node to route"),
                                                         skin.button,
                                                         GUILayout.Width(20),
                                                         GUILayout.Height(16));
                    if (listOpNode == null && addNewPressed)
                    {
                        listOpNode = Route.LastOrDefault();
                    }
                }
                GUILayout.EndHorizontal();
            }

            GUI.Separator();

            if (addNewPressed || insertBeforePressed || insertAfterPressed)
            {
                NodeT newRouteNode = null;
                // Clicking "Add" will not copy data from last node.
                newRouteNode = listOpNode != null?
                               addNewPressed?
                               RouteNode.Create <NodeT>(null, listOpNode.Position, listOpNode.Rotation) :
                                   RouteNode.Create <NodeT>(listOpNode.Parent, listOpNode.LocalPosition, listOpNode.LocalRotation) :
                                       RouteNode.Create <NodeT>();

                OnNodeCreate(newRouteNode, listOpNode, addNewPressed);

                if (addNewPressed)
                {
                    Route.Add(newRouteNode);
                }
                if (insertBeforePressed)
                {
                    Route.InsertBefore(newRouteNode, listOpNode);
                }
                if (insertAfterPressed)
                {
                    Route.InsertAfter(newRouteNode, listOpNode);
                }

                if (newRouteNode != null)
                {
                    CreateRouteNodeTool(newRouteNode);
                    Selected = newRouteNode;
                }
            }
            else if (listOpNode != null && erasePressed)
            {
                Selected = null;
                Route.Remove(listOpNode);
            }
        }