Exemple #1
0
        protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            if (subgraph == null)
            {
                return(new VFXExpression[0]);
            }
            VFXGraph graph = m_Subgraph.GetResource().GetOrCreateGraph();

            // Change all the inputExpressions of the parameters.
            var parameters = GetParameters(t => VFXSubgraphUtility.InputPredicate(t)).OrderBy(t => t.order);

            var backedUpExpressions = new List <VFXExpression>();

            VFXSubgraphUtility.TransferExpressionToParameters(inputExpression, parameters, backedUpExpressions);

            List <VFXExpression> outputExpressions = new List <VFXExpression>();

            foreach (var param in GetParameters(t => VFXSubgraphUtility.OutputPredicate(t)))
            {
                outputExpressions.AddRange(param.inputSlots[0].GetExpressionSlots().Select(t => t.GetExpression()));
            }

            foreach (var param in parameters)
            {
                param.ResetOutputValueExpression();
            }

            VFXSubgraphUtility.TransferExpressionToParameters(backedUpExpressions, parameters);

            return(outputExpressions.ToArray());
        }
        public void RecreateCopy()
        {
            ClearCopy();

            if (subgraph == null)
            {
                m_SubChildren  = null;
                m_UsedSubgraph = null;
                return;
            }

            var graph = m_Subgraph.GetResource().GetOrCreateGraph();
            HashSet <ScriptableObject> dependencies = new HashSet <ScriptableObject>();

            foreach (var child in graph.children.Where(t => t is VFXOperator || t is VFXParameter))
            {
                dependencies.Add(child);
                child.CollectDependencies(dependencies);
            }

            var copy = VFXMemorySerializer.DuplicateObjects(dependencies.ToArray());

            m_UsedSubgraph = graph;
            m_SubChildren  = copy.OfType <VFXModel>().Where(t => t is VFXOperator || t is VFXParameter).ToArray();

            foreach (var child in copy)
            {
                child.hideFlags = HideFlags.HideAndDontSave;
            }
        }
        public static                VFXParameterInfo[] BuildParameterInfo(VFXGraph graph)
        {
            var categories = graph.UIInfos.categories;

            if (categories == null)
            {
                categories = new List <VFXUI.CategoryInfo>();
            }


            var parameters = graph.children.OfType <VFXParameter>().Where(t => t.exposed && (string.IsNullOrEmpty(t.category) || !categories.Any(u => u.name == t.category)) && !t.isOutput).OrderBy(t => t.order).ToArray();

            var infos = new List <VFXParameterInfo>();

            BuildCategoryParameterInfo(parameters, infos);

            foreach (var cat in categories)
            {
                parameters = graph.children.OfType <VFXParameter>().Where(t => t.exposed && t.category == cat.name && !t.isOutput).OrderBy(t => t.order).ToArray();
                if (parameters.Length > 0)
                {
                    VFXParameterInfo paramInfo = new VFXParameterInfo(cat.name, "");

                    paramInfo.descendantCount = 0;
                    infos.Add(paramInfo);
                    BuildCategoryParameterInfo(parameters, infos);
                }
            }


            return(infos.ToArray());
        }
Exemple #4
0
 void RecurseSubgraphRecreateCopy(VFXGraph graph)
 {
     foreach (var child in graph.children)
     {
         if (child is VFXSubgraphContext)
         {
             var subgraphContext = child as VFXSubgraphContext;
             if (subgraphContext.subgraph != null)
             {
                 RecurseSubgraphRecreateCopy(subgraphContext.subgraph.GetResource().GetOrCreateGraph());
             }
             subgraphContext.RecreateCopy();
         }
         else if (child is VFXContext)
         {
             foreach (var block in child.children)
             {
                 if (block is VFXSubgraphBlock)
                 {
                     var subgraphBlock = block as VFXSubgraphBlock;
                     if (subgraphBlock.subgraph != null)
                     {
                         RecurseSubgraphRecreateCopy(subgraphBlock.subgraph.GetResource().GetOrCreateGraph());
                     }
                     subgraphBlock.RecreateCopy();
                 }
             }
         }
     }
 }
Exemple #5
0
        public static VFXData CreateDataType(VFXGraph graph, VFXDataType type)
        {
            VFXData newVFXData;

            switch (type)
            {
            case VFXDataType.Particle:
            case VFXDataType.ParticleStrip:
                newVFXData = ScriptableObject.CreateInstance <VFXDataParticle>();
                break;

            case VFXDataType.Mesh:
                newVFXData = ScriptableObject.CreateInstance <VFXDataMesh>();
                break;

            case VFXDataType.SpawnEvent:
                newVFXData = ScriptableObject.CreateInstance <VFXDataSpawner>();
                break;

            case VFXDataType.OutputEvent:
                newVFXData = ScriptableObject.CreateInstance <VFXDataOutputEvent>();
                break;

            default:                        return(null);
            }
            newVFXData.m_Parent = graph;
            return(newVFXData);
        }
