浏览代码

More robust undo/redo by removing and adding nodes

/main
Peter Bay Bastian 7 年前
当前提交
1b46d517
共有 2 个文件被更改,包括 8 次插入52 次删除
  1. 30
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs
  2. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs

30
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs


RemoveEdge(edge);
}
// Remove all nodes and re-add them.
{
var otherNode = other.GetNodeFromGuid(node.guid);
if (otherNode == null || node.GetType() != otherNode.GetType())
{
// Remove the node if it doesn't exist in the other graph, or if the types don't match.
removedNodeGuids.Add(node.guid);
}
else
{
foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
var attribute = propertyInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).FirstOrDefault();
if (attribute == null && propertyInfo.GetSetMethod() != null)
propertyInfo.SetValue(node, propertyInfo.GetValue(otherNode, null), null);
}
foreach (var fieldInfo in node.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
var nonSerializedAttribute = fieldInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).FirstOrDefault();
var serializeFieldAttribute = fieldInfo.GetCustomAttributes(typeof(SerializeField), true).FirstOrDefault();
var isSerialized = ((fieldInfo.IsPublic && nonSerializedAttribute != null) || serializeFieldAttribute != null) && !fieldInfo.IsStatic && !fieldInfo.IsLiteral && !fieldInfo.IsInitOnly;
if (isSerialized)
fieldInfo.SetValue(node, fieldInfo.GetValue(otherNode));
}
var callbackReceiver = node as ISerializationCallbackReceiver;
if (callbackReceiver != null) callbackReceiver.OnAfterDeserialize();
}
}
removedNodeGuids.Add(node.guid);
foreach (var nodeGuid in removedNodeGuids)
RemoveNode(m_Nodes[nodeGuid]);
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


if (otherMG != null)
{
using (var removedPropertiesPooledObject = ListPool<Guid>.GetDisposable())
using (var replacedPropertiesPooledObject = ListPool<IndexedProperty>.GetDisposable())
var replacedProperties = replacedPropertiesPooledObject.value;
var index = 0;
{
var otherProperty = otherMG.properties.FirstOrDefault(op => op.guid == property.guid);
if (otherProperty == null)
removedPropertyGuids.Add(property.guid);
else
replacedProperties.Add(new IndexedProperty { index = index, property = otherProperty });
index++;
}
removedPropertyGuids.Add(property.guid);
foreach (var indexedProperty in replacedProperties)
{
m_Properties[indexedProperty.index] = indexedProperty.property;
// TODO: Notify of change
}
foreach (var otherProperty in otherMG.properties)
{
if (!properties.Any(p => p.guid == otherProperty.guid))
AddShaderProperty(otherProperty);
}
}
foreach (var otherProperty in otherMG.properties)
{
if (!properties.Any(p => p.guid == otherProperty.guid))
AddShaderProperty(otherProperty);
}
}
base.ReplaceWith(other);

正在加载...
取消
保存