Esempio n. 1
0
        void AlignNodeToLinkedPort(VFXView view, VFXDataAnchorController port, VFXNodeController nodeController)
        {
            var portNode         = view.GetDataAnchorByController(port);
            var connectorElement = portNode.Q <VisualElement>("connector");
            var newNode          = view.GetNodeByController(nodeController);
            var offset           = newNode.worldBound.position - connectorElement.worldBound.position + portPositionOffset;

            nodeController.model.position += offset / view.scale;
        }
Esempio n. 2
0
            public void ConvertToSubgraphBlock(VFXView sourceView, IEnumerable <Controller> controllers, Rect rect)
            {
                this.m_Rect = rect;
                Init(sourceView, controllers);
                if (!CreateUniqueSubgraph("SubgraphBlock", VisualEffectSubgraphBlock.Extension, VisualEffectAssetEditorUtility.CreateNew <VisualEffectSubgraphBlock>))
                {
                    return;
                }

                m_SourceControllers.RemoveAll(t => t is VFXContextController); // Don't copy contexts

                m_SourceBlockControllers = m_SourceControllers.OfType <VFXBlockController>().OrderBy(t => t.index).ToList();

                VFXContextController sourceContextController = m_SourceBlockControllers.First().contextController;

                object copyData = VFXCopy.CopyBlocks(m_SourceBlockControllers);

                var targetContext = m_TargetController.graph.children.OfType <VFXBlockSubgraphContext>().FirstOrDefault();

                if (targetContext == null)
                {
                    targetContext = ScriptableObject.CreateInstance <VFXBlockSubgraphContext>();
                    m_TargetController.graph.AddChild(targetContext);
                }
                m_TargetController.LightApplyChanges();
                targetContext.position = sourceContextController.position;
                targetContext.SetSettingValue("m_SuitableContexts", (VFXBlockSubgraphContext.ContextType)m_SourceBlockControllers.Select(t => t.model.compatibleContexts).Aggregate((t, s) => t & s));
                m_TargetBlocks = new List <VFXBlockController>();

                VFXPaste.PasteBlocks(m_TargetController, copyData, targetContext, 0, m_TargetBlocks);


                Dictionary <VFXNodeController, VFXNodeController> targetControllers = new Dictionary <VFXNodeController, VFXNodeController>();

                CopyPasteOperators(targetControllers);

                m_SourceControllersWithBlocks = m_SourceControllers.Concat(m_SourceBlockControllers);
                //Create lost links between nodes and blocks
                foreach (var edge in m_SourceController.dataEdges.Where(t => m_SourceOperatorAndParameters.Contains(t.output.sourceNode) && m_SourceBlockControllers.Contains(t.input.sourceNode)))
                {
                    var outputNode = targetControllers[edge.output.sourceNode];
                    var output     = outputNode.outputPorts.First(t => t.path == edge.output.path);

                    var inputBlock = m_TargetBlocks[m_SourceBlockControllers.IndexOf(edge.input.sourceNode as VFXBlockController)];
                    var input      = inputBlock.inputPorts.First(t => t.path == edge.input.path);

                    m_TargetController.CreateLink(input, output);
                }
                //Create lost links between nodes
                foreach (var edge in m_SourceController.dataEdges.Where(t => m_SourceOperatorAndParameters.Contains(t.output.sourceNode) && m_SourceOperatorAndParameters.Contains(t.input.sourceNode)))
                {
                    var outputNode = targetControllers[edge.output.sourceNode];
                    var output     = outputNode.outputPorts.First(t => t.path == edge.output.path);

                    var inputNode = targetControllers[edge.input.sourceNode];
                    var input     = inputNode.inputPorts.First(t => t.path == edge.input.path);

                    m_TargetController.CreateLink(input, output);
                }

                var sourceBlock = ScriptableObject.CreateInstance <VFXSubgraphBlock>();

                m_SourceNode = sourceBlock;
                sourceContextController.model.AddChild(m_SourceNode, m_SourceBlockControllers.Select(t => t.index).Min());
                (m_SourceView.GetNodeByController(sourceContextController) as VFXContextUI).UpdateSelectionWithNewBlocks();
                sourceContextController.ApplyChanges();

                m_SourceNodeController = sourceContextController.blockControllers.First(t => t.model == m_SourceNode);
                PostSetup();
                m_SourceNode.SetSettingValue("m_Subgraph", m_TargetSubgraph);
                m_SourceNodeController.ApplyChanges();

                var targetContextController = m_TargetController.GetRootNodeController(targetContext, 0) as VFXContextController;

                m_SourceControllersWithBlocks = m_SourceControllers.Concat(m_SourceBlockControllers);
                m_SourceControllers           = m_SourceOperatorAndParameters.Cast <Controller>().ToList();
                m_TargetControllers           = m_TargetOperatorAndParameters;
                TransferEdges();
                m_SourceControllers = m_SourceControllersWithBlocks.ToList();
                UninitSmart();
            }