コード例 #1
0
        public void UniqueDefaultSystemNames()
        {
            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();
            VFXView       view   = window.graphView;

            view.controller = m_ViewController;

            const int count    = 16;
            var       spawners = VFXTestCommon.CreateSpawners(view, m_ViewController, count);

            var systemNames = view.controller.graph.systemNames;
            var names       = new List <string>();

            foreach (var system in spawners)
            {
                names.Add(systemNames.GetUniqueSystemName(system));
            }

            Assert.IsTrue(names.Where(name => !string.IsNullOrEmpty(name)).Distinct().Count() == count, "Some spawners have the same name or are null or empty.");

            var GPUSystems = VFXTestCommon.GetFieldValue <VFXView, List <VFXSystemBorder> >(view, "m_Systems");

            VFXTestCommon.CreateSystems(view, m_ViewController, count, count);
            var uniqueSystemNames = GPUSystems.Select(system => system.controller.title).Distinct();

            Assert.IsTrue(uniqueSystemNames.Count() == count, "Some GPU systems have the same name or are null or empty.");
        }
コード例 #2
0
        public IEnumerator Sanitize_Shape_To_TShape_And_Check_VFXParameter_State()
        {
            var kSourceAsset = "Assets/AllTests/Editor/Tests/VFXSanitizeTShape.vfx_";
            var graph        = VFXTestCommon.CopyTemporaryGraph(kSourceAsset);

            yield return(null);

            Assert.AreEqual(8, graph.children.OfType <VFXParameter>().Count());
            Assert.AreEqual(11, graph.children.OfType <VFXParameter>().SelectMany(o => o.nodes).Count());
            Assert.AreEqual(0, graph.children.OfType <VFXParameter>().SelectMany(o => o.nodes).Where(o => o.position == Vector2.zero).Count());
            Assert.AreEqual(0, graph.children.OfType <VFXParameter>().SelectMany(o => o.nodes).Where(o => !o.linkedSlots.Any()).Count());
            yield return(null);

            var window   = VFXViewWindow.GetWindow <VFXViewWindow>();
            var resource = graph.GetResource();

            window.LoadAsset(resource.asset, null);
            yield return(null);

            Assert.AreEqual(8, graph.children.OfType <VFXParameter>().Count());
            Assert.AreEqual(11, graph.children.OfType <VFXParameter>().SelectMany(o => o.nodes).Count());
            Assert.AreEqual(0, graph.children.OfType <VFXParameter>().SelectMany(o => o.nodes).Where(o => o.position == Vector2.zero).Count(), "Fail after window.LoadAsset");
            foreach (var param in graph.children.OfType <VFXParameter>())
            {
                var nodes = param.nodes.Where(o => !o.linkedSlots.Any());
                if (nodes.Any())
                {
                    Assert.Fail(param.exposedName + " as an orphan node");
                }
            }
            Assert.AreEqual(0, graph.children.OfType <VFXParameter>().SelectMany(o => o.nodes).Where(o => !o.linkedSlots.Any()).Count()); //Orphan link
        }
コード例 #3
0
    public static bool OnOpenVFX(int instanceID, int line)
    {
        var obj = EditorUtility.InstanceIDToObject(instanceID);

        if (obj is VFXGraph || obj is VFXModel || obj is VFXUI)
        {
            // for visual effect graph editor ScriptableObject select them when double clicking on them.
            //Since .vfx importer is a copyasset, the default is to open it with an external editor.
            Selection.activeInstanceID = instanceID;
            return(true);
        }
        else if (obj is VisualEffectAsset)
        {
            VFXViewWindow.GetWindow <VFXViewWindow>().LoadAsset(obj as VisualEffectAsset, null);
            return(true);
        }
        else if (obj is Shader || obj is ComputeShader)
        {
            string path = AssetDatabase.GetAssetPath(instanceID);

            if (path.EndsWith(".vfx"))
            {
                var resource = VisualEffectResource.GetResourceAtPath(path);
                if (resource != null)
                {
                    int index = resource.GetShaderIndex(obj);
                    resource.ShowGeneratedShaderFile(index, line);
                    return(true);
                }
            }
        }
        return(false);
    }
コード例 #4
0
        private void EditTestAsset(int assetIndex)
        {
            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            window.Close();
            window                      = EditorWindow.GetWindow <VFXViewWindow>();
            m_ViewController            = VFXViewController.GetController(m_GuiTestAssets[assetIndex].GetResource(), true);
            window.graphView.controller = m_ViewController;
        }