Exemple #6
0
 void RecurseSubgraphRecreateCopy(VFXGraph graph)
 {
     foreach (var child in graph.children)
     {
         if (child is VFXSubgraphContext)
         {
             var subgraphContext = child as VFXSubgraphContext;
             if (subgraphContext.subgraph != null)
             {
                 RecurseSubgraphRecreateCopy(subgraphContext.subgraph.GetResource().GetOrCreateGraph());
             }
             subgraphContext.RecreateCopy();
         }
         else if (child is VFXContext)
         {
             foreach (var block in child.children)
             {
                 if (block is VFXSubgraphBlock)
                 {
                     var subgraphBlock = block as VFXSubgraphBlock;
                     if (subgraphBlock.subgraph != null)
                     {
                         RecurseSubgraphRecreateCopy(subgraphBlock.subgraph.GetResource().GetOrCreateGraph());
                     }
                     subgraphBlock.RecreateCopy();
                 }
             }
         }
         else if (child is VFXSubgraphOperator operatorChild)
         {
             operatorChild.ResyncSlots(false);
             operatorChild.UpdateOutputExpressions();
         }
     }
 }
Exemple #7
0
        public static VFXGraph GetOrCreateGraph(this VisualEffectResource resource)
        {
            VFXGraph graph = resource.graph as VFXGraph;

            if (graph == null)
            {
                string assetPath = AssetDatabase.GetAssetPath(resource);
                AssetDatabase.ImportAsset(assetPath);

                graph = resource.GetContents().OfType <VFXGraph>().FirstOrDefault();
            }

            if (graph == null)
            {
                graph                      = ScriptableObject.CreateInstance <VFXGraph>();
                resource.graph             = graph;
                graph.hideFlags           |= HideFlags.HideInHierarchy;
                graph.visualEffectResource = resource;
                // in this case we must update the subassets so that the graph is added to the resource dependencies
                graph.UpdateSubAssets();
            }

            graph.visualEffectResource = resource;
            return(graph);
        }
Exemple #8
0
        public static void Build(bool forceDirty = false)
        {
            var vfxObjects = GetAllVisualEffectObjects();

            foreach (var vfxObj in vfxObjects)
            {
                if (VFXViewPreference.advancedLogs)
                {
                    Debug.Log(string.Format("Recompile VFX asset: {0} ({1})", vfxObj, AssetDatabase.GetAssetPath(vfxObj)));
                }

                var resource = vfxObj.GetResource();
                if (resource != null)
                {
                    VFXGraph graph = resource.GetOrCreateGraph();
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph));
                    if (forceDirty)
                    {
                        EditorUtility.SetDirty(resource);
                    }
                }
            }

            VFXExpression.ClearCache();
        }
Exemple #9
0
 public static void CallOnGraphChanged(VFXGraph graph)
 {
     if (OnGraphChanged != null)
     {
         OnGraphChanged(graph);
     }
 }
Exemple #10
0
        VFXParameter GetParameter(string name)
        {
            VisualEffect effect = (VisualEffect)target;

            if (effect.visualEffectAsset == null)
            {
                return(null);
            }

            VFXGraph graph = effect.visualEffectAsset.GetResource().graph as VFXGraph;

            if (graph == null)
            {
                return(null);
            }

            var parameter = graph.children.OfType <VFXParameter>().FirstOrDefault(t => t.exposedName == name && t.exposed == true);

            if (parameter == null)
            {
                return(null);
            }

            return(parameter);
        }
 public VFXGraphCompiledData(VFXGraph graph)
 {
     if (graph == null)
     {
         throw new ArgumentNullException("VFXGraph cannot be null");
     }
     m_Graph = graph;
 }
Exemple #12
0
        void GraphParameterChanged(VFXGraph graph)
        {
            VisualEffectAsset asset = graph != null && graph.GetResource() != null?graph.GetResource().asset : null;

            if (m_Subgraph == asset && GetParent() != null)
            {
                RecreateCopy();
            }
        }
Exemple #13
0
        IEnumerable <VFXParameter> GetParameters(Func <VFXParameter, bool> predicate)
        {
            if (m_Subgraph == null)
            {
                return(Enumerable.Empty <VFXParameter>());
            }
            VFXGraph graph = m_Subgraph.GetResource().GetOrCreateGraph();

            return(VFXSubgraphUtility.GetParameters(graph.children, predicate));
        }
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            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();
                }
            }
        }
        public static void RemoveModel(VFXModel model, bool notify = true)
        {
            VFXGraph graph = model.GetGraph();

            if (graph != null)
            {
                graph.UIInfos.Sanitize(graph); // Remove reference from groupInfos
            }
            UnlinkModel(model);
            model.Detach(notify);
        }
