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

Commit 924a28d

Browse files
Using HideFlags.HideAndDontSave on Texture2D objects
I learned that is how we can tell Unity that Texture2D objects that were loaded during "game time" need to be retained after "game time" ends
1 parent ca6dc4b commit 924a28d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,25 @@ public static Texture2D GetIcon(string filename, string filename2x = "")
1616
filename = filename2x;
1717
}
1818

19+
Texture2D texture2D = null;
20+
1921
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GitHub.Unity.IconsAndLogos." + filename);
2022
if (stream != null)
21-
return stream.ToTexture2D();
23+
{
24+
texture2D = stream.ToTexture2D();
25+
}
26+
else
27+
{
28+
var iconPath = EntryPoint.Environment.ExtensionInstallPath.Combine("IconsAndLogos", filename).ToString(SlashMode.Forward);
29+
texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
30+
}
31+
32+
if (texture2D != null)
33+
{
34+
texture2D.hideFlags = HideFlags.HideAndDontSave;
35+
}
2236

23-
var iconPath = EntryPoint.Environment.ExtensionInstallPath.Combine("IconsAndLogos", filename).ToString(SlashMode.Forward);
24-
return AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
37+
return texture2D;
2538
}
2639

2740
public static Texture2D GetTextureFromColor(Color color)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Window : BaseWindow
4040
[SerializeField] private CacheUpdateEvent lastCurrentBranchAndRemoteChangedEvent;
4141
[NonSerialized] private bool currentBranchAndRemoteHasUpdate;
4242

43+
[NonSerialized] private Texture2D smallLogo;
44+
4345
[MenuItem(LaunchMenu)]
4446
public static void Window_GitHub()
4547
{
@@ -102,7 +104,11 @@ public override void OnEnable()
102104
Selection.activeObject = this;
103105
#endif
104106
// Set window title
105-
titleContent = new GUIContent(Title, Styles.SmallLogo);
107+
if (smallLogo == null)
108+
{
109+
smallLogo = Styles.SmallLogo;
110+
titleContent = new GUIContent(Title, smallLogo);
111+
}
106112

107113
if (Repository != null)
108114
Repository.CheckCurrentBranchAndRemoteChangedEvent(lastCurrentBranchAndRemoteChangedEvent);

0 commit comments

Comments
 (0)