コード例 #5
0
        public void CopyPasteBlock()
        {
            var initContextDesc = VFXLibrary.GetContexts().Where(t => t.name == "Initialize").First();

            var newContext = m_ViewController.AddVFXContext(new Vector2(100, 100), initContextDesc);

            m_ViewController.ApplyChanges();
            Assert.AreEqual(m_ViewController.allChildren.Where(t => t is VFXContextController).Count(), 1);

            var contextController = m_ViewController.allChildren.OfType <VFXContextController>().First();

            Assert.AreEqual(contextController.model, newContext);

            var flipBookBlockDesc = VFXLibrary.GetBlocks().First(t => t.name == "Set Tex Index ");

            contextController.AddBlock(0, flipBookBlockDesc.CreateInstance());

            var newBlock = contextController.model.children.First();

            m_ViewController.ApplyChanges();

            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            VFXView view = window.graphView;

            view.controller = m_ViewController;

            view.ClearSelection();
            foreach (var element in view.Query().OfType <VFXBlockUI>().ToList().OfType <ISelectable>())
            {
                view.AddToSelection(element);
            }

            VFXBlock flipBookBlock = m_ViewController.contexts.First().blockControllers.First().model;
            VFXSlot  minValueSlot  = flipBookBlock.GetInputSlot(0);

            float originalMinValue = 123.456f;

            minValueSlot.value = originalMinValue;

            view.CopySelectionCallback();

            minValueSlot.value = 789f;

            view.PasteCallback();

            view.controller.ApplyChanges();

            var elements = view.Query().OfType <VFXBlockUI>().ToList();

            var copyBlock = elements.Select(t => t.controller).First(t => t.model != newBlock).model;

            var copyMinSlot = copyBlock.GetInputSlot(0);

            Assert.AreEqual((float)copyMinSlot.value, originalMinValue);
        }
コード例 #6
0
        public void CreateTemplate()
        {
            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            VFXView view = window.graphView;

            view.controller = m_ViewController;

            view.CreateTemplateSystem("Assets/VFXEditor/Editor/Templates/Simple Particle System.vfx", Vector2.zero, null);
        }
コード例 #7
0
 private void AutoAttachToSelection()
 {
     if ((Selection.activeObject as GameObject)?.GetComponent <VisualEffect>() is VisualEffect visualEffect)
     {
         foreach (var window in VFXViewWindow.GetAllWindows())
         {
             window.AttachTo(visualEffect);
         }
     }
 }
コード例 #8
0
        void DestroyTestAsset(string name)
        {
            var filePath = string.Format(testAssetName, name);

            AssetDatabase.DeleteAsset(filePath);

            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            window.Close();
        }
コード例 #9
0
        public void CopyPasteOperator()
        {
            var crossOperatorDesc = VFXLibrary.GetOperators().Where(t => t.name == "Cross Product").First();

            var newOperator = m_ViewController.AddVFXOperator(new Vector2(100, 100), crossOperatorDesc);

            m_ViewController.ApplyChanges();
            var operatorController = m_ViewController.allChildren.OfType <VFXOperatorController>().First();

            Assert.AreEqual(operatorController.model, newOperator);

            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            VFXView view = window.graphView;

            view.controller = m_ViewController;

            view.ClearSelection();
            foreach (var element in view.Query().OfType <GraphElement>().ToList().OfType <ISelectable>())
            {
                view.AddToSelection(element);
            }


            VFXSlot aSlot = newOperator.GetInputSlot(0);

            Vector3 originalA = Vector3.one * 123;

            aSlot.value = originalA;

            view.CopySelectionCallback();

            aSlot.value = Vector3.one * 456;

            view.PasteCallback();

            var elements = view.Query().OfType <GraphElement>().ToList();

            var copyOperator = elements.OfType <VFXOperatorUI>().First(t => t.controller.model != newOperator);

            var copaASlot = copyOperator.controller.model.GetInputSlot(0);

            Assert.AreEqual((Vector3)copaASlot.value, originalA);

            Assert.AreNotEqual(copyOperator.controller.model.position, newOperator.position);

            view.PasteCallback();

            elements = view.Query().OfType <GraphElement>().ToList();
            var copy2Operator = elements.OfType <VFXOperatorUI>().First(t => t.controller.model != newOperator && t != copyOperator);

            Assert.AreNotEqual(copy2Operator.controller.model.position, newOperator.position);
            Assert.AreNotEqual(copy2Operator.controller.model.position, copyOperator.controller.model.position);
        }