Exemple #16
0
 public void RefreshErrors(VFXGraph graph)
 {
     if (graph != null)
     {
         graph.errorManager.ClearAllErrors(this, VFXErrorOrigin.Invalidate);
         using (var reporter = new VFXInvalidateErrorReporter(graph.errorManager, this))
         {
             GenerateErrors(reporter);
         }
     }
 }
Exemple #17
0
 static void OnCompileResource(VisualEffectResource resource)
 {
     if (resource != null)
     {
         VFXGraph graph = resource.GetOrCreateGraph();
         if (graph != null)
         {
             graph.CompileForImport();
         }
     }
 }
Exemple #18
0
        public void Sync(VFXGraph graph)
        {
            var models = new HashSet <ScriptableObject>();

            graph.CollectDependencies(models, false);

            var systems = models.OfType <VFXContext>()
                          .Where(c => c.contextType == VFXContextType.Spawner || c.GetData() != null)
                          .Select(c => c.contextType == VFXContextType.Spawner ? c as VFXModel : c.GetData())
                          .Distinct();

            Init(systems);
        }
        public static void ReplaceModel(VFXModel dst, VFXModel src, bool notify = true)
        {
            // UI
            dst.m_UIPosition       = src.m_UIPosition;
            dst.m_UICollapsed      = src.m_UICollapsed;
            dst.m_UISuperCollapsed = src.m_UISuperCollapsed;

            if (notify)
            {
                dst.Invalidate(InvalidationCause.kUIChanged);
            }

            VFXGraph graph = src.GetGraph();

            if (graph != null && graph.UIInfos != null && graph.UIInfos.groupInfos != null)
            {
                // Update group nodes
                foreach (var groupInfo in graph.UIInfos.groupInfos)
                {
                    if (groupInfo.contents != null)
                    {
                        for (int i = 0; i < groupInfo.contents.Length; ++i)
                        {
                            if (groupInfo.contents[i].model == src)
                            {
                                groupInfo.contents[i].model = dst;
                            }
                        }
                    }
                }
            }

            if (dst is VFXBlock && src is VFXBlock)
            {
                ((VFXBlock)dst).enabled = ((VFXBlock)src).enabled;
            }

            // Unlink everything
            UnlinkModel(src);

            // Replace model
            var parent = src.GetParent();
            int index  = parent.GetIndex(src);

            src.Detach(notify);

            if (parent)
            {
                parent.AddChild(dst, index, notify);
            }
        }
        public void CompileExpressions(VFXGraph graph, VFXExpressionContextOption options, bool filterOutInvalidContexts = false)
        {
            var models = new HashSet <ScriptableObject>();

            graph.CollectDependencies(models, false);
            var contexts = models.OfType <VFXContext>();

            if (filterOutInvalidContexts)
            {
                contexts = contexts.Where(c => c.CanBeCompiled());
            }

            CompileExpressions(contexts, options);
        }
Exemple #21
0
        static string[] OnAddResourceDependencies(string assetPath)
        {
            VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);

            if (resource != null)
            {
                VFXGraph graph = resource.GetOrCreateGraph();
                if (graph != null)
                {
                    return(graph.GetImportDependencies());
                }
            }
            return(null);
        }
 internal void Sanitize(VFXGraph graph)
 {
     if (groupInfos != null)
     {
         foreach (var groupInfo in groupInfos)
         {
             //Check first, rebuild after because in most case the content will be valid, saving an allocation.
             if (groupInfo.contents != null && groupInfo.contents.Any(t => (!t.isStickyNote || t.id >= stickyNoteInfos.Length) && !graph.children.Contains(t.model)))
             {
                 groupInfo.contents = groupInfo.contents.Where(t => (t.isStickyNote && t.id < stickyNoteInfos.Length) || graph.children.Contains(t.model)).ToArray();
             }
         }
     }
 }
        IEnumerable <VFXParameter> GetParameters(Func <VFXParameter, bool> predicate)
        {
            if (m_Subgraph == null && !object.ReferenceEquals(m_Subgraph, null))
            {
                m_Subgraph = EditorUtility.InstanceIDToObject(m_Subgraph.GetInstanceID()) as VisualEffectSubgraphOperator;
            }
            if (m_Subgraph == null)
            {
                return(Enumerable.Empty <VFXParameter>());
            }
            VFXGraph graph = subgraph.GetResource().GetOrCreateGraph();

            return(VFXSubgraphUtility.GetParameters(m_SubChildren, predicate));
        }
