@@ -38,35 +38,52 @@ private static bool GitFileHistoryValidation()
3838 [ SerializeField ] private bool locked ;
3939 [ SerializeField ] private FileHistoryView fileHistoryView = new FileHistoryView ( ) ;
4040 [ SerializeField ] private UnityEngine . Object selectedObject ;
41- [ SerializeField ] private NPath selectedObjectPath ;
41+ [ SerializeField ] private NPath selectedObjectAssetPath ;
42+ [ SerializeField ] private string selectedObjectAssetPathStr ;
4243
43- public void SetSelectedPath ( NPath path )
44+ public void SetSelectedPath ( NPath assetPath )
4445 {
45- selectedObjectPath = path ;
46+ var fullPath = Application . dataPath . ToNPath ( ) . Parent . Combine ( assetPath ) ;
47+ this . fileHistoryView . SetFullPath ( fullPath ) ;
48+
49+ selectedObjectAssetPathStr = assetPath ;
50+ selectedObjectAssetPath = assetPath ;
4651 selectedObject = null ;
4752
53+ if ( selectedObjectAssetPath != NPath . Default )
54+ {
55+ selectedObject = AssetDatabase . LoadMainAssetAtPath ( selectedObjectAssetPath . ToString ( ) ) ;
56+ }
57+
58+ InitializeAssetIcon ( ) ;
59+
60+ // If we use selectedObjectAssetPath then this will break if the Unity project isn't located at the root
61+ // of the git repository.
62+ Repository . UpdateFileLog ( fullPath )
63+ . Start ( ) ;
64+ }
65+
66+ private void InitializeAssetIcon ( )
67+ {
4868 Texture nodeIcon = null ;
4969
50- if ( selectedObjectPath != NPath . Default )
70+ if ( selectedObjectAssetPath != NPath . Default )
5171 {
52- selectedObject = AssetDatabase . LoadMainAssetAtPath ( path . ToString ( ) ) ;
72+ selectedObject = AssetDatabase . LoadMainAssetAtPath ( selectedObjectAssetPath . ToString ( ) ) ;
5373
54- if ( selectedObjectPath . DirectoryExists ( ) )
74+ if ( selectedObjectAssetPath . DirectoryExists ( ) )
5575 {
5676 nodeIcon = Styles . FolderIcon ;
5777 }
5878 else
5979 {
60- nodeIcon = UnityEditorInternal . InternalEditorUtility . GetIconForFile ( selectedObjectPath . ToString ( ) ) ;
80+ nodeIcon = UnityEditorInternal . InternalEditorUtility . GetIconForFile ( selectedObjectAssetPath . ToString ( ) ) ;
6181 }
6282
6383 nodeIcon . hideFlags = HideFlags . HideAndDontSave ;
6484 }
6585
6686 selectedIcon = nodeIcon ;
67-
68- Repository . UpdateFileLog ( selectedObjectPath )
69- . Start ( ) ;
7087 }
7188
7289 public override void Initialize ( IApplicationManager applicationManager )
@@ -131,14 +148,14 @@ public override void OnSelectionChange()
131148 if ( ! locked )
132149 {
133150 selectedObject = Selection . activeObject ;
134- selectedObjectPath = NPath . Default ;
151+ selectedObjectAssetPath = NPath . Default ;
135152 if ( selectedObject != null )
136153 {
137- selectedObjectPath = AssetDatabase . GetAssetPath ( selectedObject )
154+ selectedObjectAssetPath = AssetDatabase . GetAssetPath ( selectedObject )
138155 . ToNPath ( ) ;
139156 }
140157
141- SetSelectedPath ( selectedObjectPath ) ;
158+ SetSelectedPath ( selectedObjectAssetPath ) ;
142159 }
143160 }
144161
@@ -151,10 +168,21 @@ public override void Refresh()
151168 Redraw ( ) ;
152169 }
153170
171+ // Ideally we'd just call this in 'Initialize()' but that is too early in the domain reload and causes exceptions
172+ private void RestoreFromDomainReload ( )
173+ {
174+ if ( selectedObjectAssetPathStr != selectedObjectAssetPath && ! string . IsNullOrEmpty ( selectedObjectAssetPathStr ) )
175+ {
176+ this . SetSelectedPath ( selectedObjectAssetPathStr . ToNPath ( ) ) ;
177+ }
178+ }
179+
154180 public override void OnUI ( )
155181 {
156182 base . OnUI ( ) ;
157183
184+ RestoreFromDomainReload ( ) ;
185+
158186 if ( selectedObject != null )
159187 {
160188 GUILayout . BeginVertical ( Styles . HeaderStyle ) ;
@@ -209,7 +237,7 @@ private void DoHeaderGUI()
209237
210238 GUILayout . Label ( selectedIcon , GUILayout . Height ( iconWidth ) , GUILayout . Width ( iconHeight ) ) ;
211239
212- GUILayout . Label ( selectedObjectPath , Styles . FileHistoryLogTitleStyle ) ;
240+ GUILayout . Label ( selectedObjectAssetPath , Styles . FileHistoryLogTitleStyle ) ;
213241
214242 GUILayout . FlexibleSpace ( ) ;
215243
0 commit comments