示例#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);
        }
示例#2
0
 public static void RunOnce(MixtureGraph graph)
 {
     using (var processor = new MixtureGraphProcessor(graph))
     {
         processor.Run();
     }
 }
        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);
                        }
                    }
                }
            }
        }
示例#4
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);
                }
            }
        }
示例#5
0
 public static void ToggleMode(MixtureGraph mixture)
 {
     mixture.isRealtime = !mixture.isRealtime;
     AssetDatabase.SaveAssets();
     mixture.UpdateOutputTexture(true);
     AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(mixture), ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive | ImportAssetOptions.DontDownloadFromCacheServer);
     AssetDatabase.Refresh();
     MixtureGraphWindow.Open(mixture);
 }
示例#6
0
 public void SetParent(MixtureGraph graph)
 {
     parentVariant = null;
     parentGraph   = graph;
     depth         = 0;
     if (!graph.variants.Contains(this))
     {
         graph.variants.Add(this);
     }
 }
示例#7
0
 public void SetParent(MixtureVariant variant)
 {
     parentGraph   = variant.parentGraph;
     parentVariant = variant;
     depth         = variant.depth + 1;
     if (!parentGraph.variants.Contains(this))
     {
         parentGraph.variants.Add(this);
     }
 }
示例#8
0
        public MixtureRTSettingsView(MixtureNode node, MixtureGraphView owner)
        {
            this.graph = owner.graph as MixtureGraph;
            this.node  = node;
            this.owner = owner;

            ReloadSettingsView();

            onChanged += ReloadSettingsView;
        }
示例#9
0
 public static void UnregisterGraph(MixtureGraph graph)
 {
     foreach (var kp in mixtureDrawerInfos)
     {
         if (kp.Value.graph == graph)
         {
             mixtureDrawerInfos.Remove(kp.Key);
         }
     }
 }
示例#10
0
 public static void ToggleMixtureGraphMode(MixtureGraph mixture)
 {
     mixture.type = mixture.type == MixtureGraphType.Realtime ? MixtureGraphType.Baked : MixtureGraphType.Realtime;
     AssetDatabase.SaveAssets();
     mixture.UpdateOutputTextures();
     mixture.FlushTexturesToDisk();
     AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(mixture), ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive | ImportAssetOptions.DontDownloadFromCacheServer);
     AssetDatabase.Refresh();
     MixtureGraphWindow.Open(mixture);
 }
示例#11
0
        protected virtual void OnEnable()
        {
            // Load the mixture graph:
            graph = MixtureEditorUtils.GetGraphAtPath(AssetDatabase.GetAssetPath(target));

            if (graph != null)
            {
                graph.onExposedParameterListChanged += UpdateExposedParameters;
                graph.onExposedParameterModified    += UpdateExposedParameters;
            }
        }
示例#12
0
 public static MixtureGraphProcessor GetOrCreate(MixtureGraph graph)
 {
     MixtureGraphProcessor.processorInstances.TryGetValue(graph, out var processorSet);
     if (processorSet == null)
     {
         return(new MixtureGraphProcessor(graph));
     }
     else
     {
         return(processorSet.FirstOrDefault(p => p != null));
     }
 }
示例#13
0
        public MixtureSettingsView(MixtureSettings settings, MixtureGraphView owner, string title = "Node Output Settings", bool showSettingsForNode = true)
        {
            this.graph               = owner.graph as MixtureGraph;
            this.settings            = settings;
            this.owner               = owner;
            this.title               = title;
            this.showSettingsForNode = showSettingsForNode;

            var stylesheet = Resources.Load <StyleSheet>("MixtureCommon");

            styleSheets.Add(stylesheet);
            ReloadSettingsView();
        }
示例#14
0
        protected virtual void OnEnable()
        {
#if UNITY_EDITOR
            if (graph == null)
            {
                var template = Resources.Load <MixtureGraph>(behaviourGraphTemplate);
                graph = ScriptableObject.Instantiate(template);
                graph.ClearObjectReferences();
            }
#endif

            graph.name = name;
            graph.LinkToScene(gameObject.scene);
        }
