UNITY_EDITOR 模式使用Assembly.Load加载的Assembly,无法通过go.GetComponent<T>()获取热更资源上的脚本
guolijun110 opened this issue · 1 comments
Describe the bug | 描述问题
UNITY_EDITOR 模式使用Assembly.Load加载的Assembly,无法通过go.GetComponent()获取热更资源上的脚本
** Enviroment | 环境 **
- Unity Version: 2021.3.9
- com.code-philosophy.hybridclr Version: 5.0.0
- Platform: Win 64 Standalone and UNITY_EDITOR
**To Reproduce | 复制步骤 **
1.HotUpdate 下新增脚本SingletonMono.cs
public abstract class SingletonMono : MonoBehaviour where T : SingletonMono
{
private static T _instance;
public static T Instance
{
get
{
if (_instance != null)
{
return _instance;
}
Debug.Log("CB");
//var prefab = AssetBundleLoaderMgr.instance.LoadResAsset<T>("Cube");
//_instance = Instantiate(prefab);
AssetBundle ab = AssetBundle.LoadFromMemory(LoadDll.ReadBytesFromStreamingAssets("prefabs"));
GameObject cube = ab.LoadAsset<GameObject>("Cube");
var data = GameObject.Instantiate(cube);
data.name = $"{typeof(T).Name}";
_instance = data.GetComponent<T>();
return _instance;
}
}
protected void Awake()
{
_instance = this as T;
}
protected void OnDestroy()
{
_instance = null;
}
}
2.修改
public class InstantiateByAsset : SingletonMono
{
public string text;
public void Log()
{
Debug.Log($"[InstantiateByAsset] Instance:{text}, Success New");
}
}
3.StartGame 在 UNITY_EDITOR模式下也使用 _hotUpdateAss = Assembly.Load(ReadBytesFromStreamingAssets("HotUpdate.dll.bytes"));
4.Entry 的 Start调用 InstantiateByAsset.Instance.Log();,会直接报错Instance为空
原因是
无法获取到T
..
测试在window下发布打包是正常的,Editer模式下获取不到热更资源上的脚本
这个跟Hybridclr无关。你不应该在Eidtor下重复加载assembly。后续还有疑问直接新手群里问吧