[SerializeField]
SerializableGraphObject m_GraphObject ;
[NonSerialized]
bool m_HasError ;
GraphEditorView m_GraphEditorView ;
GraphEditorView graphEditorView
void Update ( )
{
if ( graphObject = = null & & selectedGuid ! = null )
if ( m_HasError )
return ;
try
var guid = selectedGuid ;
selectedGuid = null ;
ChangeSelection ( guid ) ;
}
if ( graphObject = = null & & selectedGuid ! = null )
{
var guid = selectedGuid ;
selectedGuid = null ;
ChangeSelection ( guid ) ;
}
if ( graphObject = = null )
{
Close ( ) ;
return ;
}
var materialGraph = graphObject . graph as AbstractMaterialGraph ;
if ( materialGraph = = null )
return ;
if ( graphEditorView = = null )
{
var asset = AssetDatabase . LoadAssetAtPath < Object > ( AssetDatabase . GUIDToAssetPath ( selectedGuid ) ) ;
graphEditorView = new GraphEditorView ( this , materialGraph , asset . name ) { persistenceKey = AssetDatabase . AssetPathToGUID ( AssetDatabase . GUIDToAssetPath ( selectedGuid ) ) } ;
}
if ( graphObject = = null )
{
Close ( ) ;
return ;
graphEditorView . HandleGraphChanges ( ) ;
graphObject . graph . ClearChanges ( ) ;
var materialGraph = graphObject . graph as AbstractMaterialGraph ;
if ( materialGraph = = null )
return ;
if ( graphEditorView = = null )
catch ( Exception )
var asset = AssetDatabase . LoadAssetAtPath < Object > ( AssetDatabase . GUIDToAssetPath ( selectedGuid ) ) ;
graphEditorView = new GraphEditorView ( this , materialGraph , asset . name ) { persistenceKey = AssetDatabase . AssetPathToGUID ( AssetDatabase . GUIDToAssetPath ( selectedGuid ) ) } ;
m_HasError = true ;
m_GraphEditorView = null ;
graphObject = null ;
throw ;
graphEditorView . HandleGraphChanges ( ) ;
graphObject . graph . ClearChanges ( ) ;
}
void OnDisable ( )
public void ChangeSelection ( string newSelectionGuid )
{
var asset = AssetDatabase . LoadAssetAtPath < Object > ( AssetDatabase . GUIDToAssetPath ( newSelectionGuid ) ) ;
if ( asset = = null )
return ;
try
{
var asset = AssetDatabase . LoadAssetAtPath < Object > ( AssetDatabase . GUIDToAssetPath ( newSelectionGuid ) ) ;
if ( asset = = null )
return ;
if ( ! EditorUtility . IsPersistent ( asset ) )
return ;
if ( ! EditorUtility . IsPersistent ( asset ) )
return ;
if ( selectedGuid = = newSelectionGuid )
return ;
var path = AssetDatabase . GetAssetPath ( asset ) ;
var extension = Path . GetExtension ( path ) ;
Type graphType ;
switch ( extension )
{
case ".ShaderGraph" :
graphType = typeof ( MaterialGraph ) ;
break ;
case ".ShaderSubGraph" :
graphType = typeof ( SubGraph ) ;
break ;
default :
if ( selectedGuid = = newSelectionGuid )
}
selectedGuid = newSelectionGuid ;
var path = AssetDatabase . GetAssetPath ( asset ) ;
var extension = Path . GetExtension ( path ) ;
Type graphType ;
switch ( extension )
{
case ".ShaderGraph" :
graphType = typeof ( MaterialGraph ) ;
break ;
case ".ShaderSubGraph" :
graphType = typeof ( SubGraph ) ;
break ;
default :
return ;
}
var textGraph = File . ReadAllText ( path , Encoding . UTF8 ) ;
graphObject = CreateInstance < SerializableGraphObject > ( ) ;
graphObject . hideFlags = HideFlags . HideAndDontSave ;
graphObject . graph = JsonUtility . FromJson ( textGraph , graphType ) as IGraph ;
graphObject . graph . OnEnable ( ) ;
graphObject . graph . ValidateGraph ( ) ;
selectedGuid = newSelectionGuid ;
var textGraph = File . ReadAllText ( path , Encoding . UTF8 ) ;
graphObject = CreateInstance < SerializableGraphObject > ( ) ;
graphObject . hideFlags = HideFlags . HideAndDontSave ;
graphObject . graph = JsonUtility . FromJson ( textGraph , graphType ) as IGraph ;
graphObject . graph . OnEnable ( ) ;
graphObject . graph . ValidateGraph ( ) ;
graphEditorView = new GraphEditorView ( this , m_GraphObject . graph as AbstractMaterialGraph , asset . name ) { persistenceKey = AssetDatabase . GUIDToAssetPath ( selectedGuid ) } ;
graphEditorView . RegisterCallback < PostLayoutEvent > ( OnPostLayout ) ;
graphEditorView = new GraphEditorView ( this , m_GraphObject . graph as AbstractMaterialGraph , asset . name ) { persistenceKey = AssetDatabase . GUIDToAssetPath ( selectedGuid ) } ;
graphEditorView . RegisterCallback < PostLayoutEvent > ( OnPostLayout ) ;
titleContent = new GUIContent ( asset . name ) ;
titleContent = new GUIContent ( asset . name ) ;
Repaint ( ) ;
Repaint ( ) ;
}
catch ( Exception )
{
m_HasError = true ;
m_GraphEditorView = null ;
graphObject = null ;
throw ;
}
}
void OnPostLayout ( PostLayoutEvent evt )