コード例 #10
0
        public void DestroyTestAssets()
        {
            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            window.Close();

            for (int i = 0; i < testAssetCount; ++i)
            {
                DestroyTestAsset("GUITest" + i);
            }
        }
コード例 #11
0
    protected void OnEnable()
    {
        VFXViewWindow current = VFXViewWindow.GetWindow(target as VFXParameter);

        if (current != null)
        {
            controller = current.graphView.controller;
            if (controller != null)
            {
                controller.useCount++;
            }
        }
    }
コード例 #12
0
        public void DestroyTestAssets()
        {
            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            window.Close();

            for (int i = 0; i < testAssetCount; ++i)
            {
                DestroyTestAsset("GUITest" + i);
            }

            VFXTestCommon.DeleteAllTemporaryGraph();
        }
コード例 #13
0
    protected new void OnEnable()
    {
        base.OnEnable();

        VFXViewWindow current = VFXViewWindow.currentWindow;

        if (current != null)
        {
            controller = current.graphView.controller;
            if (controller != null)
            {
                controller.useCount++;
            }
        }
    }
コード例 #14
0
        new void OnDisable()
        {
            VisualEffect effect = ((VisualEffect)targets[0]);
            // Check if the component is attach in the editor. If So do not call base.OnDisable() because we don't want to reset the playrate or pause
            VFXViewWindow window = VFXViewWindow.currentWindow;

            if (window == null || window.graphView == null || window.graphView.attachedComponent != effect)
            {
                base.OnDisable();
            }

            m_ContextsPerComponent.Clear();
            EditMode.editModeStarted -= OnEditModeStart;
            EditMode.editModeEnded   -= OnEditModeEnd;
        }
コード例 #15
0
        public void ConvertToSubgraph()
        {
            //Create a new vfx based on the usual template
            var templateString = System.IO.File.ReadAllText(VisualEffectGraphPackageInfo.assetPackagePath + "/Editor/Templates/SimpleParticleSystem.vfx");

            System.IO.File.WriteAllText(testSubgraphAssetName, templateString);

            VFXViewWindow window = VFXViewWindow.GetWindow <VFXViewWindow>();

            window.LoadAsset(AssetDatabase.LoadAssetAtPath <VisualEffectAsset>(testAssetName), null);

            VFXConvertSubgraph.ConvertToSubgraphContext(window.graphView, window.graphView.Query <VFXContextUI>().ToList().Where(t => !(t.controller.model is VFXBasicSpawner)).Select(t => t.controller).Cast <Controller>(), Rect.zero, testSubgraphSubAssetName);

            window.graphView.controller = null;
        }
コード例 #16
0
        protected override void AssetField(VisualEffectResource resource)
        {
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PropertyField(m_VisualEffectAsset, Contents.assetPath);

                GUI.enabled = !m_VisualEffectAsset.hasMultipleDifferentValues && m_VisualEffectAsset.objectReferenceValue != null && resource != null; // Enabled state will be kept for all content until the end of the inspectorGUI.
                if (GUILayout.Button(Contents.openEditor, EditorStyles.miniButton, Styles.MiniButtonWidth))
                {
                    VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();
                    var           asset  = m_VisualEffectAsset.objectReferenceValue as VisualEffectAsset;
                    window.LoadAsset(asset, targets.Length > 1 ? null : target as VisualEffect);
                }
                GUI.enabled = true;
            }
        }
コード例 #17
0
        public void CopyPasteSpacableOperator()
        {
            var inlineOperatorDesc = VFXLibrary.GetOperators().Where(t => t.modelType == typeof(VFXInlineOperator)).First();

            var newOperator = m_ViewController.AddVFXOperator(new Vector2(100, 100), inlineOperatorDesc);

            newOperator.SetSettingValue("m_Type", new SerializableType(typeof(DirectionType)));

            m_ViewController.ApplyChanges();
            var operatorController = m_ViewController.allChildren.OfType <VFXOperatorController>().First();

            Assert.AreEqual(operatorController.model, newOperator);

            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            VFXView view = window.graphView;

            view.controller = m_ViewController;

            view.ClearSelection();
            foreach (var element in view.Query().OfType <GraphElement>().ToList().OfType <ISelectable>())
            {
                view.AddToSelection(element);
            }


            VFXSlot aSlot = newOperator.GetInputSlot(0);

            Assert.IsTrue(aSlot.spaceable);

            aSlot.space = VFXCoordinateSpace.World;

            string copyData = view.SerializeElements(view.selection.OfType <GraphElement>());

            aSlot.space = VFXCoordinateSpace.Local;

            view.UnserializeAndPasteElements("paste", copyData);

            var elements = view.Query().OfType <GraphElement>().ToList();

            var copyOperator = elements.OfType <VFXOperatorUI>().First(t => t.controller.model != newOperator);

            var copyASlot = copyOperator.controller.model.GetInputSlot(0);

            Assert.AreEqual(VFXCoordinateSpace.World, copyASlot.space);
        }