示例#15
0
        public override void Enable(bool fromInspector)
        {
            capabilities &= ~Capabilities.Deletable;
            outputNode    = nodeTarget as OutputNode;
            graph         = owner.graph as MixtureGraph;

            BuildOutputNodeSettings();

            base.Enable(fromInspector);

            if (!fromInspector)
            {
                // We don't need the code for removing the material because this node can't be removed
                foreach (var output in outputNode.outputTextureSettings)
                {
                    if (output.finalCopyMaterial != null && !owner.graph.IsObjectInGraph(output.finalCopyMaterial))
                    {
                        // Check if the material we have is ours
                        if (owner.graph.IsExternalSubAsset(output.finalCopyMaterial))
                        {
                            output.finalCopyMaterial           = new Material(output.finalCopyMaterial);
                            output.finalCopyMaterial.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
                        }

                        owner.graph.AddObjectToGraph(output.finalCopyMaterial);
                    }
                }

                outputNode.onTempRenderTextureUpdated += () => {
                    RefreshOutputPortSettings();
                    UpdatePreviewImage();
                };
                graph.onOutputTextureUpdated += UpdatePreviewImage;

                // Clear the input when disconnecting it:
                onPortDisconnected += port => {
                    var outputSlot = outputNode.outputTextureSettings.Find(o => o.name == port.portData.identifier);
                    if (outputSlot != null)
                    {
                        outputSlot.inputTexture = null;
                    }
                };

                InitializeDebug();
            }
        }
示例#16
0
        public override void Enable()
        {
            capabilities &= ~Capabilities.Deletable;
            outputNode    = nodeTarget as OutputNode;
            graph         = owner.graph as MixtureGraph;

            BuildOutputNodeSettings();

            base.Enable();

            outputNode.onTempRenderTextureUpdated += UpdatePreviewImage;
            graph.onOutputTextureUpdated          += UpdatePreviewImage;

            // Clear the input when disconnecting it:
            onPortDisconnected += _ => outputNode.input = null;

            InitializeDebug();
        }
示例#17
0
        protected virtual void OnEnable()
        {
            // Load the mixture graph:
            var assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(target));

            foreach (var asset in assets)
            {
                if (asset is MixtureGraph mixture)
                {
                    graph = mixture;
                }
            }

            if (graph != null)
            {
                graph.onExposedParameterListChanged += UpdateExposedParameters;
                graph.onExposedParameterModified    += UpdateExposedParameters;
            }
        }
示例#18
0
        public static Shader    CreateNewShaderText(MixtureGraph graph, string name, OutputDimension dimension)
        {
            name += ".shader";
            switch (dimension)
            {
            case OutputDimension.Texture2D:
                return(CopyAssetWithNameFromTemplate <Shader>(graph, name, GetAssetTemplatePath <Shader>(shaderTextTexture2DTemplate)));

            case OutputDimension.Texture3D:
                return(CopyAssetWithNameFromTemplate <Shader>(graph, name, GetAssetTemplatePath <Shader>(shaderTextTexture3DTemplate)));

            case OutputDimension.CubeMap:
                return(CopyAssetWithNameFromTemplate <Shader>(graph, name, GetAssetTemplatePath <Shader>(shaderTextTextureCubeTemplate)));

            default:
                Debug.LogError("Can't find template to create new shader for dimension: " + dimension);
                return(null);
            }
        }
示例#19
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);
        }
示例#20
0
        Texture2D ExecuteAndReadback(MixtureGraph graph)
        {
            // Process the graph andreadback the result
            var processor = new MixtureGraphProcessor(graph);

            processor.Run();

            graph.outputNode.outputTextureSettings.First().enableCompression = false;
            var       settings    = graph.outputNode.rtSettings;
            Texture2D destination = new Texture2D(
                settings.GetWidth(graph),
                settings.GetHeight(graph),
                settings.GetGraphicsFormat(graph),
                TextureCreationFlags.None
                );

            graph.ReadbackMainTexture(destination);

            // Output the image to a file

            return(destination);
        }
