private void Add_Valid_System(VFXGraph 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>(); //only needed to allocate a minimal attributeBuffer 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); }
private void UpdateDebugMode(VFXGraph graph) { //Update now... UpdateDebugMode(); //.. but in some case, the onRuntimeDataChanged is called too soon, need to update twice //because VFXUIDebug relies on VisualEffect : See m_VFX.GetParticleSystemNames m_View.schedule.Execute(UpdateDebugMode).ExecuteLater(0 /* next frame */); }
VFXGraph MakeTemporaryGraph() { if (System.IO.File.Exists(tempFilePath)) { AssetDatabase.DeleteAsset(tempFilePath); } var asset = VisualEffectAssetEditorUtility.CreateNewAsset(tempFilePath); VisualEffectResource resource = asset.GetResource(); // force resource creation VFXGraph graph = ScriptableObject.CreateInstance <VFXGraph>(); graph.visualEffectResource = resource; return(graph); }
public static VFXGraph MakeTemporaryGraph() { var guid = System.Guid.NewGuid().ToString(); string tempFilePath = string.Format(tempFileFormat, guid); System.IO.Directory.CreateDirectory(tempBasePath); var asset = VisualEffectAssetEditorUtility.CreateNewAsset(tempFilePath); VisualEffectResource resource = asset.GetOrCreateResource(); // force resource creation VFXGraph graph = resource.GetOrCreateGraph(); return(graph); }
public void FlushAndPushGraphState(VFXGraph graph) { int lastCursorInStack = m_undoStack.Last().Key; while (lastCursorInStack > m_lastGraphUndoCursor) { //An action has been performed which overwrite m_undoStack.Remove(lastCursorInStack); lastCursorInStack = m_undoStack.Last().Key; } m_undoStack.Add(m_graphUndoCursor.index, new SerializedState() { serializedGraph = graph.Backup() }); }
public VFXGraphUndoStack(VFXGraph initialState) { m_graphUndoCursor = ScriptableObject.CreateInstance <VFXGraphUndoCursor>(); m_graphUndoCursor.hideFlags = HideFlags.HideAndDontSave; m_undoStack = new SortedDictionary <int, SerializedState>(); m_graphUndoCursor.index = 0; m_lastGraphUndoCursor = 0; m_undoStack.Add(0, new SerializedState() { serializedGraph = initialState.Backup() }); m_Graph = initialState; }
VFXGraph MakeTemporaryGraph() { m_Asset = VisualEffectResource.CreateNewAsset(tempFilePath); VisualEffectResource resource = m_Asset.GetResource(); // force resource creation VFXGraph graph = ScriptableObject.CreateInstance<VFXGraph>(); graph.visualEffectResource = resource; var window = EditorWindow.GetWindow<VFXViewWindow>(); window.Close(); window = EditorWindow.GetWindow<VFXViewWindow>(); m_ViewController = VFXViewController.GetController(m_Asset.GetResource(), true); m_View = window.graphView; m_View.controller = m_ViewController; return graph; }
VFXGraph MakeTemporaryGraph() { m_TempFileCounter++; string tempFilePath = string.Format(tempFileFormat, m_TempFileCounter); if (System.IO.File.Exists(tempFilePath)) { AssetDatabase.DeleteAsset(tempFilePath); } var asset = VisualEffectResource.CreateNewAsset(tempFilePath); VisualEffectResource resource = asset.GetResource(); // force resource creation VFXGraph graph = ScriptableObject.CreateInstance <VFXGraph>(); graph.visualEffectResource = resource; return(graph); }
void Init(VFXView sourceView, IEnumerable <Controller> controllers) { this.m_SourceView = sourceView; m_SourceControllers = controllers.Concat(sourceView.controller.dataEdges.Where(t => controllers.Contains(t.input.sourceNode) && controllers.Contains(t.output.sourceNode))).Distinct().ToList(); parameterNodeControllers = m_SourceControllers.OfType <VFXParameterNodeController>().ToList(); m_SourceController = sourceView.controller; VFXGraph sourceGraph = m_SourceController.graph; m_SourceController.useCount++; m_SourceParameters = new Dictionary <string, VFXParameterNodeController>(); foreach (var parameterNode in parameterNodeControllers) { m_SourceParameters[parameterNode.exposedName] = parameterNode; } }
public void CheckTypeMenu(SerializedProperty property, VFXPropertyBindingAttribute attribute, VisualEffectAsset asset) { VFXGraph graph = null; if (asset != null) { var resource = asset.GetResource(); if (resource != null) //If VisualEffectGraph is store in asset bundle, we can't use this following code { graph = resource.graph as VFXGraph; } } if (graph == null) { return; } var menu = new GenericMenu(); var parameters = graph.children.OfType <UnityEditor.VFX.VFXParameter>(); foreach (var param in parameters) { string typeName = param.type.ToString(); if (attribute.EditorTypes.Contains(typeName)) { MenuPropertySetName set = new MenuPropertySetName { property = property, value = param.exposedName }; menu.AddItem(new GUIContent(param.exposedName), false, SetFieldName, set); } } menu.ShowAsContext(); }
private static void LoadVFXGraph(string vfxAssetName, out string fullPath, out VFXGraph graph) { var vfxAssets = new List <VisualEffectAsset>(); var vfxAssetsGuids = AssetDatabase.FindAssets("t:VisualEffectAsset " + vfxAssetName) .Where(o => System.IO.Path.GetFileNameWithoutExtension(AssetDatabase.GUIDToAssetPath(o)) == vfxAssetName); if (vfxAssetsGuids.Count() != 1) { throw new InvalidOperationException("Cannot retrieve (or several asset with same name) " + vfxAssetName); } var vfxAssetsGuid = vfxAssetsGuids.First(); fullPath = AssetDatabase.GUIDToAssetPath(vfxAssetsGuid); using (Measure.Scope("VFXGraphLoad.ImportAsset")) { AssetDatabase.ImportAsset(fullPath, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); } VisualEffectAsset vfxAsset = null; using (Measure.Scope("VFXGraphLoad.LoadAsset")) { vfxAsset = AssetDatabase.LoadAssetAtPath <VisualEffectAsset>(fullPath); } using (Measure.Scope("VFXGraphLoad.GetResource")) { var resource = k_fnGetResource.Invoke(null, new object[] { vfxAsset }); if (resource == null) { graph = null; } graph = k_fnGetOrCreateGraph.Invoke(null, new object[] { resource }) as VFXGraph; } }
public VFXUIDebug(VFXView view) { m_View = view; m_Graph = m_View.controller.graph; m_GpuSystems = new List <int>(); }
public override void OnInspectorGUI() { resourceObject.Update(); bool enable = GUI.enabled; //Everything in external asset is disabled by default GUI.enabled = true; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = resourceUpdateModeProperty.hasMultipleDifferentValues; VFXUpdateMode newUpdateMode = (VFXUpdateMode)EditorGUILayout.EnumPopup(EditorGUIUtility.TrTextContent("Update Mode"), (VFXUpdateMode)resourceUpdateModeProperty.intValue); if (EditorGUI.EndChangeCheck()) { resourceUpdateModeProperty.intValue = (int)newUpdateMode; resourceObject.ApplyModifiedProperties(); } EditorGUILayout.BeginHorizontal(); EditorGUI.showMixedValue = cullingFlagsProperty.hasMultipleDifferentValues; EditorGUILayout.PrefixLabel(EditorGUIUtility.TrTextContent("Culling Flags")); EditorGUI.BeginChangeCheck(); int newOption = EditorGUILayout.Popup(Array.IndexOf(k_CullingOptionsValue, (VFXCullingFlags)cullingFlagsProperty.intValue), k_CullingOptionsContents); if (EditorGUI.EndChangeCheck()) { cullingFlagsProperty.intValue = (int)k_CullingOptionsValue[newOption]; resourceObject.ApplyModifiedProperties(); } EditorGUILayout.EndHorizontal(); bool needRecompile = false; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = motionVectorRenderModeProperty.hasMultipleDifferentValues; EditorGUI.BeginChangeCheck(); bool motionVector = EditorGUILayout.Toggle(EditorGUIUtility.TrTextContent("Use Motion Vectors"), motionVectorRenderModeProperty.intValue == (int)MotionVectorGenerationMode.Object); if (EditorGUI.EndChangeCheck()) { motionVectorRenderModeProperty.intValue = motionVector ? (int)MotionVectorGenerationMode.Object : (int)MotionVectorGenerationMode.Camera; resourceObject.ApplyModifiedProperties(); needRecompile = true; } if (needRecompile) { foreach (VisualEffectResource resource in resourceObject.targetObjects) { VFXGraph graph = resource.GetOrCreateGraph() as VFXGraph; if (graph != null) { graph.SetExpressionGraphDirty(); graph.RecompileIfNeeded(); } } } if (!serializedObject.isEditingMultipleObjects) { VisualEffectEditor.ShowHeader(EditorGUIUtility.TrTextContent("Shaders"), true, true, false, false); VisualEffectAsset asset = (VisualEffectAsset)target; VisualEffectResource resource = asset.GetResource(); var shaderSources = resource.shaderSources; string assetPath = AssetDatabase.GetAssetPath(asset); UnityObject[] objects = AssetDatabase.LoadAllAssetsAtPath(assetPath); string directory = Path.GetDirectoryName(assetPath) + "/" + VFXExternalShaderProcessor.k_ShaderDirectory + "/" + asset.name + "/"; foreach (var shader in objects) { if (shader is Shader || shader is ComputeShader) { GUILayout.BeginHorizontal(); GUILayout.Label(shader.name, GUILayout.ExpandWidth(true)); int index = resource.GetShaderIndex(shader); if (index >= 0 && index < shaderSources.Length) { if (VFXExternalShaderProcessor.allowExternalization) { string externalPath = directory + shaderSources[index].name; if (!shaderSources[index].compute) { externalPath = directory + shaderSources[index].name.Replace('/', '_') + VFXExternalShaderProcessor.k_ShaderExt; } else { externalPath = directory + shaderSources[index].name + VFXExternalShaderProcessor.k_ShaderExt; } if (System.IO.File.Exists(externalPath)) { if (GUILayout.Button("Reveal External")) { EditorUtility.RevealInFinder(externalPath); } } else { if (GUILayout.Button("Externalize", GUILayout.Width(80))) { Directory.CreateDirectory(directory); File.WriteAllText(externalPath, "//" + shaderSources[index].name + "," + index.ToString() + "\n//Don't delete the previous line or this one\n" + shaderSources[index].source); } } } if (GUILayout.Button("Show Generated", GUILayout.Width(110))) { resource.ShowGeneratedShaderFile(index); } } if (GUILayout.Button("Select", GUILayout.Width(50))) { Selection.activeObject = shader; } GUILayout.EndHorizontal(); } } } GUI.enabled = false; }
public VFXGraphValidation(VFXGraph graph) { m_Graph = graph; }
private void UpdateDebugMode(VFXGraph graph) { UpdateDebugMode(); }
private void CreateAssetAndComponent(float spawnCountValue, string playEventName, out VFXGraph graph, out VisualEffect vfxComponent, out GameObject gameObj, out GameObject cameraObj) { EditorApplication.ExecuteMenuItem("Window/General/Game"); graph = MakeTemporaryGraph(); var eventStart = ScriptableObject.CreateInstance <VFXBasicEvent>(); eventStart.eventName = playEventName; var spawnerContext = ScriptableObject.CreateInstance <VFXBasicSpawner>(); var blockConstantRate = ScriptableObject.CreateInstance <VFXSpawnerConstantRate>(); var slotCount = blockConstantRate.GetInputSlot(0); var spawnerInit = ScriptableObject.CreateInstance <VFXBasicInitialize>(); var spawnerOutput = ScriptableObject.CreateInstance <VFXPlanarPrimitiveOutput>(); slotCount.value = spawnCountValue; spawnerContext.AddChild(blockConstantRate); graph.AddChild(eventStart); graph.AddChild(spawnerContext); graph.AddChild(spawnerInit); graph.AddChild(spawnerOutput); spawnerContext.LinkFrom(eventStart, 0, 0); spawnerInit.LinkFrom(spawnerContext); spawnerOutput.LinkFrom(spawnerInit); graph.RecompileIfNeeded(); gameObj = new GameObject("CreateAssetAndComponentSpawner"); vfxComponent = gameObj.AddComponent <VisualEffect>(); vfxComponent.visualEffectAsset = graph.visualEffectResource.asset; cameraObj = new GameObject("CreateAssetAndComponentSpawner_Camera"); var camera = cameraObj.AddComponent <Camera>(); camera.transform.localPosition = Vector3.one; camera.transform.LookAt(vfxComponent.transform); }
void OnEnable() { m_OutputContexts.Clear(); VisualEffectAsset target = this.target as VisualEffectAsset; var resource = target.GetResource(); if (resource != null) //Can be null if VisualEffectAsset is in Asset Bundle { m_CurrentGraph = resource.GetOrCreateGraph(); m_CurrentGraph.systemNames.Sync(m_CurrentGraph); m_OutputContexts.AddRange(m_CurrentGraph.children.OfType <IVFXSubRenderer>().OrderBy(t => t.sortPriority)); } m_ReorderableList = new ReorderableList(m_OutputContexts, typeof(IVFXSubRenderer)); m_ReorderableList.displayRemove = false; m_ReorderableList.displayAdd = false; m_ReorderableList.onReorderCallback = OnReorder; m_ReorderableList.drawHeaderCallback = DrawHeader; m_ReorderableList.drawElementCallback = DrawOutputContextItem; if (m_VisualEffectGO == null) { m_PreviewUtility = new PreviewRenderUtility(); m_PreviewUtility.camera.fieldOfView = 60.0f; m_PreviewUtility.camera.allowHDR = true; m_PreviewUtility.camera.allowMSAA = false; m_PreviewUtility.camera.farClipPlane = 10000.0f; m_PreviewUtility.camera.clearFlags = CameraClearFlags.SolidColor; m_PreviewUtility.ambientColor = new Color(.1f, .1f, .1f, 1.0f); m_PreviewUtility.lights[0].intensity = 1.4f; m_PreviewUtility.lights[0].transform.rotation = Quaternion.Euler(40f, 40f, 0); m_PreviewUtility.lights[1].intensity = 1.4f; m_VisualEffectGO = new GameObject("VisualEffect (Preview)"); m_VisualEffectGO.hideFlags = HideFlags.DontSave; m_VisualEffect = m_VisualEffectGO.AddComponent <VisualEffect>(); m_PreviewUtility.AddManagedGO(m_VisualEffectGO); m_VisualEffectGO.transform.localPosition = Vector3.zero; m_VisualEffectGO.transform.localRotation = Quaternion.identity; m_VisualEffectGO.transform.localScale = Vector3.one; m_VisualEffect.visualEffectAsset = target; m_CurrentBounds = new Bounds(Vector3.zero, Vector3.one); m_FrameCount = 0; m_Distance = 10; m_Angles = Vector3.forward; if (s_CubeWireFrame == null) { s_CubeWireFrame = new Mesh(); var vertices = new Vector3[] { new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, -0.5f) }; var indices = new int[] { 0, 1, 0, 3, 0, 4, 6, 2, 6, 5, 6, 7, 1, 2, 1, 5, 3, 7, 3, 2, 4, 5, 4, 7 }; s_CubeWireFrame.vertices = vertices; s_CubeWireFrame.SetIndices(indices, MeshTopology.Lines, 0); } } var targetResources = targets.Cast <VisualEffectAsset>().Select(t => t.GetResource()).Where(t => t != null).ToArray(); if (targetResources.Any()) { resourceObject = new SerializedObject(targetResources); resourceUpdateModeProperty = resourceObject.FindProperty("m_Infos.m_UpdateMode"); cullingFlagsProperty = resourceObject.FindProperty("m_Infos.m_CullingFlags"); motionVectorRenderModeProperty = resourceObject.FindProperty("m_Infos.m_RendererSettings.motionVectorGenerationMode"); prewarmDeltaTime = resourceObject.FindProperty("m_Infos.m_PreWarmDeltaTime"); prewarmStepCount = resourceObject.FindProperty("m_Infos.m_PreWarmStepCount"); initialEventName = resourceObject.FindProperty("m_Infos.m_InitialEventName"); } }