//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); }
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); }