/// <summary> 加载Graph </summary>
        /// <param name="_graph"></param>
        public static BaseGraphWindow LoadGraph(BaseGraph _graph)
        {
            Type windowType = GraphProcessorEditorUtility.GetGraphWindowType(_graph.GetType());

            UnityObject[]   objs   = Resources.FindObjectsOfTypeAll(windowType);
            BaseGraphWindow window = null;

            foreach (var obj in objs)
            {
                if (obj.GetType() == windowType)
                {
                    window = obj as BaseGraphWindow;
                    break;
                }
            }
            if (window == null)
            {
                window = CreateInstance(windowType) as BaseGraphWindow;
                window.SetUp(_graph);
                window.Show();
            }
            else
            {
                window.Focus();
                if (window.Graph != _graph)
                {
                    window.SetUp(_graph);
                }
            }

            return(window);
        }
        //public void Initialize(BaseGraphView _graphView, IEnumerable<Type> _nodeTypes, NodePort _port, Action<BaseNode> _onNodeCreated)
        //{
        //    graphView = _graphView;
        //    port = _port;
        //    nodeTypes = _nodeTypes;
        //    tree = foreach (var item in GraphProcessorCache.PortCache)
        //    {
        //        foreach (var cachedPort in item.Value)
        //        {
        //            if (NodePort.IsCompatible(port, cachedPort))
        //                yield return item.Key;
        //        }
        //    }
        //    onNodeCreated = _onNodeCreated;
        //}

        private List <SearchTreeEntry> CreateSearchTree()
        {
            List <SearchTreeEntry> tempTree = new List <SearchTreeEntry>()
            {
                new SearchTreeGroupEntry(new GUIContent("Create Elements"))
            };

            foreach (Type type in nodeTypes)
            {
                if (Utility_Attribute.TryGetTypeAttribute(type, out NodeMenuItemAttribute attribute))
                {
                    if (attribute.showInList)
                    {
                        if (attribute.titles.Length > 1)
                        {
                            SearchTreeGroupEntry groupTemp = null;
                            for (int i = 1; i < attribute.titles.Length; i++)
                            {
                                SearchTreeGroupEntry group = tempTree.Find(item =>
                                                                           (item.content.text == attribute.titles[i - 1] && item.level == i)) as
                                                             SearchTreeGroupEntry;
                                if (group == null)
                                {
                                    group = new SearchTreeGroupEntry(new GUIContent(attribute.titles[i - 1]), i);
                                    int index = groupTemp == null ? 0 : tempTree.IndexOf(groupTemp);
                                    tempTree.Insert(index + 1, group);
                                }

                                groupTemp = group;
                            }
                            tempTree.Insert(tempTree.IndexOf(groupTemp) + 1,
                                            new SearchTreeEntry(new GUIContent(attribute.titles.Last()))
                            {
                                userData = type, level = attribute.titles.Length
                            });
                        }
                        else
                        {
                            tempTree.Add(new SearchTreeEntry(new GUIContent(attribute.titles.Last()))
                            {
                                userData = type, level = 1
                            });
                        }
                    }
                }
                else
                {
                    GUIContent content = new GUIContent(GraphProcessorEditorUtility.GetNodeDisplayName(type));
                    tempTree.Add(new SearchTreeEntry(content)
                    {
                        userData = type, level = 1
                    });
                }
            }
            return(tempTree);
        }
        void BindingProperties()
        {
            // 初始化
            portName = GraphProcessorEditorUtility.GetDisplayName(Model.FieldName);
            tooltip  = Model.Tooltip;
            if (orientation == Orientation.Vertical && string.IsNullOrEmpty(Model.Tooltip))
            {
                Model.Tooltip = GraphProcessorEditorUtility.GetDisplayName(Model.FieldName);
            }

            Model.BindingProperty <string>(nameof(Model.PortName), OnPortNameChanged);
            Model.BindingProperty <string>(nameof(Model.Tooltip), OnToolTipChanged);
            Model.BindingProperty <Color>(nameof(Model.PortColor), OnColorChanged);
        }
        protected virtual void BindingProperties()
        {
            // 初始化
            base.expanded = Model.Expanded;
            title         = Model.Title;
            OnIconChanged(Model.Icon);
            tooltip = Model.Tooltip; base.SetPosition(new Rect(Model.Position, GetPosition().size));
            titleContainer.style.backgroundColor = Model.TitleColor;
            TitleLabel.style.color = Model.TitleColor.GetLuminance() > 0.5f && Model.TitleColor.a > 0.5f ? Color.black : Color.white * 0.9f;


            Model.BindingProperty <bool>(nameof(Model.Expanded), OnExpandedChanged);
            Model.BindingProperty <string>(nameof(Model.Title), OnTitleChanged);
            Model.Title = GraphProcessorEditorUtility.GetNodeDisplayName(Model.GetType());
            Model.BindingProperty <Texture>(nameof(Model.Icon), OnIconChanged);
            Model.BindingProperty <Vector2>(nameof(Model.IconSize), OnIconSizeChanged);
            Model.BindingProperty <string>(nameof(Model.Tooltip), OnTooltipChanged);
            Model.BindingProperty <Vector2>(nameof(Model.Position), OnPositionChanged);
            Model.BindingProperty <Color>(nameof(Model.TitleColor), OnTitleColorChanged);
        }
Пример #5
0
        public BaseNodeView AddNodeView(BaseNode _node)
        {
            Type nodeViewType = null;

            if (_node is ParameterNode parameterNode)
            {
                nodeViewType = typeof(ParameterNodeView);
            }
            else
            {
                nodeViewType = GraphProcessorEditorUtility.GetNodeViewType(_node.GetType());
            }

            if (nodeViewType == null)
            {
                nodeViewType = GetDefaultNodeViewType(_node);
            }
            BaseNodeView nodeView = Activator.CreateInstance(nodeViewType) as BaseNodeView;

            nodeView.SetUp(_node, CommandDispatcher, this);
            NodeViews[_node.GUID] = nodeView;
            AddElement(nodeView);
            return(nodeView);
        }
 void OnPortNameChanged(string _name)
 {
     portName = GraphProcessorEditorUtility.GetDisplayName(_name);
 }