Example #1
0
            public override void Action(int instanceId, string pathName, string resourceFile)
            {
                var mixture = CreateMixtureGraphAsset();

                mixture.name      = Path.GetFileNameWithoutExtension(pathName);
                mixture.hideFlags = HideFlags.HideInHierarchy;

                AssetDatabase.CreateAsset(mixture, pathName);

                // Generate the output texture:
                mixture.outputTextures.Clear();
                if (mixture.type == MixtureGraphType.Realtime)
                {
                    mixture.UpdateRealtimeAssetsOnDisk();
                }
                else
                {
                    MixtureGraphProcessor.RunOnce(mixture);
                    mixture.SaveAllTextures(false);
                }

                ProjectWindowUtil.ShowCreatedAsset(mixture.mainOutputTexture);
                Selection.activeObject       = mixture.mainOutputTexture;
                EditorApplication.delayCall += () => EditorGUIUtility.PingObject(mixture.mainOutputTexture);
            }
Example #2
0
        void UpdateExposedParameters()
        {
            parameters.Clear();

            bool header           = true;
            bool showUpdateButton = false;

            foreach (var param in graph.exposedParameters)
            {
                if (param.settings.isHidden)
                {
                    continue;
                }

                if (header)
                {
                    var headerLabel = new Label("Exposed Parameters");
                    headerLabel.AddToClassList("Header");
                    parameters.Add(headerLabel);
                    header           = false;
                    showUpdateButton = true;
                }
                VisualElement prop = new VisualElement();
                prop.AddToClassList("Indent");
                prop.style.display = DisplayStyle.Flex;
                Type paramType = Type.GetType(param.type);
                var  field     = FieldFactory.CreateField(paramType, param.serializedValue.value, (newValue) => {
                    Undo.RegisterCompleteObjectUndo(graph, "Changed Parameter " + param.name + " to " + newValue);
                    param.serializedValue.value = newValue;
                }, param.name);
                prop.Add(field);
                parameters.Add(prop);
            }

            if (showUpdateButton)
            {
                var updateButton = new Button(() => {
                    MixtureGraphProcessor.RunOnce(graph);
                    graph.SaveAllTextures(false);
                })
                {
                    text = "Update"
                };
                updateButton.AddToClassList("Indent");
                parameters.Add(updateButton);
            }
        }
Example #3
0
        void UpdateAllVariantTextures()
        {
            variant.UpdateAllVariantTextures();

            // Update all child variants:
            foreach (var child in variant.GetChildVariants())
            {
                if (child.IsDirty())
                {
                    child.UpdateAllVariantTextures();
                }
            }

            // If the parentGraph is opened in the editor, we don't want to mess with previews
            // so we update the parentGraph with the original params again.
            if (IsMixtureEditorOpened(graph))
            {
                MixtureGraphProcessor.RunOnce(graph);
            }
        }
Example #4
0
        void UpdateIsDirtyAndPreview()
        {
            if (updateNeededInfoBox == null)
            {
                return;
            }

            isDirty = variant.IsDirty();
            updateNeededInfoBox.style.display = isDirty ? DisplayStyle.Flex : DisplayStyle.None;

            if (isDirty)
            {
                // Copy the result into the inspector preview RT
                var output = graph.outputNode.outputTextureSettings.FirstOrDefault(n => n.name == defaultTextureEditor.target.name);
                if (output == null)
                {
                    output = graph.outputNode.outputTextureSettings.First();
                }

                // Refresh the preview in the inspector:
                var graphicsFormat = graph.outputNode.settings.GetGraphicsFormat(graph);
                var width          = graph.outputNode.settings.GetResolvedWidth(graph);
                var height         = graph.outputNode.settings.GetResolvedHeight(graph);
                var depth          = graph.outputNode.settings.GetResolvedDepth(graph);
                var filterMode     = graph.outputNode.settings.GetResolvedFilterMode(graph);
                var wrapMode       = graph.outputNode.settings.GetResolvedWrapMode(graph);
                var dimension      = graph.outputNode.settings.GetResolvedTextureDimension(graph);

                if (variantPreview.graphicsFormat != graphicsFormat ||
                    variantPreview.height != height ||
                    variantPreview.width != width ||
                    variantPreview.volumeDepth != depth ||
                    variantPreview.filterMode != filterMode ||
                    variantPreview.wrapMode != wrapMode ||
                    variantPreview.dimension != dimension ||
                    variantPreview.useMipMap != output.hasMipMaps)
                {
                    variantPreview.Release();
                    variantPreview.graphicsFormat = graphicsFormat;
                    variantPreview.width          = width;
                    variantPreview.height         = height;
                    variantPreview.volumeDepth    = depth;
                    variantPreview.filterMode     = filterMode;
                    variantPreview.wrapMode       = wrapMode;
                    variantPreview.dimension      = dimension;
                    variantPreview.name           = target.name + "*";
                    variantPreview.useMipMap      = output.hasMipMaps;
                    variantPreview.Create();
                }

                // Update the texture in the inspector
                variant.ProcessGraphWithOverrides();

                TextureUtils.CopyTexture(output.finalCopyRT, variantPreview);

                // If the parentGraph is opened in the editor, we don't want to mess with previews
                // so we update the parentGraph with the original params again.
                if (IsMixtureEditorOpened(graph))
                {
                    MixtureGraphProcessor.RunOnce(graph);
                }

                if (variantPreviewEditor == null || variantPreviewEditor.target != variantPreview)
                {
                    Editor.CreateCachedEditor(variantPreview, renderTextureEditorType, ref variantPreviewEditor);
                }
            }
        }
Example #5
0
        protected void UpdateExposedParameters()
        {
            if (root == null)
            {
                return;
            }

            if (parameters == null || !root.Contains(parameters))
            {
                parameters = new VisualElement()
                {
                    name = "ExposedParameters"
                };
                root.Add(parameters);
            }

            parameters.Clear();

            bool header           = true;
            bool showUpdateButton = false;

            foreach (var param in graph.exposedParameters)
            {
                if (param.settings.isHidden)
                {
                    continue;
                }

                if (header)
                {
                    var headerLabel = new Label("Exposed Parameters");
                    headerLabel.AddToClassList("Header");
                    parameters.Add(headerLabel);
                    header           = false;
                    showUpdateButton = true;
                }
                VisualElement prop = new VisualElement();
                prop.AddToClassList("Indent");
                prop.style.display = DisplayStyle.Flex;
                var p = exposedParameterFactory.GetParameterValueField(param, (newValue) => {
                    param.value = newValue;
                    graph.NotifyExposedParameterValueChanged(param);
                });
                prop.Add(p);
                parameters.Add(prop);
            }

            if (showUpdateButton)
            {
                var updateButton = new Button(() => {
                    MixtureGraphProcessor.RunOnce(graph);
                    graph.SaveAllTextures(false);
                    graph.UpdateLinkedVariants();
                })
                {
                    text = "Update Texture(s)"
                };
                updateButton.AddToClassList("Indent");
                updateButton.AddToClassList("UpdateTextureButton");
                parameters.Add(updateButton);
            }
        }