示例#1
0
        static void ShowAnimationNodeTypesMenu()
        {
            RuntimeGenericMenu menu = new RuntimeGenericMenu();

            if (DashEditorCore.EditorConfig.editingGraph != null)
            {
                Type[] nodeTypes = ReflectionUtils.GetAllTypes(typeof(NodeBase)).ToArray();
                foreach (Type type in nodeTypes)
                {
                    CategoryAttribute attribute = type.GetCustomAttribute <CategoryAttribute>();
                    if (attribute == null || attribute.type != NodeCategoryType.ANIMATION)
                    {
                        continue;
                    }

                    TooltipAttribute tooltipAttribute = type.GetCustomAttribute <TooltipAttribute>();
                    string           tooltip          = tooltipAttribute != null ? tooltipAttribute.help : "";

                    string node = type.ToString().Substring(type.ToString().IndexOf(".") + 1);
                    node = node.Substring(0, node.Length - 4);

                    menu.AddItem(new GUIContent(node, tooltip), false, CreateAnimationNodesFromSelection, type);
                }
            }

            GenericMenuPopup.Show(menu, "", Event.current.mousePosition, 240, 300, false);
        }
示例#2
0
        public static void Show(DashGraph p_graph)
        {
            RuntimeGenericMenu menu = new RuntimeGenericMenu();

            menu.AddItem(new GUIContent("Settings/Show Experimental"), DashEditorCore.EditorConfig.showExperimental, () => DashEditorCore.EditorConfig.showExperimental = !DashEditorCore.EditorConfig.showExperimental);
            menu.AddItem(new GUIContent("Settings/Show Obsolete"), DashEditorCore.EditorConfig.showObsolete, () => DashEditorCore.EditorConfig.showObsolete             = !DashEditorCore.EditorConfig.showObsolete);
            menu.AddItem(new GUIContent("Settings/Show Node Ids"), DashEditorCore.EditorConfig.showNodeIds, () => DashEditorCore.EditorConfig.showNodeIds          = !DashEditorCore.EditorConfig.showNodeIds);
            menu.AddItem(new GUIContent("Settings/Show Node Search"), DashEditorCore.EditorConfig.showNodeSearch, () => DashEditorCore.EditorConfig.showNodeSearch = !DashEditorCore.EditorConfig.showNodeSearch);
            menu.AddItem(new GUIContent("Settings/Show Node Asynchronity"), DashEditorCore.EditorConfig.showNodeAsynchronity, () => DashEditorCore.EditorConfig.showNodeAsynchronity = !DashEditorCore.EditorConfig.showNodeAsynchronity);
            menu.AddItem(new GUIContent("Settings/Enable Sound in Editor"), DashEditorCore.EditorConfig.enableSoundInPreview, () => DashEditorCore.EditorConfig.enableSoundInPreview = !DashEditorCore.EditorConfig.enableSoundInPreview);
            menu.AddItem(new GUIContent("Settings/Enable AnimateNode Interface"), DashEditorCore.EditorConfig.enableAnimateNodeInterface, () => DashEditorCore.EditorConfig.enableAnimateNodeInterface = !DashEditorCore.EditorConfig.enableAnimateNodeInterface);

            menu.AddSeparator("");
            //menu.AddItem(new GUIContent("Advanced/Validate Serialization"), false, p_graph.ValidateSerialization);
            menu.AddItem(new GUIContent("Advanced/Cleanup Null"), false, p_graph.RemoveNullReferences);
            //menu.AddItem(new GUIContent("Advanced/Cleanup Exposed"), false, p_graph.CleanupExposedReferenceTable);

            menu.AddItem(new GUIContent("Reset Graph Position"), false, p_graph.ResetPosition);

            menu.AddItem(new GUIContent("Help"), false, () =>
            {
                Application.OpenURL("https://github.com/pshtif/Dash/tree/main/Documentation");
            });

            //menu.ShowAsEditorMenu();
            GenericMenuPopup.Show(menu, "Preferences", Event.current.mousePosition, 240, 300, false, false);
        }
