diff --git a/UnityProject/Assets/Dependencies/JEngine/Core/Manager/LifeCycleMgr.cs b/UnityProject/Assets/Dependencies/JEngine/Core/Manager/LifeCycleMgr.cs index 8d6c0b47..4f8bb893 100644 --- a/UnityProject/Assets/Dependencies/JEngine/Core/Manager/LifeCycleMgr.cs +++ b/UnityProject/Assets/Dependencies/JEngine/Core/Manager/LifeCycleMgr.cs @@ -38,11 +38,13 @@ private class LifeCycleItem { public readonly ILTypeInstance ItemInstance; public readonly MethodInfo Method; + public readonly Func ExecuteCondition; - public LifeCycleItem(ILTypeInstance itemInstance, MethodInfo method) + public LifeCycleItem(ILTypeInstance itemInstance, MethodInfo method, Func cond) { ItemInstance = itemInstance; Method = method; + ExecuteCondition = cond; } } @@ -113,7 +115,7 @@ public LifeCycleItem(ILTypeInstance itemInstance, MethodInfo method) /// public void AddAwakeItem(ILTypeInstance instance, MethodInfo method) { - _awakeItems.Add(new LifeCycleItem(instance, method)); + _awakeItems.Add(new LifeCycleItem(instance, method, () => true)); _awakeObjs.Add(instance); } @@ -124,7 +126,7 @@ public void AddAwakeItem(ILTypeInstance instance, MethodInfo method) /// public void AddOnEnableItem(ILTypeInstance instance, MethodInfo method) { - _enableItems.Add(new LifeCycleItem(instance, method)); + _enableItems.Add(new LifeCycleItem(instance, method, () => true)); _enableObjs.Add(instance); } @@ -135,7 +137,7 @@ public void AddOnEnableItem(ILTypeInstance instance, MethodInfo method) /// public void AddStartItem(ILTypeInstance instance, MethodInfo method) { - _startItems.Add(new LifeCycleItem(instance, method)); + _startItems.Add(new LifeCycleItem(instance, method, () => true)); _startObjs.Add(instance); } @@ -144,9 +146,21 @@ public void AddStartItem(ILTypeInstance instance, MethodInfo method) /// /// /// + [Obsolete("Please provide a gameObject that holds this instance to be able to monitor whether or not it should update")] public void AddUpdateItem(ILTypeInstance instance, MethodInfo method) { - _updateItems.Add(new LifeCycleItem(instance, method)); + _updateItems.Add(new LifeCycleItem(instance, method, () => (instance.GetGameObject().gameObject.activeInHierarchy))); + } + + /// + /// Add update task + /// + /// + /// + /// + public void AddUpdateItem(ILTypeInstance instance, MethodInfo method, GameObject parent) + { + _updateItems.Add(new LifeCycleItem(instance, method, () => parent.activeInHierarchy)); } /// @@ -163,9 +177,21 @@ public void RemoveUpdateItem(ILTypeInstance instance) /// /// /// + [Obsolete("Please provide a gameObject that holds this instance to be able to monitor whether or not it should lateUpdate")] public void AddLateUpdateItem(ILTypeInstance instance, MethodInfo method) { - _lateUpdateItems.Add(new LifeCycleItem(instance, method)); + _lateUpdateItems.Add(new LifeCycleItem(instance, method, () => (instance.GetGameObject().gameObject.activeInHierarchy))); + } + + /// + /// Add lateUpdate task + /// + /// + /// + /// + public void AddLateUpdateItem(ILTypeInstance instance, MethodInfo method, GameObject parent) + { + _lateUpdateItems.Add(new LifeCycleItem(instance, method, () => parent.activeInHierarchy)); } /// @@ -182,9 +208,21 @@ public void RemoveLateUpdateItem(ILTypeInstance instance) /// /// /// + [Obsolete("Please provide a gameObject that holds this instance to be able to monitor whether or not it should fixedUpdate")] public void AddFixedUpdateItem(ILTypeInstance instance, MethodInfo method) { - _fixedUpdateItems.Add(new LifeCycleItem(instance, method)); + _fixedUpdateItems.Add(new LifeCycleItem(instance, method, () => (instance.GetGameObject().gameObject.activeInHierarchy))); + } + + /// + /// Add fixedUpdate task + /// + /// + /// + /// + public void AddFixedUpdateItem(ILTypeInstance instance, MethodInfo method, GameObject parent) + { + _fixedUpdateItems.Add(new LifeCycleItem(instance, method, () => parent.activeInHierarchy)); } /// @@ -225,7 +263,7 @@ private void ExecuteItems(List items, bool removeAfterInvoke = tr { var item = items[i]; //忽略 - if (ignoreCondition != null && ignoreCondition(item.ItemInstance)) + if (ignoreCondition != null && ignoreCondition(item.ItemInstance)|| !item.ExecuteCondition()) { continue; } diff --git a/UnityProject/Assets/Dependencies/JEngine/Templates/MonoAdapter.txt b/UnityProject/Assets/Dependencies/JEngine/Templates/MonoAdapter.txt index 4e9e621b..d31e132a 100644 --- a/UnityProject/Assets/Dependencies/JEngine/Templates/MonoAdapter.txt +++ b/UnityProject/Assets/Dependencies/JEngine/Templates/MonoAdapter.txt @@ -55,9 +55,9 @@ LifeCycleMgr.Instance.AddOnEnableItem(instance, GetMethodInfo(type, "OnEnable")); } LifeCycleMgr.Instance.AddStartItem(instance, GetMethodInfo(type, "Start")); - LifeCycleMgr.Instance.AddFixedUpdateItem(instance, GetMethodInfo(type, "FixedUpdate")); - LifeCycleMgr.Instance.AddUpdateItem(instance, GetMethodInfo(type, "Update")); - LifeCycleMgr.Instance.AddLateUpdateItem(instance, GetMethodInfo(type, "LateUpdate")); + LifeCycleMgr.Instance.AddFixedUpdateItem(instance, GetMethodInfo(type, "FixedUpdate"), gameObject); + LifeCycleMgr.Instance.AddUpdateItem(instance, GetMethodInfo(type, "Update"), gameObject); + LifeCycleMgr.Instance.AddLateUpdateItem(instance, GetMethodInfo(type, "LateUpdate"), gameObject); isAwaking = false; awaked = true; diff --git a/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll b/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll index 3447f369..664d5f5c 100644 Binary files a/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll and b/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll differ diff --git a/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb b/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb index 7391e2d9..44b61734 100644 Binary files a/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb and b/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb differ diff --git a/UnityProject/Assets/Scripts/Adapters/MonoBehaviourAdapter.cs b/UnityProject/Assets/Scripts/Adapters/MonoBehaviourAdapter.cs index 9bd9cfaa..a1344519 100644 --- a/UnityProject/Assets/Scripts/Adapters/MonoBehaviourAdapter.cs +++ b/UnityProject/Assets/Scripts/Adapters/MonoBehaviourAdapter.cs @@ -162,9 +162,9 @@ public async void Awake() LifeCycleMgr.Instance.AddOnEnableItem(instance, GetMethodInfo(type, "OnEnable")); } LifeCycleMgr.Instance.AddStartItem(instance, GetMethodInfo(type, "Start")); - LifeCycleMgr.Instance.AddFixedUpdateItem(instance, GetMethodInfo(type, "FixedUpdate")); - LifeCycleMgr.Instance.AddUpdateItem(instance, GetMethodInfo(type, "Update")); - LifeCycleMgr.Instance.AddLateUpdateItem(instance, GetMethodInfo(type, "LateUpdate")); + LifeCycleMgr.Instance.AddFixedUpdateItem(instance, GetMethodInfo(type, "FixedUpdate"), gameObject); + LifeCycleMgr.Instance.AddUpdateItem(instance, GetMethodInfo(type, "Update"), gameObject); + LifeCycleMgr.Instance.AddLateUpdateItem(instance, GetMethodInfo(type, "LateUpdate"), gameObject); isAwaking = false; awaked = true;