//对于非监控的创建游戏物体 从节点不可以自己分配id 需要等待主节点发送过来的id信息
 void ProcessAssignViewIdRequest()
 {
     if (FduSupportClass.isMaster)
     {
         return;
     }
     for (int i = 0; i < _waitForAssignViewIdList.Count; ++i)
     {
         Debug.Log("Before assign:" + _unallocateViews.Count);
         for (int j = 0; j < _unallocateViews.Count; ++j)
         {
             if (_unallocateViews[j].gameObject.name == _waitForAssignViewIdList[i].name)
             {
                 _unallocateViews[j].UnRegistToObjectSyncSlave();
                 _unallocateViews[j].ObjectID = _waitForAssignViewIdList[i].id;
                 if (_waitForAssignViewIdList[i].id != FduSyncBaseIDManager.getInvalidSyncId())
                 {
                     _unallocateViews[j].RegistToObjectSyncSlave();
                     RegistToViewManager(_unallocateViews[j]);
                     _unallocateViews.RemoveAt(j);
                 }
                 else
                 {
                     Debug.LogError("Get Invalid Id from Master Node! Object Name:" + _waitForAssignViewIdList[i].name);
                 }
                 break;
             }
         }
         Debug.Log("After assign:" + _unallocateViews.Count);
     }
 }
Esempio n. 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);
        }
Esempio n. 3
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;
                }
            }
        }
Esempio n. 4
0
        //设置该RPC执行的view的ID
        public void setUpViewId(int viewId, string methodName)
        {
            if (viewId < 0 || viewId == FduSyncBaseIDManager.getInvalidSyncId())
            {
                Debug.LogError("[FDURPC]Invalid view id");
            }
            if (methodName == "" || methodName == null)
            {
                Debug.LogError("[RPCRPC]Method Name can not be null");
            }

            _rpcData.Add((byte)0, viewId);
            _rpcData.Add((byte)1, methodName);

            inited = true;
        }
 //注册至此manager 每一个view都需要注册
 static public void RegistToViewManager(FduClusterView _view)
 {
     if (_view == null)
     {
         return;
     }
     if (_view.ViewId == FduSyncBaseIDManager.getInvalidSyncId())
     {
         if (!FduSupportClass.isMaster)
         {
             _unallocateViews.Add(_view);
         }
         else
         {
             Debug.LogError("[FduClusterViewManager]The Cluster View can not regist to view manager, please allocate a validate view id first");
         }
         return;
     }
     _FduClusterViews.Add_overlay(_view.ViewId, _view);
 }
Esempio n. 6
0
 //SyncBase Strat函数执行前执行的函数 在这里需要监测该场景中的静态物体是否分配了ID 如果不是静态分配的Id 则判定为运行时创建的 则动态申请ID
 //而对于从节点 如果不是静态物体 则ID必须从主节点获取 赋值过程在此函数执行前 所以如果此时从节点上该view还没有分配ID 就说明前面的机制发生了错误
 protected override void BeforeInit()
 {
     if (FduSyncBaseIDManager.needsAllocateSceneViewId() && FduClusterLevelLoader.Instance.isSceneLoaded())
     {
         Debug.Log("first happen " + name);
         FduClusterViewManager.ClearUnusedViews();
         FduSyncBaseIDManager.AllocateSceneObjectViewId();
     }
     if (ClusterHelper.Instance.Server != null)
     {
         if (ObjectID == FduSyncBaseIDManager.getInvalidSyncId())
         {
             ObjectID = FduSyncBaseIDManager.ApplyNextAvaliableId();
         }
         if (IsObservingCreation) //如果监控这个view的创建
         {
             if (FduClusterAssetManager.Instance.validateId(AssetId))
             {
                 FduClusterViewManager.NotifyOneNewViewAppear(AssetId, this);
             }
             else
             {
                 Debug.LogError("This Prefab is not added to FduClusterAssetManager! Name:" + gameObject.name);
             }
         }
         else
         {
             FduClusterViewManager.NotifyOneNewViewAppear(this);
         }
         //FduClusterViewManager.RegistToViewManager(this);
     }
     else
     {
         FduClusterViewManager.RegistToViewManager(this); //如果此时从节点没有被分配id 会被放到一个等待列表中 当收到主节点的id信息后进行赋值
     }
     //检测是否有空的observer存在
     checkObserverExist();
 }
Esempio n. 7
0
 public FduClusterView()
     : base()
 {
     ObjectID = FduSyncBaseIDManager.getInvalidSyncId();
 }