void PasteDataEdges(ref SerializableGraph serializableGraph) { if (serializableGraph.dataEdges != null) { foreach (var dataEdge in serializableGraph.dataEdges) { if (dataEdge.input.targetIndex == InvalidID || dataEdge.output.targetIndex == InvalidID) { continue; } //TODO: This bypasses viewController.CreateLink, and all its additional checks it shouldn't. VFXModel inputModel = newControllers.ContainsKey(dataEdge.input.targetIndex) ? newControllers[dataEdge.input.targetIndex].model : null; VFXNodeController outputController = newControllers.ContainsKey(dataEdge.output.targetIndex) ? newControllers[dataEdge.output.targetIndex] : null; VFXModel outputModel = outputController != null ? outputController.model : null; if (inputModel != null && outputModel != null) { VFXSlot outputSlot = FetchSlot(outputModel as IVFXSlotContainer, dataEdge.output.slotPath, false); VFXSlot inputSlot = FetchSlot(inputModel as IVFXSlotContainer, dataEdge.input.slotPath, true); inputSlot.Link(outputSlot); if (outputController is VFXParameterNodeController) { var parameterNodeController = outputController as VFXParameterNodeController; parameterNodeController.infos.linkedSlots.Add(new VFXParameter.NodeLinkedSlot { inputSlot = inputSlot, outputSlot = outputSlot }); } } } } }
private static void CopyDataEdges(Data copyData, ScriptableObject[] allSerializedObjects) { if (copyData.dataEdges != null) { foreach (var dataEdge in copyData.dataEdges) { VFXSlot inputSlot = null; if (dataEdge.inputContext) { VFXContext targetContext = allSerializedObjects[dataEdge.input.targetIndex] as VFXContext; if (dataEdge.inputBlockIndex == -1) { inputSlot = FetchSlot(targetContext, dataEdge.input.slotPath, true); } else { inputSlot = FetchSlot(targetContext[dataEdge.inputBlockIndex], dataEdge.input.slotPath, true); } } else { VFXModel model = allSerializedObjects[dataEdge.input.targetIndex] as VFXModel; inputSlot = FetchSlot(model as IVFXSlotContainer, dataEdge.input.slotPath, true); } IVFXSlotContainer outputContainer = null; if (dataEdge.outputParameter) { var parameter = copyData.parameters[dataEdge.outputParameterIndex]; outputContainer = parameter.parameter; } else { outputContainer = allSerializedObjects[dataEdge.output.targetIndex] as IVFXSlotContainer; } VFXSlot outputSlot = FetchSlot(outputContainer, dataEdge.output.slotPath, false); if (inputSlot != null && outputSlot != null) { if (inputSlot.Link(outputSlot) && dataEdge.outputParameter) { var parameter = copyData.parameters[dataEdge.outputParameterIndex]; var node = parameter.parameter.nodes[dataEdge.outputParameterNodeIndex + parameter.infoIndexOffset]; if (node.linkedSlots == null) { node.linkedSlots = new List <VFXParameter.NodeLinkedSlot>(); } node.linkedSlots.Add(new VFXParameter.NodeLinkedSlot() { inputSlot = inputSlot, outputSlot = outputSlot }); } } } } }
public void Link_Multiple() { VFXSlot input0 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput); VFXSlot input1 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput); VFXSlot output0 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kOutput); VFXSlot output1 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kOutput); output0.Link(input0); output0.Link(input1); Assert.AreEqual(2, output0.GetNbLinks()); output1.Link(input0); Assert.AreEqual(1, input0.GetNbLinks()); Assert.AreEqual(1, input1.GetNbLinks()); Assert.AreEqual(1, output0.GetNbLinks()); Assert.AreEqual(1, output1.GetNbLinks()); Assert.AreEqual(output1, input0.refSlot); Assert.AreEqual(output0, input1.refSlot); }
public void Link() { VFXSlot input = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput); VFXSlot output = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kOutput); input.Link(output); Assert.AreEqual(1, input.GetNbLinks()); Assert.AreEqual(1, output.GetNbLinks()); Assert.AreEqual(output, input.refSlot); Assert.AreEqual(output, output.refSlot); }
public void Link_Fail() { VFXSlot input0 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput); VFXSlot input1 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput); VFXSlot output0 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput); VFXSlot output1 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput); input0.Link(input1); output0.Link(output1); Assert.AreEqual(0, input0.GetNbLinks()); Assert.AreEqual(0, input1.GetNbLinks()); Assert.AreEqual(0, output0.GetNbLinks()); Assert.AreEqual(0, output1.GetNbLinks()); }
public void UnlinkAll() { const int NB_INPUTS = 10; VFXSlot output = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kOutput); for (int i = 0; i < NB_INPUTS; ++i) { output.Link(VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput)); } Assert.AreEqual(NB_INPUTS, output.GetNbLinks()); output.UnlinkAll(); Assert.AreEqual(0, output.GetNbLinks()); }
void IEdgeConnectorListener.OnDropOutsidePort(Edge edge, Vector2 position) { VFXSlot startSlot = controller.model; VFXView view = this.GetFirstAncestorOfType <VFXView>(); VFXViewController viewController = view.controller; List <VisualElement> picked = new List <VisualElement>(); panel.PickAll(position, picked); VFXNodeUI endNode = null; foreach (var element in picked) { if (element is VFXNodeUI node) { endNode = node; break; } } VFXDataEdge dataEdge = edge as VFXDataEdge; bool exists = false; if (dataEdge.controller != null) { exists = true; view.controller.RemoveElement(dataEdge.controller); } if (endNode != null) { VFXNodeController nodeController = endNode.controller; if (nodeController != null) { IVFXSlotContainer slotContainer = nodeController.slotContainer; if (controller.direction == Direction.Input) { foreach (var output in nodeController.outputPorts.Where(t => t.model == null || t.model.IsMasterSlot())) { if (viewController.CreateLink(controller, output)) { break; } } } else { foreach (var input in nodeController.inputPorts.Where(t => t.model == null || t.model.IsMasterSlot() && !t.model.HasLink(true))) { if (viewController.CreateLink(input, controller)) { break; } } } } } else if (controller.direction == Direction.Input && Event.current.modifiers == EventModifiers.Alt) { var targetType = controller.portType; var attribute = VFXLibrary.GetAttributeFromSlotType(controller.portType); VFXModelDescriptorParameters parameterDesc; if (attribute != null && attribute.usages.HasFlag(VFXTypeAttribute.Usage.ExcludeFromProperty)) { parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t => { if (!t.model.outputSlots[0].CanLink(controller.model)) { return(false); } var attributeCandidate = VFXLibrary.GetAttributeFromSlotType(t.model.type); return(attributeCandidate == null || !attributeCandidate.usages.HasFlag(VFXTypeAttribute.Usage.ExcludeFromProperty)); }); } else { parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t => { return(t.model.type == targetType); }); } if (parameterDesc != null) { Vector2 pos = view.contentViewContainer.GlobalToBound(position) - new Vector2(140, 20); view.UpdateSelectionWithNewNode(); VFXParameter parameter = viewController.AddVFXParameter(pos, parameterDesc, false); parameter.SetSettingValue("m_Exposed", true); startSlot.Link(parameter.outputSlots[0]); CopyValueToParameter(parameter); viewController.AddVFXModel(pos, parameter); } } else if (!exists) { var window = VFXViewWindow.GetWindow(view); if (direction == Direction.Input || viewController.model.visualEffectObject is VisualEffectSubgraphOperator || viewController.model.visualEffectObject is VisualEffectSubgraphBlock) // no context for subgraph operators. { VFXFilterWindow.Show(window, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter) })); } else { VFXFilterWindow.Show(window, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter), typeof(VFXContext) })); } } }
public void ConvertToInline() { if (parentController.isOutput) { return; } VFXInlineOperator op = ScriptableObject.CreateInstance <VFXInlineOperator>(); op.SetSettingValue("m_Type", (SerializableType)parentController.model.type); viewController.graph.AddChild(op); op.position = position; if (infos.linkedSlots != null) { foreach (var link in infos.linkedSlots.ToArray()) { var ancestors = new List <VFXSlot>(); ancestors.Add(link.outputSlot); VFXSlot parent = link.outputSlot.GetParent(); while (parent != null) { ancestors.Add(parent); parent = parent.GetParent(); } int index = parentController.model.GetSlotIndex(ancestors.Last()); if (index >= 0 && index < op.GetNbOutputSlots()) { VFXSlot slot = op.outputSlots[index]; for (int i = ancestors.Count() - 2; i >= 0; --i) { int subIndex = ancestors[i + 1].GetIndex(ancestors[i]); if (subIndex >= 0 && subIndex < slot.GetNbChildren()) { slot = slot[subIndex]; } else { slot = null; break; } } if (slot.path != link.outputSlot.path.Substring(1)) // parameters output are still named 0, inline outputs have no name. { Debug.LogError("New inline don't have the same subslot as old parameter"); } else { link.outputSlot.Unlink(link.inputSlot); slot.Link(link.inputSlot); } } } } op.inputSlots[0].value = value; viewController.LightApplyChanges(); viewController.PutInSameGroupNodeAs(viewController.GetNodeController(op, 0), this); viewController.RemoveElement(this); }
void IEdgeConnectorListener.OnDropOutsidePort(Edge edge, Vector2 position) { VFXSlot startSlot = controller.model; VFXView view = this.GetFirstAncestorOfType <VFXView>(); VFXViewController viewController = view.controller; VFXNodeUI endNode = null; foreach (var node in view.GetAllNodes()) { if (node.worldBound.Contains(position)) { endNode = node; } } VFXDataEdge dataEdge = edge as VFXDataEdge; bool exists = false; if (dataEdge.controller != null) { exists = true; view.controller.RemoveElement(dataEdge.controller); } if (endNode != null) { VFXNodeController nodeController = endNode.controller; if (nodeController != null) { IVFXSlotContainer slotContainer = nodeController.slotContainer; if (controller.direction == Direction.Input) { foreach (var output in nodeController.outputPorts.Where(t => t.model == null || t.model.IsMasterSlot())) { if (viewController.CreateLink(controller, output)) { break; } } } else { foreach (var input in nodeController.inputPorts.Where(t => t.model == null || t.model.IsMasterSlot())) { if (viewController.CreateLink(input, controller)) { break; } } } } } else if (controller.direction == Direction.Input && Event.current.modifiers == EventModifiers.Alt) { VFXModelDescriptorParameters parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t => t.name == controller.portType.UserFriendlyName()); if (parameterDesc != null) { VFXParameter parameter = viewController.AddVFXParameter(view.contentViewContainer.GlobalToBound(position) - new Vector2(140, 20), parameterDesc); parameter.SetSettingValue("m_Exposed", true); startSlot.Link(parameter.outputSlots[0]); CopyValueToParameter(parameter); } } else if (!exists) { VFXFilterWindow.Show(VFXViewWindow.currentWindow, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter), typeof(VFXContext) })); } }
public IEnumerator CreateComponentWithAllBasicTypeExposed([ValueSource("linkModes")] bool linkMode, [ValueSource("bindingModes")] bool bindingModes) { var commonBaseName = "abcd_"; Func <Type, object> GetValue_A_Type = delegate(Type type) { if (typeof(float) == type) { return(2.0f); } else if (typeof(Vector2) == type) { return(new Vector2(3.0f, 4.0f)); } else if (typeof(Vector3) == type) { return(new Vector3(8.0f, 9.0f, 10.0f)); } else if (typeof(Vector4) == type) { return(new Vector4(11.0f, 12.0f, 13.0f, 14.0f)); } else if (typeof(Color) == type) { return(new Color(0.1f, 0.2f, 0.3f, 0.4f)); } else if (typeof(int) == type) { return(15); } else if (typeof(uint) == type) { return(16u); } else if (typeof(AnimationCurve) == type) { return(new AnimationCurve(new Keyframe(0, 13), new Keyframe(1, 14))); } else if (typeof(Gradient) == type) { return new Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(Color.white, 0.2f) } } } ; else if (typeof(Mesh) == type) { return(m_cubeEmpty.GetComponent <MeshFilter>().sharedMesh); } else if (typeof(Texture2D) == type) { return(m_texture2D_A); } else if (typeof(Texture2DArray) == type) { return(m_texture2DArray_A); } else if (typeof(Texture3D) == type) { return(m_texture3D_A); } else if (typeof(Cubemap) == type) { return(m_textureCube_A); } else if (typeof(CubemapArray) == type) { return(m_textureCubeArray_A); } else if (typeof(bool) == type) { return(true); } else if (typeof(Matrix4x4) == type) { return(Matrix4x4.identity); } Assert.Fail(); return(null); }; Func <Type, object> GetValue_B_Type = delegate(Type type) { if (typeof(float) == type) { return(50.0f); } else if (typeof(Vector2) == type) { return(new Vector2(53.0f, 54.0f)); } else if (typeof(Vector3) == type) { return(new Vector3(58.0f, 59.0f, 510.0f)); } else if (typeof(Vector4) == type || typeof(Color) == type)// ValueB_Type is used to set a component value, so return a Vector4 with color values { return(new Vector4(511.0f, 512.0f, 513.0f, 514.0f)); } else if (typeof(int) == type) { return(515); } else if (typeof(uint) == type) { return(516u); } else if (typeof(AnimationCurve) == type) { return(new AnimationCurve(new Keyframe(0, 47), new Keyframe(0.5f, 23), new Keyframe(1.0f, 17))); } else if (typeof(Gradient) == type) { return new Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(Color.white, 0.2f), new GradientColorKey(Color.black, 0.6f) } } } ; else if (typeof(Mesh) == type) { return(m_sphereEmpty.GetComponent <MeshFilter>().sharedMesh); } else if (typeof(Texture2D) == type) { return(m_texture2D_B); } else if (typeof(Texture2DArray) == type) { return(m_texture2DArray_B); } else if (typeof(Texture3D) == type) { return(m_texture3D_B); } else if (typeof(Cubemap) == type) { return(m_textureCube_B); } else if (typeof(CubemapArray) == type) { return(m_textureCubeArray_B); } else if (typeof(bool) == type) { return(true); } else if (typeof(Matrix4x4) == type) { return(Matrix4x4.identity); } Assert.Fail(); return(null); }; Func <VFXValueType, VisualEffect, string, bool> fnHas_UsingBindings = delegate(VFXValueType type, VisualEffect vfx, string name) { switch (type) { case VFXValueType.Float: return(vfx.HasFloat(name)); case VFXValueType.Float2: return(vfx.HasVector2(name)); case VFXValueType.Float3: return(vfx.HasVector3(name)); case VFXValueType.Float4: return(vfx.HasVector4(name)); case VFXValueType.Int32: return(vfx.HasInt(name)); case VFXValueType.Uint32: return(vfx.HasUInt(name)); case VFXValueType.Curve: return(vfx.HasAnimationCurve(name)); case VFXValueType.ColorGradient: return(vfx.HasGradient(name)); case VFXValueType.Mesh: return(vfx.HasMesh(name)); case VFXValueType.Texture2D: return(vfx.HasTexture(name) && vfx.GetTextureDimension(name) == TextureDimension.Tex2D); case VFXValueType.Texture2DArray: return(vfx.HasTexture(name) && vfx.GetTextureDimension(name) == TextureDimension.Tex2DArray); case VFXValueType.Texture3D: return(vfx.HasTexture(name) && vfx.GetTextureDimension(name) == TextureDimension.Tex3D); case VFXValueType.TextureCube: return(vfx.HasTexture(name) && vfx.GetTextureDimension(name) == TextureDimension.Cube); case VFXValueType.TextureCubeArray: return(vfx.HasTexture(name) && vfx.GetTextureDimension(name) == TextureDimension.CubeArray); case VFXValueType.Boolean: return(vfx.HasBool(name)); case VFXValueType.Matrix4x4: return(vfx.HasMatrix4x4(name)); } Assert.Fail(); return(false); }; Func <VFXValueType, VisualEffect, string, object> fnGet_UsingBindings = delegate(VFXValueType type, VisualEffect vfx, string name) { switch (type) { case VFXValueType.Float: return(vfx.GetFloat(name)); case VFXValueType.Float2: return(vfx.GetVector2(name)); case VFXValueType.Float3: return(vfx.GetVector3(name)); case VFXValueType.Float4: return(vfx.GetVector4(name)); case VFXValueType.Int32: return(vfx.GetInt(name)); case VFXValueType.Uint32: return(vfx.GetUInt(name)); case VFXValueType.Curve: return(vfx.GetAnimationCurve(name)); case VFXValueType.ColorGradient: return(vfx.GetGradient(name)); case VFXValueType.Mesh: return(vfx.GetMesh(name)); case VFXValueType.Texture2D: case VFXValueType.Texture2DArray: case VFXValueType.Texture3D: case VFXValueType.TextureCube: case VFXValueType.TextureCubeArray: return(vfx.GetTexture(name)); case VFXValueType.Boolean: return(vfx.GetBool(name)); case VFXValueType.Matrix4x4: return(vfx.GetMatrix4x4(name)); } Assert.Fail(); return(null); }; Action <VFXValueType, VisualEffect, string, object> fnSet_UsingBindings = delegate(VFXValueType type, VisualEffect vfx, string name, object value) { switch (type) { case VFXValueType.Float: vfx.SetFloat(name, (float)value); break; case VFXValueType.Float2: vfx.SetVector2(name, (Vector2)value); break; case VFXValueType.Float3: vfx.SetVector3(name, (Vector3)value); break; case VFXValueType.Float4: vfx.SetVector4(name, (Vector4)value); break; case VFXValueType.Int32: vfx.SetInt(name, (int)value); break; case VFXValueType.Uint32: vfx.SetUInt(name, (uint)value); break; case VFXValueType.Curve: vfx.SetAnimationCurve(name, (AnimationCurve)value); break; case VFXValueType.ColorGradient: vfx.SetGradient(name, (Gradient)value); break; case VFXValueType.Mesh: vfx.SetMesh(name, (Mesh)value); break; case VFXValueType.Texture2D: case VFXValueType.Texture2DArray: case VFXValueType.Texture3D: case VFXValueType.TextureCube: case VFXValueType.TextureCubeArray: vfx.SetTexture(name, (Texture)value); break; case VFXValueType.Boolean: vfx.SetBool(name, (bool)value); break; case VFXValueType.Matrix4x4: vfx.SetMatrix4x4(name, (Matrix4x4)value); break; } }; Func <VFXValueType, VisualEffect, string, bool> fnHas_UsingSerializedProperty = delegate(VFXValueType type, VisualEffect vfx, string name) { var editor = Editor.CreateEditor(vfx); try { var propertySheet = editor.serializedObject.FindProperty("m_PropertySheet"); var fieldName = VisualEffectSerializationUtility.GetTypeField(VFXExpression.TypeToType(type)) + ".m_Array"; var vfxField = propertySheet.FindPropertyRelative(fieldName); if (vfxField != null) { for (int i = 0; i < vfxField.arraySize; ++i) { var property = vfxField.GetArrayElementAtIndex(i); var nameProperty = property.FindPropertyRelative("m_Name").stringValue; if (nameProperty == name) { return(true); } } } } finally { GameObject.DestroyImmediate(editor); } return(false); }; Func <SerializedProperty, Matrix4x4> fnMatrixFromSerializedProperty = delegate(SerializedProperty property) { var mat = new Matrix4x4(); mat.m00 = property.FindPropertyRelative("e00").floatValue; mat.m01 = property.FindPropertyRelative("e01").floatValue; mat.m02 = property.FindPropertyRelative("e02").floatValue; mat.m03 = property.FindPropertyRelative("e03").floatValue; mat.m10 = property.FindPropertyRelative("e10").floatValue; mat.m11 = property.FindPropertyRelative("e11").floatValue; mat.m12 = property.FindPropertyRelative("e12").floatValue; mat.m13 = property.FindPropertyRelative("e13").floatValue; mat.m20 = property.FindPropertyRelative("e20").floatValue; mat.m21 = property.FindPropertyRelative("e21").floatValue; mat.m22 = property.FindPropertyRelative("e22").floatValue; mat.m23 = property.FindPropertyRelative("e23").floatValue; mat.m30 = property.FindPropertyRelative("e30").floatValue; mat.m31 = property.FindPropertyRelative("e31").floatValue; mat.m32 = property.FindPropertyRelative("e32").floatValue; mat.m33 = property.FindPropertyRelative("e33").floatValue; return(mat); }; Action <SerializedProperty, Matrix4x4> fnMatrixToSerializedProperty = delegate(SerializedProperty property, Matrix4x4 mat) { property.FindPropertyRelative("e00").floatValue = mat.m00; property.FindPropertyRelative("e01").floatValue = mat.m01; property.FindPropertyRelative("e02").floatValue = mat.m02; property.FindPropertyRelative("e03").floatValue = mat.m03; property.FindPropertyRelative("e10").floatValue = mat.m10; property.FindPropertyRelative("e11").floatValue = mat.m11; property.FindPropertyRelative("e12").floatValue = mat.m12; property.FindPropertyRelative("e13").floatValue = mat.m13; property.FindPropertyRelative("e20").floatValue = mat.m20; property.FindPropertyRelative("e21").floatValue = mat.m21; property.FindPropertyRelative("e22").floatValue = mat.m22; property.FindPropertyRelative("e23").floatValue = mat.m23; property.FindPropertyRelative("e30").floatValue = mat.m30; property.FindPropertyRelative("e31").floatValue = mat.m31; property.FindPropertyRelative("e32").floatValue = mat.m32; property.FindPropertyRelative("e33").floatValue = mat.m33; }; Func <VFXValueType, VisualEffect, string, object> fnGet_UsingSerializedProperty = delegate(VFXValueType type, VisualEffect vfx, string name) { var editor = Editor.CreateEditor(vfx); try { var propertySheet = editor.serializedObject.FindProperty("m_PropertySheet"); editor.serializedObject.Update(); var fieldName = VisualEffectSerializationUtility.GetTypeField(VFXExpression.TypeToType(type)) + ".m_Array"; var vfxField = propertySheet.FindPropertyRelative(fieldName); if (vfxField != null) { for (int i = 0; i < vfxField.arraySize; ++i) { var property = vfxField.GetArrayElementAtIndex(i); var nameProperty = property.FindPropertyRelative("m_Name").stringValue; if (nameProperty == name) { property = property.FindPropertyRelative("m_Value"); switch (type) { case VFXValueType.Float: return(property.floatValue); case VFXValueType.Float2: return(property.vector2Value); case VFXValueType.Float3: return(property.vector3Value); case VFXValueType.Float4: return(property.vector4Value); case VFXValueType.Int32: return(property.intValue); case VFXValueType.Uint32: return(property.intValue); // there isn't uintValue case VFXValueType.Curve: return(property.animationCurveValue); case VFXValueType.ColorGradient: return(property.gradientValue); case VFXValueType.Mesh: return(property.objectReferenceValue); case VFXValueType.Texture2D: case VFXValueType.Texture2DArray: case VFXValueType.Texture3D: case VFXValueType.TextureCube: case VFXValueType.TextureCubeArray: return(property.objectReferenceValue); case VFXValueType.Boolean: return(property.boolValue); case VFXValueType.Matrix4x4: return(fnMatrixFromSerializedProperty(property)); } Assert.Fail(); } } } } finally { GameObject.DestroyImmediate(editor); } return(null); }; Action <VFXValueType, VisualEffect, string, object> fnSet_UsingSerializedProperty = delegate(VFXValueType type, VisualEffect vfx, string name, object value) { var editor = Editor.CreateEditor(vfx); try { editor.serializedObject.Update(); var propertySheet = editor.serializedObject.FindProperty("m_PropertySheet"); var fieldName = VisualEffectSerializationUtility.GetTypeField(VFXExpression.TypeToType(type)) + ".m_Array"; var vfxField = propertySheet.FindPropertyRelative(fieldName); if (vfxField != null) { for (int i = 0; i < vfxField.arraySize; ++i) { var property = vfxField.GetArrayElementAtIndex(i); var propertyName = property.FindPropertyRelative("m_Name").stringValue; if (propertyName == name) { var propertyValue = property.FindPropertyRelative("m_Value"); var propertyOverriden = property.FindPropertyRelative("m_Overridden"); switch (type) { case VFXValueType.Float: propertyValue.floatValue = (float)value; break; case VFXValueType.Float2: propertyValue.vector2Value = (Vector2)value; break; case VFXValueType.Float3: propertyValue.vector3Value = (Vector3)value; break; case VFXValueType.Float4: propertyValue.vector4Value = (Vector4)value; break; case VFXValueType.Int32: propertyValue.intValue = (int)value; break; case VFXValueType.Uint32: propertyValue.intValue = (int)((uint)value); break; // there isn't uintValue case VFXValueType.Curve: propertyValue.animationCurveValue = (AnimationCurve)value; break; case VFXValueType.ColorGradient: propertyValue.gradientValue = (Gradient)value; break; case VFXValueType.Mesh: propertyValue.objectReferenceValue = (UnityEngine.Object)value; break; case VFXValueType.Texture2D: case VFXValueType.Texture2DArray: case VFXValueType.Texture3D: case VFXValueType.TextureCube: case VFXValueType.TextureCubeArray: propertyValue.objectReferenceValue = (UnityEngine.Object)value; break; case VFXValueType.Boolean: propertyValue.boolValue = (bool)value; break; case VFXValueType.Matrix4x4: fnMatrixToSerializedProperty(propertyValue, (Matrix4x4)value); break; } propertyOverriden.boolValue = true; } } } editor.serializedObject.ApplyModifiedProperties(); } finally { GameObject.DestroyImmediate(editor); } }; Func <VFXValueType, VisualEffect, string, bool> fnHas = bindingModes ? fnHas_UsingBindings : fnHas_UsingSerializedProperty; Func <VFXValueType, VisualEffect, string, object> fnGet = bindingModes ? fnGet_UsingBindings : fnGet_UsingSerializedProperty; Action <VFXValueType, VisualEffect, string, object> fnSet = bindingModes ? fnSet_UsingBindings : fnSet_UsingSerializedProperty; EditorApplication.ExecuteMenuItem("Window/General/Game"); var graph = MakeTemporaryGraph(); var contextInitialize = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var allType = ScriptableObject.CreateInstance <AllType>(); contextInitialize.AddChild(allType); graph.AddChild(contextInitialize); // Needs a spawner and output for the system to be valid { var spawner = ScriptableObject.CreateInstance <VFXBasicSpawner>(); spawner.LinkTo(contextInitialize); graph.AddChild(spawner); var output = ScriptableObject.CreateInstance <VFXPointOutput>(); output.LinkFrom(contextInitialize); graph.AddChild(output); } var types = Enum.GetValues(typeof(VFXValueType)).Cast <VFXValueType>() .Where(e => e != VFXValueType.Spline && e != VFXValueType.None).ToArray(); foreach (var parameter in VFXLibrary.GetParameters()) { var newInstance = parameter.CreateInstance(); VFXValueType type = types.FirstOrDefault(e => VFXExpression.GetVFXValueTypeFromType(newInstance.type) == e); if (type != VFXValueType.None) { newInstance.SetSettingValue("m_exposedName", commonBaseName + newInstance.type.UserFriendlyName()); newInstance.SetSettingValue("m_exposed", true); var value = GetValue_A_Type(newInstance.type); Assert.IsNotNull(value); newInstance.value = value; graph.AddChild(newInstance); } } if (linkMode) { foreach (var type in types) { VFXSlot slot = null; for (int i = 0; i < allType.GetNbInputSlots(); ++i) { var currentSlot = allType.GetInputSlot(i); var expression = currentSlot.GetExpression(); if (expression != null && expression.valueType == type) { slot = currentSlot; break; } } Assert.IsNotNull(slot, type.ToString()); var parameter = graph.children.OfType <VFXParameter>().FirstOrDefault(o => { if (o.GetNbOutputSlots() > 0) { var expression = o.outputSlots[0].GetExpression(); if (expression != null && expression.valueType == type) { return(true); } } return(false); }); Assert.IsNotNull(parameter, "parameter with type : " + type.ToString()); slot.Link(parameter.GetOutputSlot(0)); } } graph.RecompileIfNeeded(); while (m_mainObject.GetComponent <VisualEffect>() != null) { UnityEngine.Object.DestroyImmediate(m_mainObject.GetComponent <VisualEffect>()); } var vfxComponent = m_mainObject.AddComponent <VisualEffect>(); vfxComponent.visualEffectAsset = graph.visualEffectResource.asset; yield return(null); Func <AnimationCurve, AnimationCurve, bool> fnCompareCurve = delegate(AnimationCurve left, AnimationCurve right) { return(left.keys.Length == right.keys.Length); }; Func <Gradient, Gradient, bool> fnCompareGradient = delegate(Gradient left, Gradient right) { return(left.colorKeys.Length == right.colorKeys.Length); }; //Check default Value_A & change to Value_B (At this stage, it's useless to access with SerializedProperty) foreach (var parameter in VFXLibrary.GetParameters()) { VFXValueType type = types.FirstOrDefault(e => VFXExpression.GetVFXValueTypeFromType(parameter.model.type) == e); if (type == VFXValueType.None) { continue; } var currentName = commonBaseName + parameter.model.type.UserFriendlyName(); var baseValue = GetValue_A_Type(parameter.model.type); var newValue = GetValue_B_Type(parameter.model.type); Assert.IsTrue(fnHas_UsingBindings(type, vfxComponent, currentName)); var currentValue = fnGet_UsingBindings(type, vfxComponent, currentName); if (type == VFXValueType.ColorGradient) { Assert.IsTrue(fnCompareGradient((Gradient)baseValue, (Gradient)currentValue)); } else if (type == VFXValueType.Curve) { Assert.IsTrue(fnCompareCurve((AnimationCurve)baseValue, (AnimationCurve)currentValue)); } else if (parameter.model.type == typeof(Color)) { Color col = (Color)baseValue; Assert.AreEqual(new Vector4(col.r, col.g, col.b, col.a), currentValue); } else { Assert.AreEqual(baseValue, currentValue); } fnSet_UsingBindings(type, vfxComponent, currentName, newValue); yield return(null); } //Compare new setted values foreach (var parameter in VFXLibrary.GetParameters()) { VFXValueType type = types.FirstOrDefault(e => VFXExpression.GetVFXValueTypeFromType(parameter.model.type) == e); if (type == VFXValueType.None) { continue; } var currentName = commonBaseName + parameter.model.type.UserFriendlyName(); var baseValue = GetValue_B_Type(parameter.model.type); Assert.IsTrue(fnHas(type, vfxComponent, currentName)); var currentValue = fnGet(type, vfxComponent, currentName); if (type == VFXValueType.ColorGradient) { Assert.IsTrue(fnCompareGradient((Gradient)baseValue, (Gradient)currentValue)); } else if (type == VFXValueType.Curve) { Assert.IsTrue(fnCompareCurve((AnimationCurve)baseValue, (AnimationCurve)currentValue)); } else { Assert.AreEqual(baseValue, currentValue); } yield return(null); } //Test ResetOverride function foreach (var parameter in VFXLibrary.GetParameters()) { VFXValueType type = types.FirstOrDefault(e => VFXExpression.GetVFXValueTypeFromType(parameter.model.type) == e); if (type == VFXValueType.None) { continue; } var currentName = commonBaseName + parameter.model.type.UserFriendlyName(); vfxComponent.ResetOverride(currentName); { //If we use bindings, internal value is restored but it doesn't change serialized property (strange at first but intended behavior) var baseValue = bindingModes ? GetValue_A_Type(parameter.model.type) : GetValue_B_Type(parameter.model.type); var currentValue = fnGet(type, vfxComponent, currentName); if (type == VFXValueType.ColorGradient) { Assert.IsTrue(fnCompareGradient((Gradient)baseValue, (Gradient)currentValue)); } else if (type == VFXValueType.Curve) { Assert.IsTrue(fnCompareCurve((AnimationCurve)baseValue, (AnimationCurve)currentValue)); } else if (bindingModes && parameter.model.type == typeof(Color)) { Color col = (Color)baseValue; Assert.AreEqual(new Vector4(col.r, col.g, col.b, col.a), currentValue); } else { Assert.AreEqual(baseValue, currentValue); } } if (!bindingModes) { var internalValue = fnGet_UsingBindings(type, vfxComponent, currentName); var originalAssetValue = GetValue_A_Type(parameter.model.type); if (type == VFXValueType.ColorGradient) { Assert.IsTrue(fnCompareGradient((Gradient)originalAssetValue, (Gradient)internalValue)); } else if (type == VFXValueType.Curve) { Assert.IsTrue(fnCompareCurve((AnimationCurve)originalAssetValue, (AnimationCurve)internalValue)); } else if (parameter.model.type == typeof(Color)) { Color col = (Color)originalAssetValue; Assert.AreEqual(new Vector4(col.r, col.g, col.b, col.a), internalValue); } else { Assert.AreEqual(originalAssetValue, internalValue); } } yield return(null); } }