Ejemplo n.º 1
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            MultipurposeNode node = source as MultipurposeNode;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (ConditionNode n) => {
                n.Condition.AddBlockRange(BlockUtility.GetConditionBlockFromNode(source));
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
Ejemplo n.º 2
0
 public override bool IsValidNode(Node source)
 {
     if (source is MultipurposeNode)
     {
         MultipurposeNode node = source as MultipurposeNode;
         if (node.CanGetValue() && node.ReturnType() == typeof(bool))
         {
             if (node.IsFlowNode())
             {
                 var nodes = NodeEditorUtility.FindConnectedNodeToFlowNode(node);
                 if (nodes.Count > 0)
                 {
                     return(false);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        protected override void InitializeView()
        {
            base.InitializeView();
            MultipurposeNode node = targetNode as MultipurposeNode;

            if (UIElementGraph.richText && richTitle == null)
            {
                richTitle = new RichLabel {
                    name = "title-label"
                };
                titleContainer.Insert(titleContainer.IndexOf(titleIcon) + 1, richTitle);
            }
            if (richTitle != null)
            {
                titleContainer.AddToClassList("rich-title");
                title          = "";
                richTitle.text = uNodeUtility.GetNicelyDisplayName(node.target.target, uNodeUtility.preferredDisplay, true);
                m_Title        = uNodeEditorUtility.RemoveHTMLTag(richTitle.text);
            }
            isCompact = false;
            EnableInClassList("compact", false);
            EnableInClassList("compact-value", false);
            if (nodeFlowPort != null || outputControls.Count != 0)
            {
                if (uNodeUtility.preferredDisplay == DisplayKind.Partial)
                {
                    ConstructCompactTitle();
                }
                return;
            }
            if (inputControls.Count == 0)
            {
                int valueOutputCount = outputPorts.Count(x => x.orientation == Orientation.Horizontal);
                int valueInputCount  = inputPorts.Count(x => x.orientation == Orientation.Horizontal);
                if (valueOutputCount == 1 && valueInputCount == 0)
                {
                    isCompact = true;
                    EnableInClassList("compact", true);
                    if (nodeValuePort != null)
                    {
                        nodeValuePort.SetName("");
                    }
                }
            }
            else if (inputControls.Count > 0 && node.target.target.targetType == MemberData.TargetType.Values)
            {
                isCompact = true;
                ControlView control = inputControls.First();
                if (control.control as MemberControl != null)
                {
                    var config = control.control.config;
                    if (config.filter != null)
                    {
                        config.filter.ValidTargetType = MemberData.TargetType.Values;
                    }
                    if (config.type == typeof(string))
                    {
                        control.control.AddToClassList("multiline");
                        control.style.height   = new StyleLength(StyleKeyword.Auto);
                        control.style.flexGrow = 1;
                    }
                    (control.control as MemberControl).UpdateControl();
                }
                if (inputControls.Count == 1)
                {
                    EnableInClassList("compact-value", true);
                    if (nodeValuePort != null)
                    {
                        nodeValuePort.SetName("");
                    }
                }
            }
            if (isCompact && nodeValuePort != null)
            {
                Color c = uNodePreference.GetColorForType(nodeValuePort.GetPortType());
                c.a = 0.8f;
                elementTypeColor = c;
                if (UIElementUtility.Theme.coloredNodeBorder)
                {
                    border.style.SetBorderColor(c);
                }
            }
            else if (uNodeUtility.preferredDisplay == DisplayKind.Partial)
            {
                ConstructCompactTitle();
                if (nodeValuePort != null)
                {
                    EnableInClassList("compact-title", true);
                    Color c = uNodePreference.GetColorForType(nodeValuePort.GetPortType());
                    c.a = 0.8f;
                    elementTypeColor = c;
                    if (UIElementUtility.Theme.coloredNodeBorder)
                    {
                        border.style.SetBorderColor(c);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            var             rType  = source.ReturnType();
            FilterAttribute filter = new FilterAttribute {
                VoidType          = true,
                MaxMethodParam    = int.MaxValue,
                Public            = true,
                Instance          = true,
                Static            = false,
                UnityReference    = false,
                InvalidTargetType = MemberData.TargetType.Null | MemberData.TargetType.Values,
                // DisplayDefaultStaticType = false
                ValidateMember = (member) => {
                    if (member is System.Reflection.MethodInfo)
                    {
                        var parameters = (member as System.Reflection.MethodInfo).GetParameters();
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            if (rType.IsCastableTo(parameters[i].ParameterType))
                            {
                                return(true);
                            }
                        }
                    }
                    return(false);
                },
            };
            List <ItemSelector.CustomItem> customItems = null;

            if (rType.IsCastableTo(typeof(IGraphSystem)) && source is MultipurposeNode)
            {
                MultipurposeNode multipurposeNode = source as MultipurposeNode;
                if (multipurposeNode.target != null && multipurposeNode.target.target != null && (multipurposeNode.target.target.targetType == MemberData.TargetType.SelfTarget || multipurposeNode.target.target.targetType == MemberData.TargetType.Values))
                {
                    var sTarget = multipurposeNode.target.target.startTarget;
                    if (sTarget is IGraphSystem)
                    {
                        customItems = ItemSelector.MakeCustomItems(sTarget as Object);
                        customItems.AddRange(ItemSelector.MakeCustomItems(typeof(uNodeRoot), sTarget, filter, "Inherit Member"));
                    }
                }
            }
            bool flag = false;

            if (customItems == null)
            {
                if (rType is RuntimeType)
                {
                    customItems = ItemSelector.MakeCustomItems((rType as RuntimeType).GetRuntimeMembers(), filter);
                    if (rType.BaseType != null)
                    {
                        customItems.AddRange(ItemSelector.MakeCustomItems(rType.BaseType, filter, "Inherit Member"));
                    }
                }
                else
                {
                    customItems = ItemSelector.MakeCustomItems(rType, filter, " " + rType.PrettyName());
                }
                var usedNamespaces = source.owner.GetNamespaces().ToHashSet();
                if (usedNamespaces != null)
                {
                    customItems.AddRange(ItemSelector.MakeExtensionItems(rType, usedNamespaces, filter, "Extensions"));
                    flag = true;
                }

                var customInputItems = NodeEditorUtility.FindCustomInputPortItems();
                if (customInputItems != null && customInputItems.Count > 0)
                {
                    var mData = new MemberData(source, MemberData.TargetType.ValueNode);
                    foreach (var c in customInputItems)
                    {
                        c.graph = graph;
                        c.mousePositionOnCanvas = mousePositionOnCanvas;
                        if (c.IsValidPort(rType, PortAccessibility.OnlyGet))
                        {
                            var items = c.GetItems(source, mData, rType);
                            if (items != null)
                            {
                                customItems.AddRange(items);
                            }
                        }
                    }
                }
            }
            if (customItems != null)
            {
                filter.Static = false;
                customItems.Sort((x, y) => {
                    if (x.category != y.category)
                    {
                        return(string.Compare(x.category, y.category));
                    }
                    return(string.Compare(x.name, y.name));
                });
                ItemSelector w = ItemSelector.ShowWindow(source, MemberData.none, filter, delegate(MemberData value) {
                    flag = flag && value.targetType == MemberData.TargetType.Method && !rType.IsCastableTo(value.startType);
                    if (!flag && !value.isStatic)
                    {
                        value.instance = new MemberData(source, MemberData.TargetType.ValueNode);
                    }
                    NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(MultipurposeNode n) {
                        if (n.target == null)
                        {
                            n.target = new MultipurposeMember();
                        }
                        n.target.target = value;
                        MemberDataUtility.UpdateMultipurposeMember(n.target);
                        if (flag)
                        {
                            var pTypes = value.ParameterTypes;
                            if (pTypes != null)
                            {
                                int paramIndex   = 0;
                                MemberData param = null;
                                for (int i = 0; i < pTypes.Length; i++)
                                {
                                    var types = pTypes[i];
                                    if (types != null)
                                    {
                                        for (int y = 0; y < types.Length; y++)
                                        {
                                            if (rType.IsCastableTo(types[y]))
                                            {
                                                param = new MemberData(source, MemberData.TargetType.ValueNode);
                                                break;
                                            }
                                            paramIndex++;
                                        }
                                        if (param != null)
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (n.target.parameters.Length > paramIndex && param != null)
                                {
                                    n.target.parameters[paramIndex] = param;
                                }
                            }
                        }
                    });
                    graph.Refresh();
                }, customItems).ChangePosition(GUIUtility.GUIToScreenPoint(mousePosition));
                w.displayRecentItem = false;
                w.displayNoneOption = false;
            }
        }