Esempio n. 1
0
 public static void UpdateSubAssets(this VisualEffectResource resource)
 {
     resource.GetOrCreateGraph().UpdateSubAssets();
 }
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            Profiler.BeginSample("VFXShaderGraphPostProcessor");

            try
            {
                if (!disableImportDependentVFX)
                {
                    var modifiedShaderGraphs = new HashSet <ShaderGraphVfxAsset>();

                    foreach (var asset in importedAssets.Concat(deletedAssets))
                    {
                        if (asset.EndsWith(".shadergraph", StringComparison.InvariantCultureIgnoreCase))
                        {
                            var ass = AssetDatabase.LoadAssetAtPath <ShaderGraphVfxAsset>(asset);
                            if (ass != null)
                            {
                                modifiedShaderGraphs.Add(ass);
                            }
                        }
                    }

                    if (modifiedShaderGraphs.Count > 0)
                    {
                        string[] guids            = AssetDatabase.FindAssets("t:VisualEffectAsset");
                        var      assetsToReimport = new HashSet <VFXGraph>();

                        foreach (var vfxPath in guids.Select(t => AssetDatabase.GUIDToAssetPath(t)))
                        {
                            var resource = VisualEffectResource.GetResourceAtPath(vfxPath);
                            if (resource != null)
                            {
                                VFXGraph graph = resource.GetOrCreateGraph();

                                if (graph != null)
                                {
                                    if (graph.children.OfType <VFXShaderGraphParticleOutput>().Any(t => modifiedShaderGraphs.Contains(t.shaderGraph)))
                                    {
                                        assetsToReimport.Add(graph);
                                    }
                                }
                            }
                        }

                        foreach (var graph in assetsToReimport)
                        {
                            foreach (var sgOutput in graph.children.OfType <VFXShaderGraphParticleOutput>().Where(t => modifiedShaderGraphs.Contains(t.shaderGraph)))
                            {
                                int instanceID = sgOutput.shaderGraph.GetInstanceID();

                                // This is needed because the imported invalidate the object
                                sgOutput.shaderGraph = EditorUtility.InstanceIDToObject(instanceID) as ShaderGraphVfxAsset;

                                sgOutput.ResyncSlots(true);
                            }

                            graph.SetExpressionGraphDirty();
                            graph.RecompileIfNeeded();
                        }
                    }

                    // Update currently edited VFX mesh outputs if needed
                    var currentGraph = VFXViewWindow.currentWindow?.graphView?.controller?.graph;
                    if (currentGraph)
                    {
                        var meshOutputs = currentGraph.children.OfType <VFXStaticMeshOutput>();
                        if (meshOutputs.Any())
                        {
                            foreach (var asset in importedAssets.Concat(deletedAssets))
                            {
                                if (asset.EndsWith(".shadergraph", StringComparison.InvariantCultureIgnoreCase) || asset.EndsWith(".shader", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    var shader = AssetDatabase.LoadAssetAtPath <Shader>(asset);
                                    foreach (var output in meshOutputs)
                                    {
                                        output.RefreshShader(shader);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                Profiler.EndSample();
            }
        }
Esempio n. 3
0
        protected override void EmptyLineControl(string name, string tooltip, int depth, VisualEffectResource resource)
        {
            if (depth != 1)
            {
                base.EmptyLineControl(name, tooltip, depth, resource);
                return;
            }

            VFXParameter parameter = GetParameter(name, resource);

            if (!VFXGizmoUtility.HasGizmo(parameter.type))
            {
                base.EmptyLineControl(name, tooltip, depth, resource);
                return;
            }

            if (m_EditJustStarted && m_GizmoedParameter == null)
            {
                m_EditJustStarted  = false;
                m_GizmoedParameter = parameter;
            }
            m_GizmoableParameters.Add(parameter);
            if (!m_GizmoDisplayed)
            {
                base.EmptyLineControl(name, tooltip, depth, resource);
                return;
            }

            GUILayout.BeginHorizontal();


            GUILayout.Space(overrideWidth);
            // Make the label half the width to make the tooltip
            EditorGUILayout.LabelField(GetGUIContent(name, tooltip), EditorStyles.boldLabel, GUILayout.Width(EditorGUIUtility.labelWidth));

            GUILayout.FlexibleSpace();

            // Toggle Button
            EditorGUI.BeginChangeCheck();
            bool result = GUILayout.Toggle(m_GizmoedParameter == parameter, new GUIContent("Edit Gizmo"), EditorStyles.miniButton);

            if (EditorGUI.EndChangeCheck() && result)
            {
                m_GizmoedParameter = parameter;
            }

            //GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
 extern private static void CreateVisualEffectResource([Writable] VisualEffectResource resource);
Esempio n. 5
0
 public static bool IsAssetEditable(this VisualEffectResource resource)
 {
     return(AssetDatabase.IsOpenForEdit(resource.asset, StatusQueryOptions.UseCachedIfPossible));
 }
Esempio n. 6
0
 public static bool IsAssetEditable(this VisualEffectResource resource)
 {
     return(AssetDatabase.IsOpenForEdit((UnityEngine.Object)resource.asset ?? resource.subgraph, StatusQueryOptions.UseCachedIfPossible));
 }
Esempio n. 7
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);
                    }
                }
            }
        }