示例#3
0
        public static void VariableField(DashVariables p_variables, string p_name, GameObject p_boundObject, float p_maxWidth)
        {
            var variable = p_variables.GetVariable(p_name);

            GUILayout.BeginHorizontal();
            string newName = EditorGUILayout.TextField(p_name, GUILayout.Width(120));

            GUILayout.Space(2);
            if (newName != p_name)
            {
                p_variables.RenameVariable(p_name, newName);
            }

            variable.ValueField(p_maxWidth - 150, p_boundObject);

            var oldColor = GUI.color;

            GUI.color = variable.IsBound || variable.IsLookup ? Color.yellow : Color.gray;

            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical(GUILayout.Width(16));
            GUILayout.Space(2);
            if (GUILayout.Button(IconManager.GetIcon("bind_icon"), GUIStyle.none, GUILayout.Height(16), GUILayout.Width(16)))
            {
                var menu = GetVariableMenu(p_variables, p_name, p_boundObject);
                GenericMenuPopup.Show(menu, "", Event.current.mousePosition, 240, 300, false, false);
            }
            GUILayout.EndVertical();

            GUI.color = oldColor;

            GUILayout.EndHorizontal();
        }
示例#4
0
        static public void Show(GraphBox p_region)
        {
            RuntimeGenericMenu menu = new RuntimeGenericMenu();

            menu.AddItem(new GUIContent("Delete Box"), false, DeleteBox, p_region);

            //menu.ShowAsContext();
            GenericMenuPopup.Show(menu, "", Event.current.mousePosition, 200, 300, false, false);
        }
示例#5
0
        public static void Show(DashGraph p_graph)
        {
            RuntimeGenericMenu menu = new RuntimeGenericMenu();

            menu.AddItem(new GUIContent("Import JSON"), false, () => GraphUtils.ImportJSON(p_graph));
            menu.AddItem(new GUIContent("Export JSON"), false, () => GraphUtils.ExportJSON(p_graph));

            //menu.ShowAsContext();
            GenericMenuPopup.Show(menu, "File", Event.current.mousePosition, 240, 300, false, false);
        }
示例#6
0
        static public void Show(NodeConnection p_connection)
        {
            RuntimeGenericMenu menu = new RuntimeGenericMenu();

            if (p_connection.active)
            {
                menu.AddItem(new GUIContent("Deactivate Connection"), false, DeactivateConnection, p_connection);
            }
            else
            {
                menu.AddItem(new GUIContent("Activate Connection"), false, ActivateConnection, p_connection);
            }

            menu.AddItem(new GUIContent("Delete Connection"), false, DeleteConnection, p_connection);

            //menu.ShowAsContext();
            GenericMenuPopup.Show(menu, "", Event.current.mousePosition, 200, 300, false, false);
        }
示例#7
0
        static public void ShowAsPopup()
        {
            _lastMousePosition = Event.current.mousePosition;

            GenericMenuPopup.Show(Get(), "Create Node", _lastMousePosition, 240, 300);
        }
示例#8
0
        public static void Show(NodeBase p_node)
        {
            RuntimeGenericMenu menu = new RuntimeGenericMenu();

            if (SelectionManager.SelectedCount > 1)
            {
                menu.AddItem(new GUIContent("Copy Nodes"), false, CopyNode, null);
                menu.AddItem(new GUIContent("Delete Nodes"), false, DeleteNode, null);
                menu.AddItem(new GUIContent("Duplicate Nodes"), false, DuplicateNode, null);
                menu.AddItem(new GUIContent("Create Box"), false, CreateBox);
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Create SubGraph"), false, CreateSubGraph, null);
            }
            else
            {
                menu.AddItem(new GUIContent("Copy Node"), false, CopyNode, p_node);
                menu.AddItem(new GUIContent("Delete Node"), false, DeleteNode, p_node);
                menu.AddItem(new GUIContent("Duplicate Node"), false, DuplicateNode, p_node);

                menu.AddSeparator("");
                if (p_node.HasComment())
                {
                    menu.AddItem(new GUIContent("Remove Comment"), false, p_node.RemoveComment);
                }
                else
                {
                    menu.AddItem(new GUIContent("Create Comment"), false, p_node.CreateComment);
                }

                menu.AddSeparator("");
                if (p_node is SubGraphNode)
                {
                    menu.AddItem(new GUIContent("Unpack SubGraph"), false, UnpackSubGraph, p_node);
                }

                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Set as Preview"), false, SetAsPreview, p_node);
                menu.AddItem(new GUIContent("Instant Preview"), false, InstantPreview, p_node);

                var controller = DashEditorCore.EditorConfig.editingController;
                if (p_node is InputNode && controller != null)
                {
                    InputNode node = p_node as InputNode;
                    menu.AddSeparator("");
                    if (!controller.autoStart || controller.autoStartInput != node.Model.inputName)
                    {
                        menu.AddItem(new GUIContent("Set as Start Input"), false, SetAsStartInput, p_node);
                    }
                    else
                    {
                        menu.AddItem(new GUIContent("Remove as Start Input"), false, RemoveAsStartInput, p_node);
                    }

                    if (!controller.autoOnEnable || controller.autoOnEnableInput != node.Model.inputName)
                    {
                        menu.AddItem(new GUIContent("Set as OnEnable Input"), false, SetAsOnEnableInput, p_node);
                    }
                    else
                    {
                        menu.AddItem(new GUIContent("Remove as OnEnable Input"), false, RemoveAsOnEnableInput, p_node);
                    }
                }
            }

            menu.AddSeparator("");

            if (!SelectionManager.selectedNodes.Contains(Graph.Nodes.IndexOf(p_node)))
            {
                menu.AddItem(new GUIContent("Connect Selection as Output"), false, ConnectSelectionAsOutput, p_node);
                menu.AddItem(new GUIContent("Connect Selection as Input"), false, ConnectSelectionAsInput, p_node);
            }

            ((INodeAccess)p_node).GetCustomContextMenu(ref menu);

            //menu.ShowAsEditorMenu();
            GenericMenuPopup.Show(menu, "", Event.current.mousePosition, 240, 300, false, false);
        }
