public override void Action(int instanceId, string pathName, string resourceFile)
            {
                CreateTemplateAsset(pathName);
                var resource = VisualEffectResource.GetResourceAtPath(pathName);

                ProjectWindowUtil.FrameObjectInProjectWindow(resource.asset.GetInstanceID());
            }
    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);
    }
Esempio n. 3
0
        public void LoadAsset(VisualEffectAsset asset, VisualEffect effectToAttach)
        {
            string assetPath = AssetDatabase.GetAssetPath(asset);

            VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);

            //Transitionning code
            if (resource == null)
            {
                resource = new VisualEffectResource();
                resource.SetAssetPath(AssetDatabase.GetAssetPath(asset));
            }

            LoadResource(resource, effectToAttach);
        }
Esempio n. 4
0
        static bool CanPasteSubgraph(VisualEffectSubgraph subgraph, string openedAssetPath)
        {
            var path = AssetDatabase.GetAssetPath(subgraph);

            if (path == openedAssetPath)
            {
                return(false);
            }

            var resource = VisualEffectResource.GetResourceAtPath(path);
            var graph    = resource.GetOrCreateGraph();

            return(graph.children
                   .OfType <VFXSubgraphOperator>()
                   .All(x => CanPasteSubgraph(x.subgraph, openedAssetPath)));
        }
Esempio n. 5
0
            public override void Action(int instanceId, string pathName, string resourceFile)
            {
                try
                {
                    var templateString = System.IO.File.ReadAllText(templatePath + templateAssetName);
                    System.IO.File.WriteAllText(pathName, templateString);
                }
                catch (FileNotFoundException)
                {
                    CreateNewAsset(pathName);
                }

                AssetDatabase.ImportAsset(pathName);

                var resource = VisualEffectResource.GetResourceAtPath(pathName);

                ProjectWindowUtil.FrameObjectInProjectWindow(resource.asset.GetInstanceID());
            }
Esempio n. 6
0
        protected VisualEffectResource GetCurrentResource()
        {
            var objs = Selection.objects;

            VisualEffectResource selectedResource = null;

            if (objs != null && objs.Length == 1)
            {
                if (objs[0] is VisualEffectAsset)
                {
                    VisualEffectAsset asset = objs[0] as VisualEffectAsset;
                    selectedResource = asset.GetResource();
                }
                else if (objs[0] is VisualEffectResource)
                {
                    selectedResource = objs[0] as VisualEffectResource;
                }
            }
            if (selectedResource == null)
            {
                int instanceID = Selection.activeInstanceID;

                if (instanceID != 0)
                {
                    string path = AssetDatabase.GetAssetPath(instanceID);
                    if (path.EndsWith(".vfx"))
                    {
                        selectedResource = VisualEffectResource.GetResourceAtPath(path);
                    }
                }
            }
            if (selectedResource == null && m_DisplayedResource != null)
            {
                selectedResource = m_DisplayedResource;
            }
            return(selectedResource);
        }