예제 #1
0
 /// <summary>
 /// Get Obsever ID by instance.
 /// </summary>
 /// <param name="ob">Observer Instance</param>
 /// <returns>Observer ID</returns>
 public int getObserverId(FduObserverBase ob)
 {
     if (ob == null)
     {
         return(-1);
     }
     return(observerList.FindIndex((FduObserverBase _ob) => { return _ob.Equals(ob); }));
 }
예제 #2
0
        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);
        }
예제 #3
0
 /// <summary>
 /// Add an oberver instance to this view.
 /// Please make sure that it is called both on master node and slave node.
 /// </summary>
 /// <param name="ob"></param>
 /// <returns></returns>
 public bool addObserver(FduObserverBase ob)
 {
     if (ob != null)
     {
         observerList.Add(ob);
         ob.setViewInstance(this);
         return(true);
     }
     return(false);
 }
예제 #4
0
        public static object Rpc(this FduObserverBase ob, string methodName, RpcTarget target, params object[] paras)
        {
            FduClusterView _viewInstance = ob.GetClusterView();

            if (_viewInstance == null)
            {
                Debug.LogError("[FduRPC]This observer is not registed to a cluster view yet. Game object name:" + ob.gameObject.name);
                return(null);
            }
            else
            {
                return(_viewInstance.Rpc(methodName, target, paras));
            }
        }
예제 #5
0
        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;
                }
            }
        }
예제 #6
0
        public void registToView(FduObserverBase observer)
        {
#if UNITY_EDITOR
            if (observer != null && !observerList.Find((FduObserverBase ob) => { if (ob == null)
                                                                                 {
                                                                                     return(false);
                                                                                 }
                                                                                 else
                                                                                 {
                                                                                     return(ob.Equals(observer));
                                                                                 } }))
            {
                observerList.Add(observer);
            }
#endif
        }
 /// <summary>
 /// Set the FduObserver instance. Not recommended.
 /// </summary>
 /// <param name="_ob"></param>
 public virtual void setObserver(FduObserverBase _ob)
 {
     targetObject = _ob;
 }
예제 #8
0
 //内部使用 移除所有obsevrer
 public void removeObserver(FduObserverBase ob)
 {
     observerList.Remove(ob);
 }