示例#9
0
        protected override void OnGUISelf(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            var labelPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

            EditorGUI.LabelField(labelPosition, label);

            var attribute = (SerializeReferenceDrawerAttribute)Decorator;
            var filters   = GetAllBuiltInTypeRestrictions();

            var(renamePattern, renameReplacement) = attribute.RenamePatter.ParseReplaceRegex();
            var categoryMethodInfo = attribute.CategoryName == null ? null : property.GetSiblingMethodInfo(attribute.CategoryName);
            var categoryFunc       = categoryMethodInfo == null
                ? null
                : (Func <Type, string>)categoryMethodInfo.CreateDelegate(typeof(Func <Type, string>), property.serializedObject.targetObject)
            ;

            var isNullable = string.IsNullOrEmpty(attribute.NullableVariable) ? attribute.Nullable : (bool)property.GetSiblingValue(attribute.NullableVariable);

            DrawSelectionButtonForManagedReference();

            EditorGUI.PropertyField(position, property, GUIContent.none, true);

            EditorGUI.EndProperty();

            IEnumerable <Func <Type, bool> > GetAllBuiltInTypeRestrictions()
            {
                var result = new List <Func <Type, bool> >();

                if (!string.IsNullOrEmpty(attribute.TypeRestrictBySiblingProperty))
                {
                    var baseType     = property.GetSiblingPropertyInfo(attribute.TypeRestrictBySiblingProperty).PropertyType;
                    var derivedTypes = TypeCache.GetTypesDerivedFrom(baseType);
                    result.Add(derivedTypes.Contains);
                }

                if (!string.IsNullOrEmpty(attribute.TypeRestrictBySiblingTypeName))
                {
                    var baseType     = Type.GetType((string)property.GetSiblingValue(attribute.TypeRestrictBySiblingTypeName));
                    var derivedTypes = TypeCache.GetTypesDerivedFrom(baseType);
                    result.Add(derivedTypes.Contains);
                }

                return(result);
            }

            void DrawSelectionButtonForManagedReference()
            {
                var buttonPosition = position;

                buttonPosition.x     += EditorGUIUtility.labelWidth + 1 * EditorGUIUtility.standardVerticalSpacing;
                buttonPosition.width  = position.width - EditorGUIUtility.labelWidth - 1 * EditorGUIUtility.standardVerticalSpacing;
                buttonPosition.height = EditorGUIUtility.singleLineHeight;

                var referenceType = GetTypeFromName(property.managedReferenceFullTypename);

                var storedIndent = EditorGUI.indentLevel;

                EditorGUI.indentLevel = 0;
                var storedColor = GUI.backgroundColor;

                GUI.backgroundColor = !isNullable && referenceType == null ? new Color(1, 0, 0) : new Color(0.1f, 0.55f, 0.9f, 1f);

                var content = referenceType == null ? new GUIContent("Null ( Assign )") : MakeContent(referenceType);

                if (GUI.Button(buttonPosition, content))
                {
                    ShowContextMenuForManagedReference();
                }

                GUI.backgroundColor   = storedColor;
                EditorGUI.indentLevel = storedIndent;

                void ShowContextMenuForManagedReference()
                {
                    var context = new GenericMenu();

                    FillContextMenu(context);
                    var popup = GenericMenuPopup.Get(context, "");

                    popup.showSearch      = true;
                    popup.showTooltip     = false;
                    popup.resizeToContent = true;
                    popup.Show(new Vector2(buttonPosition.x, buttonPosition.y));
                }
            }

            void FillContextMenu(GenericMenu contextMenu)
            {
                // Adds "Make Null" menu command
                if (isNullable)
                {
                    contextMenu.AddItem(new GUIContent("Null"), false, SetManagedReferenceToNull);
                }

                // Collects appropriate types
                var appropriateTypes = GetAppropriateTypesForAssigningToManagedReference();

                // Adds appropriate types to menu
                var typeContentMap =
                    from type in appropriateTypes
                    select(type, content : MakeContent(type))
                ;

                if (attribute.AlphabeticalOrder)
                {
                    typeContentMap = typeContentMap.OrderBy(t => t.content.text);
                }
                foreach (var(type, content) in typeContentMap)
                {
                    contextMenu.AddItem(content, false, AssignNewInstanceCommand, type);
                }
            }

            void SetManagedReferenceToNull()
            {
                property.serializedObject.Update();
                property.managedReferenceValue = null;
                property.serializedObject.ApplyModifiedProperties();
            }

            void AssignNewInstanceCommand(object typeObject)
            {
                var type = (Type)typeObject;

                if (type == property.GetObject()?.GetType())
                {
                    return;
                }

                var instance = Activator.CreateInstance(type);

                property.serializedObject.Update();
                property.managedReferenceValue = instance;
                property.serializedObject.ApplyModifiedProperties();
            }

            GUIContent MakeContent(Type type)
            {
                var entryName = type.FullName;

                if (renamePattern != null)
                {
                    entryName = renamePattern.Replace(entryName, renameReplacement);
                }
                if (attribute.DisplayAssemblyName)
                {
                    entryName += "  ( " + type.Assembly.GetName().Name + " )";
                }
                if (categoryFunc != null)
                {
                    var category = categoryFunc(type);
                    if (!string.IsNullOrEmpty(category))
                    {
                        entryName = category + "/" + entryName;
                    }
                }
                return(new GUIContent(entryName, $"{type.FullName} ( {type.Assembly.GetName().Name} )"));
            }

            IEnumerable <Type> GetAppropriateTypesForAssigningToManagedReference()
            {
                var fieldType        = GetTypeFromName(property.managedReferenceFieldTypename);
                var appropriateTypes = new List <Type>();

                if (fieldType == null)
                {
                    return(appropriateTypes);
                }

                // Get and filter all appropriate types
                var derivedTypes = TypeCache.GetTypesDerivedFrom(fieldType);

                foreach (var type in derivedTypes)
                {
                    // Skips unity engine Objects (because they are not serialized by SerializeReference)
                    if (type.IsSubclassOf(typeof(UnityEngine.Object)))
                    {
                        continue;
                    }
                    // Skip abstract classes because they should not be instantiated
                    if (type.IsAbstract)
                    {
                        continue;
                    }
                    if (type.IsGenericType)
                    {
                        continue;
                    }
                    if (!type.IsPublic && !type.IsNestedPublic)
                    {
                        continue;
                    }
                    // Skip types that has no public empty constructors (activator can not create them)
                    if (type.IsClass && type.GetConstructor(Type.EmptyTypes) == null) // Structs still can be created (strangely)
                    {
                        continue;
                    }
                    // Filter types by provided filters if there is ones
                    if (filters != null && filters.All(f => f == null || f.Invoke(type)) == false)
                    {
                        continue;
                    }

                    appropriateTypes.Add(type);
                }

                return(appropriateTypes);
            }

            Type GetTypeFromName(string fullName)
            {
                var names = fullName.Split(' ');

                return(names.Length != 2 ? null : Type.GetType($"{names[1]}, {names[0]}"));
            }
        }
