private void DisableBehaviour(BaseBehaviour behaviour) { if (!behaviour.IsEnable() && behaviour.IsLastEnable()) { try { MDebug.LogVerbose("Core" , $"Before execute {behaviour.GetName()}.OnDisable"); behaviour.OnDisable(); MDebug.LogVerbose("Core" , $"After execute {behaviour.GetName()}.OnDisable"); } catch (Exception e) { MDebug.LogError("Core" , $"Execute {behaviour.GetName()}.OnDisable Exception:{e.ToString()}"); } finally { behaviour.SetLastEnable(false); } } }
private void BeginFrame() { if (Time.frameCount <= m_LastBeginFrame) { return; } m_LastBeginFrame = Time.frameCount; MDebug.LogVerbose("Core", "BeginFrame " + m_LastBeginFrame); WaitTaskUpdate(); CollectionBehavioursForTraverse(); #region Handle Initialize for (int iBehaviour = 0; iBehaviour < m_AddBehavioursCache.Count; iBehaviour++) { BaseBehaviour behaviour = m_AddBehavioursCache[iBehaviour]; try { MDebug.LogVerbose("Core" , $"Before execute {behaviour.GetName()}.OnInitialize"); behaviour.OnInitialize(); MDebug.LogVerbose("Core" , $"After execute {behaviour.GetName()}.OnInitialize"); } catch (Exception e) { MDebug.LogError("Core" , $"Execute {behaviour.GetName()}.OnInitialize Exception:{e.ToString()}"); } behaviour.SetAlive(true); } m_AddBehavioursCache.Clear(); #endregion #region Handle Enable for (int iBehaviour = 0; iBehaviour < m_BehavioursForTraverse.Count; iBehaviour++) { BaseBehaviour behaviour = m_BehavioursForTraverse[iBehaviour]; if (behaviour.IsEnable() && !behaviour.IsLastEnable()) { try { MDebug.LogVerbose("Core" , $"Before execute {behaviour.GetName()}.OnEnable"); behaviour.OnEnable(); MDebug.LogVerbose("Core" , $"After execute {behaviour.GetName()}.OnEnable"); } catch (Exception e) { MDebug.LogError("Core" , $"Execute {behaviour.GetName()}.OnEnable Exception:{e.ToString()}"); } finally { behaviour.SetLastEnable(true); } } } #endregion }