コード例 #18
0
        protected override void AssetField()
        {
            var component = (VisualEffect)target;

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PropertyField(m_VisualEffectAsset, Contents.assetPath);

                GUI.enabled = component.visualEffectAsset != null; // Enabled state will be kept for all content until the end of the inspectorGUI.
                if (GUILayout.Button(Contents.openEditor, EditorStyles.miniButton, Styles.MiniButtonWidth))
                {
                    VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

                    window.LoadAsset(component.visualEffectAsset, component);
                }
            }
        }
コード例 #19
0
 public static void RefreshVfxErrorsIfNeeded(ref bool needRefreshVfxErrors)
 {
     if (needRefreshVfxErrors)
     {
         foreach (var vfxWindow in VFXViewWindow.GetAllWindows())
         {
             if (vfxWindow != null)
             {
                 var vfxGraph = vfxWindow.graphView.controller.graph;
                 foreach (var output in vfxGraph.children.OfType <VFXDecalHDRPOutput>())
                 {
                     output.RefreshErrors(vfxGraph);
                 }
             }
         }
     }
     needRefreshVfxErrors = false;
 }
コード例 #20
0
        public void CreateTestAsset(string name)
        {
            var filePath      = string.Format(testAssetName, name);
            var directoryPath = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }


            m_Asset = VisualEffectResource.CreateNewAsset(filePath);
            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            window.Close();
            window                      = EditorWindow.GetWindow <VFXViewWindow>();
            m_ViewController            = VFXViewController.GetController(m_Asset.GetResource(), true);
            window.graphView.controller = m_ViewController;
        }
コード例 #21
0
        public IEnumerator VFXViewWindow_Open_And_Render([ValueSource("allVisualEffectAsset")] string vfxAssetPath)
        {
            VFXGraph graph;
            string   fullPath;

            LoadVFXGraph(vfxAssetPath, out fullPath, out graph);

            VFXViewWindow window = null;

            using (Measure.Scope("VFXViewWindow.Show"))
            {
                window = EditorWindow.GetWindow <VFXViewWindow>();
                window.Show();
                window.position    = new UnityEngine.Rect(0, 0, 1600, 900);
                window.autoCompile = false;
                window.Repaint();
            }
            yield return(null);

            using (Measure.Scope("VFXViewWindow.LoadAsset"))
            {
                var asset = k_fnGetAsset.Invoke(graph.visualEffectResource, new object[] { }) as VisualEffectAsset;
                window.LoadAsset(asset, null);
                window.graphView.FrameAll();
            }

            for (int i = 0; i < 8; ++i) //Render n frames
            {
                var position = window.graphView.viewTransform.position;
                position.x += i % 2 == 1 ? 3.0f : -3.0f;
                window.graphView.viewTransform.position = position;
                window.Repaint();
                yield return(Measure.Frames().SampleGroup("VFXViewWindow.Render").MeasurementCount(4).Run());
            }

            using (Measure.Scope("VFXViewWindow.Close"))
            {
                window.Close();
                yield return(null); //Ensure window is closed for next test
            }
        }
