如何解决Unity精灵在运行时被损坏
在我们的项目中,我们有一些预制件是从流媒体资产捆绑中加载的。它最近开始在编辑器(而不是内部版本)中加载损坏的精灵。
如果将预制件拖到场景中,它将起作用并且看起来不错。
我尝试删除和重建我的流媒体资源以及库,但是它仍然损坏了。我还在项目设置中重置了图形着色器
您还有其他建议可能会导致这种情况吗?
请注意,除了背景之外,还有更多的元素变形。当图像放大时,会出现子文本对象,它们也会变形。
此问题也开始在每个人的计算机上发生,因此它不是本地问题(例如,不是库或资产捆绑包的修复错误)。
这是我的资产捆绑管理器,它为我的ScriptableObjects和Prefabs对象类型创建资产捆绑
{
private static AssetBundle _scriptableObjectsBundle;
private static AssetBundle _prefabsBundle;
public static T LoadScriptableObject<T>(string assetName) where T : ScriptableObject
{
if (_scriptableObjectsBundle == null)
{
AssetBundle.UnloadAllAssetBundles(true); // Required for editor editing which loads this (or you get a duplicate asset bundle load error)
_scriptableObjectsBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/scriptableobjects");
if (_scriptableObjectsBundle == null)
{
Debug.Log("Failed to load 'scriptableobjects' AssetBundle!");
return null;
}
}
if (!_scriptableObjectsBundle.Contains(assetName))
{
Debug.LogError("scriptableobjects asset bundle does not contain: " + assetName);
}
return _scriptableObjectsBundle.LoadAsset<T>(assetName);
}
/// <summary>
/// Loads the base prefab. Don't use this to edit objects,other objects must use this objects clone via the Prefabs class.
/// </summary>
/// <param name="assetName"></param>
/// <returns></returns>
public static GameObject LoadBasePrefab(string assetName)
{
if (_prefabsBundle == null)
{
_prefabsBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/prefabs");
if (_prefabsBundle == null)
{
Debug.Log("Failed to load 'prefabs' AssetBundle!");
return null;
}
}
if (!_prefabsBundle.Contains(assetName))
{
Debug.LogError("prefabs asset bundle does not contain: " + assetName);
}
GameObject baseGameObject = _prefabsBundle.LoadAsset<GameObject>(assetName);
return baseGameObject;
}
}
然后,我有一个Prefabs类,该类专门处理实例化的预制件副本(因为我的可脚本编写的对象只是我从地图读取的数据)。这是相关的加载代码:
public static GameObject LoadPrefab(T_Prefabs type)
{
if (_MAP == null)
{
init();
}
if (!_MAP.ContainsKey(type) || _MAP[type] == null)
{
Debug.LogError("Missing prefab type: " + type + " did you add the 'prefabs' asset tag!?");
}
GameObject obj = Object.Instantiate(MAP[type]);
if (obj.GetComponent<S_SerializedMonoBehaviour>())
{
obj.GetComponent<S_SerializedMonoBehaviour>().ResetState();
}
return obj;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。