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(); }
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(); }
private int PasteBlocks(VFXViewController viewController, Node[] blocks, VFXContext targetModelContext, int targetIndex, List <VFXBlockController> blocksInTheSameOrder = null) { newControllers.Clear(); m_NodesInTheSameOrder = new VFXNodeID[blocks.Length]; int cpt = 0; foreach (var block in blocks) { Node blk = block; VFXBlock newBlock = PasteAndInitializeNode <VFXBlock>(viewController, Vector2.zero, Rect.zero, ref blk); newBlock.enabled = (blk.flags & Node.Flags.Enabled) == Node.Flags.Enabled; if (targetModelContext.AcceptChild(newBlock, targetIndex)) { m_NodesInTheSameOrder[cpt] = new VFXNodeID(newBlock, 0); targetModelContext.AddChild(newBlock, targetIndex, false); // only notify once after all blocks have been added targetIndex++; } ++cpt; } targetModelContext.Invalidate(VFXModel.InvalidationCause.kStructureChanged); var targetContextController = viewController.GetRootNodeController(targetModelContext, 0) as VFXContextController; targetContextController.ApplyChanges(); if (blocksInTheSameOrder != null) { blocksInTheSameOrder.Clear(); for (int i = 0; i < m_NodesInTheSameOrder.Length; ++i) { blocksInTheSameOrder.Add(m_NodesInTheSameOrder[i].model != null ? targetContextController.blockControllers.First(t => t.model == m_NodesInTheSameOrder[i].model as VFXBlock) : null); } } return(targetIndex); }