コード例 #22
0
        public void PasteSystems()
        {
            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            VFXView view = window.graphView;

            view.controller = m_ViewController;

            // Create a bunch of systems
            const int spawnerCount = 4, GPUSystemsCount = 4;
            var       spawners = VFXTestCommon.CreateSpawners(view, m_ViewController, spawnerCount);

            VFXTestCommon.CreateSystems(view, m_ViewController, GPUSystemsCount, 0);

            // Copy paste them
            view.ClearSelection();
            foreach (var element in view.Query().OfType <GraphElement>().ToList().OfType <ISelectable>())
            {
                view.AddToSelection(element);
            }
            view.CopySelectionCallback();
            view.PasteCallback();

            // Query unique names
            var systemNames = view.controller.graph.systemNames;
            var uniqueNames = new List <string>();

            foreach (var system in spawners)
            {
                uniqueNames.Add(systemNames.GetUniqueSystemName(system));
            }
            var GPUSystems = VFXTestCommon.GetFieldValue <VFXView, List <VFXSystemBorder> >(view, "m_Systems");

            uniqueNames = uniqueNames.Concat(GPUSystems.Select(system => system.controller.title)).ToList();

            // Remove null or empty names, and duplicates
            uniqueNames = uniqueNames.Where(name => !string.IsNullOrEmpty(name)).Distinct().ToList();

            // Assert all names are unique, and the expected number of elements was obtained
            Assert.IsTrue(uniqueNames.Count() == spawnerCount + GPUSystemsCount, "Some systems have the same name or are null or empty.");
        }
コード例 #23
0
        public void Subgraph_Event_Link_To_Spawn()
        {
            VFXViewWindow window = VFXViewWindow.GetWindow <VFXViewWindow>();

            window.LoadAsset(AssetDatabase.LoadAssetAtPath <VisualEffectAsset>(testAssetName), null);

            //Create Spawner in subgraph
            {
                var spawner = ScriptableObject.CreateInstance <VFXBasicSpawner>();
                m_ViewController.graph.AddChild(spawner);
                m_ViewController.LightApplyChanges();

                var controller = window.graphView.Query <VFXContextUI>().ToList().Select(t => t.controller).Cast <Controller>();
                Assert.AreEqual(1, controller.Count());
                VFXConvertSubgraph.ConvertToSubgraphContext(window.graphView, controller, Rect.zero, testSubgraphSubAssetName);
            }

            var subGraphController = m_ViewController.allChildren.OfType <VFXContextController>().FirstOrDefault(o => o.model is VFXSubgraphContext);

            Assert.IsNotNull(subGraphController);

            //Create Event Context & Link the two input flow
            var subGraphContext = subGraphController.model;
            var eventContext    = ScriptableObject.CreateInstance <VFXBasicEvent>();

            Assert.IsTrue(VFXContext.CanLink(eventContext, subGraphContext, 0, 0));
            Assert.IsTrue(VFXContext.CanLink(eventContext, subGraphContext, 0, 1));

            eventContext.LinkTo(subGraphContext, 0, 0);
            eventContext.LinkTo(subGraphContext, 0, 1);

            var flow = eventContext.outputFlowSlot.First().link;

            Assert.AreEqual(2, flow.Count());
            Assert.IsTrue(flow.All(o => o.context == subGraphContext));
            Assert.IsTrue(flow.Any(o => o.slotIndex == 0));
            Assert.IsTrue(flow.Any(o => o.slotIndex == 1));

            window.graphView.controller = null;
        }
コード例 #24
0
        protected override void AssetField(VisualEffectResource resource)
        {
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PropertyField(m_VisualEffectAsset, Contents.assetPath);

                bool saveEnabled = GUI.enabled;
                if (m_VisualEffectAsset.objectReferenceValue == null && !m_VisualEffectAsset.hasMultipleDifferentValues)
                {
                    GUI.enabled = saveEnabled;
                    if (GUILayout.Button(Contents.createAsset, EditorStyles.miniButton, Styles.MiniButtonWidth))
                    {
                        string filePath = EditorUtility.SaveFilePanelInProject("", "New Graph", "vfx", "Create new VisualEffect Graph");
                        if (!string.IsNullOrEmpty(filePath))
                        {
                            VisualEffectAssetEditorUtility.CreateTemplateAsset(filePath);
                            var asset = AssetDatabase.LoadAssetAtPath <VisualEffectAsset>(filePath);
                            m_VisualEffectAsset.objectReferenceValue = asset;
                            serializedObject.ApplyModifiedProperties();

                            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();
                            window.LoadAsset(asset, targets.Length > 1 ? null : target as VisualEffect);
                        }
                    }
                }
                else
                {
                    GUI.enabled = saveEnabled && !m_VisualEffectAsset.hasMultipleDifferentValues && m_VisualEffectAsset.objectReferenceValue != null && resource != null; // Enabled state will be kept for all content until the end of the inspectorGUI.
                    if (GUILayout.Button(Contents.openEditor, EditorStyles.miniButton, Styles.MiniButtonWidth))
                    {
                        VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();
                        var           asset  = m_VisualEffectAsset.objectReferenceValue as VisualEffectAsset;
                        window.LoadAsset(asset, targets.Length > 1 ? null : target as VisualEffect);
                    }
                }
                GUI.enabled = saveEnabled;
            }
        }
