コード例 #1
0
        public NodeMenuItem[] AddNodeMenuItems(NodeMachineModel model, Vector2 mousePosition, NodeMachineEditor editor)
        {
            HashSet <Type>         types     = LoadStateTypes(model);
            HashSet <NodeMenuItem> menuItems = new HashSet <NodeMenuItem>();
            int stateCount = 0;

            foreach (Type type in types)
            {
                foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    StateAttribute methodStateInfo = method.GetCustomAttribute <StateAttribute>();
                    if (methodStateInfo != null)
                    {
                        if (!methodStateInfo.Visible)
                        {
                            continue;
                        }
                        stateCount++;
                        bool runOnEncounter = methodStateInfo.RunOnEncounter;
                        menuItems.Add(new NodeMenuItem("States/" + type.ToString() + "/" + method.Name, () => {
                            StateNode node      = new StateNode(type, method.Name, model, mousePosition);
                            node.runOnEncounter = runOnEncounter;
                            editor.AddNode(node);
                        }, false, false));
                    }
                }
            }
            if (stateCount == 0)
            {
                menuItems.Add(new NodeMenuItem("States", null, false, true));
            }
            return(menuItems.ToArray());
        }
コード例 #2
0
        public NodeMenuItem[] AddNodeMenuItems(NodeMachineModel model, Vector2 mousePosition, NodeMachineEditor editor)
        {
            HashSet <Type>         types     = StateNodeMenuHandler.LoadStateTypes(model);
            HashSet <NodeMenuItem> menuItems = new HashSet <NodeMenuItem>();
            int eventCount = 0;

            foreach (Type type in types)
            {
                foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    EventAttribute methodEventInfo = method.GetCustomAttribute <EventAttribute>();
                    if (methodEventInfo != null)
                    {
                        eventCount++;
                        menuItems.Add(new NodeMenuItem("Events/" + type.ToString() + "/" + method.Name, () => {
                            EventNode node = new EventNode(type, method.Name, model, mousePosition);
                            editor.AddNode(node);
                        }, false, false));
                    }
                }
            }
            if (eventCount == 0)
            {
                menuItems.Add(new NodeMenuItem("Events", null, false, true));
            }
            return(menuItems.ToArray());
        }
コード例 #3
0
        public NodeMenuItem[] AddNodeMenuItems(NodeMachineModel model, Vector2 mousePosition, NodeMachineEditor editor)
        {
            NodeMenuItem menuItem;

            if (model.machinePropsSchema.Count > 0)
            {
                menuItem = new NodeMenuItem("Conditional/Condition", () =>
                {
                    // TODO : CONDITIONS AND PROPERTIES WITH NO STANDARD TYPES???
                    KeyValuePair <string, Type> kvp      = model.machinePropsSchema.First();
                    Condition.ConditionType?tryParseType = Condition.ParseConditionType(kvp.Value);
                    if (tryParseType == null)
                    {
                        EditorUtility.DisplayDialog("Error", "There was an error while creating the condition!", "OK");
                        return;
                    }
                    Condition.ConditionType fieldType = (Condition.ConditionType)tryParseType;
                    string fieldName    = kvp.Key;
                    Condition condition = new Condition(fieldName, fieldType, Condition.Comparison.EQUAL, Condition.GetDefaultValue(fieldType, kvp.Value));
                    ConditionNode node  = new ConditionNode(editor._model, condition, mousePosition);
                    editor.AddNode(node);
                }, false, false);
            }
            else
            {
                menuItem = new NodeMenuItem("Conditional/Condition", null, false, true);
            }

            NodeMenuItem[] menuItems = { menuItem };
            return(menuItems);
        }