示例#1
0
        internal static void CreateSystems(VFXView view, VFXViewController viewController, int count, int offset, string name = null)
        {
            Func <int, VFXContextController> fnContextController = delegate(int i)
            {
                viewController.ApplyChanges();
                var controller = viewController.allChildren.OfType <VFXContextController>().Cast <VFXContextController>().ToArray();
                return(controller[i]);
            };

            var contextInitializeDesc = VFXLibrary.GetContexts().FirstOrDefault(o => o.name.Contains("Init"));
            var contextOutputDesc     = VFXLibrary.GetContexts().FirstOrDefault(o => o.name.StartsWith("Output Particle Quad"));

            for (int i = 0; i < count; ++i)
            {
                var output = viewController.AddVFXContext(new Vector2(2 * i, 2 * i), contextOutputDesc);
                var init   = viewController.AddVFXContext(new Vector2(i, i), contextInitializeDesc);

                var flowEdge = new VFXFlowEdgeController(fnContextController(2 * i + offset).flowInputAnchors.FirstOrDefault(), fnContextController(2 * i + offset + 1).flowOutputAnchors.FirstOrDefault());
                viewController.AddElement(flowEdge);
            }

            viewController.ApplyChanges();

            if (name != null)
            {
                var systems = GetFieldValue <VFXView, List <VFXSystemBorder> >(view, "m_Systems");
                foreach (var sys in systems)
                {
                    SetTextFieldValue(sys, name);
                    CallMethod(sys, "OnTitleBlur", new object[] { null });
                }
            }
        }
