Example #1
0
        void PasteBlocks(VFXView view, ref SerializableGraph serializableGraph, List <VFXNodeController> nodesInTheSameOrder)
        {
            var selectedContexts = view.selection.OfType <VFXContextUI>();
            var selectedBlocks   = view.selection.OfType <VFXBlockUI>();

            VFXBlockUI   targetBlock   = null;
            VFXContextUI targetContext = null;

            if (selectedBlocks.Count() > 0)
            {
                targetBlock   = selectedBlocks.OrderByDescending(t => t.context.controller.model.GetIndex(t.controller.model)).First();
                targetContext = targetBlock.context;
            }
            else if (selectedContexts.Count() == 1)
            {
                targetContext = selectedContexts.First();
            }
            else
            {
                Debug.LogError(m_BlockPasteError.text);
                return;
            }

            VFXContext targetModelContext = targetContext.controller.model;

            int targetIndex = -1;

            if (targetBlock != null)
            {
                targetIndex = targetModelContext.GetIndex(targetBlock.controller.model) + 1;
            }


            List <VFXBlockController> blockControllers = nodesInTheSameOrder != null ? new List <VFXBlockController>() : null;

            targetIndex = PasteBlocks(view.controller, serializableGraph.operators, targetModelContext, targetIndex, blockControllers);

            if (nodesInTheSameOrder != null)
            {
                nodesInTheSameOrder.AddRange(blockControllers.Cast <VFXNodeController>());
            }

            targetModelContext.Invalidate(VFXModel.InvalidationCause.kStructureChanged);

            if (view != null)
            {
                view.ClearSelection();

                foreach (var uiBlock in targetContext.Query().OfType <VFXBlockUI>().Where(t => m_NodesInTheSameOrder.Any(u => u.model == t.controller.model)).ToList())
                {
                    view.AddToSelection(uiBlock);
                }
            }
        }
Example #2
0
        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);
        }
Example #3
0
        static void PasteBlocks(VFXView view, Data copyData)
        {
            var selectedContexts = view.selection.OfType <VFXContextUI>();
            var selectedBlocks   = view.selection.OfType <VFXBlockUI>();

            VFXBlockUI   targetBlock   = null;
            VFXContextUI targetContext = null;

            if (selectedBlocks.Count() > 0)
            {
                targetBlock   = selectedBlocks.OrderByDescending(t => t.context.controller.model.GetIndex(t.controller.model)).First();
                targetContext = targetBlock.context;
            }
            else if (selectedContexts.Count() == 1)
            {
                targetContext = selectedContexts.First();
            }
            else
            {
                Debug.LogError(m_BlockPasteError.text);
                return;
            }

            VFXContext targetModelContext = targetContext.controller.model;

            int targetIndex = -1;

            if (targetBlock != null)
            {
                targetIndex = targetModelContext.GetIndex(targetBlock.controller.model) + 1;
            }

            var newBlocks = new HashSet <VFXBlock>();

            foreach (var block in copyData.blocks)
            {
                if (targetModelContext.AcceptChild(block, targetIndex))
                {
                    newBlocks.Add(block);

                    foreach (var slot in block.inputSlots)
                    {
                        slot.UnlinkAll(true, false);
                    }
                    foreach (var slot in block.outputSlots)
                    {
                        slot.UnlinkAll(true, false);
                    }
                    targetModelContext.AddChild(block, targetIndex, false); // only notify once after all blocks have been added
                }
            }

            targetModelContext.Invalidate(VFXModel.InvalidationCause.kStructureChanged);

            // Create all ui based on model
            view.controller.LightApplyChanges();

            view.ClearSelection();

            foreach (var uiBlock in targetContext.Query().OfType <VFXBlockUI>().Where(t => newBlocks.Contains(t.controller.model)).ToList())
            {
                view.AddToSelection(uiBlock);
            }
        }
Example #4
0
        void PasteBlocks(VFXView view, ref SerializableGraph serializableGraph)
        {
            var selectedContexts = view.selection.OfType <VFXContextUI>();
            var selectedBlocks   = view.selection.OfType <VFXBlockUI>();

            VFXBlockUI   targetBlock   = null;
            VFXContextUI targetContext = null;

            if (selectedBlocks.Count() > 0)
            {
                targetBlock   = selectedBlocks.OrderByDescending(t => t.context.controller.model.GetIndex(t.controller.model)).First();
                targetContext = targetBlock.context;
            }
            else if (selectedContexts.Count() == 1)
            {
                targetContext = selectedContexts.First();
            }
            else
            {
                Debug.LogError(m_BlockPasteError.text);
                return;
            }

            VFXContext targetModelContext = targetContext.controller.model;

            int targetIndex = -1;

            if (targetBlock != null)
            {
                targetIndex = targetModelContext.GetIndex(targetBlock.controller.model) + 1;
            }

            var newBlocks = new HashSet <VFXBlock>();

            newControllers.Clear();

            foreach (var block in serializableGraph.operatorsOrBlocks)
            {
                Node     blk      = block;
                VFXBlock newBlock = PasteAndInitializeNode <VFXBlock>(view.controller, ref blk);

                if (targetModelContext.AcceptChild(newBlock, targetIndex))
                {
                    newBlocks.Add(newBlock);
                    targetModelContext.AddChild(newBlock, targetIndex, false); // only notify once after all blocks have been added

                    targetIndex++;
                }
            }

            targetModelContext.Invalidate(VFXModel.InvalidationCause.kStructureChanged);

            //TODO fill infos.indexToController for when external links will be optionally copied.

            view.ClearSelection();

            foreach (var uiBlock in targetContext.Query().OfType <VFXBlockUI>().Where(t => newBlocks.Contains(t.controller.model)).ToList())
            {
                view.AddToSelection(uiBlock);
            }
        }