Example #1
0
        public static void CreateMixtureVariant(MixtureGraph targetGraph, MixtureVariant parentVariant)
        {
            string path;

            if (targetGraph != null)
            {
                path = AssetDatabase.GetAssetPath(targetGraph);
            }
            else
            {
                targetGraph = parentVariant.parentGraph;
                path        = AssetDatabase.GetAssetPath(parentVariant);
            }

            // Patch path name to add Variant
            string fileName = Path.GetFileNameWithoutExtension(path) + " Variant";

            path = Path.Combine(Path.GetDirectoryName(path), fileName + Path.GetExtension(path));
            path = AssetDatabase.GenerateUniqueAssetPath(path);

            var action = ScriptableObject.CreateInstance <MixtureVariantAction>();

            action.targetGraph   = targetGraph;
            action.parentVariant = parentVariant;
            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, action,
                                                                    Path.GetFileName(path), targetGraph.type == MixtureGraphType.Realtime ? MixtureUtils.realtimeVariantIcon : MixtureUtils.iconVariant, null);
        }
Example #2
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);
                }
            }
        }
Example #3
0
        protected void OnDisable()
        {
            if (graph != null)
            {
                graph.onExposedParameterListChanged  -= UpdateParameters;
                graph.onExposedParameterModified     -= UpdateParameters;
                graph.onExposedParameterValueChanged -= UpdateParameters;
                Undo.undoRedoPerformed -= UpdateParameters;
            }

            variant.variantTexturesUpdated -= UpdateIsDirtyAndPreview;

            MixtureVariant parent = variant.parentVariant;

            while (parent != null)
            {
                parent.parameterValueChanged -= UpdateParameters;
                parent = parent.parentVariant;
            }

            if (variantPreview != null)
            {
                variantPreview.Release();
                variantPreview = null;
            }

            if (variantPreviewEditor != null)
            {
                DestroyImmediate(variantPreviewEditor);
                variantPreviewEditor = null;
            }

            exposedParameterFactory.Dispose();
        }
Example #4
0
 public void SetParent(MixtureVariant variant)
 {
     parentGraph   = variant.parentGraph;
     parentVariant = variant;
     depth         = variant.depth + 1;
     if (!parentGraph.variants.Contains(this))
     {
         parentGraph.variants.Add(this);
     }
 }
Example #5
0
 public void SetParent(MixtureGraph graph)
 {
     parentVariant = null;
     parentGraph   = graph;
     depth         = 0;
     if (!graph.variants.Contains(this))
     {
         graph.variants.Add(this);
     }
 }
Example #6
0
 static void DrawMixtureSmallIcon(Rect rect, MixtureVariant variant, bool focused)
 {
     // Show an error icon if the variant graph was destroyed
     if (variant.parentGraph == null)
     {
         DrawMixtureSmallIcon(rect, EditorGUIUtility.IconContent("console.erroricon").image as Texture2D, focused);
     }
     else
     {
         DrawMixtureSmallIcon(rect, variant.parentGraph.type == MixtureGraphType.Realtime ? MixtureUtils.realtimeVariantIcon32 : MixtureUtils.iconVariant32, focused);
     }
 }
Example #7
0
            static IEnumerable <ExposedParameter> GetOverrideParamsForVariant(MixtureVariant variant)
            {
                if (variant.parentVariant != null)
                {
                    foreach (var param in GetOverrideParamsForVariant(variant.parentVariant))
                    {
                        yield return(param);
                    }
                }

                foreach (var param in variant.overrideParameters)
                {
                    yield return(param);
                }
            }
Example #8
0
        void UpdateParentView()
        {
            var container = new VisualElement();

            var headerLabel = new Label("Parent Hierarchy");

            headerLabel.AddToClassList("Header");
            container.Add(headerLabel);

            // Create a hierarchy queue
            Queue <Object> parents        = new Queue <Object>();
            MixtureVariant currentVariant = variant.parentVariant;

            while (currentVariant != null)
            {
                parents.Enqueue(currentVariant);
                currentVariant = currentVariant.parentVariant;
            }
            parents.Enqueue(graph);

            // UIElements breadcrumbs bar
            var parentBar = new ToolbarBreadcrumbs();

            parentBar.AddToClassList("Indent");
            parentBar.AddToClassList("VariantBreadcrumbs");
            foreach (var obj in parents.Reverse())
            {
                var v = obj as MixtureVariant;
                var g = obj as MixtureGraph;

                parentBar.PushItem(obj.name, () => {
                    Selection.activeObject = v?.mainOutputTexture ?? g?.mainOutputTexture ?? obj;
                });
            }

            // Add new variant button:
            parentBar.PushItem("+", () => {
                MixtureAssetCallbacks.CreateMixtureVariant(null, variant);
            });

            container.Add(parentBar);

            root.Add(container);
        }
Example #9
0
        protected void OnEnable()
        {
            variant = target as MixtureVariant;
            graph   = variant.parentGraph;
            if (graph != null)
            {
                graph.onExposedParameterListChanged  += UpdateParameters;
                graph.onExposedParameterModified     += UpdateParameters;
                graph.onExposedParameterValueChanged += UpdateParameters;
                Undo.undoRedoPerformed += UpdateParameters;
            }

            variant.variantTexturesUpdated += UpdateIsDirtyAndPreview;

            MixtureVariant parent = variant.parentVariant;

            while (parent != null)
            {
                parent.parameterValueChanged += UpdateParameters;
                parent = parent.parentVariant;
            }

            // TODO: create a temp render texture to copy the result of the graph we process
            // it will be used to display in real time how the parameter changes affects the texture

            // Update serialized parameters (for the inspector)
            SyncParameters();
            exposedParameterFactory = new ExposedParameterFieldFactory(graph, visibleParameters);

            overrideParameterView = Resources.Load <VisualTreeAsset>("UI Blocks/MixtureVariantParameter");

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                renderTextureEditorType = assembly.GetType("UnityEditor.RenderTextureEditor");
                if (renderTextureEditorType != null)
                {
                    break;
                }
            }

            variantPreview = new RenderTexture(1, 1, 0);
        }
Example #10
0
        void SyncParameters()
        {
            // Clone the graph parameters into visible parameters
            visibleParameters.Clear();
            visibleParameters.AddRange(graph.exposedParameters.Select(p => p.Clone()));

            MixtureVariant currentVariant = variant;

            foreach (var overrideParam in variant.GetAllOverrideParameters())
            {
                var param = visibleParameters.FirstOrDefault(p => p == overrideParam);
                if (param != null)
                {
                    if (param.GetValueType().IsAssignableFrom(overrideParam.GetValueType()))
                    {
                        param.value = overrideParam.value;
                    }
                }
            }
        }
Example #11
0
 static void DrawMixtureSmallIcon(Rect rect, MixtureVariant variant, bool focused)
 => DrawMixtureSmallIcon(rect, variant.parentGraph.type == MixtureGraphType.Realtime ? MixtureUtils.realtimeVariantIcon32 : MixtureUtils.iconVariant32, focused);