浏览代码

[Material graph]Mark asset as dirty on modification so it can be saved properly when modified.

/main
Tim Cooper 9 年前
当前提交
516c1760
共有 10 个文件被更改,包括 123 次插入67 次删除
  1. 30
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
  2. 88
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
  3. 7
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
  4. 11
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/SerializableGraphAsset.cs
  5. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraphAsset.cs
  6. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/PixelGraph.cs
  7. 13
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs
  8. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs.meta
  9. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/IGraphAsset.cs
  10. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/IGraphAsset.cs.meta

30
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs


namespace UnityEditor.Graphing.Drawing
{
public interface ICustomNodeUi
{
float GetNodeUiHeight(float width);
GUIModificationType Render(Rect area);
void SetNode(INode node);
float GetNodeWidth();
}
public class DrawableNode : CanvasElement
{
private readonly GraphDataSource m_Data;

m_CustomUiRect = new Rect(10, pos.y, width - 20, customUiHeight);
pos.y += customUiHeight;
}
/*
if (node.hasPreview && node.drawMode != DrawMode.Collapsed)
{
m_PreviewArea = new Rect(10, pos.y, width - 20, width - 20);
pos.y += m_PreviewArea.height;
}*/
OnWidget += MarkDirtyIfNeedsTime;
OnWidget += InvalidateUIIfNeedsTime;
private bool MarkDirtyIfNeedsTime(CanvasElement element, Event e, Canvas2D parent)
private bool InvalidateUIIfNeedsTime(CanvasElement element, Event e, Canvas2D parent)
{
var childrenNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes, m_Node);

if (m_Ui != null)
{
var modificationType = m_Ui.Render(m_CustomUiRect);
if (modificationType == GUIModificationType.ModelChanged)
if (modificationType != GUIModificationType.None)
m_Data.MarkDirty();
if (modificationType == GUIModificationType.DataChanged)
ParentCanvas().Repaint();
ParentCanvas().Repaint();
return;
}

88
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs


{
readonly List<DrawableNode> m_DrawableNodes = new List<DrawableNode>();
public IGraph graph { get; set; }
public IGraphAsset graphAsset { get; set; }
public ICollection<DrawableNode> lastGeneratedNodes
{

public CanvasElement[] FetchElements()
{
m_DrawableNodes.Clear();
Debug.LogFormat("Trying to convert: {0}", graph);
var graph = graphAsset.graph;
Debug.LogFormat("Trying to convert: {0}", graphAsset.graph);
foreach (var node in graph.nodes)
{
var nodeType = node.GetType();

public void DeleteElements(List<CanvasElement> elements)
{
var graph = graphAsset.graph;
var toRemoveEdge = new List<IEdge>();
// delete selected edges first
foreach (var e in elements.OfType<Edge<NodeAnchor>>())

toRemoveNode.Add(e.m_Node);
}
graph.RemoveElements(toRemoveNode, toRemoveEdge);
MarkDirty();
var graph = graphAsset.graph;
MarkDirty();
/* private string m_LastPath;
public void Export(bool quickExport)
public void Addnode(INode node)
var path = quickExport ? m_LastPath : EditorUtility.SaveFilePanelInProject("Export shader to file...", "shader.shader", "shader", "Enter file name");
m_LastPath = path; // For quick exporting
if (!string.IsNullOrEmpty(path))
graph.ExportShader(path);
else
EditorUtility.DisplayDialog("Export Shader Error", "Cannot export shader", "Ok");
var graph = graphAsset.graph;
graph.AddNode(node);
MarkDirty();
}
public class FloatingPreview : CanvasElement
{
private AbstractMaterialNode m_Node;
public FloatingPreview(Rect position, AbstractMaterialNode node)
public void MarkDirty()
m_Node = node as AbstractMaterialNode;
m_Translation = new Vector2(position.x, position.y);
m_Scale = new Vector3(position.width, position.height, 1);
m_Caps |= Capabilities.Floating | Capabilities.Unselectable;
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
public override void Render(Rect parentRect, Canvas2D canvas)
{
var drawArea = new Rect(0, 0, scale.x, scale.y);
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
EditorGUI.DrawRect(drawArea, backgroundColor);
/* private string m_LastPath;
public void Export(bool quickExport)
{
var path = quickExport ? m_LastPath : EditorUtility.SaveFilePanelInProject("Export shader to file...", "shader.shader", "shader", "Enter file name");
m_LastPath = path; // For quick exporting
if (!string.IsNullOrEmpty(path))
graph.ExportShader(path);
else
EditorUtility.DisplayDialog("Export Shader Error", "Cannot export shader", "Ok");
}
}
drawArea.width -= 10;
drawArea.height -= 10;
drawArea.x += 5;
drawArea.y += 5;
public class FloatingPreview : CanvasElement
{
private AbstractMaterialNode m_Node;
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(drawArea, m_Node.RenderPreview(new Rect(0, 0, drawArea.width, drawArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
public FloatingPreview(Rect position, AbstractMaterialNode node)
{
m_Node = node as AbstractMaterialNode;
m_Translation = new Vector2(position.x, position.y);
m_Scale = new Vector3(position.width, position.height, 1);
m_Caps |= Capabilities.Floating | Capabilities.Unselectable;
}
Invalidate();
canvas.Repaint();
}*/
public override void Render(Rect parentRect, Canvas2D canvas)
{
var drawArea = new Rect(0, 0, scale.x, scale.y);
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
EditorGUI.DrawRect(drawArea, backgroundColor);
drawArea.width -= 10;
drawArea.height -= 10;
drawArea.x += 5;
drawArea.y += 5;
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(drawArea, m_Node.RenderPreview(new Rect(0, 0, drawArea.width, drawArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
Invalidate();
canvas.Repaint();
}*/
}
}

7
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs


var drawstate = node.drawState;
drawstate.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, drawstate.position.width, drawstate.position.height);
node.drawState = drawstate;
m_LastSelection.graph.AddNode(node);
EditorUtility.SetDirty(m_LastSelection);
m_DataSource.Addnode(node);
Rebuild();
Repaint();
}

private void Rebuild()
{
if (m_Canvas == null || m_LastSelection == null || m_LastSelection.graph == null)
if (m_Canvas == null || m_LastSelection == null)
m_DataSource.graph = m_LastSelection.graph;
m_DataSource.graphAsset = m_LastSelection;
m_Canvas.ReloadData();
}

11
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/SerializableGraphAsset.cs


namespace UnityEngine.Graphing
{
public interface IGraphAsset
{
IGraph graph { get; }
bool shouldRepaint { get; }
}
public class SerializableGraphAsset : ScriptableObject, IGraphAsset
{
[SerializeField]

public bool shouldRepaint
{
get { return false; }
}
public ScriptableObject GetScriptableObject()
{
return this;
}
}
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/MaterialGraphAsset.cs


get { return m_MaterialGraph.currentGraph; }
}
public bool shouldRepaint
public bool shouldRepaint
}
public ScriptableObject GetScriptableObject()
{
return this;
}
public Material GetMaterial()

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/PixelGraph.cs


public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
m_PixelMasterNode = null;
}

13
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs


using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public interface ICustomNodeUi
{
float GetNodeUiHeight(float width);
GUIModificationType Render(Rect area);
void SetNode(INode node);
float GetNodeWidth();
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs.meta


fileFormatVersion: 2
guid: 84b49ec2bf7469c41a2181d884788be7
timeCreated: 1465557420
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/IGraphAsset.cs


namespace UnityEngine.Graphing
{
public interface IGraphAsset
{
IGraph graph { get; }
bool shouldRepaint { get; }
ScriptableObject GetScriptableObject();
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/IGraphAsset.cs.meta


fileFormatVersion: 2
guid: b6c42fafc7c73f84b8d030cc6743346d
timeCreated: 1465555773
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存