public override NetworkState.NETWORK_STATE_TYPE Deserialize() { if (this == null) //由于跨场景时 在新的view 没有在start中完成注册之前 旧的view会接收数据 { return(NetworkState.NETWORK_STATE_TYPE.SUCCESS); } if (ViewId == FduSyncBaseIDManager.getInvalidSyncId()) { return(NetworkState.NETWORK_STATE_TYPE.SUCCESS); } UnityEngine.Profiling.Profiler.BeginSample("OnReceiveData"); NetworkState.NETWORK_STATE_TYPE networkState = NetworkState.NETWORK_STATE_TYPE.SUCCESS; FduObserverBase observer = null; for (index = 0; index < observerList.Count; ++index) { try { observer = observerList[index]; #if !UNSAFE_MODE if (observer != null) { bool receiveOrNot = BufferedNetworkUtilsClient.ReadBool(ref networkState); if (receiveOrNot) { observer.OnReceiveData(ref networkState); FduClusterViewManager.updateSentDataObserverCount(); } } #else if (observer.getDataTransmitStrategy().receiveOrNot()) { observer.OnReceiveData(ref networkState); #if DEBUG FduClusterViewManager.updateSentDataObserverCount(); #endif } #endif } catch (System.NullReferenceException) { } catch (System.Exception e) { string erroMessage = string.Format("An error occured when observer {0} call OnReceiveDataMethod. Game Object Name:{1},View Id:{2}, Error Message:{3}, Stack Trace:{4}", observer.GetType().Name, observer.name, ViewId, e.Message, e.StackTrace); Debug.LogError(erroMessage); throw; } if (networkState == NetworkState.NETWORK_STATE_TYPE.FORMAT_ERROR) { Debug.LogError("Data length not match in this observer! Observer name" + observer.GetType().FullName + " View id " + ViewId + " Game Object name " + observer.gameObject.name); } } UnityEngine.Profiling.Profiler.EndSample(); return(networkState); }
public override void Serialize() { if (ViewId == FduSyncBaseIDManager.getInvalidSyncId()) { return; } FduObserverBase observer = null; for (index = 0; index < observerList.Count; ++index) { try { observer = observerList[index]; #if !UNSAFE_MODE if (observer != null) { bool send = false; if (observer.getDataTransmitStrategy() != null) { send = observer.getDataTransmitStrategy().sendOrNot(); } BufferedNetworkUtilsServer.SendBool(send); if (send) { FduClusterViewManager.updateSentDataObserverCount(); observer.OnSendData(); } } #else if (observer.getDataTransmitStrategy().sendOrNot()) { #if DEBUG FduClusterViewManager.updateSentDataObserverCount(); #endif observer.OnSendData(); } #endif } catch (System.NullReferenceException) { } catch (System.Exception e) { string erroMessage = string.Format("An error occured when observer {0} call OnSendData method. Game Object Name:{1},View Id:{2}, Error Message:{3}, Stack Trace:{4}", observer.GetType().Name, observer.name, ViewId, e.Message, e.StackTrace); Debug.LogError(erroMessage); throw; } } }