示例#1
0
        public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context)
        {
            Node node = null;

            switch (SearchTreeEntry.name)
            {
            case "Clip":
                node = new ClipNodeUI();

                break;

            case "Layer Mixer":
                node = new LayerMixerNodeUI();

                break;

            case "Mixer":
                node = new MixerNodeUI();

                break;

            case "1D Blendspace":
                node = new Blendspace1DNodeUI();

                break;

            case "2D Blendspace":
                node = new Blendspace2DNodeUI();

                break;

            case "State Machine":
                node = new StateMachineNodeUI();

                break;

            case "Wildcard":
                node = new WildcardNodeUI();

                break;

            case "Output":
                node = new OutputNodeUI();
                GraphView.OutputIndicatorNode = (OutputNodeUI)node;
                break;

            default:
                break;
            }

            if (node is BaseNodeUI baseNode)
            {
                baseNode.ID = Guid.NewGuid().ToString();
            }

            GraphView.AddNode(node, context.screenMousePosition);

            return(true);
        }
示例#2
0
        private void OpenAnimationGraphAsset(AnimationGraphAsset asset)
        {
            AnimationGraphAsset = asset;

            _closeButton.style.display = DisplayStyle.Flex;

            _assetName.style.display = DisplayStyle.Flex;
            _assetName.text          = asset.name;

            _closeToAssetNameSpacer.style.display = DisplayStyle.Flex;
            _assetNameToSaveSpacer.style.display  = DisplayStyle.Flex;

            rootVisualElement.Remove(GraphView);
            CreateGraphView();

            Dictionary <NodeAsset, BaseNodeUI> nodeMap = new Dictionary <NodeAsset, BaseNodeUI>();

            asset.Nodes.ForEach(n =>
            {
                BaseNodeUI nodeUI = null;

                switch (n.Data)
                {
                case ClipNode clipNode:
                    nodeUI = new ClipNodeUI();
                    break;

                case MixerNode mixerNode:
                    nodeUI = new MixerNodeUI();
                    break;

                case LayerMixerNode layerMixerNode:
                    nodeUI = new LayerMixerNodeUI();
                    break;

                case Blendspace1DNode blendspace1DNode:
                    nodeUI = new Blendspace1DNodeUI();
                    break;

                case Blendspace2DNode blendspace2DNode:
                    nodeUI = new Blendspace2DNodeUI();
                    break;

                case StateMachineNode stateMachineNode:
                    nodeUI = new StateMachineNodeUI();
                    break;

                case WildcardNode wildcardNode:
                    nodeUI = new WildcardNodeUI();
                    break;

                default:
                    break;
                }

                if (nodeUI != null)
                {
                    GraphView.AddNode(nodeUI);
                    nodeUI.SetPosition(new Rect(n.Position, Vector2.zero));
                    nodeUI.expanded = n.IsExpanded;
                    nodeMap.Add(n, nodeUI);
                }
            });

            foreach (var entry in nodeMap)
            {
                entry.Value.LoadData(GraphView, entry.Key, nodeMap);
            }

            if (asset.OutputIndicatorNode != null)
            {
                var outputIndicatorNode = new OutputNodeUI();
                GraphView.OutputIndicatorNode = outputIndicatorNode;
                GraphView.AddNode(outputIndicatorNode);
                outputIndicatorNode.SetPosition(new Rect(asset.OutputIndicatorNode.Position, Vector2.zero));
                outputIndicatorNode.expanded = asset.OutputIndicatorNode.IsExpanded;

                if (asset.OutputNode != null)
                {
                    BaseNodeUI outputNode = nodeMap[asset.OutputNode];
                    Edge       edge       = new Edge {
                        output = outputNode.OutputPort, input = outputIndicatorNode.InputPort
                    };
                    edge.input.Connect(edge);
                    edge.output.Connect(edge);
                    GraphView.AddElement(edge);
                    GraphView.OutputNode = outputNode;
                }
            }
        }