コード例 #25
0
        protected override void GenerateErrors(VFXInvalidateErrorReporter manager)
        {
            VFXSetting capacitySetting = GetSetting("capacity");

            if ((uint)capacitySetting.value > 1000000)
            {
                manager.RegisterError("CapacityOver1M", VFXErrorType.PerfWarning, "Systems with large capacities can be slow to simulate");
            }
            var data = GetData() as VFXDataParticle;

            if (data != null && CanBeCompiled())
            {
                if (data.boundsMode == BoundsSettingMode.Recorded)
                {
                    if (VFXViewWindow.GetWindow(GetGraph(), false, false)?.graphView?.attachedComponent == null ||
                        !BoardPreferenceHelper.IsVisible(BoardPreferenceHelper.Board.componentBoard, false))
                    {
                        manager.RegisterError("NeedsRecording", VFXErrorType.Warning,
                                              "In order to record the bounds, the current graph needs to be attached to a scene instance via the Target Game Object panel");
                    }
                    var boundsSlot = inputSlots.FirstOrDefault(s => s.name == "bounds");
                    if (boundsSlot != null && boundsSlot.HasLink(true))
                    {
                        manager.RegisterError("OverriddenRecording", VFXErrorType.Warning,
                                              "This system bounds will not be recorded because they are set from operators.");
                    }
                }

                if (data.boundsMode == BoundsSettingMode.Automatic)
                {
                    manager.RegisterError("CullingFlagAlwaysSimulate", VFXErrorType.Warning,
                                          "Setting the system Bounds Mode to Automatic will switch the culling flags of the Visual Effect asset" +
                                          " to 'Always recompute bounds and simulate'.");
                }
            }
        }
コード例 #26
0
        public void CopyPasteContextWithBlock()
        {
            var initContextDesc = VFXLibrary.GetContexts().Where(t => t.name == "Initialize").First();

            var newContext = m_ViewController.AddVFXContext(new Vector2(100, 100), initContextDesc);

            m_ViewController.ApplyChanges();

            Assert.AreEqual(m_ViewController.allChildren.Where(t => t is VFXContextController).Count(), 1);

            var contextController = m_ViewController.allChildren.OfType <VFXContextController>().First();

            Assert.AreEqual(contextController.model, newContext);

            var flipBookBlockDesc = VFXLibrary.GetBlocks().First(t => t.name == "Set Tex Index ");

            contextController.AddBlock(0, flipBookBlockDesc.CreateInstance());

            m_ViewController.ApplyChanges();

            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            VFXView view = window.graphView;

            view.controller = m_ViewController;

            view.ClearSelection();
            foreach (var element in view.Query().OfType <GraphElement>().ToList().OfType <ISelectable>())
            {
                view.AddToSelection(element);
            }

            VFXSlot boundsSlot = newContext.GetInputSlot(0);

            AABox originalBounds = new AABox()
            {
                center = Vector3.one, size = Vector3.one * 10
            };

            boundsSlot.value = originalBounds;

            VFXBlock flipBookBlock = m_ViewController.contexts.First().blockControllers.First().model;
            VFXSlot  minValueSlot  = flipBookBlock.GetInputSlot(0);


            float originalMinValue = 123.456f;

            minValueSlot.value = originalMinValue;

            view.CopySelectionCallback();

            boundsSlot.value = new AABox()
            {
                center = Vector3.zero, size = Vector3.zero
            };
            minValueSlot.value = 789f;

            view.PasteCallback();
            var elements = view.Query().OfType <GraphElement>().ToList();

            var contexts    = elements.OfType <VFXContextUI>().ToArray();
            var copyContext = elements.OfType <VFXContextUI>().Select(t => t.controller).First(t => t.model != newContext).model;

            var copyBoundsSlot = copyContext.GetInputSlot(0);
            var copyMinSlot    = copyContext[0].GetInputSlot(0);

            Assert.AreEqual((AABox)copyBoundsSlot.value, originalBounds);
            Assert.AreEqual((float)copyMinSlot.value, originalMinValue);
            Assert.AreNotEqual(copyContext.position, newContext.position);


            view.PasteCallback();

            elements = view.Query().OfType <GraphElement>().ToList();
            contexts = elements.OfType <VFXContextUI>().ToArray();

            var copy2Context = contexts.First(t => t.controller.model != newContext && t.controller.model != copyContext).controller.model;

            Assert.AreNotEqual(copy2Context.position, newContext.position);
            Assert.AreNotEqual(copy2Context.position, copyContext.position);
        }
