//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); }
/// <summary> /// Rpc Function. You can call any function marked with FduRPC attribute,which is DEFINED in the classes derived from FduObserverBase or other monobehaviors belong to the gameobject. /// Notice that you can only use it on MasterNode. /// </summary> /// <param name="view">the view instance which will execute the rpc</param> /// <param name="methodName">name of the rpc mehthod</param> /// <param name="target">rpc target</param> /// <param name="paras">rpc parameters</param> public object RPC(FduClusterView view, string methodName, RpcTarget target, params object[] paras) { if (!inited) { Debug.LogWarning("[FduRpc]Rpc Manager is not set up yet. Ignore this operation"); return(null); } if (view == null || methodName == null) { Debug.LogError("[FduRpc]Cluster view or method name can not be null!"); return(null); } ; if (ClusterHelper.Instance.Client != null) { return(null); } FduRPCEvent e = new FduRPCEvent(); e.setUpViewId(view.ViewId, methodName); e.setUpParameters(paras); _rpcEventList.Add(e); if (target == RpcTarget.All) { return(executeRpc(e.getRpcData())); } else { return(null); } }
public static void NotifyOneNewViewAppear(FduClusterView view) { SyncViewIdData data = new SyncViewIdData(); data.id = view.ViewId; data.name = view.gameObject.name; _waitForAssignViewIdList.Add(data); }
//创建函数 para包含了所有创建该物体所必须的参数 包括位置信息、父节点信息、子节点信息等等 public static GameObject createGameObjectWithClusterView(FduClusterViewManager.ClusterGameObjectCreatePara para) { GameObject go = FduClusterAssetManager.Instance.getGameObjectFromId(para.assetId); if (go == null) { return(null); } GameObject parent = FduSupportClass.getGameObjectByPath(para.parentPath); GameObject instance; if (parent == null) { instance = GameObject.Instantiate(go, para.position, para.rotation); } else { instance = GameObject.Instantiate(go, para.position, para.rotation, parent.transform); } FduClusterView view = instance.GetComponent <FduClusterView>(); if (view != null) { view.ObjectID = para.viewId; FduSyncBaseIDManager.ReceiveIdFromMaster(para.viewId); } var subViewList = instance.GetClusterView().getSubViews(); int index = 0; foreach (FduClusterView subView in subViewList) { if (subView != null) { subView.ObjectID = para.subViewId[index++]; FduSyncBaseIDManager.ReceiveIdFromMaster(subView.ViewId); } 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 (index != subViewList.Count) { Debug.LogError("[FduClusterGameObjectCreator]Sub View Count Not matched!"); } return(instance); }
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)); } }
public static object Rpc(this UnityEngine.MonoBehaviour mono, string methodName, RpcTarget target, params object[] paras) { FduClusterView _viewInstance = mono.GetClusterView(); if (_viewInstance == null) { Debug.LogError("[FduRPC]There is no cluster view component attach to this game object. Game obejct name:" + mono.gameObject.name); return(null); } else { return(_viewInstance.Rpc(methodName, target, paras)); } }
//注册到cluster view中 protected void registToClusterView() { if (_viewInstance == null) { _viewInstance = findViewInstance(); } if (_viewInstance != null) { _viewInstance.registToView(this); } else { Debug.LogWarning("[FduObserver]Can not find any cluster view which can be registed to"); } }
/// <summary> /// Find an Appropriate view instance which can control this observer. /// </summary> /// <returns></returns> public FduClusterView findViewInstance() { FduClusterView view = null; Transform ts = transform; while (ts != null) { view = ts.gameObject.GetClusterView(); if (view == null) { ts = ts.parent; } else { break; } } return(view); }
//注册至此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); }
public void LateUpdateFunc() { if (_client != null) { return; } //每帧遍历检测激活状态 Dictionary <int, FduClusterView> .Enumerator enumerator = FduClusterViewManager.getClusterViews(); while (enumerator.MoveNext()) { FduClusterView view = enumerator.Current.Value; if (view != null && view.gameObject != null) { if (view.getObserveActiveState()) //该view必须设置是否监控激活状态 { if (view.gameObject.activeSelf != viewActiveStates[enumerator.Current.Key] || flushedCount > 0) //如果激活状态更改 或者flushedCount大于0 则发送数据 { var para = new ActiveSynPara(); para.viewId = enumerator.Current.Key; para.obFrameCount = view.getAllFrameCountForEveryNFrameDTS(); if (enumerator.Current.Value.gameObject.activeSelf) { _WaitForActiveList.Add(para); } else { _WaitForInActiveList.Add(para); } viewActiveStates[enumerator.Current.Key] = view.gameObject.activeSelf; } } } } flushedCount = flushedCount > 0 ? flushedCount - 1 : flushedCount; _server.SendState(ObjectID, this); //_server.SendState(ObjectID, this,false); }
//根据rpc数据执行对应的rpc方法 public object executeRpc(Dictionary <byte, object> rpcdata) { object returnValue = null; int viewId = (int)rpcdata[(byte)0]; string methodName = (string)rpcdata[(byte)1]; int paraCount = (int)rpcdata[(byte)2]; object[] parameters = (object[])rpcdata[(byte)3]; FduClusterView view = FduClusterViewManager.getClusterView(viewId); if (view == null) { Debug.LogWarning("[FduRpc]FduSyncView not exist .View id is " + viewId + " method Name is " + methodName); return(returnValue); } bool isSent = false; List <FduObserverBase> .Enumerator observerEnum = view.getObservers(); var monos = view.GetComponents <MonoBehaviour>(); HashSet <MonoBehaviour> monoset = new HashSet <MonoBehaviour>(monos); while (observerEnum.MoveNext()) { monoset.Add(observerEnum.Current); } foreach (MonoBehaviour mono in monoset) { List <MethodInfo> methodInfo = GetMethods(mono.GetType(), typeof(FduRPC)); if (methodInfo == null) { return(returnValue); } Type[] argTypes = new Type[paraCount]; for (int i = 0; i < paraCount; i++) { argTypes[i] = parameters[i].GetType(); } for (int i = 0; i < methodInfo.Count; ++i) { MethodInfo mi = methodInfo[i]; if (mi.Name.Equals(methodName)) { ParameterInfo[] paraInfo = mi.GetParameters(); if (paraInfo.Length == parameters.Length) { if (this.CheckTypeMatch(paraInfo, argTypes)) { if (!isSent) { returnValue = mi.Invoke((object)mono, parameters); isSent = true; } else { Debug.LogWarning("[FduRpc]More than one function can match the method name and parameters. Please check."); } } } } } } if (!isSent) { Debug.LogWarning("[FduRpc]Parameters not matched for FduRpc Call. Method Name:" + methodName); } return(returnValue); }
internal void setViewInstance(FduClusterView view) { _viewInstance = view; }