Unity AddressablesC#脚本修改导致关联预设Prefab也被识别到变化 解决方案

https://forum.unity.com/threads/content-update-preview-bug.1299783/
有人发现Addressables热更有个bug:

  1. 在C#脚本加个空格
  2. 执行Check For Content Update Restrictions后,就被Addressables检测到发生改变
  3. 导致:挂上这个脚本的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#变化即可解决问题。

    [Serializable]
    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;
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容