Ну, у меня возникают некоторые ошибки в Unity 2019.2.14f. По какой-то причине у меня появляется следующая ошибка:
Copied style is null. Using StyleNotFound instead.
Проблема связана с этой строкой: https://github.com/uta-org/uzLib.Lite/blob/82eb85bc34c804cfd392b447e97e1e92079ca10f/uzLib.Lite/Unity/Global/IMGUI/GlobalGUILayout.cs#L233
public string InputIO(string label, string path, FileBrowserType browserType = FileBrowserType.File, bool isEnabled = true, bool fEditor = false, int verticalSpacing = 7)
{
if (verticalSpacing > 0)
GUILayout.Space(verticalSpacing);
bool hasLabel = !string.IsNullOrEmpty(label);
var boxStyle = MyGuiSkin?.box;
if (hasLabel)
{
if (boxStyle != null)
GUILayout.BeginVertical(boxStyle);
else
GUILayout.BeginVertical();
//GUILayout.Label(label);
GUILayout.Label(label, GlobalStyles.BoldCenteredLabelStyle); <===== here is the problem
GUILayout.BeginHorizontal();
}
else
{
if (boxStyle != null)
GUILayout.BeginHorizontal(boxStyle);
else
GUILayout.BeginHorizontal();
}
// TODO: Fix the alignment of the two labels
GUILayout.Label(string.IsNullOrEmpty(path) ? $"Select a {browserType.ToString().ToLowerInvariant()}..." : path, GlobalStyles.CenteredLabelStyle);
//GUILayout.Label(path ?? "Select a file...", GlobalStyles.CenteredLabelStyle); // GlobalStyles.CenteredLabelStyle --> GUI.skin.label returns null and an error
GUI.enabled = isEnabled;
if (GUILayout.Button("Browse...", GUILayout.MaxWidth(100)))
{
if (fEditor)
{
#if UNITY_EDITOR
var p = EditorUtility.OpenFilePanelWithFilters("Select a file", path,
new[] { "Image files", "png,jpg,jpeg,bmp,gif,tif" });
path = string.IsNullOrEmpty(p) ? null : p;
#endif
}
else
{
if (MyFileBrowser == null)
MyFileBrowser = FileBrowser.Create(browserType);
path = MyFileBrowser.Open();
}
}
GUI.enabled = true;
GUILayout.EndHorizontal();
if (hasLabel)
GUILayout.EndVertical();
if (!fEditor && MyFileBrowser != null && MyFileBrowser.IsReady())
{
path = MyFileBrowser.CurrentPath;
//Debug.Log($"Setting path to '{path}'...");
}
return path;
//return string.Empty;
}
По какой-то причине стиль GlobalStyles.BoldCenteredLabelStyle
и любой стиль, который я создал на GlobalStyles
, создают проблемы:
private static GUIStyle s_boldCenteredLabelStyle;
public static GUIStyle BoldCenteredLabelStyle =>
s_boldCenteredLabelStyle ?? (s_boldCenteredLabelStyle = new GUIStyle(DefaultLabelStyle)
{ fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter });
Источник: https://github.com/uta-org/uzLib.Lite/blob/master/uzLib.Lite.ExternalCode/Unity/Global/IMGUI/GlobalStyles.cs#L506 -L510
Я просмотрел код UnityEngine и обнаружил следующее:
public GUIStyle(GUIStyle other)
{
if (other == null)
{
Debug.LogError("Copied style is null. Using StyleNotFound instead.");
other = GUISkin.error;
}
m_Ptr = Internal_Copy(this, other);
}
Источник: https://github.com/Unity-Technologies/UnityCsReference/blob/master/Modules/IMGUI/GUIStyle.cs#L81 -L89
Это происходит, когда нулевой стиль передается через конструктор GUIStyle, но, как вы можете видеть, я ничего не делаю (до использования DefaultLabelStyle
я использовал GUI.skin.label
, но удалил его и создал мой собственный стиль). Кроме того, я попытался передать пустой конструктор, но он также дает мне ошибки.
Так что я заблудился, я не знаю, что попробовать, любая помощь приветствуется!
PD: Я думаю, что это может быть ошибкой ... Но я не уверен.