/// <summary> /// 请求物体假如场景 /// </summary> private void RequestObjectJoin() { NetObjectJoinUpData data = new NetObjectJoinUpData(); data.InstanceId = instanceId; data.TypeName = GetType().Name; if (NetSceneManager.Instance.currentServer != null) { NetSceneManager.Instance .Request(HandlerConst.RequestId.NetObjectJoinUpHandler, data, (res) => { BoolData isSucc = res.GetValue <BoolData>(); if (isSucc.Value == true) { isConnectNetScene = true; EventDispatcher.TriggerEvent <NetBehavior>(NetSceneEvent.NetBehaviorAddToScene, this); } else { Debug.logger.LogError("NetPost", "NetBehavior加入到场景失败" + NetSceneManager.Instance.currentSceneId); } }); } }
/// <summary> /// 请求物体假如场景 /// </summary> private void RequestObjectJoin() { if (NetSceneManager.Instance.sceneConnected == false) { EventDispatcher.AddEventListener(NetSceneEvent.NetSceneReady, RequestObjectJoin); } else { NetObjectJoinUpData data = new NetObjectJoinUpData(); data.InstanceId = instanceId; data.TypeName = GetType().Name; int chnId = NetSceneManager.Instance.currentSceneId; if (NetSceneManager.Instance.currentServer != null) { NetSceneManager.Instance.currentServer .Request(HandlerConst.RequestId.NetObjectJoinUpHandler, chnId, data, SendType.TCP, (res) => { EventDispatcher.RemoveEventListener(NetSceneEvent.NetSceneReady, RequestObjectJoin); BoolData isSucc = res.GetValue <BoolData>(); if (isSucc.Value == true) { Debug.logger.Log("成功将NetBehavior加入到场景" + chnId); EventDispatcher.TriggerEvent <NetBehavior>(NetSceneEvent.NetBehaviorAddToScene, this); } else { Debug.logger.LogError("NetPost", "NetBehavior加入到场景失败" + chnId); } }); } else { Debug.logger.LogError("NetPost", "服务器被提前销毁" + chnId); } } }