浏览代码

[material graph]Fixing position + serializing positions

/main
Tim Cooper 8 年前
当前提交
d55cb3d6
共有 8 个文件被更改,包括 80 次插入24 次删除
  1. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs
  2. 67
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs
  3. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs
  4. 11
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs
  5. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/UnitTests/SerializedGraphTests.cs
  6. 3
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Data/GraphElementData.cs
  7. 10
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/SelectionDragger.cs
  8. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs


{
var theElements = m_Elements.OfType<MaterialNodeData>().ToList();
var found = theElements.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNode in found)
drawableNode.MarkDirtyHack();
foreach (var drawableNodeData in found)
drawableNodeData.MarkDirtyHack();
}
}

67
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;

namespace UnityEditor.Graphing.Drawing
{
class PreviewImage : Image
{
public override void DoRepaint(PaintContext args)
{
Handles.DrawSolidRectangleWithOutline(position, Color.blue, Color.blue);
base.DoRepaint(args);
}
}
[GUISkinStyle("window")]
public class MaterialGraphNode : GraphElement
{

private List<NodePreviewData> m_currentPreviewData;
public MaterialGraphNode()
{

name = "preview", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_currentPreviewData = new List<NodePreviewData>();
}
public override void DoRepaint(PaintContext painter)

private void AddPreview(MaterialNodeData nodeData)
{
m_PreviewContainer.ClearChildren();
var previews = nodeData.elements.OfType<NodePreviewData>().ToList();
var isSamePreviews = m_currentPreviewData.Count == previews.Count;
foreach (var preview in nodeData.elements.OfType<NodePreviewData>())
if (isSamePreviews)
{
for (int i = 0; i < previews.Count; i++)
{
if (!ReferenceEquals(previews[i], m_currentPreviewData[i]))
{
isSamePreviews = false;
break;
}
}
}
if (isSamePreviews)
var image = preview.Render(new Vector2(200, 200));
var thePreview = new PreviewImage
for (int i = 0; i < previews.Count; i++)
image = image,
name = "image"
};
m_PreviewContainer.AddChild(thePreview);
var preview = previews[i];
var thePreview = m_PreviewContainer.GetChildAtIndex(i) as Image;
// TODO: Consider null exception
// TODO: Need to share the texture
// right now it's allocating all the time.
thePreview.image = preview.Render(new Vector2(200, 200));
}
else
{
m_PreviewContainer.ClearChildren();
m_currentPreviewData.Clear();
foreach (var preview in previews)
{
var image = preview.Render(new Vector2(200, 200));
var thePreview = new Image
{
image = image,
name = "image"
};
m_PreviewContainer.AddChild(thePreview);
m_currentPreviewData.Add(preview);
}
}
AddChild(m_PreviewContainer);
}

ClearChildren();
m_ControlsContainer.ClearChildren();
m_PreviewContainer.ClearChildren();
// m_PreviewContainer.ClearChildren();
var nodeData = dataProvider as MaterialNodeData;

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs


if (node == null)
return;
var drawstate = node.drawState;
drawstate.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, drawstate.position.width, drawstate.position.height);
drawstate.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, 0 , 0);
node.drawState = drawstate;
/*m_DataSource.Addnode(node);
Rebuild();

11
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs


{}
public override void CommitChanges()
{
base.CommitChanges();
var drawData = node.drawState;
drawData.position = position;
node.drawState = drawData;
}
//TODO: Kill this and the function below after talking with shanti
[SerializeField]
private int m_SerializationRandom;

m_Children.AddRange(controlData);
//position = new Rect(node.drawState.position.x, node.drawState.position.y, 100, 200);
position = new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0);
//position
}

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/UnitTests/SerializedGraphTests.cs


node.name = "Test Node";
var drawState = node.drawState;
var newPos = new Rect(10, 10, 10, 10);
var newPos = new Rect(10, 10, 0, 0);
drawState.position = newPos;
drawState.expanded = false;
node.drawState = drawState;

3
MaterialGraphProject/Assets/NewUI/Editor/Elements/Data/GraphElementData.cs


get { return m_Capabilities; }
set { m_Capabilities = value; }
}
public virtual void CommitChanges()
{}
}
}

10
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/SelectionDragger.cs


using System;
using System.Linq;
using UnityEngine;
using UnityEngine.RMGUI;

case EventType.MouseUp:
if (this.HasCapture() && evt.button == (int)activateButton)
{
this.ReleaseCapture();
foreach (var s in graphView.selection.OfType<GraphElement>())
{
if (s.dataProvider == null)
continue;
s.dataProvider.CommitChanges();
}
this.ReleaseCapture();
return EventPropagation.Stop;
}
break;

5
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs


UpdateNodeAfterDeserialization();
}
public override bool hasPreview
{
get { return true; }
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));

正在加载...
取消
保存