コード例 #1
0
        public void RemoveBlock(VFXBlockUI block)
        {
            if (block == null)
            {
                return;
            }

            controller.RemoveBlock(block.controller.model);
        }
コード例 #2
0
ファイル: VFXPaste.cs プロジェクト: RemanKoshaba/SchizoSim
        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);
                }
            }
        }
コード例 #3
0
        private void InstantiateBlock(VFXBlockController blockController)
        {
            Profiler.BeginSample("VFXContextUI.InstantiateBlock");
            Profiler.BeginSample("VFXContextUI.new VFXBlockUI");
            var blockUI = new VFXBlockUI();

            Profiler.EndSample();
            blockUI.controller = blockController;

            m_BlockContainer.Add(blockUI);
            Profiler.EndSample();
        }
コード例 #4
0
        private VFXBlockUI InstantiateBlock(VFXBlockController blockController)
        {
            Profiler.BeginSample("VFXContextUI.InstantiateBlock");
            Profiler.BeginSample("VFXContextUI.new VFXBlockUI");
            var blockUI = new VFXBlockUI();

            Profiler.EndSample();
            blockUI.controller      = blockController;
            blocks[blockController] = blockUI;
            Profiler.EndSample();

            return(blockUI);
        }
コード例 #5
0
        public void RefreshContext()
        {
            Profiler.BeginSample("VFXContextUI.RefreshContext");
            var blockControllers     = controller.blockControllers;
            int blockControllerCount = blockControllers.Count();

            bool somethingChanged = m_BlockContainer.childCount < blockControllerCount || (!m_CanHaveBlocks && m_NoBlock.parent != null);

            int cptBlock = 0;

            for (int i = 0; i < m_BlockContainer.childCount; ++i)
            {
                var child = m_BlockContainer.ElementAt(i) as VFXBlockUI;
                if (child != null)
                {
                    if (!somethingChanged && blockControllerCount > cptBlock && child.controller != blockControllers[cptBlock])
                    {
                        somethingChanged = true;
                    }
                    cptBlock++;
                }
            }
            if (somethingChanged || cptBlock != blockControllerCount)
            {
                foreach (var controller in blocks.Keys.Except(blockControllers).ToArray())
                {
                    GetFirstAncestorOfType <VFXView>().RemoveNodeEdges(blocks[controller]);
                    m_BlockContainer.Remove(blocks[controller]);
                    blocks.Remove(controller);
                }
                if (blockControllers.Count() > 0 || !m_CanHaveBlocks)
                {
                    m_NoBlock.RemoveFromHierarchy();
                }
                else if (m_NoBlock.parent == null)
                {
                    m_BlockContainer.Add(m_NoBlock);
                }
                if (blockControllers.Count > 0)
                {
                    VFXBlockUI prevBlock = null;
                    foreach (var blockController in blockControllers)
                    {
                        VFXBlockUI blockUI;
                        if (blocks.TryGetValue(blockController, out blockUI))
                        {
                            if (prevBlock != null)
                            {
                                blockUI.PlaceInFront(prevBlock);
                            }
                            else
                            {
                                blockUI.SendToBack();
                            }
                        }
                        else
                        {
                            blockUI = InstantiateBlock(blockController);
                            m_BlockContainer.Add(blockUI);
                            m_BlockContainer.Insert(prevBlock == null ? 0: m_BlockContainer.IndexOf(prevBlock) + 1, blockUI);
                        }
                        prevBlock = blockUI;
                    }
                    VFXBlockUI firstBlock = m_BlockContainer.Query <VFXBlockUI>();
                    firstBlock.AddToClassList("first");
                }
            }
            Profiler.EndSample();
        }
コード例 #6
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);
            }
        }
コード例 #7
0
        public void RefreshContext()
        {
            Profiler.BeginSample("VFXContextUI.RefreshContext");
            var blockControllers     = controller.blockControllers;
            int blockControllerCount = blockControllers.Count();

            // recreate the children list based on the controller list to keep the order.

            var blocksUIs = new Dictionary <VFXBlockController, VFXBlockUI>();

            bool somethingChanged = m_BlockContainer.childCount < blockControllerCount || (!m_CanHaveBlocks && m_NoBlock.parent != null);

            int cptBlock = 0;

            for (int i = 0; i < m_BlockContainer.childCount; ++i)
            {
                var child = m_BlockContainer.ElementAt(i) as VFXBlockUI;
                if (child != null)
                {
                    blocksUIs.Add(child.controller, child);

                    if (!somethingChanged && blockControllerCount > cptBlock && child.controller != blockControllers[cptBlock])
                    {
                        somethingChanged = true;
                    }
                    cptBlock++;
                }
            }
            if (somethingChanged || cptBlock != blockControllerCount)
            {
                foreach (var kv in blocksUIs)
                {
                    kv.Value.RemoveFromClassList("first");
                    m_BlockContainer.Remove(kv.Value);
                }
                if (blockControllers.Count() > 0 || !m_CanHaveBlocks)
                {
                    m_NoBlock.RemoveFromHierarchy();
                }
                else if (m_NoBlock.parent == null)
                {
                    m_BlockContainer.Add(m_NoBlock);
                }
                if (blockControllers.Count > 0)
                {
                    foreach (var blockController in blockControllers)
                    {
                        VFXBlockUI blockUI;
                        if (blocksUIs.TryGetValue(blockController, out blockUI))
                        {
                            m_BlockContainer.Add(blockUI);
                        }
                        else
                        {
                            InstantiateBlock(blockController);
                        }
                    }
                    VFXBlockUI firstBlock = m_BlockContainer.Query <VFXBlockUI>();
                    firstBlock.AddToClassList("first");
                }
            }
            Profiler.EndSample();
        }
コード例 #8
0
ファイル: VFXPaste.cs プロジェクト: KoniroIris/VFX
        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);
            }
        }