Skip to content

Commit bd80f00

Browse files
committed
Fix potential packagecache directory issues
1 parent d3c814f commit bd80f00

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

Editor/DataVisualizer/DataVisualizer.cs

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,55 +1037,73 @@ private static void TryLoadStyleSheet(VisualElement root)
10371037
);
10381038

10391039
const string packageCache = "PackageCache";
1040-
int packageCacheIndex = unityRelativeStyleSheetPath.IndexOf(
1041-
packageCache,
1042-
StringComparison.OrdinalIgnoreCase
1043-
);
1044-
if (0 <= packageCacheIndex)
1045-
{
1046-
unityRelativeStyleSheetPath = unityRelativeStyleSheetPath[
1047-
(packageCacheIndex + packageCache.Length)..
1048-
];
1049-
unityRelativeStyleSheetPath = "Packages" + unityRelativeStyleSheetPath;
1050-
}
1040+
int packageCacheIndex;
10511041
if (!string.IsNullOrWhiteSpace(unityRelativeStyleSheetPath))
10521042
{
10531043
styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(
10541044
unityRelativeStyleSheetPath
10551045
);
1056-
if (styleSheet == null)
1046+
}
1047+
1048+
if (styleSheet == null)
1049+
{
1050+
packageCacheIndex = unityRelativeStyleSheetPath.IndexOf(
1051+
packageCache,
1052+
StringComparison.OrdinalIgnoreCase
1053+
);
1054+
if (0 <= packageCacheIndex)
1055+
{
1056+
unityRelativeStyleSheetPath = unityRelativeStyleSheetPath[
1057+
(packageCacheIndex + packageCache.Length)..
1058+
];
1059+
unityRelativeStyleSheetPath = "Packages" + unityRelativeStyleSheetPath;
1060+
}
1061+
1062+
if (!string.IsNullOrWhiteSpace(unityRelativeStyleSheetPath))
1063+
{
1064+
styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(
1065+
unityRelativeStyleSheetPath
1066+
);
1067+
if (styleSheet == null)
1068+
{
1069+
Debug.LogError(
1070+
$"Failed to load Data Visualizer style sheet (package root: '{packageRoot}'), relative path '{unityRelativeStyleSheetPath}'."
1071+
);
1072+
}
1073+
}
1074+
else
10571075
{
10581076
Debug.LogError(
1059-
$"Failed to load Data Visualizer style sheet (package root: '{packageRoot}'), relative path '{unityRelativeStyleSheetPath}'."
1077+
$"Failed to convert absolute path '{styleSheetPath}' to Unity relative path."
10601078
);
10611079
}
10621080
}
1063-
else
1064-
{
1065-
Debug.LogError(
1066-
$"Failed to convert absolute path '{styleSheetPath}' to Unity relative path."
1067-
);
1068-
}
10691081

10701082
string fontPath =
10711083
$"{packageRoot}{pathSeparator}Editor{pathSeparator}Fonts{pathSeparator}IBMPlexMono-Regular.ttf";
10721084
string unityRelativeFontPath = DirectoryHelper.AbsoluteToUnityRelativePath(
10731085
fontPath
10741086
);
1075-
packageCacheIndex = unityRelativeFontPath.IndexOf(
1076-
packageCache,
1077-
StringComparison.OrdinalIgnoreCase
1078-
);
1079-
if (0 <= packageCacheIndex)
1080-
{
1081-
unityRelativeFontPath = unityRelativeFontPath[
1082-
(packageCacheIndex + packageCache.Length)..
1083-
];
1084-
unityRelativeFontPath = "Packages" + unityRelativeFontPath;
1085-
}
1086-
if (!string.IsNullOrWhiteSpace(unityRelativeFontPath))
1087+
1088+
font = AssetDatabase.LoadAssetAtPath<Font>(unityRelativeFontPath);
1089+
if (font == null)
10871090
{
1088-
font = AssetDatabase.LoadAssetAtPath<Font>(unityRelativeFontPath);
1091+
packageCacheIndex = unityRelativeFontPath.IndexOf(
1092+
packageCache,
1093+
StringComparison.OrdinalIgnoreCase
1094+
);
1095+
if (0 <= packageCacheIndex)
1096+
{
1097+
unityRelativeFontPath = unityRelativeFontPath[
1098+
(packageCacheIndex + packageCache.Length)..
1099+
];
1100+
unityRelativeFontPath = "Packages" + unityRelativeFontPath;
1101+
}
1102+
1103+
if (!string.IsNullOrWhiteSpace(unityRelativeFontPath))
1104+
{
1105+
font = AssetDatabase.LoadAssetAtPath<Font>(unityRelativeFontPath);
1106+
}
10891107
}
10901108
}
10911109
else

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.wallstop-studios.data-visualizer",
3-
"version": "0.0.35-rc03.2",
3+
"version": "0.0.35-rc03.3",
44
"displayName": "Data Visualizer",
55
"description": "Data Management UI for Unity's Scriptable Objects",
66
"dependencies": {},
@@ -40,3 +40,4 @@
4040

4141

4242

43+

0 commit comments

Comments
 (0)