Unity Addressables热更不检测C#脚本变化解决方案
https://forum.unity.com/threads/content-update-preview-bug.1299783/有人发现Addressables热更有个bug:
在C#脚本加个空格执行Check For Content Update Restrictions后,就被Addressables检测到发生改变导致:挂上这个脚本的Prefab就当做变化的资源显示到Content Update Preview window了。
I am using Unity 2019.4.22f1 and Addressables 1.16.19. But I guess this bug happens on every Addressables version and every Unity version. I have a Prefab in a group, the prefab has a MonoBehaviour script attached to it. I execute the New Build option. Then I modify the script without changing the serialized properties and fields, for example, I just add a space somewhere in the script, then run Check For Content Update Restrictions. We will see that the group shows up on the Content Update Preview window. However, the prefab wasn't modified, why is it being regarded as the bundle that will be changed after running Update A Previous Build?
其实解决这个方法很简单,以Addressables1.19.19为例。只需要在 Packages/Addressables/Editor/Build/ContentUpdateScript.cs文件,加几行代码,不检测C#变化即可解决问题。
public struct AssetState : IEquatable<AssetState> { /// <summary> /// Check if one asset state is equal to another. /// </summary> /// <param name="other">Right hand side of comparision.</param> /// <returns>Returns true if the Asset States are equal to one another.</returns> public bool Equals(AssetState other) { //剔除C#变化检测 Start if(guid == other.guid && hash == other.hash){ return true;}else{ var assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(guid.ToString()); if (assetPath == null) { UnityEngine.Debug.LogError("Can not find Path:" + guid); return false; }else if (assetPath.EndsWith(".cs")){ UnityEngine.Debug.LogWarning("C# default is consider equal:" + assetPath); return true; }return false;}//剔除C#变化检测 End //return guid == other.guid && hash == other.hash; } }
页:
[1]