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

89 行
2.1 KiB

using System;
using UnityEditor;
using UnityEngine;
namespace UnityEditor.Graphing
{
public class GraphObject : ScriptableObject, IGraphObject, ISerializationCallbackReceiver
{
[SerializeField]
SerializationHelper.JSONSerializedElement m_SerializedGraph;
[SerializeField]
bool m_IsDirty;
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 bool isDirty
{
get { return m_IsDirty; }
set { m_IsDirty = value; }
}
public void RegisterCompleteObjectUndo(string name)
{
Undo.RegisterCompleteObjectUndo(this, name);
m_IsDirty = true;
}
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;
}
void Validate()
{
if (graph != null)
{
graph.OnEnable();
graph.ValidateGraph();
}
}
void OnEnable()
{
Validate();
Undo.undoRedoPerformed += UndoRedoPerformed;
UndoRedoPerformed();
}
void OnDisable()
{
Undo.undoRedoPerformed -= UndoRedoPerformed;
}
void UndoRedoPerformed()
{
if (m_DeserializedGraph != null)
{
graph.ReplaceWith(m_DeserializedGraph);
m_DeserializedGraph = null;
}
}
}
}