//Only called in matser node 通知一个新的view出现
        public static void NotifyOneNewViewAppear(int assetId, FduClusterView view)
        {
            ClusterGameObjectCreatePara para = new ClusterGameObjectCreatePara(view.ViewId, assetId, view.transform.position, view.transform.rotation);

            if (view.transform.parent != null)
            {
                para.parentPath = FduSupportClass.getGameObjectPath(view.transform.parent.gameObject);
            }
            para.viewInstance = view;
            var subViews = view.getSubViews();

            if (subViews != null)
            {
                for (int i = 0; i < subViews.Count; ++i)
                {
                    if (subViews[i] != null)
                    {
                        if (!subViews[i].gameObject.activeSelf)
                        {
                            subViews[i].ObjectID = FduSyncBaseIDManager.ApplyNextAvaliableId();
                            FduClusterViewManager.RegistToViewManager(subViews[i]);
                        }
                    }
                    else
                    {
                        Debug.LogError("Find Invalid sub view in one FduClusterView.View id :" + view.ViewId + " Object name:" + view.name + ". Please press the Refresh Button in Inspector");
                    }
                }
            }
            if (_waitForCreateList.Count == 0)
            {
                levelPrefix = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
            }
            _waitForCreateList.Add(para);
        }
Exemple #2
0
        //Executed on both Master node and slave node Independently
        //Called In Start of FduClusterViewManager and LevelLoadManager
        internal static void AllocateSceneObjectViewId()
        {
            Debug.Log("start allocate scene view id");
            Scene s = SceneManager.GetActiveScene();

            if (s.isLoaded)
            {
                Debug.Log("scene name " + s.name);
                var allGameObjects = s.GetRootGameObjects();
                for (int j = 0; j < allGameObjects.Length; j++)
                {
                    var go = allGameObjects[j];
                    foreach (FduClusterView view in (go.GetComponentsInChildren <FduClusterView>(true)))
                    {
                        view.ObjectID = FduSyncBaseIDManager.ApplyNextAvaliableId();
                        FduClusterViewManager.RegistToViewManager(view);
                    }
                    ;
                }
                _allocateFlag = false;
            }
            else
            {
                Debug.LogWarning("This scene is not loaded yet");
            }
        }
Exemple #3
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();
 }