public void ConvertToSubgraphBlock(VFXView sourceView, IEnumerable <Controller> controllers, Rect rect)
            {
                this.m_Rect = rect;
                Init(sourceView, controllers);
                CreateUniqueSubgraph("SubgraphBlock", VisualEffectSubgraphBlock.Extension, VisualEffectAssetEditorUtility.CreateNew <VisualEffectSubgraphBlock>);

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

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

                var otherSourceControllers = m_SourceControllers.OfType <VFXNodeController>().Where(t => !(t is VFXBlockController)).ToList();

                //Create lost links between nodes and blocks
                foreach (var edge in m_SourceController.dataEdges.Where(t => otherSourceControllers.Contains(t.output.sourceNode) && m_SourceBlockControllers.Contains(t.input.sourceNode)))
                {
                    var outputNode = m_TargetControllers[m_SourceControllers.IndexOf(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);
                }

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

                m_SourceNode = sourceBlock;
                sourceContextController.model.AddChild(m_SourceNode, m_SourceBlockControllers.Select(t => t.index).Min());
                sourceContextController.ApplyChanges();
                m_SourceNodeController = sourceContextController.blockControllers.First(t => t.model == m_SourceNode);
                PostSetup();
                m_SourceNodeController.ApplyChanges();

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

                m_SourceControllersWithBlocks = m_SourceControllers.Concat(m_SourceBlockControllers);
                TransferEdges();
                UninitSmart();
            }
 void PostSetupNode()
 {
     PostSetup();
     m_SourceNode.position = m_Rect.center;
     m_SourceController.graph.AddChild(m_SourceNode);
     m_SourceController.LightApplyChanges();
     m_SourceNodeController = m_SourceController.GetRootNodeController(m_SourceNode, 0);
     m_SourceNodeController.ApplyChanges();
 }
Beispiel #3
0
 void PostSetupNode()
 {
     PostSetup();
     m_SourceNode.position = m_Rect.center;
     m_SourceController.graph.AddChild(m_SourceNode);
     m_SourceNode.SetSettingValue("m_Subgraph", m_TargetSubgraph);
     m_SourceController.LightApplyChanges();
     m_SourceNodeController = m_SourceController.GetRootNodeController(m_SourceNode, 0);
     m_SourceNodeController.ApplyChanges();
 }
Beispiel #4
0
            void TransfertDataEdges()
            {
                m_SourceControllersWithBlocks = m_SourceControllers.Concat(m_SourceControllers.OfType <VFXContextController>().SelectMany(t => t.blockControllers));

                // Search for links between with inputs in the selected part and the output in other parts of the graph.
                Dictionary <VFXDataAnchorController, List <VFXDataAnchorController> > traversingInEdges = new Dictionary <VFXDataAnchorController, List <VFXDataAnchorController> >();

                foreach (var edge in m_SourceController.dataEdges.Where(
                             t =>
                {
                    if (parameterNodeControllers.Contains(t.output.sourceNode))
                    {
                        return(false);
                    }
                    var inputInControllers = m_SourceControllersWithBlocks.Contains(t.input.sourceNode);
                    var outputInControllers = m_SourceControllersWithBlocks.Contains(t.output.sourceNode);

                    return(inputInControllers && !outputInControllers);
                }
                             ))
                {
                    List <VFXDataAnchorController> outputs = null;
                    if (!traversingInEdges.TryGetValue(edge.input, out outputs))
                    {
                        outputs = new List <VFXDataAnchorController>();
                        traversingInEdges[edge.input] = outputs;
                    }

                    outputs.Add(edge.output);
                }

                var newSourceInputs = traversingInEdges.Keys.ToArray();

                for (int i = 0; i < newSourceInputs.Length; ++i)
                {
                    VFXParameter newTargetParameter = m_TargetController.AddVFXParameter(Vector2.zero, VFXLibrary.GetParameters().First(t => t.model.type == newSourceInputs[i].portType));

                    m_TargetController.LightApplyChanges();

                    VFXParameterController newTargetParamController = m_TargetController.GetParameterController(newTargetParameter);
                    newTargetParamController.exposed = true;

                    var outputs = traversingInEdges[newSourceInputs[i]];

                    var linkedParameter = outputs.FirstOrDefault(t => t.sourceNode is VFXParameterNodeController);
                    if (linkedParameter != null)
                    {
                        newTargetParamController.exposedName = (linkedParameter.sourceNode as VFXParameterNodeController).parentController.exposedName;
                    }
                    else
                    {
                        newTargetParamController.exposedName = newSourceInputs[i].name;
                    }

                    //first the equivalent of sourceInput in the target

                    VFXNodeController targetNode = null;
                    Vector2           position;

                    if (newSourceInputs[i].sourceNode is VFXBlockController)
                    {
                        var blockController = newSourceInputs[i].sourceNode as VFXBlockController;
                        if (m_TargetBlocks != null)
                        {
                            targetNode = m_TargetBlocks[m_SourceBlockControllers.IndexOf(blockController)];
                            position   = blockController.contextController.position;
                        }
                        else
                        {
                            var targetContext = m_TargetControllers[m_SourceControllers.IndexOf(blockController.contextController)] as VFXContextController;

                            targetNode = targetContext.blockControllers[blockController.index];
                            position   = blockController.contextController.position;
                        }
                    }
                    else
                    {
                        targetNode = m_TargetControllers[m_SourceControllers.IndexOf(newSourceInputs[i].sourceNode)];
                        position   = targetNode.position;
                    }

                    VFXDataAnchorController targetAnchor = targetNode.inputPorts.First(t => t.path == newSourceInputs[i].path);


                    position.y += targetAnchor.model.owner.inputSlots.IndexOf(targetAnchor.model) * 32;

                    VFXNodeController parameterNode = m_TargetController.AddVFXParameter(position - new Vector2(200, 0), newTargetParamController, null);

                    // Link the parameternode and the input in the target
                    m_TargetController.CreateLink(targetAnchor, parameterNode.outputPorts[0]);

                    if (m_SourceSlotContainer is VFXOperator)
                    {
                        (m_SourceSlotContainer as VFXOperator).ResyncSlots(true);
                    }
                    else if (m_SourceSlotContainer is VFXSubgraphBlock)
                    {
                        VFXSubgraphBlock blk = (m_SourceSlotContainer as VFXSubgraphBlock);
                        blk.RecreateCopy();
                        blk.ResyncSlots(true);
                    }
                    else if (m_SourceSlotContainer is VFXSubgraphContext)
                    {
                        VFXSubgraphContext ctx = (m_SourceSlotContainer as VFXSubgraphContext);
                        ctx.RecreateCopy();
                        ctx.ResyncSlots(true);
                    }

                    m_SourceNodeController.ApplyChanges();
                    //Link all the outputs to the matching input of the subgraph
                    foreach (var output in outputs)
                    {
                        m_SourceController.CreateLink(m_SourceNodeController.inputPorts.First(t => t.model == m_SourceSlotContainer.inputSlots.Last()), output);
                    }
                }
            }