@@ -38,35 +38,52 @@ private static bool GitFileHistoryValidation()
38
38
[ SerializeField ] private bool locked ;
39
39
[ SerializeField ] private FileHistoryView fileHistoryView = new FileHistoryView ( ) ;
40
40
[ SerializeField ] private UnityEngine . Object selectedObject ;
41
- [ SerializeField ] private NPath selectedObjectPath ;
41
+ [ SerializeField ] private NPath selectedObjectAssetPath ;
42
+ [ SerializeField ] private string selectedObjectAssetPathStr ;
42
43
43
- public void SetSelectedPath ( NPath path )
44
+ public void SetSelectedPath ( NPath assetPath )
44
45
{
45
- selectedObjectPath = path ;
46
+ var fullPath = Application . dataPath . ToNPath ( ) . Parent . Combine ( assetPath ) ;
47
+ this . fileHistoryView . SetFullPath ( fullPath ) ;
48
+
49
+ selectedObjectAssetPathStr = assetPath ;
50
+ selectedObjectAssetPath = assetPath ;
46
51
selectedObject = null ;
47
52
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
+ {
48
68
Texture nodeIcon = null ;
49
69
50
- if ( selectedObjectPath != NPath . Default )
70
+ if ( selectedObjectAssetPath != NPath . Default )
51
71
{
52
- selectedObject = AssetDatabase . LoadMainAssetAtPath ( path . ToString ( ) ) ;
72
+ selectedObject = AssetDatabase . LoadMainAssetAtPath ( selectedObjectAssetPath . ToString ( ) ) ;
53
73
54
- if ( selectedObjectPath . DirectoryExists ( ) )
74
+ if ( selectedObjectAssetPath . DirectoryExists ( ) )
55
75
{
56
76
nodeIcon = Styles . FolderIcon ;
57
77
}
58
78
else
59
79
{
60
- nodeIcon = UnityEditorInternal . InternalEditorUtility . GetIconForFile ( selectedObjectPath . ToString ( ) ) ;
80
+ nodeIcon = UnityEditorInternal . InternalEditorUtility . GetIconForFile ( selectedObjectAssetPath . ToString ( ) ) ;
61
81
}
62
82
63
83
nodeIcon . hideFlags = HideFlags . HideAndDontSave ;
64
84
}
65
85
66
86
selectedIcon = nodeIcon ;
67
-
68
- Repository . UpdateFileLog ( selectedObjectPath )
69
- . Start ( ) ;
70
87
}
71
88
72
89
public override void Initialize ( IApplicationManager applicationManager )
@@ -131,14 +148,14 @@ public override void OnSelectionChange()
131
148
if ( ! locked )
132
149
{
133
150
selectedObject = Selection . activeObject ;
134
- selectedObjectPath = NPath . Default ;
151
+ selectedObjectAssetPath = NPath . Default ;
135
152
if ( selectedObject != null )
136
153
{
137
- selectedObjectPath = AssetDatabase . GetAssetPath ( selectedObject )
154
+ selectedObjectAssetPath = AssetDatabase . GetAssetPath ( selectedObject )
138
155
. ToNPath ( ) ;
139
156
}
140
157
141
- SetSelectedPath ( selectedObjectPath ) ;
158
+ SetSelectedPath ( selectedObjectAssetPath ) ;
142
159
}
143
160
}
144
161
@@ -151,10 +168,21 @@ public override void Refresh()
151
168
Redraw ( ) ;
152
169
}
153
170
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
+
154
180
public override void OnUI ( )
155
181
{
156
182
base . OnUI ( ) ;
157
183
184
+ RestoreFromDomainReload ( ) ;
185
+
158
186
if ( selectedObject != null )
159
187
{
160
188
GUILayout . BeginVertical ( Styles . HeaderStyle ) ;
@@ -209,7 +237,7 @@ private void DoHeaderGUI()
209
237
210
238
GUILayout . Label ( selectedIcon , GUILayout . Height ( iconWidth ) , GUILayout . Width ( iconHeight ) ) ;
211
239
212
- GUILayout . Label ( selectedObjectPath , Styles . FileHistoryLogTitleStyle ) ;
240
+ GUILayout . Label ( selectedObjectAssetPath , Styles . FileHistoryLogTitleStyle ) ;
213
241
214
242
GUILayout . FlexibleSpace ( ) ;
215
243
0 commit comments