示例#21
0
        static void DrawMixtureSmallIcon(Rect rect, MixtureGraph graph)
        {
            Rect clearRect = new Rect(rect.x, rect.y, 20, 16);
            Rect iconRect  = new Rect(rect.x + 2, rect.y, 16, 16);

            // TODO: find a way to detect the focus of the project window instantaneously
            bool focused = false;

            // Draw a quad of the color of the background
            Color backgroundColor;

            if (EditorGUIUtility.isProSkin)
            {
                backgroundColor = focused ? new Color32(44, 93, 135, 255) : new Color32(56, 56, 56, 255);
            }
            else
            {
                backgroundColor = new Color32(194, 194, 194, 255);
            }

            EditorGUI.DrawRect(clearRect, backgroundColor);
            GUI.DrawTexture(iconRect, graph.isRealtime ? MixtureUtils.realtimeIcon32 : MixtureUtils.icon32);
        }
示例#22
0
        static T            CopyAssetWithNameFromTemplate <T>(MixtureGraph graph, string name, string templatePath) where T : Object
        {
            var newDirectory = GetMixtureAssetFolderPath(graph);

            if (!Directory.Exists(newDirectory))
            {
                Directory.CreateDirectory(newDirectory);
            }

            var newPath = newDirectory + "/" + name;

            newPath = AssetDatabase.GenerateUniqueAssetPath(newPath);

            AssetDatabase.CopyAsset(templatePath, newPath);

            AssetDatabase.Refresh();

            var asset = AssetDatabase.LoadAssetAtPath <T>(newPath);

            ProjectWindowUtil.ShowCreatedAsset(asset);
            EditorGUIUtility.PingObject(asset);
            return(asset);
        }
示例#23
0
        public static MixtureGraphWindow Open(MixtureGraph graph)
        {
            // Focus the window if the graph is already opened
            var mixtureWindows = Resources.FindObjectsOfTypeAll <MixtureGraphWindow>();

            foreach (var mixtureWindow in mixtureWindows)
            {
                if (mixtureWindow.graph == graph)
                {
                    mixtureWindow.Show();
                    mixtureWindow.Focus();
                    return(mixtureWindow);
                }
            }

            var graphWindow = EditorWindow.CreateWindow <MixtureGraphWindow>();

            graphWindow.Show();
            graphWindow.Focus();

            graphWindow.InitializeGraph(graph);

            return(graphWindow);
        }
示例#24
0
 protected virtual void DrawerGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor, MixtureGraph graph, MixtureNodeView nodeView)
 {
 }
示例#25
0
 public static void RegisterEditor(MaterialEditor editor, MixtureNodeView nodeView, MixtureGraph graph)
 {
     mixtureDrawerInfos[editor] = new MixtureDrawerInfo {
         graph = graph, nodeView = nodeView
     };
 }
示例#26
0
 protected override void DrawerGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor, MixtureGraph graph, MixtureNodeView nodeView)
 {
     prop.floatValue = EditorGUI.Slider(position, prop.displayName, prop.floatValue, prop.rangeLimits.x, prop.rangeLimits.y);
 }
示例#27
0
        protected override void DrawerGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor, MixtureGraph graph, MixtureNodeView nodeView)
        {
            EditorGUI.BeginChangeCheck();
            int value = (int)(Blend)EditorGUI.EnumPopup(position, label, (Blend)(int)prop.floatValue);

            if (EditorGUI.EndChangeCheck())
            {
                prop.floatValue = (float)value;
            }
        }
示例#28
0
        static string       GetMixtureAssetFolderPath(MixtureGraph graph)
        {
            var path = AssetDatabase.GetAssetPath(graph);

            return(Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path));
        }
示例#29
0
        protected override void DrawerGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor, MixtureGraph graph, MixtureNodeView nodeView)
        {
            //Enum(ScaleBias,0,BiasScale,1,Scale,2,Bias,3,TwiceMinusOne,4,HalvePlusHalf,5)

            int value = EditorGUI.IntPopup(position, label, (int)prop.floatValue, displayedOptions, optionValues);

            if (GUI.changed)
            {
                prop.floatValue = (float)value;
            }
        }
示例#30
0
 bool IsMixtureEditorOpened(MixtureGraph graph)
 => Resources.FindObjectsOfTypeAll <MixtureGraphWindow>().Any(w => w.GetCurrentGraph() == graph);