示例#1
0
        protected virtual void OnEnable()
        {
            // Load the mixture graph:
            graph   = MixtureEditorUtils.GetGraphAtPath(AssetDatabase.GetAssetPath(target));
            variant = MixtureEditorUtils.GetVariantAtPath(AssetDatabase.GetAssetPath(target));

            if (graph != null)
            {
                exposedParameterFactory              = new ExposedParameterFieldFactory(graph);
                graph.onExposedParameterListChanged += UpdateExposedParameters;
                graph.onExposedParameterModified    += UpdateExposedParameters;
                Undo.undoRedoPerformed += UpdateExposedParameters;
            }
            if (variant != null)
            {
                graph = variant.parentGraph;

                if (graph != null)
                {
                    exposedParameterFactory = new ExposedParameterFieldFactory(variant.parentGraph);
                    Editor.CreateCachedEditor(variant, typeof(MixtureVariantInspector), ref variantEditor);
                }
                else
                {
                    Debug.LogError("Can't find parent graph for Mixture Variant " + variant);
                }
            }
        }
示例#2
0
        public static bool OnBaseGraphOpened(int instanceID, int line)
        {
            var asset = EditorUtility.InstanceIDToObject(instanceID);

            if (asset is Texture)
            {
                // Check if the CustomRenderTexture we're opening is a Mixture graph
                var path    = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID));
                var graph   = MixtureEditorUtils.GetGraphAtPath(path);
                var variant = MixtureEditorUtils.GetVariantAtPath(path);

                graph ??= variant?.parentGraph;

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

                MixtureGraphWindow.Open(graph);
                return(true);
            }
            else if (asset is MixtureVariant variant)
            {
                MixtureGraphWindow.Open(variant.parentGraph);
            }
            return(false);
        }
示例#3
0
        static void DrawMixtureSmallIcon(string assetGUID, Rect rect)
        {
            // If the icon is not small
            if (rect.height != 16)
            {
                return;
            }

            MixtureGraph graph;

            if (mixtureAssets.TryGetValue(assetGUID, out graph))
            {
                DrawMixtureSmallIcon(rect, graph, Selection.Contains(graph.mainOutputTexture));
                return;
            }

            if (mixtureVariants.TryGetValue(assetGUID, out var v))
            {
                // TODO: draw the mixture variant icon
                DrawMixtureSmallIcon(rect, v, Selection.Contains(v.mainOutputTexture));
                return;
            }

            string assetPath = AssetDatabase.GUIDToAssetPath(assetGUID);

            // Mixture assets are saved as .asset files
            if (!assetPath.EndsWith($".{MixtureAssetCallbacks.Extension}"))
            {
                return;
            }

            // ensure that the asset is a texture:
            var texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath);

            if (texture == null)
            {
                return;
            }

            // Check if the current texture is a mixture variant
            var variant = MixtureEditorUtils.GetVariantAtPath(assetPath);

            if (variant != null)
            {
                mixtureVariants.Add(assetGUID, variant);
                DrawMixtureSmallIcon(rect, variant, Selection.Contains(texture));
                return;
            }

            // and then that it have a Mixture Graph as subasset
            graph = MixtureEditorUtils.GetGraphAtPath(assetPath);
            if (graph != null)
            {
                mixtureAssets.Add(assetGUID, graph);
                DrawMixtureSmallIcon(rect, graph, Selection.Contains(texture));
                return;
            }
        }
示例#4
0
        protected virtual void OnEnable()
        {
            // Load the mixture graph:
            graph = MixtureEditorUtils.GetGraphAtPath(AssetDatabase.GetAssetPath(target));

            if (graph != null)
            {
                graph.onExposedParameterListChanged += UpdateExposedParameters;
                graph.onExposedParameterModified    += UpdateExposedParameters;
            }
        }
示例#5
0
            // By default isRealtime is false so we don't need to initialize it like in the realtime mixture create function
            public override MixtureGraph CreateMixtureGraphAsset()
            {
                var g = MixtureEditorUtils.GetGraphAtPath(template);

                g = ScriptableObject.Instantiate(g) as MixtureGraph;

                g.ClearObjectReferences();

                foreach (var node in g.nodes)
                {
                    // Duplicate all the materials from the template
                    if (node is ShaderNode s && s.material != null)
                    {
                        s.material           = new Material(s.material);
                        s.material.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
                    }
示例#6
0
        public static void BuildMixtureAssetBundle(BuildTarget buildTarget)
        {
            AssetBundleBuild buildMap = new AssetBundleBuild {
                assetBundleName = "MixtureAssetBundle"
            };
            List <string> mixturePathes = new List <string>();

            var db = ScriptableObject.CreateInstance <MixtureDatabase>();

            foreach (var path in Directory.GetFiles("Assets", "*.asset", SearchOption.AllDirectories))
            {
                AddMixtureToAssetBundle(path);
            }
            foreach (var path in Directory.GetFiles("Packages", "*.asset", SearchOption.AllDirectories))
            {
                AddMixtureToAssetBundle(path);
            }

            void AddMixtureToAssetBundle(string path)
            {
                var graph = MixtureEditorUtils.GetGraphAtPath(path);

                if (graph != null)
                {
                    if (graph.isRealtime)
                    {
                        db.realtimeGraphs.Add(graph);
                    }
                    else if (graph.embedInBuild)
                    {
                        db.staticGraphs.Add(graph);
                    }
                }
            }

            buildMap.assetNames = mixturePathes.ToArray();

            if (!Directory.Exists("Assets/Resources/Mixture"))
            {
                Directory.CreateDirectory("Assets/Resources/Mixture");
            }
            AssetDatabase.DeleteAsset("Assets/Resources/Mixture/DataBase.asset");
            AssetDatabase.CreateAsset(db, "Assets/Resources/Mixture/DataBase.asset");
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
示例#7
0
        static void DrawMixtureSmallIcon(string assetGUID, Rect rect)
        {
            // If the icon is not small
            if (rect.height != 16)
            {
                return;
            }

            MixtureGraph graph;

            if (mixtureAssets.TryGetValue(assetGUID, out graph))
            {
                DrawMixtureSmallIcon(rect, graph);
                return;
            }

            string assetPath = AssetDatabase.GUIDToAssetPath(assetGUID);

            // Mixture assets are saved as .asset files
            if (!assetPath.EndsWith($".{MixtureAssetCallbacks.Extension}"))
            {
                return;
            }

            // ensure that the asset is a texture:
            var texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath);

            if (texture == null)
            {
                return;
            }

            // and then that it have a Mixture Graph as subasset
            graph = MixtureEditorUtils.GetGraphAtPath(assetPath);
            if (graph == null)
            {
                return;
            }

            mixtureAssets.Add(assetGUID, graph);

            DrawMixtureSmallIcon(rect, graph);
        }
示例#8
0
        public static IEnumerable <MixtureTestCase> GetMixtureTestCases()
        {
            foreach (var assetPath in Directory.GetFiles(mixtureTestFolder, "*.asset", SearchOption.AllDirectories))
            {
                var    graph              = MixtureEditorUtils.GetGraphAtPath(assetPath);
                string graphName          = Path.GetFileNameWithoutExtension(assetPath);
                string referenceImagePath = Path.Combine(referenceImagesFolder, graphName + ".png");
                var    expectedImage      = AssetDatabase.LoadAssetAtPath <Texture2D>(referenceImagePath);

                if (graph != null)
                {
                    yield return(new MixtureTestCase
                    {
                        graph = graph,
                        expected = expectedImage
                    });
                }
            }
        }