您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

67 行
1.7 KiB

using System;
using UnityEditor;
namespace UnityEngine.Graphing
{
public class SerializableGraphObject : ScriptableObject, IGraphObject, ISerializationCallbackReceiver
{
[SerializeField]
SerializationHelper.JSONSerializedElement m_SerializedGraph;
IGraph m_Graph;
IGraph m_DeserializedGraph;
public IGraph graph
{
get { return m_Graph; }
set
{
if (m_Graph != null)
m_Graph.owner = null;
m_Graph = value;
if (m_Graph != null)
m_Graph.owner = this;
}
}
public void RegisterCompleteObjectUndo(string name)
{
Undo.RegisterCompleteObjectUndo(this, name);
}
public void OnBeforeSerialize()
{
if (graph != null)
m_SerializedGraph = SerializationHelper.Serialize(graph);
}
public void OnAfterDeserialize()
{
var deserializedGraph = SerializationHelper.Deserialize<IGraph>(m_SerializedGraph, null);
if (graph == null)
graph = deserializedGraph;
else
m_DeserializedGraph = deserializedGraph; // graph.ReplaceWith(m_DeserializedGraph);
}
void OnEnable()
{
Undo.undoRedoPerformed += UndoRedoPerformed;
UndoRedoPerformed();
}
void OnDisable()
{
Undo.undoRedoPerformed -= UndoRedoPerformed;
}
void UndoRedoPerformed()
{
if (m_DeserializedGraph != null)
{
graph.ReplaceWith(m_DeserializedGraph);
m_DeserializedGraph = null;
}
}
}
}