浏览代码

[Material Graph]Add in general node collapse.

/main
Tim Cooper 9 年前
当前提交
3e4c0174
共有 10 个文件被更改,包括 83 次插入92 次删除
  1. 37
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
  2. 5
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
  3. 28
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs
  4. 2
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/INode.cs
  5. 34
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/AbstractMaterialNode.cs
  6. 10
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/PixelShaderNode.cs
  7. 27
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/DrawingData.cs
  8. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/DrawingData.cs.meta
  9. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/DrawMode.cs
  10. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/DrawMode.cs.meta

37
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs


using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEngine;

public sealed class DrawableNode : CanvasElement
{
protected int previewWidth
{
get { return kPreviewWidth; }
}
protected int previewHeight
{
get { return kPreviewHeight; }
}
public delegate void NeedsRepaint();
public NeedsRepaint onNeedsRepaint;
private const int kPreviewWidth = 64;
private const int kPreviewHeight = 64;
private readonly GraphDataSource m_Data;
public INode m_Node;

public DrawableNode(INode node, float width, GraphDataSource data)
{
translation = node.position.min;
var drawData = node.drawState;
translation = drawData.position.min;
scale = new Vector2(width, width);
m_Node = node;

{
var edges = node.owner.GetEdges(node.GetSlotReference(slot.name));
// don't show empty output slots in collapsed mode
//if (node.drawMode == DrawMode.Collapsed && !edges.Any())
// continue;
if (!node.drawState.expanded && !edges.Any())
continue;
pos.y += 22;
AddChild(new NodeAnchor(pos, typeof(Vector4), node, slot, data, Direction.Output));

public override void UpdateModel(UpdateType t)
{
base.UpdateModel(t);
var pos = m_Node.position;
var drawState = m_Node.drawState;
var pos = drawState.position;
m_Node.position = pos;
drawState.position = pos;
m_Node.drawState = drawState;
}
public override void Render(Rect parentRect, Canvas2D canvas)

EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar"));
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Node.name, EditorStyles.toolbarTextField);
/*if (GUI.Button(new Rect(scale.x - 20f, 3f, 14f, 14f), m_Node.drawMode == DrawMode.Full ? "-" : "+"))
var drawState = m_Node.drawState;
if (GUI.Button(new Rect(scale.x - 20f, 3f, 14f, 14f), drawState.expanded ? "-" : "+"))
m_Node.drawMode = m_Node.drawMode == DrawMode.Full ? DrawMode.Collapsed : DrawMode.Full;
drawState.expanded = !drawState.expanded;
m_Node.drawState = drawState;
}*/
}
/*var modificationType = m_Node.NodeUI(m_NodeUIRect);
if (modificationType == GUIModificationType.Repaint)

5
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs


if (node == null)
return;
node.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, node.position.width, node.position.height);
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);
Rebuild();

28
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs


namespace UnityEditor.Graphing
{
[Serializable]
public class SerializableNode : ISerializationCallbackReceiver, INode
public class SerializableNode : INode, ISerializationCallbackReceiver
public delegate void NeedsRepaint();
public NeedsRepaint onNeedsRepaint;
private const int kPreviewWidth = 64;
private const int kPreviewHeight = 64;
private Rect m_Position;
private DrawingData m_DrawData;
[NonSerialized]
private List<ISlot> m_Slots = new List<ISlot>();

get { return true; }
}
protected virtual int previewWidth
{
get { return kPreviewWidth; }
}
protected virtual int previewHeight
{
get { return kPreviewHeight; }
}
public Rect position
public DrawingData drawState
get { return m_Position; }
set { m_Position = value; }
get { return m_DrawData; }
set { m_DrawData = value; }
}
public IEnumerable<ISlot> inputSlots

2
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/INode.cs


Guid guid { get; }
string name { get; set; }
bool canDeleteNode { get; }
Rect position { get; set; }
IEnumerable<ISlot> inputSlots { get; }
IEnumerable<ISlot> outputSlots { get; }
IEnumerable<ISlot> slots { get; }

ISlot FindInputSlot(string name);
ISlot FindOutputSlot(string name);
IEnumerable<ISlot> GetInputsWithNoConnection();
DrawingData drawState { get; set; }
}
}

34
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/AbstractMaterialNode.cs


[Serializable]
public abstract class AbstractMaterialNode : SerializableNode, IGenerateProperties
{
private static readonly Mesh[] s_Meshes = {null, null, null, null};
private static readonly Mesh[] s_Meshes = {null, null, null, null};
[SerializeField]
private DrawMode m_DrawMode = DrawMode.Full;
protected PreviewMode m_GeneratedShaderMode = PreviewMode.Preview2D;
[NonSerialized]

get { return PreviewMode.Preview2D; }
}
public DrawMode drawMode
{
get { return m_DrawMode; }
set { m_DrawMode = value; }
}
protected virtual bool generateDefaultInputs
{
get { return true; }

public bool hasError
{
get
{
return m_HasError;
}
protected set
{
if (m_HasError != value)
{
m_HasError = value;
ExecuteRepaint();
}
}
get { return m_HasError; }
protected set { m_HasError = value; }
}
public IEnumerable<MaterialSlot> materialSlots

}
}
/*
protected virtual void OnPreviewGUI()
{
if (!ShaderUtil.hardwareSupportsRectRenderTexture)

GUI.DrawTexture(rect, preview, ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
}
*/
protected string GetSlotValue(MaterialSlot inputSlot, GenerationMode generationMode)
{
var edges = owner.GetEdges(GetSlotReference(inputSlot.name)).ToArray();

{
var inputSlotType = inputSlot.concreteValueType;
return inputSlot.OnGUI(rect, inputSlotType);
}
public void ExecuteRepaint()
{
if (onNeedsRepaint != null)
onNeedsRepaint();
}
protected virtual bool UpdatePreviewShader()

10
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/PixelShaderNode.cs


GetLightFunction().DoSlotsForConfiguration(this);
}
protected override int previewWidth
{
get { return 300; }
}
protected override int previewHeight
{
get { return 300; }
}
protected override bool generateDefaultInputs { get { return false; } }
public override bool canDeleteNode { get { return false; } }

27
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/DrawingData.cs


using System;
using UnityEngine;
namespace UnityEditor.Graphing
{
[Serializable]
public struct DrawingData
{
[SerializeField]
private bool m_Expanded;
[SerializeField]
private Rect m_Position;
public bool expanded
{
get { return m_Expanded; }
set { m_Expanded = value; }
}
public Rect position
{
get { return m_Position; }
set { m_Position = value; }
}
}
}

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/DrawingData.cs.meta


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

8
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/DrawMode.cs


namespace UnityEditor.MaterialGraph
{
public enum DrawMode
{
Full,
Collapsed
}
}

12
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/DrawMode.cs.meta


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