示例#2
0
        void CreateFlowEdges(IList <VFXContextController> contextControllers)
        {
            for (int i = 0; i < contextControllers.Count() - 1; ++i)
            {
                VFXFlowEdgeController edgeController = new VFXFlowEdgeController(contextControllers[i + 1].flowInputAnchors.First(), contextControllers[i].flowOutputAnchors.First());
                m_ViewController.AddElement(edgeController);
            }

            m_ViewController.ApplyChanges();
        }
        public void UndoRedoContextLink()
        {
            Func <VFXContextController[]> fnContextController = delegate()
            {
                m_ViewController.ApplyChanges();
                return(m_ViewController.allChildren.OfType <VFXContextController>().Cast <VFXContextController>().ToArray());
            };

            Func <VFXContextController> fnInitializeController = delegate()
            {
                var controller = fnContextController();
                return(controller.FirstOrDefault(o => o.model.name.Contains("Init")));
            };

            Func <VFXContextController> fnUpdateController = delegate()
            {
                var controller = fnContextController();
                return(controller.FirstOrDefault(o => o.model.name.Contains("Update")));
            };

            Func <int> fnFlowEdgeCount = delegate()
            {
                m_ViewController.ApplyChanges();
                return(m_ViewController.allChildren.OfType <VFXFlowEdgeController>().Count());
            };

            var contextInitializeDesc = VFXLibrary.GetContexts().FirstOrDefault(o => o.name.Contains("Init"));
            var contextUpdateDesc     = VFXLibrary.GetContexts().FirstOrDefault(o => o.name.Contains("Update"));

            m_ViewController.AddVFXContext(new Vector2(1, 1), contextInitializeDesc);
            m_ViewController.AddVFXContext(new Vector2(2, 2), contextUpdateDesc);

            //Creation
            var flowEdge = new VFXFlowEdgeController(fnUpdateController().flowInputAnchors.FirstOrDefault(), fnInitializeController().flowOutputAnchors.FirstOrDefault());

            Undo.IncrementCurrentGroup();
            m_ViewController.AddElement(flowEdge);
            Assert.AreEqual(1, fnFlowEdgeCount());

            Undo.PerformUndo();
            Assert.AreEqual(0, fnFlowEdgeCount(), "Fail undo Create");

            //Deletion
            flowEdge = new VFXFlowEdgeController(fnUpdateController().flowInputAnchors.FirstOrDefault(), fnInitializeController().flowOutputAnchors.FirstOrDefault());
            m_ViewController.AddElement(flowEdge);
            Assert.AreEqual(1, fnFlowEdgeCount());

            Undo.IncrementCurrentGroup();
            m_ViewController.RemoveElement(m_ViewController.allChildren.OfType <VFXFlowEdgeController>().FirstOrDefault());
            Assert.AreEqual(0, fnFlowEdgeCount());

            Undo.PerformUndo();
            Assert.AreEqual(1, fnFlowEdgeCount(), "Fail undo Delete");
        }
        public void UndoRedoContextLinkMultiSlot()
        {
            Func <VFXContextController[]> fnContextController = delegate()
            {
                m_ViewController.ApplyChanges();
                return(m_ViewController.allChildren.OfType <VFXContextController>().Cast <VFXContextController>().ToArray());
            };

            Func <VFXContextController> fnSpawner = delegate()
            {
                var controller = fnContextController();
                return(controller.FirstOrDefault(o => o.model.name.Contains("Spawn")));
            };

            Func <string, VFXContextController> fnEvent = delegate(string name)
            {
                var controller = fnContextController();
                var allEvent   = controller.Where(o => o.model.name.Contains("Event"));
                return(allEvent.FirstOrDefault(o => (o.model as VFXBasicEvent).eventName == name) as VFXContextController);
            };

            Func <VFXContextController> fnStart = delegate()
            {
                return(fnEvent("Start"));
            };

            Func <VFXContextController> fnStop = delegate()
            {
                return(fnEvent("Stop"));
            };

            Func <int> fnFlowEdgeCount = delegate()
            {
                m_ViewController.ApplyChanges();
                return(m_ViewController.allChildren.OfType <VFXFlowEdgeController>().Count());
            };

            var contextSpawner = VFXLibrary.GetContexts().FirstOrDefault(o => o.name.Contains("Spawn"));
            var contextEvent   = VFXLibrary.GetContexts().FirstOrDefault(o => o.name.Contains("Event"));

            m_ViewController.AddVFXContext(new Vector2(1, 1), contextSpawner);
            var eventStartController = m_ViewController.AddVFXContext(new Vector2(2, 2), contextEvent) as VFXBasicEvent;
            var eventStopController  = m_ViewController.AddVFXContext(new Vector2(3, 3), contextEvent) as VFXBasicEvent;

            eventStartController.SetSettingValue("eventName", "Start");
            eventStopController.SetSettingValue("eventName", "Stop");

            //Creation
            var flowEdge = new VFXFlowEdgeController(fnSpawner().flowInputAnchors.ElementAt(0), fnStart().flowOutputAnchors.FirstOrDefault());

            Undo.IncrementCurrentGroup();
            m_ViewController.AddElement(flowEdge);
            Assert.AreEqual(1, fnFlowEdgeCount());

            flowEdge = new VFXFlowEdgeController(fnSpawner().flowInputAnchors.ElementAt(1), fnStop().flowOutputAnchors.FirstOrDefault());

            Undo.IncrementCurrentGroup();
            m_ViewController.AddElement(flowEdge);
            Assert.AreEqual(2, fnFlowEdgeCount());

            //Test a single deletion
            var allFlowEdge = m_ViewController.allChildren.OfType <VFXFlowEdgeController>().ToArray();

            // Integrity test...
            var inputSlotIndex  = allFlowEdge.Select(o => (o.input as VFXFlowAnchorController).slotIndex).OrderBy(o => o).ToArray();
            var outputSlotIndex = allFlowEdge.Select(o => (o.output as VFXFlowAnchorController).slotIndex).OrderBy(o => o).ToArray();

            Assert.AreEqual(inputSlotIndex[0], 0);
            Assert.AreEqual(inputSlotIndex[1], 1);
            Assert.AreEqual(outputSlotIndex[0], 0);
            Assert.AreEqual(outputSlotIndex[1], 0);

            var edge = allFlowEdge.First(o => o.input == fnSpawner().flowInputAnchors.ElementAt(1) && o.output == fnStop().flowOutputAnchors.FirstOrDefault());

            Undo.IncrementCurrentGroup();
            m_ViewController.RemoveElement(edge);
            Assert.AreEqual(1, fnFlowEdgeCount());

            Undo.PerformUndo();
            Assert.AreEqual(2, fnFlowEdgeCount());

            Undo.PerformRedo();
            Assert.AreEqual(1, fnFlowEdgeCount());

            Undo.PerformUndo();
            Assert.AreEqual(2, fnFlowEdgeCount());

            //Global Deletion
            Undo.PerformUndo();
            Assert.AreEqual(1, fnFlowEdgeCount());

            Undo.PerformUndo();
            Assert.AreEqual(0, fnFlowEdgeCount());
        }