コード例 #27
0
 private void DetachIfDeleted()
 {
     VFXViewWindow.GetAllWindows().ToList().ForEach(x => x.DetachIfDeleted());
 }
コード例 #28
0
        public void CopyPasteEdges()
        {
            VisualEffectAsset asset = AssetDatabase.LoadAssetAtPath <VisualEffectAsset>("Assets/AllTests/Editor/Tests/CopyPasteTest.vfx");

            VFXViewController controller = VFXViewController.GetController(asset.GetResource(), true);

            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();
            VFXView       view   = window.graphView;

            view.controller = controller;

            view.ClearSelection();


            var originalElements = view.Query().OfType <GraphElement>().ToList().OfType <ISelectable>().ToArray();

            Assert.AreNotEqual(originalElements.Length, 0);

            foreach (var element in originalElements)
            {
                view.AddToSelection(element);
            }

            view.CopySelectionCallback();

            view.controller = m_ViewController;

            view.PasteCallback();

            m_ViewController.ApplyChanges();

            VFXParameterUI[] parameters = view.Query().OfType <VFXParameterUI>().ToList().ToArray();

            Assert.AreEqual(parameters.Length, 2);

            if (parameters[0].title == "Vector3")
            {
                var tmp = parameters[0];
                parameters[0] = parameters[1];
                parameters[1] = tmp;
            }

            VFXOperatorUI[] operators = view.Query().OfType <VFXOperatorUI>().ToList().ToArray();

            Assert.AreEqual(operators.Length, 2);

            VFXContextUI[] contexts = view.Query().OfType <VFXContextUI>().ToList().ToArray();

            Assert.AreEqual(contexts.Length, 2);

            if (contexts[0].controller.model is VFXBasicUpdate)
            {
                var tmp = contexts[0];
                contexts[0] = contexts[1];
                contexts[1] = tmp;
            }


            VFXDataEdge[] dataEdges = view.Query().OfType <VFXDataEdge>().ToList().ToArray();

            Assert.AreEqual(dataEdges.Length, 4);

            Assert.IsNotNull(dataEdges.Where(t =>
                                             t.output.GetFirstAncestorOfType <VFXNodeUI>() == parameters[1] &&
                                             operators.Contains(t.input.GetFirstAncestorOfType <VFXOperatorUI>())
                                             ).FirstOrDefault());

            Assert.IsNotNull(dataEdges.Where(t =>
                                             operators.Contains(t.input.GetFirstAncestorOfType <VFXOperatorUI>()) &&
                                             operators.Contains(t.output.GetFirstAncestorOfType <VFXOperatorUI>()) &&
                                             t.output.GetFirstAncestorOfType <VFXNodeUI>() != t.input.GetFirstAncestorOfType <VFXNodeUI>()
                                             ).FirstOrDefault());

            Assert.IsNotNull(dataEdges.Where(t =>
                                             t.output.GetFirstAncestorOfType <VFXNodeUI>() == parameters[0] &&
                                             t.input.GetFirstAncestorOfType <VFXNodeUI>() == contexts[0]
                                             ).FirstOrDefault());

            Assert.IsNotNull(dataEdges.Where(t =>
                                             operators.Contains(t.output.GetFirstAncestorOfType <VFXNodeUI>()) &&
                                             t.input.GetFirstAncestorOfType <VFXNodeUI>() == contexts[0].GetAllBlocks().First()
                                             ).FirstOrDefault());


            VFXFlowEdge flowEdge = view.Query().OfType <VFXFlowEdge>();

            Assert.IsNotNull(flowEdge);

            Assert.AreEqual(flowEdge.output.GetFirstAncestorOfType <VFXContextUI>(), contexts[1]);
            Assert.AreEqual(flowEdge.input.GetFirstAncestorOfType <VFXContextUI>(), contexts[0]);
        }
コード例 #29
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            List <string> assetToReimport = null;

#if VFX_HAS_TIMELINE
            UnityEditor.VFX.Migration.ActivationToControlTrack.SanitizePlayable(importedAssets);
