public IEnumerator Save_Then_Modify_Something_Check_The_Content_Isnt_Reverted() { string path = null; uint baseValue = 100; var graph = VFXTestCommon.MakeTemporaryGraph(); { path = AssetDatabase.GetAssetPath(graph); var unsigned = ScriptableObject.CreateInstance <VFXInlineOperator>(); unsigned.SetSettingValue("m_Type", (SerializableType)typeof(uint)); unsigned.inputSlots[0].value = baseValue; graph.AddChild(unsigned); AssetDatabase.ImportAsset(path); } yield return(null); for (uint i = 0; i < 3; ++i) { var inlineOperator = graph.children.OfType <VFXInlineOperator>().FirstOrDefault(); Assert.IsNotNull(inlineOperator); Assert.AreEqual(baseValue + i, (uint)inlineOperator.inputSlots[0].value, "Failing at iteration : " + i); graph.GetResource().WriteAsset(); inlineOperator.inputSlots[0].value = baseValue + i + 1; //Update for next iteration Assert.AreEqual(baseValue + i + 1, (uint)inlineOperator.inputSlots[0].value); AssetDatabase.ImportAsset(path); yield return(null); } }
public void GraphUsingGPUConstant() { var graph = VFXTestCommon.MakeTemporaryGraph(); var updateContext = ScriptableObject.CreateInstance <VFXBasicUpdate>(); var blockSetVelocity = ScriptableObject.CreateInstance <SetAttribute>(); blockSetVelocity.SetSettingValue("attribute", "velocity"); var attributeParameter = ScriptableObject.CreateInstance <VFXAttributeParameter>(); attributeParameter.SetSettingValue("attribute", "color"); var add = ScriptableObject.CreateInstance <Operator.Add>(); var length = ScriptableObject.CreateInstance <Operator.Length>(); var float4 = VFXLibrary.GetParameters().First(o => o.name == "Vector4").CreateInstance(); graph.AddChild(updateContext); updateContext.AddChild(blockSetVelocity); graph.AddChild(attributeParameter); graph.AddChild(add); graph.AddChild(float4); graph.AddChild(length); graph.RecompileIfNeeded(); attributeParameter.outputSlots[0].Link(blockSetVelocity.inputSlots[0]); graph.RecompileIfNeeded(); attributeParameter.outputSlots[0].Link(add.inputSlots[0]); float4.outputSlots[0].Link(add.inputSlots[1]); add.outputSlots[0].Link(length.inputSlots[0]); length.outputSlots[0].Link(blockSetVelocity.inputSlots[0]); graph.RecompileIfNeeded(); }
public IEnumerable Verify_Orphan_Dependencies_Are_Correctly_Cleared() { string path = null; { var graph = VFXTestCommon.MakeTemporaryGraph(); path = AssetDatabase.GetAssetPath(graph); var spawnerContext = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var blockConstantRate = ScriptableObject.CreateInstance <VFXSpawnerConstantRate>(); var slotCount = blockConstantRate.GetInputSlot(0); var basicInitialize = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var quadOutput = ScriptableObject.CreateInstance <VFXPlanarPrimitiveOutput>(); quadOutput.SetSettingValue("blendMode", VFXAbstractParticleOutput.BlendMode.Additive); var setPosition = ScriptableObject.CreateInstance <Block.SetAttribute>(); setPosition.SetSettingValue("attribute", "position"); setPosition.inputSlots[0].value = VFX.Position.defaultValue; basicInitialize.AddChild(setPosition); slotCount.value = 1.0f; spawnerContext.AddChild(blockConstantRate); graph.AddChild(spawnerContext); graph.AddChild(basicInitialize); graph.AddChild(quadOutput); basicInitialize.LinkFrom(spawnerContext); quadOutput.LinkFrom(basicInitialize); } var recordedSize = new List <long>(); for (uint i = 0; i < 16; ++i) { AssetDatabase.ImportAsset(path); var asset = AssetDatabase.LoadAssetAtPath <VisualEffectAsset>(path); var graph = asset.GetResource().GetOrCreateGraph(); graph.GetResource().WriteAsset(); recordedSize.Add(new FileInfo(path).Length); var quadOutput = graph.children.OfType <VFXPlanarPrimitiveOutput>().FirstOrDefault(); quadOutput.UnlinkAll(); graph.RemoveChild(quadOutput); var newQuadOutput = ScriptableObject.CreateInstance <VFXPlanarPrimitiveOutput>(); newQuadOutput.SetSettingValue("blendMode", VFXAbstractParticleOutput.BlendMode.Additive); graph.AddChild(newQuadOutput); var basicInitialize = graph.children.OfType <VFXBasicInitialize>().FirstOrDefault(); newQuadOutput.LinkFrom(basicInitialize); } Assert.AreEqual(1, recordedSize.GroupBy(o => o).Count()); Assert.AreNotEqual(0u, recordedSize[0]); yield return(null); }
public IEnumerator CreatePrefab_And_Disable_Root_Then_Modify_Exposed_Finally_Renable_Root() { //Cover case 1230230 : VFX parameters are not set when the gameobject is immediately deactivated and is not selected in the Hierarchy var graph = VFXTestCommon.MakeTemporaryGraph(); var parametersUintDesc = VFXLibrary.GetParameters().Where(o => o.model.type == typeof(uint)).First(); var parameter = parametersUintDesc.CreateInstance(); parameter.SetSettingValue("m_ExposedName", m_Exposed_name_CreatePrefab_And_Disable_Root_Then_Modify_Exposed_Finally_Renable); parameter.SetSettingValue("m_Exposed", true); parameter.value = 123u; graph.AddChild(parameter); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var mainObject = new GameObject("CreatePrefab_And_Disable_Root_Then_Modify_Exposed_Finally_Renable", typeof(VisualEffect)); mainObject.GetComponent <VisualEffect>().visualEffectAsset = graph.visualEffectResource.asset; GameObject newGameObject, prefabInstanceObject; MakeTemporaryPrebab(mainObject, out newGameObject, out prefabInstanceObject); GameObject.DestroyImmediate(mainObject); m_Prefab_CreatePrefab_And_Disable_Root_Then_Modify_Exposed_Finally_Renable = prefabInstanceObject; yield return(new EnterPlayMode()); var exposedExpectedValue = 43000u; var exposedName = m_Exposed_name_CreatePrefab_And_Disable_Root_Then_Modify_Exposed_Finally_Renable; var r = GameObject.Instantiate(m_Prefab_CreatePrefab_And_Disable_Root_Then_Modify_Exposed_Finally_Renable, Vector3.zero, Quaternion.identity); var vfx = r.GetComponent <VisualEffect>(); Assert.IsTrue(vfx.HasUInt(exposedName)); Assert.AreNotEqual(exposedExpectedValue, vfx.GetUInt(exposedName)); vfx.SetUInt(exposedName, exposedExpectedValue); r.SetActive(false); for (int i = 0; i < 4; ++i) { yield return(null); } Assert.AreEqual(exposedExpectedValue, vfx.GetUInt(exposedName)); r.SetActive(true); Assert.AreEqual(exposedExpectedValue, vfx.GetUInt(exposedName)); for (int i = 0; i < 4; ++i) { yield return(null); } Assert.AreEqual(exposedExpectedValue, vfx.GetUInt(exposedName)); yield return(new ExitPlayMode()); m_Prefab_CreatePrefab_And_Disable_Root_Then_Modify_Exposed_Finally_Renable = null; }
public IEnumerator Create_Prefab_And_Verify_Empty_Override() { var graph = VFXTestCommon.MakeTemporaryGraph(); const int systemCount = 3; for (int i = 0; i < systemCount; ++i) { Add_Valid_System(graph); } AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var mainObject = MakeTemporaryGameObject(); GameObject prefabInstanceObject; { var tempVFX = mainObject.AddComponent <VisualEffect>(); tempVFX.visualEffectAsset = graph.visualEffectResource.asset; GameObject newGameObject; MakeTemporaryPrebab(mainObject, out newGameObject, out prefabInstanceObject); GameObject.DestroyImmediate(mainObject); mainObject = PrefabUtility.InstantiatePrefab(prefabInstanceObject) as GameObject; } yield return(null); Assert.IsNotNull(mainObject.GetComponent <VisualEffect>()); var properties = PrefabUtility.GetPropertyModifications(mainObject); //Filter out transform properties & GameObject.m_Name properties = properties.Where(o => { if (o.target is UnityEngine.Transform) { return(false); } if (o.target is GameObject && o.propertyPath == "m_Name") { return(false); } return(true); }).ToArray(); var logMessage = string.Empty; if (properties.Any()) { logMessage = properties.Select(o => string.Format("{0} at {1} : {2}", o.target, o.propertyPath, o.value)) .Aggregate((a, b) => a + "\n" + b); } Assert.AreEqual(0, properties.Length, logMessage); }
public IEnumerator Create_Asset_And_Component_Check_Overflow_MaxDeltaTime([ValueSource("updateModes")] object updateMode) { var graph = VFXTestCommon.MakeTemporaryGraph(); graph.visualEffectResource.updateMode = (VFXUpdateMode)updateMode; var spawnerContext = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var constantRate = ScriptableObject.CreateInstance <VFXSpawnerConstantRate>(); var initContext = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var outputContext = ScriptableObject.CreateInstance <VFXPointOutput>(); graph.AddChild(initContext); graph.AddChild(outputContext); spawnerContext.LinkTo(initContext); initContext.LinkTo(outputContext); spawnerContext.AddChild(constantRate); graph.AddChild(spawnerContext); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var vfxComponent = m_gameObject.AddComponent <VisualEffect>(); vfxComponent.visualEffectAsset = graph.visualEffectResource.asset; float fixedTimeStep = 1.0f / 20.0f; float maxTimeStep = 1.0f / 10.0f; UnityEngine.VFX.VFXManager.fixedTimeStep = fixedTimeStep; UnityEngine.VFX.VFXManager.maxDeltaTime = maxTimeStep; /* waiting for culling (simulating big delay between each frame) */ int maxFrame = 512; VFXSpawnerState spawnerState = VisualEffectUtility.GetSpawnerState(vfxComponent, 0u); float sleepTimeInSeconds = maxTimeStep * 5.0f; while (--maxFrame > 0 && spawnerState.deltaTime != maxTimeStep) { System.Threading.Thread.Sleep((int)(sleepTimeInSeconds * 1000.0f)); yield return(null); spawnerState = VisualEffectUtility.GetSpawnerState(vfxComponent, 0u); } Assert.IsTrue(maxFrame > 0); if (graph.visualEffectResource.updateMode == VFXUpdateMode.FixedDeltaTime) { Assert.AreEqual(maxTimeStep, spawnerState.deltaTime); } else { Assert.AreEqual(maxTimeStep, spawnerState.deltaTime); //< There is clamp even in delta time mode //Assert.AreEqual((double)sleepTimeInSeconds, spawnerState.deltaTime, 0.01f); } yield return(null); }
private static VFXViewController StartEditTestAsset() { var window = EditorWindow.GetWindow <VFXViewWindow>(); window.Show(); var graph = VFXTestCommon.MakeTemporaryGraph(); var viewController = VFXViewController.GetController(graph.GetResource(), true); window.graphView.controller = viewController; return(viewController); }
public IEnumerator Create_Asset_And_Component_Check_Expected_TotalTime() { yield return(new EnterPlayMode()); var graph = VFXTestCommon.MakeTemporaryGraph(); var spawnerContext = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var constantRate = ScriptableObject.CreateInstance <VFXSpawnerConstantRate>(); // Attach to a valid particle system so that spawner is compiled var initContext = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var outputContext = ScriptableObject.CreateInstance <VFXPointOutput>(); graph.AddChild(initContext); graph.AddChild(outputContext); spawnerContext.LinkTo(initContext); initContext.LinkTo(outputContext); var slotRate = constantRate.GetInputSlot(0); var totalTime = GetTotalTimeOperator().CreateInstance(); slotRate.Link(totalTime.GetOutputSlot(0)); spawnerContext.AddChild(constantRate); graph.AddChild(spawnerContext); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var expressionIndex = graph.FindReducedExpressionIndexFromSlotCPU(slotRate); while (m_gameObject.GetComponent <VisualEffect>() != null) { UnityEngine.Object.DestroyImmediate(m_gameObject.GetComponent <VisualEffect>()); } var vfxComponent = m_gameObject.AddComponent <VisualEffect>(); vfxComponent.visualEffectAsset = graph.visualEffectResource.asset; int maxFrame = 512; while (vfxComponent.culled && --maxFrame > 0) { yield return(null); } Assert.IsTrue(maxFrame > 0); maxFrame = 512; while (!(VisualEffectUtility.GetExpressionFloat(vfxComponent, expressionIndex) > 0.01f) && --maxFrame > 0) { yield return(null); } Assert.IsTrue(maxFrame > 0); yield return(new ExitPlayMode()); }
public IEnumerator Create_Simple_Graph_Then_Remove_Edge_Between_Init_And_Update([ValueSource(nameof(Create_Simple_Graph_Then_Remove_Edget_Between_Init_And_Update_TestCase))] bool autoCompile) { var graph = VFXTestCommon.MakeTemporaryGraph(); var path = AssetDatabase.GetAssetPath(graph); var spawner = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var init = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var update = ScriptableObject.CreateInstance <VFXBasicUpdate>(); var output = ScriptableObject.CreateInstance <VFXPlanarPrimitiveOutput>(); graph.AddChild(spawner); graph.AddChild(init); graph.AddChild(update); graph.AddChild(output); init.LinkFrom(spawner); update.LinkFrom(init); output.LinkFrom(update); AssetDatabase.ImportAsset(path); yield return(null); //The issue is actually visible in VFXView var window = EditorWindow.GetWindow <VFXViewWindow>(); window.Show(); var bckpAutoCompile = window.autoCompile; window.autoCompile = autoCompile; window.LoadAsset(graph.GetResource().asset, null); //update.UnlinkFrom(init); //Doesn't reproduce the issue var allFlowEdges = window.graphView.controller.allChildren.OfType <VFXFlowEdgeController>().ToArray(); var flowEdgeToDelete = allFlowEdges.Where(o => o.output.context.model.contextType == VFXContextType.Init && o.input.context.model.contextType == VFXContextType.Update).ToArray(); Assert.AreEqual(1u, flowEdgeToDelete.Length); window.graphView.controller.Remove(flowEdgeToDelete); window.graphView.controller.NotifyUpdate(); //<= This function will indirectly try to access system name before update (called by VFXView.Update yield return(null); window.autoCompile = bckpAutoCompile; }
void GraphWithImplicitBehavior_Internal(VFXBlock[] initBlocks) { var graph = VFXTestCommon.MakeTemporaryGraph(); var spawnerContext = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var initContext = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var updateContext = ScriptableObject.CreateInstance <VFXBasicUpdate>(); var outputContext = ScriptableObject.CreateInstance <VFXPointOutput>(); graph.AddChild(spawnerContext); graph.AddChild(initContext); graph.AddChild(updateContext); graph.AddChild(outputContext); spawnerContext.LinkTo(initContext); initContext.LinkTo(updateContext); updateContext.LinkTo(outputContext); foreach (var initBlock in initBlocks) { initContext.AddChild(initBlock); } graph.RecompileIfNeeded(); }
public IEnumerator Create_Prefab_Several_Override() { var graph = VFXTestCommon.MakeTemporaryGraph(); var parametersIntDesc = VFXLibrary.GetParameters().Where(o => o.model.type == typeof(int)).First(); Func <VisualEffect, string> dumpPropertySheetInteger = delegate(VisualEffect target) { var r = "{"; var editor = Editor.CreateEditor(target); editor.serializedObject.Update(); var propertySheet = editor.serializedObject.FindProperty("m_PropertySheet"); var fieldName = VisualEffectSerializationUtility.GetTypeField(VFXExpression.TypeToType(VFXValueType.Int32)) + ".m_Array"; var vfxField = propertySheet.FindPropertyRelative(fieldName); for (int i = 0; i < vfxField.arraySize; ++i) { var itField = vfxField.GetArrayElementAtIndex(i); var name = itField.FindPropertyRelative("m_Name").stringValue; var value = itField.FindPropertyRelative("m_Value").intValue; var overridden = itField.FindPropertyRelative("m_Overridden").boolValue; r += string.Format("({0}, {1}, {2})", name, value, overridden); if (i != vfxField.arraySize - 1) { r += ", "; } } GameObject.DestroyImmediate(editor); r += "}"; return(r); }; var log = string.Empty; var exposedProperties = new[] { "a", "b", "c" }; for (var i = 0; i < exposedProperties.Length; ++i) { var parameter = parametersIntDesc.CreateInstance(); parameter.SetSettingValue("m_ExposedName", exposedProperties[i]); parameter.SetSettingValue("m_Exposed", true); parameter.value = i + 1; graph.AddChild(parameter); } AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var mainObject = MakeTemporaryGameObject(); var vfx = mainObject.AddComponent <VisualEffect>(); vfx.visualEffectAsset = graph.visualEffectResource.asset; GameObject newGameObject, prefabInstanceObject; MakeTemporaryPrebab(mainObject, out newGameObject, out prefabInstanceObject); GameObject.DestroyImmediate(mainObject); yield return(null); var currentPrefabInstanceObject = PrefabUtility.InstantiatePrefab(prefabInstanceObject) as GameObject; var overridenParametersInScene = new[] { new { name = "b", value = 666 }, new { name = "a", value = 444 } }; var overridenParametersInPrefab = new[] { new { name = "c", value = -123 } }; log += "Initial Sheet\n"; log += "Prefab : " + dumpPropertySheetInteger(prefabInstanceObject.GetComponent <VisualEffect>()) + "\n"; log += "Instance : " + dumpPropertySheetInteger(currentPrefabInstanceObject.GetComponent <VisualEffect>()) + "\n"; yield return(null); foreach (var overridenParameter in overridenParametersInScene) { currentPrefabInstanceObject.GetComponent <VisualEffect>().SetInt(overridenParameter.name, overridenParameter.value); } log += "\nIntermediate Sheet\n"; log += "Prefab : " + dumpPropertySheetInteger(prefabInstanceObject.GetComponent <VisualEffect>()) + "\n"; log += "Instance : " + dumpPropertySheetInteger(currentPrefabInstanceObject.GetComponent <VisualEffect>()) + "\n"; yield return(null); foreach (var overridenParameter in overridenParametersInPrefab) { prefabInstanceObject.GetComponent <VisualEffect>().SetInt(overridenParameter.name, overridenParameter.value); } yield return(null); log += "\nEnd Sheet\n"; log += "Prefab : " + dumpPropertySheetInteger(prefabInstanceObject.GetComponent <VisualEffect>()) + "\n"; log += "Instance : " + dumpPropertySheetInteger(currentPrefabInstanceObject.GetComponent <VisualEffect>()) + "\n"; var stringFormat = @"({0} : {1}) "; var expectedValues = string.Empty; for (var i = 0; i < exposedProperties.Length; ++i) { var expectedValue = i; var expectedName = exposedProperties[i]; var overrideInPrefab = overridenParametersInPrefab.FirstOrDefault(o => o.name == exposedProperties[i]); var overrideInScene = overridenParametersInScene.FirstOrDefault(o => o.name == exposedProperties[i]); if (overrideInPrefab != null) { expectedValue = overrideInPrefab.value; } if (overrideInScene != null) { expectedValue = overrideInScene.value; } expectedValues += string.Format(stringFormat, expectedName, expectedValue); } var actualValues = string.Empty; for (var i = 0; i < exposedProperties.Length; ++i) { var expectedName = exposedProperties[i]; var actualValue = currentPrefabInstanceObject.GetComponent <VisualEffect>().GetInt(expectedName); actualValues += string.Format(stringFormat, expectedName, actualValue); } if (k_HasFixed_Several_PrefabOverride) { Assert.AreEqual(expectedValues, actualValues, log); } else { Assert.AreNotEqual(expectedValues, actualValues, log); //Did you fixed it ? Should enable this test : k_HasFixed_Several_PrefabOverride } yield return(null); }
public IEnumerator Create_Prefab_Modify_And_Expect_No_Override() { var graph = VFXTestCommon.MakeTemporaryGraph(); var parametersVector3Desc = VFXLibrary.GetParameters().Where(o => o.model.type == typeof(Vector3)).First(); var exposedName = "ghjkl"; var parameter = parametersVector3Desc.CreateInstance(); parameter.SetSettingValue("m_ExposedName", exposedName); parameter.SetSettingValue("m_Exposed", true); parameter.value = new Vector3(0, 0, 0); graph.AddChild(parameter); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var mainObject = MakeTemporaryGameObject(); var vfx = mainObject.AddComponent <VisualEffect>(); vfx.visualEffectAsset = graph.visualEffectResource.asset; Assert.IsTrue(vfx.HasVector3(exposedName)); vfx.SetVector3(exposedName, new Vector3(1, 2, 3)); GameObject newGameObject, prefabInstanceObject; MakeTemporaryPrebab(mainObject, out newGameObject, out prefabInstanceObject); GameObject.DestroyImmediate(mainObject); var currentPrefabInstanceObject = PrefabUtility.InstantiatePrefab(prefabInstanceObject) as GameObject; yield return(null); var vfxInPrefab = prefabInstanceObject.GetComponent <VisualEffect>(); var expectedNewValue = new Vector3(4, 5, 6); if (k_HasFixed_DisabledState) { Assert.IsTrue(vfxInPrefab.HasVector3(exposedName)); vfxInPrefab.SetVector3(exposedName, expectedNewValue); } else { /* modifying prefab using serialized property */ var editor = Editor.CreateEditor(vfxInPrefab); editor.serializedObject.Update(); var propertySheet = editor.serializedObject.FindProperty("m_PropertySheet"); var fieldName = VisualEffectSerializationUtility.GetTypeField(VFXExpression.TypeToType(VFXValueType.Float3)) + ".m_Array"; var vfxField = propertySheet.FindPropertyRelative(fieldName); Assert.AreEqual(1, vfxField.arraySize); var property = vfxField.GetArrayElementAtIndex(0); property = property.FindPropertyRelative("m_Value"); property.vector3Value = expectedNewValue; editor.serializedObject.ApplyModifiedPropertiesWithoutUndo(); GameObject.DestroyImmediate(editor); EditorUtility.SetDirty(prefabInstanceObject); } //AssetDatabase.SaveAssets(); //Helps debug but not necessary PrefabUtility.SavePrefabAsset(prefabInstanceObject); yield return(null); var currentVFXInstanciedFromPrefab = currentPrefabInstanceObject.GetComponent <VisualEffect>(); Assert.IsTrue(currentVFXInstanciedFromPrefab.HasVector3(exposedName)); var refExposedValue = currentVFXInstanciedFromPrefab.GetVector3(exposedName); var newInstanciedFromPrefab = PrefabUtility.InstantiatePrefab(prefabInstanceObject) as GameObject; var newVFXInstanciedFromPrefab = newInstanciedFromPrefab.GetComponent <VisualEffect>(); Assert.IsTrue(newVFXInstanciedFromPrefab.HasVector3(exposedName)); var newExposedValue = newVFXInstanciedFromPrefab.GetVector3(exposedName); var overrides = PrefabUtility.GetObjectOverrides(currentPrefabInstanceObject); Assert.AreEqual(newExposedValue.x, expectedNewValue.x); Assert.AreEqual(newExposedValue.y, expectedNewValue.y); Assert.AreEqual(newExposedValue.z, expectedNewValue.z); //< Expected to work if (k_HasFixed_PrefabOverride) { //Known issue : Failing due to fogbugz 1117103 Assert.AreEqual(refExposedValue.x, expectedNewValue.x); Assert.AreEqual(refExposedValue.y, expectedNewValue.y); Assert.AreEqual(refExposedValue.z, expectedNewValue.z); Assert.IsEmpty(overrides); } }
public IEnumerator Create_Prefab_Switch_To_Empty_VisualEffectAsset() { var graph = VFXTestCommon.MakeTemporaryGraph(); const int systemCount = 3; for (int i = 0; i < systemCount; ++i) { Add_Valid_System(graph); } AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var mainObject = MakeTemporaryGameObject(); GameObject prefabInstanceObject; { var tempVFX = mainObject.AddComponent <VisualEffect>(); tempVFX.visualEffectAsset = graph.visualEffectResource.asset; GameObject newGameObject; MakeTemporaryPrebab(mainObject, out newGameObject, out prefabInstanceObject); GameObject.DestroyImmediate(mainObject); mainObject = PrefabUtility.InstantiatePrefab(prefabInstanceObject) as GameObject; } yield return(null); var vfx = mainObject.GetComponent <VisualEffect>(); var vfxInPrefab = prefabInstanceObject.GetComponent <VisualEffect>(); var systemNames = new List <string>(); systemNames.Clear(); vfx.GetSystemNames(systemNames); Assert.AreEqual(systemCount * 2, systemNames.Count); systemNames.Clear(); vfxInPrefab.GetSystemNames(systemNames); Assert.AreEqual(systemCount * 2, systemNames.Count); while (!vfx.isActiveAndEnabled) { yield return(null); } yield return(null); { //vfxInPrefab.visualEffectAsset = null; //Doesn't cover awake from load beahavior which is the most common //modifying prefab using serialized property var editor = Editor.CreateEditor(vfxInPrefab); editor.serializedObject.Update(); var assetProperty = editor.serializedObject.FindProperty("m_Asset"); assetProperty.objectReferenceValue = null; editor.serializedObject.ApplyModifiedPropertiesWithoutUndo(); GameObject.DestroyImmediate(editor); EditorUtility.SetDirty(prefabInstanceObject); } PrefabUtility.SavePrefabAsset(prefabInstanceObject); //It will crash ! yield return(null); systemNames.Clear(); vfx.GetSystemNames(systemNames); Assert.AreEqual(0u, systemNames.Count); systemNames.Clear(); vfxInPrefab.GetSystemNames(systemNames); Assert.AreEqual(0u, systemNames.Count); Assert.IsTrue(true); //Should not have crashed here }
public IEnumerator CreateAssetAndComponent_Space_Bounds([ValueSource("available_Space")] object systemSpace, [ValueSource("available_Space")] object boundSpace) { var objectPosition = new Vector3(0.123f, 0.0f, 0.0f); var boundPosition = new Vector3(0.0f, 0.0987f, 0.0f); yield return(new EnterPlayMode()); var graph = VFXTestCommon.MakeTemporaryGraph(); var spawnerContext = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var blockConstantRate = ScriptableObject.CreateInstance <VFXSpawnerConstantRate>(); var basicInitialize = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var basicUpdate = ScriptableObject.CreateInstance <VFXBasicUpdate>(); var quadOutput = ScriptableObject.CreateInstance <VFXPlanarPrimitiveOutput>(); quadOutput.SetSettingValue("blendMode", VFXAbstractParticleOutput.BlendMode.Additive); var setLifetime = ScriptableObject.CreateInstance <SetAttribute>(); //only needed to allocate a minimal attributeBuffer setLifetime.SetSettingValue("attribute", "lifetime"); setLifetime.inputSlots[0].value = 1.0f; basicInitialize.AddChild(setLifetime); spawnerContext.AddChild(blockConstantRate); graph.AddChild(spawnerContext); graph.AddChild(basicInitialize); graph.AddChild(basicUpdate); graph.AddChild(quadOutput); basicInitialize.LinkFrom(spawnerContext); basicUpdate.LinkFrom(basicInitialize); quadOutput.LinkFrom(basicUpdate); basicInitialize.space = (VFXCoordinateSpace)systemSpace; basicInitialize.inputSlots[0].space = (VFXCoordinateSpace)boundSpace; basicInitialize.inputSlots[0][0].value = boundPosition; basicInitialize.inputSlots[0][1].value = Vector3.one * 5.0f; AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var gameObj = new GameObject("CreateAssetAndComponentToCheckBound"); gameObj.transform.position = objectPosition; var vfxComponent = gameObj.AddComponent <VisualEffect>(); vfxComponent.visualEffectAsset = graph.visualEffectResource.asset; var cameraObj = new GameObject("CreateAssetAndComponentToCheckBound_Camera"); var camera = cameraObj.AddComponent <Camera>(); camera.transform.localPosition = Vector3.one; camera.transform.LookAt(vfxComponent.transform); int maxFrame = 512; while (vfxComponent.culled && --maxFrame > 0) { yield return(null); } Assert.IsTrue(maxFrame > 0); yield return(null); //wait for exactly one more update if visible var renderer = vfxComponent.GetComponent <VFXRenderer>(); var parentFromCenter = VFXSpacePropagationTest.CollectParentExpression(basicInitialize.inputSlots[0][0].GetExpression()).ToArray(); if ((VFXCoordinateSpace)systemSpace == VFXCoordinateSpace.Local && (VFXCoordinateSpace)boundSpace == VFXCoordinateSpace.Local) { Assert.IsFalse(parentFromCenter.Any(o => o.operation == VFXExpressionOperation.LocalToWorld || o.operation == VFXExpressionOperation.WorldToLocal)); Assert.AreEqual(boundPosition.x + objectPosition.x, renderer.bounds.center.x, 0.0001); Assert.AreEqual(boundPosition.y + objectPosition.y, renderer.bounds.center.y, 0.0001); Assert.AreEqual(boundPosition.z + objectPosition.z, renderer.bounds.center.z, 0.0001); } else if ((VFXCoordinateSpace)systemSpace == VFXCoordinateSpace.World && (VFXCoordinateSpace)boundSpace == VFXCoordinateSpace.Local) { Assert.IsFalse(parentFromCenter.Any(o => o.operation == VFXExpressionOperation.LocalToWorld || o.operation == VFXExpressionOperation.WorldToLocal)); Assert.AreEqual(boundPosition.x + objectPosition.x, renderer.bounds.center.x, 0.0001); Assert.AreEqual(boundPosition.y + objectPosition.y, renderer.bounds.center.y, 0.0001); Assert.AreEqual(boundPosition.z + objectPosition.z, renderer.bounds.center.z, 0.0001); } else if ((VFXCoordinateSpace)systemSpace == VFXCoordinateSpace.World && (VFXCoordinateSpace)boundSpace == VFXCoordinateSpace.World) { Assert.IsTrue(parentFromCenter.Count(o => o.operation == VFXExpressionOperation.WorldToLocal) == 1); //object position has no influence in that case Assert.AreEqual(boundPosition.x, renderer.bounds.center.x, 0.0001); Assert.AreEqual(boundPosition.y, renderer.bounds.center.y, 0.0001); Assert.AreEqual(boundPosition.z, renderer.bounds.center.z, 0.0001); } else if ((VFXCoordinateSpace)systemSpace == VFXCoordinateSpace.Local && (VFXCoordinateSpace)boundSpace == VFXCoordinateSpace.World) { Assert.IsTrue(parentFromCenter.Count(o => o.operation == VFXExpressionOperation.WorldToLocal) == 1); //object position has no influence in that case Assert.AreEqual(boundPosition.x, renderer.bounds.center.x, 0.0001); Assert.AreEqual(boundPosition.y, renderer.bounds.center.y, 0.0001); Assert.AreEqual(boundPosition.z, renderer.bounds.center.z, 0.0001); } else { //Unknown case, should not happen Assert.IsFalse(true); } yield return(new ExitPlayMode()); }
public void CheckName_Sharing_Between_Output_Event() { var graph = VFXTestCommon.MakeTemporaryGraph(); var gameObj = new GameObject("CheckData_Sharing_Between_Output_Event"); var vfxComponent = gameObj.AddComponent <VisualEffect>(); vfxComponent.visualEffectAsset = graph.visualEffectResource.asset; var sourceSpawner = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var eventOutput_A = ScriptableObject.CreateInstance <VFXOutputEvent>(); var eventOutput_B = ScriptableObject.CreateInstance <VFXOutputEvent>(); eventOutput_A.LinkFrom(sourceSpawner); eventOutput_B.LinkFrom(sourceSpawner); Assert.AreEqual(1u, eventOutput_A.inputContexts.Count()); Assert.AreEqual(1u, eventOutput_B.inputContexts.Count()); graph.AddChild(sourceSpawner); graph.AddChild(eventOutput_A); graph.AddChild(eventOutput_B); var name_A = eventOutput_A.GetSetting("eventName").value as string; var name_B = eventOutput_B.GetSetting("eventName").value as string; //Equals names Assert.AreEqual(name_A, name_B); Assert.AreNotEqual(eventOutput_A.GetData(), eventOutput_B.GetData()); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var names = new List <string>(); vfxComponent.GetOutputEventNames(names); Assert.AreEqual(1, names.Count); Assert.AreEqual(name_A, names[0]); var newName = "miaou"; eventOutput_A.SetSettingValue("eventName", newName); name_A = eventOutput_A.GetSetting("eventName").value as string; name_B = eventOutput_B.GetSetting("eventName").value as string; //Now, different names Assert.AreNotEqual(name_A, name_B); Assert.AreNotEqual(eventOutput_A.GetData(), eventOutput_B.GetData()); Assert.AreEqual((eventOutput_A.GetData() as VFXDataOutputEvent).eventName, name_A); Assert.AreEqual((eventOutput_B.GetData() as VFXDataOutputEvent).eventName, name_B); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); vfxComponent.GetOutputEventNames(names); Assert.AreEqual(2, names.Count); Assert.IsTrue(names.Contains(newName)); Assert.AreNotEqual(name_B, newName); Assert.IsTrue(names.Contains(name_B)); //Back to equals names eventOutput_B.SetSettingValue("eventName", newName); name_A = eventOutput_A.GetSetting("eventName").value as string; name_B = eventOutput_B.GetSetting("eventName").value as string; Assert.AreEqual(name_A, name_B); Assert.AreNotEqual(eventOutput_A.GetData(), eventOutput_B.GetData()); Assert.AreEqual((eventOutput_A.GetData() as VFXDataOutputEvent).eventName, name_A); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); vfxComponent.GetOutputEventNames(names); Assert.AreEqual(1, names.Count); Assert.AreEqual(newName, names[0]); UnityEngine.Object.DestroyImmediate(gameObj); }
public IEnumerator Check_Total_Time_Is_Always_The_Sum_of_DeltaTime() { yield return(new EnterPlayMode()); var graph = VFXTestCommon.MakeTemporaryGraph(); var spawnerContext = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var blockCustomSpawner = ScriptableObject.CreateInstance <VFXSpawnerCustomWrapper>(); blockCustomSpawner.SetSettingValue("m_customType", new SerializableType(typeof(VFXCustomSpawnerTimeCheckerTest))); var initContext = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var outputContext = ScriptableObject.CreateInstance <VFXPointOutput>(); spawnerContext.LinkTo(initContext); initContext.LinkTo(outputContext); spawnerContext.AddChild(blockCustomSpawner); graph.AddChild(spawnerContext); graph.AddChild(initContext); graph.AddChild(outputContext); //plug total time into custom spawn total time var builtInParameter = ScriptableObject.CreateInstance <VFXBuiltInParameter>(); builtInParameter.SetSettingValue("m_expressionOp", VFXExpressionOperation.TotalTime); blockCustomSpawner.inputSlots[0].Link(builtInParameter.outputSlots[0]); graph.AddChild(builtInParameter); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); var vfxComponent = m_gameObject.AddComponent <VisualEffect>(); vfxComponent.visualEffectAsset = graph.visualEffectResource.asset; int maxFrame = 64; while (vfxComponent.culled && --maxFrame > 0) { yield return(null); } Assert.IsTrue(maxFrame > 0); while (--maxFrame > 0 && VFXCustomSpawnerTimeCheckerTest.s_ReadInternalTotalTime < 0.2f) { yield return(null); } Assert.IsTrue(maxFrame > 0); //Moved the object until culled var backupPosition = vfxComponent.transform.position; maxFrame = 64; while (--maxFrame > 0 && !vfxComponent.culled) { vfxComponent.transform.position = vfxComponent.transform.position + Vector3.up * 5.0f; yield return(null); } Assert.IsTrue(maxFrame > 0); for (int i = 0; i < 8; ++i) { yield return(null); } vfxComponent.transform.position = backupPosition; for (int i = 0; i < 8; ++i) { yield return(null); } Assert.AreEqual((double)VFXCustomSpawnerTimeCheckerTest.s_ReadInternalTotalTime, (double)VFXCustomSpawnerTimeCheckerTest.s_ReadTotalTimeThroughInput, 0.0001f); yield return(new ExitPlayMode()); }