Пример #1
0
        public static bool CreateMixtureVariantEnabled()
        {
            var selectedMixtures    = Selection.GetFiltered <Texture>(SelectionMode.Assets);
            int graphOrVariantCount = selectedMixtures.Count(m => MixtureDatabase.GetGraphFromTexture(m) != null || MixtureEditorUtils.GetVariantAtPath(AssetDatabase.GetAssetPath(m)));

            return((graphOrVariantCount) > 0);
        }
Пример #2
0
        static void BeforeCustomRenderTextureUpdate(CommandBuffer cmd, CustomRenderTexture crt)
        {
            MixtureGraph graph = MixtureDatabase.GetGraphFromTexture(crt);;

            // If the graph is valid and realtime
            if (graph != null && graph.type == MixtureGraphType.Realtime)
            {
                MixtureGraphProcessor.processorInstances.TryGetValue(graph, out var processorSet);
                if (processorSet == null)
                {
                    var processor = new MixtureGraphProcessor(graph);
                    // Relay the event to the processor
                    processor.BeforeCustomRenderTextureUpdate(cmd, crt);
                }
                else
                {
                    foreach (var processor in processorSet)
                    {
                        // Relay the event to the processor
                        if (processor.isProcessing == 0)
                        {
                            processor.BeforeCustomRenderTextureUpdate(cmd, crt);
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Get the graph from the mixture
        /// </summary>
        /// <param name="texture"></param>
        /// <returns></returns>
        public static MixtureGraph GetGraphFromTexture(Texture texture)
        {
            if (texture == null)
            {
                return(null);
            }

// In the editor, we can directly use the AssetDatabase instead of relying on the resources.
#if UNITY_EDITOR
            string graphPath = UnityEditor.AssetDatabase.GetAssetPath(texture);

            if (!String.IsNullOrEmpty(graphPath))
            {
                return(UnityEditor.AssetDatabase.LoadAllAssetsAtPath(graphPath).OfType <MixtureGraph>().FirstOrDefault());
            }
            else
            {
                return(null);
            }
#else
            if (instance == null)
            {
                instance = Resources.Load <MixtureDatabase>(databaseResourcePath);
                if (instance == null)
                {
                    Debug.LogError("Mixture Database asset not found! Realtime Mixtures won't work as expected.");
                    return(null);
                }
            }

            instance.graphMap.TryGetValue(texture, out var graph);
            return(graph);
#endif
        }
Пример #4
0
        public static void CreateMixtureVariant()
        {
            var selectedMixtures = Selection.GetFiltered <Texture>(SelectionMode.Assets);

            foreach (var mixtureTexture in selectedMixtures)
            {
                var graph   = MixtureDatabase.GetGraphFromTexture(mixtureTexture);
                var variant = MixtureEditorUtils.GetVariantAtPath(AssetDatabase.GetAssetPath(mixtureTexture));

                if (graph != null)
                {
                    CreateMixtureVariant(graph, null);
                }
                else if (variant != null)
                {
                    CreateMixtureVariant(null, variant);
                }
            }
        }