示例#10
0
        static public void ShowAsPopup(Action <object> p_callback)
        {
            _lastMousePosition = Event.current.mousePosition;

            GenericMenuPopup.Show(Get(p_callback), "Select Type", _lastMousePosition, 300, 300, true, false);
        }
示例#11
0
        protected override void OnGUISelf(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType != SerializedPropertyType.String)
            {
                EditorGUI.PropertyField(position, property, label, true);
                return;
            }

            property.serializedObject.Update();

            position.height = EditorGUIUtility.singleLineHeight;
            EditorGUI.LabelField(position, label);

            position.x    += EditorGUIUtility.labelWidth + 1 * EditorGUIUtility.standardVerticalSpacing;
            position.width = position.width - EditorGUIUtility.labelWidth - 1 * EditorGUIUtility.standardVerticalSpacing;

            var attribute = (SerializedTypeAttribute)Decorator;

            var(renamePattern, renameReplacement) = attribute.RenamePatter.ParseReplaceRegex();
            var self = property.GetDeclaringObject();
            var categoryMethodInfo = attribute.CategoryName == null ? null : property.GetSiblingMethodInfo(attribute.CategoryName);
            var categoryFunc       = categoryMethodInfo == null
                ? null
                : (Func <Type, string>)categoryMethodInfo.CreateDelegate(typeof(Func <Type, string>), self)
            ;
            var whereMethodInfo = attribute.Where == null ? null : property.GetSiblingMethodInfo(attribute.Where);
            var whereFunc       = whereMethodInfo == null
                ? type => true
                : (Func <Type, bool>)whereMethodInfo.CreateDelegate(typeof(Func <Type, bool>), self)
            ;

            ShowButton();

            void ShowButton()
            {
                // var buttonPosition = position;
                // buttonPosition.x += EditorGUIUtility.labelWidth + 1 * EditorGUIUtility.standardVerticalSpacing;
                // buttonPosition.width = position.width - EditorGUIUtility.labelWidth - 1 * EditorGUIUtility.standardVerticalSpacing;
                // buttonPosition.height = EditorGUIUtility.singleLineHeight;

                var type = Type.GetType(property.stringValue);

                var storedColor = GUI.backgroundColor;

                GUI.backgroundColor = attribute.Nullable == false && type == null ? new Color(1, 0, 0) : new Color(0.1f, 0.55f, 0.9f, 1f);

                var content = type == null ? new GUIContent("Null ( Assign )") : MakeContent(type);

                if (GUI.Button(position, content))
                {
                    ShowContextMenuForManagedReference();
                }

                GUI.backgroundColor = storedColor;
                // EditorGUI.indentLevel = storedIndent;

                // EditorGUI.DropdownButton(position, label, FocusType.Passive);
                // if (_options == null)
                // {
                //     var baseType = ((SerializedTypeAttribute) Decorator).BaseType;
                //     _options = TypeCache.GetTypesDerivedFrom(baseType).Select(type => type.AssemblyQualifiedName).ToArray();
                // }
                // property.PopupFunc()(position, label.text, _options);
            }

            GUIContent MakeContent(Type type)
            {
                var entryName = type.FullName;

                if (renamePattern != null)
                {
                    entryName = renamePattern.Replace(entryName, renameReplacement);
                }
                if (attribute.DisplayAssemblyName)
                {
                    entryName += "  ( " + type.Assembly.GetName().Name + " )";
                }
                if (categoryFunc != null)
                {
                    var category = categoryFunc(type);
                    if (!string.IsNullOrEmpty(category))
                    {
                        entryName = category + "/" + entryName;
                    }
                }
                return(new GUIContent(entryName, $"{type.FullName} ( {type.Assembly.GetName().Name} )"));
            }

            void ShowContextMenuForManagedReference()
            {
                var context = new GenericMenu();

                FillContextMenu(context);
                var popup = GenericMenuPopup.Get(context, "");

                popup.showSearch      = true;
                popup.showTooltip     = false;
                popup.resizeToContent = true;
                popup.Show(new Vector2(position.x, position.y));
            }

            void FillContextMenu(GenericMenu contextMenu)
            {
                // Adds "Make Null" menu command
                if (attribute.Nullable)
                {
                    contextMenu.AddItem(new GUIContent("Null"), false, SetNull);
                }

                // Collects appropriate types
                var appropriateTypes = GetAppropriateTypesForAssigningToManagedReference();

                // Adds appropriate types to menu
                var typeContentMap =
                    from type in appropriateTypes
                    select(type, content : MakeContent(type))
                ;

                if (attribute.AlphabeticalOrder)
                {
                    typeContentMap = typeContentMap.OrderBy(t => t.content.text);
                }
                foreach (var(type, content) in typeContentMap)
                {
                    contextMenu.AddItem(content, false, AssignNewInstanceCommand, type);
                }
            }

            void SetNull()
            {
                property.serializedObject.Update();
                property.stringValue = "";
                property.serializedObject.ApplyModifiedProperties();
            }

            void AssignNewInstanceCommand(object typeObject)
            {
                var type = (Type)typeObject;

                if (type == property.GetObject()?.GetType())
                {
                    return;
                }

                property.serializedObject.Update();
                property.stringValue = type.AssemblyQualifiedName;
                property.serializedObject.ApplyModifiedProperties();
            }

            IEnumerable <Type> GetAppropriateTypesForAssigningToManagedReference()
            {
                var baseType = attribute.BaseType ?? typeof(object);

                return(TypeCache.GetTypesDerivedFrom(baseType).Where(whereFunc));
            }
        }