Exemple #24
0
 static void OnCompileResource(VisualEffectResource resource)
 {
     if (resource != null)
     {
         VFXGraph graph = resource.graph as VFXGraph;
         if (graph != null)
         {
             resource.GetOrCreateGraph().CompileForImport();
         }
         else
         {
             Debug.LogError("VisualEffectGraphResource without graph");
         }
     }
 }
            public void FillExpression(VFXGraph graph)
            {
                var allExposedParameter = graph.children.OfType <VFXParameter>().Where(o => o.exposed);
                var expressionsList     = new List <VFXExpression>();

                foreach (var parameter in allExposedParameter)
                {
                    CollectExposedExpression(expressionsList, parameter.outputSlots[0]);
                }

                mapper = new VFXExpressionMapper();
                for (int i = 0; i < expressionsList.Count; ++i)
                {
                    mapper.AddExpression(expressionsList[i], "ImplicitExposedExpression", i);
                }
            }
Exemple #26
0
 public void RefreshErrors(VFXGraph graph)
 {
     if (graph != null)
     {
         graph.errorManager.ClearAllErrors(this, VFXErrorOrigin.Invalidate);
         using (var reporter = new VFXInvalidateErrorReporter(graph.errorManager, this))
         {
             try
             {
                 GenerateErrors(reporter);
             }
             catch (Exception e)
             {
                 Debug.LogException(e);
             }
         }
     }
 }
Exemple #27
0
        static string[] OnAddResourceDependencies(string assetPath)
        {
            VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);

            if (resource != null)
            {
                VFXGraph graph = resource.graph as VFXGraph;
                if (graph != null)
                {
                    return(resource.GetOrCreateGraph().GetImportDependencies());
                }
                else
                {
                    Debug.LogError("VisualEffectGraphResource without graph");
                }
            }
            return(null);
        }
Exemple #28
0
        public static VFXData CreateDataType(VFXGraph graph, VFXDataType type)
        {
            VFXData newVFXData;

            switch (type)
            {
            case VFXDataType.kParticle:
                newVFXData = ScriptableObject.CreateInstance <VFXDataParticle>();
                break;

            case VFXDataType.kMesh:
                newVFXData = ScriptableObject.CreateInstance <VFXDataMesh>();
                break;

            default:                        return(null);
            }
            newVFXData.m_Parent = graph;
            return(newVFXData);
        }
Exemple #29
0
        void OnPreprocessAsset()
        {
            bool isVFX = VisualEffectAssetModicationProcessor.HasVFXExtension(assetPath);

            if (isVFX)
            {
                VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);
                if (resource == null)
                {
                    return;
                }
                VFXGraph graph = resource.graph as VFXGraph;
                if (graph != null)
                {
                    graph.SanitizeForImport();
                }
                else
                {
                    Debug.LogError("VisualEffectGraphResource without graph");
                }
            }
        }
Exemple #30
0
        private static VFXSlot CorrectPositionFromCylinderToCone(VFXGraph graph, Vector2 basePosition, VFXSlot height, VFXSlot center)
        {
            var inlineHeight = ScriptableObject.CreateInstance <VFXInlineOperator>();

            inlineHeight.SetSettingValue("m_Type", (SerializableType)typeof(float));
            inlineHeight.position = basePosition - new Vector2(700.0f, -151.0f);
            VFXSlot.CopyLinksAndValue(inlineHeight.inputSlots[0], height, true);
            graph.AddChild(inlineHeight);

            var halfHeight = ScriptableObject.CreateInstance <Operator.Multiply>();

            halfHeight.SetOperandType(0, typeof(float));
            halfHeight.SetOperandType(1, typeof(float));
            halfHeight.inputSlots[0].Link(inlineHeight.outputSlots[0]);
            halfHeight.inputSlots[1].value = 0.5f;
            halfHeight.position            = basePosition - new Vector2(480.0f, -111.0f);
            graph.AddChild(halfHeight);

            var inlinePosition = ScriptableObject.CreateInstance <VFXInlineOperator>();

            inlinePosition.SetSettingValue("m_Type", (SerializableType)typeof(Position));
            inlinePosition.position = basePosition - new Vector2(555.0f, -20.0f);
            VFXSlot.CopyLinksAndValue(inlinePosition.inputSlots[0], center, true);
            graph.AddChild(inlinePosition);

            var correctedPosition = ScriptableObject.CreateInstance <Operator.Subtract>();

            correctedPosition.SetOperandType(0, typeof(Position));
            correctedPosition.SetOperandType(1, typeof(Position));
            VFXSlot.CopySpace(correctedPosition.inputSlots[0], inlinePosition.outputSlots[0], true);
            VFXSlot.CopySpace(correctedPosition.inputSlots[1], inlinePosition.outputSlots[0], true);
            correctedPosition.inputSlots[0].Link(inlinePosition.outputSlots[0]);
            correctedPosition.inputSlots[1][0][1].Link(halfHeight.outputSlots[0]);
            correctedPosition.position = basePosition - new Vector2(282.0f, -20.0f);
            graph.AddChild(correctedPosition);

            return(correctedPosition.outputSlots[0]);
        }