Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 1b3d0de

Browse files
Layout and functionality to find file in asset explorer
1 parent bf5ddc4 commit 1b3d0de

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Styles
6565
headerBranchLabelStyle,
6666
headerUrlLabelStyle,
6767
headerRepoLabelStyle,
68+
fileHistoryLogTitleStyle,
6869
headerTitleStyle,
6970
headerDescriptionStyle,
7071
toolbarButtonStyle,
@@ -734,8 +735,7 @@ public static GUIStyle BoldCenteredLabel
734735
return boldCenteredLabel;
735736
}
736737
}
737-
738-
738+
739739
public static GUIStyle CommitDescriptionFieldStyle
740740
{
741741
get
@@ -802,6 +802,20 @@ public static GUIStyle HyperlinkStyle
802802
}
803803
}
804804

805+
public static GUIStyle FileHistoryLogTitleStyle
806+
{
807+
get
808+
{
809+
if (fileHistoryLogTitleStyle == null)
810+
{
811+
fileHistoryLogTitleStyle = new GUIStyle(EditorStyles.largeLabel);
812+
fileHistoryLogTitleStyle.name = "FileHistoryLogTitleStyle";
813+
fileHistoryLogTitleStyle.margin = new RectOffset(0, 0, 0, 0);
814+
}
815+
return fileHistoryLogTitleStyle;
816+
}
817+
}
818+
805819
public static Texture2D ActiveBranchIcon
806820
{
807821
get

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/FileHistoryWindow.cs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,35 @@ private static bool GitFileHistoryValidation()
3737

3838
[SerializeField] private bool locked;
3939
[SerializeField] private FileHistoryView fileHistoryView = new FileHistoryView();
40-
[SerializeField] private NPath selectedAssetPath;
40+
[SerializeField] private UnityEngine.Object selectedObject;
41+
[SerializeField] private NPath selectedObjectPath;
4142

4243
public void SetSelectedPath(NPath path)
4344
{
44-
selectedAssetPath = path;
45+
selectedObjectPath = path;
46+
selectedObject = null;
4547

4648
Texture nodeIcon = null;
4749

48-
if (selectedAssetPath != NPath.Default)
50+
if (selectedObjectPath != NPath.Default)
4951
{
50-
if (selectedAssetPath.DirectoryExists())
52+
selectedObject = AssetDatabase.LoadMainAssetAtPath(path.ToString());
53+
54+
if (selectedObjectPath.DirectoryExists())
5155
{
5256
nodeIcon = Styles.FolderIcon;
5357
}
5458
else
5559
{
56-
nodeIcon = UnityEditorInternal.InternalEditorUtility.GetIconForFile(selectedAssetPath.ToString());
60+
nodeIcon = UnityEditorInternal.InternalEditorUtility.GetIconForFile(selectedObjectPath.ToString());
5761
}
58-
}
5962

60-
if (nodeIcon != null)
61-
{
6263
nodeIcon.hideFlags = HideFlags.HideAndDontSave;
6364
}
6465

6566
selectedIcon = nodeIcon;
6667

67-
Repository.UpdateFileLog(selectedAssetPath)
68+
Repository.UpdateFileLog(selectedObjectPath)
6869
.Start();
6970
}
7071

@@ -129,16 +130,15 @@ public override void OnSelectionChange()
129130

130131
if (!locked)
131132
{
132-
var assetGuid = Selection.assetGUIDs.FirstOrDefault();
133-
134-
selectedAssetPath = NPath.Default;
135-
if (assetGuid != null)
133+
selectedObject = Selection.activeObject;
134+
selectedObjectPath = NPath.Default;
135+
if (selectedObject != null)
136136
{
137-
selectedAssetPath = AssetDatabase.GUIDToAssetPath(assetGuid)
137+
selectedObjectPath = AssetDatabase.GetAssetPath(selectedObject)
138138
.ToNPath();
139139
}
140140

141-
SetSelectedPath(selectedAssetPath);
141+
SetSelectedPath(selectedObjectPath);
142142
}
143143
}
144144

@@ -155,13 +155,16 @@ public override void OnUI()
155155
{
156156
base.OnUI();
157157

158-
GUILayout.BeginVertical(Styles.HeaderStyle);
158+
if (selectedObject != null)
159159
{
160-
DoHeaderGUI();
160+
GUILayout.BeginVertical(Styles.HeaderStyle);
161+
{
162+
DoHeaderGUI();
161163

162-
fileHistoryView.OnGUI();
164+
fileHistoryView.OnGUI();
165+
}
166+
GUILayout.EndVertical();
163167
}
164-
GUILayout.EndVertical();
165168
}
166169

167170
private void MaybeUpdateData()
@@ -201,16 +204,23 @@ private void DoHeaderGUI()
201204
{
202205
GUILayout.BeginHorizontal(Styles.HeaderBoxStyle);
203206
{
204-
GUILayout.BeginVertical();
205-
{
206-
GUILayout.Space(3);
207+
var iconWidth = 32;
208+
var iconHeight = 32;
209+
210+
GUILayout.Label(selectedIcon, GUILayout.Height(iconWidth), GUILayout.Width(iconHeight));
207211

208-
var iconWidth = 32;
209-
var iconHeight = 32;
212+
GUILayout.Label(selectedObjectPath, Styles.FileHistoryLogTitleStyle);
210213

211-
GUILayout.Label(selectedIcon, GUILayout.Height(iconWidth), GUILayout.Width(iconHeight));
214+
GUILayout.FlexibleSpace();
215+
216+
GUILayout.BeginVertical();
217+
{
218+
GUILayout.Space(16);
212219

213-
GUILayout.Label(selectedAssetPath, Styles.Label);
220+
if (GUILayout.Button("Show in Project"))
221+
{
222+
EditorGUIUtility.PingObject(selectedObject);
223+
}
214224
}
215225
GUILayout.EndVertical();
216226
}

0 commit comments

Comments
 (0)