#endif

            foreach (var assetPath in importedAssets)
            {
                bool isVFX = VisualEffectAssetModicationProcessor.HasVFXExtension(assetPath);
                if (isVFX)
                {
                    VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);
                    if (resource == null)
                    {
                        continue;
                    }
                    VFXGraph graph = resource.GetOrCreateGraph(); //resource.graph should be already != null at this stage but GetOrCreateGraph is also assigning the visualEffectResource. It's required for UpdateSubAssets
                    if (graph != null)
                    {
                        bool wasGraphSanitized = graph.sanitized;

                        try
                        {
                            graph.SanitizeForImport();
                            if (!wasGraphSanitized && graph.sanitized)
                            {
                                assetToReimport ??= new List <string>();
                                assetToReimport.Add(assetPath);
                            }
                        }
                        catch (Exception exception)
                        {
                            Debug.LogErrorFormat("Exception during sanitization of {0} : {1}", assetPath, exception);
                        }

                        var window = VFXViewWindow.GetWindow(graph, false, false);
                        if (window != null)
                        {
                            window.UpdateTitle(assetPath);
                        }
                    }
                    else
                    {
                        Debug.LogErrorFormat("VisualEffectGraphResource without graph : {0}", assetPath);
                    }
                }
            }

            //Relaunch previously skipped OnCompileResource
            if (assetToReimport != null)
            {
                foreach (var assetPath in assetToReimport)
                {
                    try
                    {
                        AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
                    }
                    catch (Exception exception)
                    {
                        Debug.LogErrorFormat("Exception during reimport of {0} : {1}", assetPath, exception);
                    }
                }
            }
        }
コード例 #30
0
        public IEnumerator TestBoundsHelperResults([ValueSource(nameof(availableSpaces))] object systemSpace)
        {
            string             kSourceAsset = "Assets/AllTests/Editor/Tests/VFXBoundsHelperTest.vfx";
            var                graph        = VFXTestCommon.CopyTemporaryGraph(kSourceAsset);
            VFXCoordinateSpace space        = (VFXCoordinateSpace)systemSpace;

            graph.children.OfType <VFXBasicInitialize>().First().space = space;

            var gameObj = new GameObject("GameObjectToCheck");

            gameObj.transform.position   = m_Translation;
            gameObj.transform.rotation   = m_Rotation;
            gameObj.transform.localScale = m_Scale;

            var vfxComponent = gameObj.AddComponent <VisualEffect>();

            vfxComponent.visualEffectAsset = graph.visualEffectResource.asset;

            VFXViewWindow     window     = EditorWindow.GetWindow <VFXViewWindow>();
            VFXView           view       = window.graphView;
            VFXViewController controller = VFXViewController.GetController(vfxComponent.visualEffectAsset.GetResource(), true);

            view.controller        = controller;
            view.attachedComponent = vfxComponent;

            VFXBoundsRecorder boundsRecorder = new VFXBoundsRecorder(vfxComponent, view);

            boundsRecorder.ToggleRecording();
            vfxComponent.Simulate(1.0f / 60.0f);
            const int maxFrameTimeout = 100;

            for (int i = 0; i < maxFrameTimeout; i++)
            {
                boundsRecorder.UpdateBounds();
                if (boundsRecorder.bounds.Count > 0)
                {
                    break;
                }
                yield return(null); //skip a frame.
            }
            boundsRecorder.ToggleRecording();
            Bounds bounds = boundsRecorder.bounds.FirstOrDefault().Value;

            boundsRecorder.CleanUp();

            Vector3 expectedCenter = Vector3.zero;
            Vector3 expectedExtent = new Vector3(2.0f, 2.0f, 2.0f);

            expectedExtent += 0.5f * m_ParticleSize * (space == VFXCoordinateSpace.Local
                ? Mathf.Sqrt(3.0f)
                : Mathf.Sqrt(1.0f / Mathf.Pow(m_Scale.x, 2) + 1.0f / Mathf.Pow(m_Scale.y, 2) + 1.0f / Mathf.Pow(m_Scale.z, 2)));

            Assert.AreEqual(expectedCenter.x, bounds.center.x, .002);
            Assert.AreEqual(expectedCenter.y, bounds.center.y, .002);
            Assert.AreEqual(expectedCenter.z, bounds.center.z, .002);
            Assert.AreEqual(expectedExtent.x, bounds.extents.x, .005);
            Assert.AreEqual(expectedExtent.y, bounds.extents.y, .005);
            Assert.AreEqual(expectedExtent.z, bounds.extents.z, .005);

            view.attachedComponent = null;
            window.Close();

            yield return(null);
        }