/// <summary> /// 更新参赛选手的运动路程信息. /// </summary> public void UpdataDisMoveValue(float disVal) { if (Network.peerType == NetworkPeerType.Client || Network.peerType == NetworkPeerType.Server) { if (Network.peerType == NetworkPeerType.Server && NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie <= 0) { //没有玩家选择链接服务器进行联机游戏. if (PlayerController.GetInstance().m_IsFinished || PlayerController.GetInstance().m_UIController.m_IsGameOver) { return; } } else { //多人联机. if (NetworkServerNet.GetInstance().mNetworkRootGame != null) { if (NetworkServerNet.GetInstance().mNetworkRootGame.ePlayerGameNetState == NetworkServerNet.PlayerGameNetType.GameBackMovie) { //游戏结束. return; } } } } else { //单机游戏. if (PlayerController.GetInstance().m_IsFinished || PlayerController.GetInstance().m_UIController.m_IsGameOver) { return; } } DisMoveVal = disVal; }
GameObject SpawnNpcByNpcPrefab(GameObject npcPrefab) { if (NpcPrefabName == "" || NpcPrefabName == null) { NpcPrefabName = npcPrefab.name; } GameObject obj = null; Vector3 posVal = new Vector3(-18000f, -18000f, 0f); Quaternion rotVal = Quaternion.Euler(Vector3.zero); if (Network.peerType == NetworkPeerType.Disconnected) { obj = (GameObject)Instantiate(npcPrefab, posVal, rotVal); } else { int playerID = int.Parse(Network.player.ToString()); obj = (GameObject)Network.Instantiate(npcPrefab, posVal, rotVal, playerID); if (NetworkServerNet.GetInstance() != null) { NetworkServerNet.GetInstance().AddNpcObjList(obj); } } HandleNpcList(obj); return(obj); }
public void HanldeClientSelectLink() { if (NetCtrlScript == null) { NetCtrlScript = NetCtrl.GetInstance(); if (NetCtrlScript == null) { return; } } NetworkServerNet NetworkServerScript = NetworkServerNet.GetInstance(); if (NetworkServerScript != null && !NetworkServerScript.CheckIsLinkedServerPort()) { //ScreenLog.LogWarning("the client have not linked server..."); return; } if (!isHandleNetLink) { //ScreenLog.Log("link server mode"); isHandleNetLink = true; NetCtrlScript.ClientCallHandleSelectLinkCount(true); } }
[RPC] void NetCtrlSendTryCloseServerPort() { if (NetworkServerNet.GetInstance() != null) { NetworkServerNet.GetInstance().TryToCloseServerPort(); //Close ServerNet } }
[RPC] void NetCtrlSendAddLinkCount() { if (Network.peerType != NetworkPeerType.Server) { return; } SelectLinkCount++; Debug.Log("Unity:" + "NetCtrlSendAddLinkCount -> SelectLinkCount " + SelectLinkCount + ", MaxPlayerCount " + MaxPlayerCount); if (SelectLinkCount >= MaxPlayerCount) { //Loading game, start to link game. SelectLinkCount = 0; Network.incomingPassword = ServerPassword.XKGame.ToString(); SendClientLoadGameLevel(); if (NetworkServerNet.GetInstance() != null) { NetworkServerNet.GetInstance().SetIsCheckServerPortPlayerNum(); } } else { IsSendLoadLevel = false; } }
public void StartIntoGame() { MyCOMDevice.ComThreadClass.IsLoadingLevel = true; LoadingCtrl.GetInstance().InitActiveAllObj(); LoadingBJObj.SetActive(true); if (GlobalData.GetInstance().gameMode == GameMode.SoloMode) { IsIntoPlayGame = true; GlobalData.GetInstance().gameLeve = GameLeve.Waterwheel; System.GC.Collect(); AsyncStatus = Application.LoadLevelAsync((int)GameLeve.Waterwheel); } else { GlobalData.GetInstance().gameLeve = GameLeve.WaterwheelNet; if (Network.peerType == NetworkPeerType.Server) { NetworkServerNet.GetInstance().RemoveMasterServerHost(); if (NetworkRpcMsgCtrl.MaxLinkServerCount == 0) { NetworkRpcMsgCtrl.MaxLinkServerCount = NetworkRpcMsgCtrl.NoLinkClientCount; } } System.GC.Collect(); AsyncStatus = Application.LoadLevelAsync((int)GameLeve.WaterwheelNet); } AsyncStatus.allowSceneActivation = false; Invoke("CheckAsyncIsDone", 8f); }
void FixedUpdate() { if (!IsNetControlPort) { //非主控制端. SynNetPosition(); SynNetRotation(); return; } if (Network.peerType == NetworkPeerType.Client || Network.peerType == NetworkPeerType.Server) { if (NetworkServerNet.GetInstance().mNetworkRootGame.ePlayerGameNetState == NetworkServerNet.PlayerGameNetType.GameBackMovie) { //游戏准备返回循环动画场景,无需继续同步信息! } else { //主控制端同步坐标. if (mNetPos != transform.position) { mNetPos = transform.position; mNetworkView.RPC("RpcNetSynPosition", RPCMode.Others, mNetPos); } //主控制端同步转向. if (mNetRot != transform.forward) { mNetRot = transform.forward; mNetworkView.RPC("RpcNetSynRotation", RPCMode.Others, mNetRot); } } } }
/// <summary> /// 有玩家链接到服务器(服务端消息). /// </summary> void OnPlayerConnectedEvent() { int movieNum = NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie; if (movieNum <= NetworkServerNet.GetInstance().LinkServerPlayerNum_Game) { //其他玩家全部链接到该服务器. Debug.Log("SSGameRoot::OnPlayerConnectedEvent -> creat server player..."); mSSGameDataManage.mGameData.SpawnPlayer(0); //movieNum == 1 -- 2,3; movieNum == 2 -- 3; movieNum == 3 -- 不产生npc; for (int i = 0; i < 4; i++) { if (i > movieNum) { mSSGameDataManage.mGameData.SpawnNpc(i); } } //mUIController.SetActiveUIRoot(true); if (PlayerController.GetInstance() != null) { PlayerController.GetInstance().NetSendPlayerAcitveUIPanel(); } } }
void LoadMovieLevel() { if (IsLoadMovie) { return; } IsLoadMovie = true; if (Network.peerType == NetworkPeerType.Client) { NetworkServerNet.GetInstance().RemoveClientHost(); } if (Network.peerType == NetworkPeerType.Server) { NetworkServerNet.GetInstance().RemoveMasterServerHost(); } if (SSGameCtrl.GetInstance().eGameMode == NetworkRootMovie.GameMode.Link) { //重置网络玩家索引信息. NetworkServerNet.GetInstance().SetIndexSpawnPlayer(0); //重置选择联机游戏的玩家数量. NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie = 0; } StartCoroutine(CheckUnloadUnusedAssets()); }
void Awake() { Debug.Log("SSGameRoot::Awake -> peerType " + Network.peerType + ", eGameMode " + SSGameCtrl.GetInstance().eGameMode); SSGameCtrl.GetInstance().mSSGameRoot = this; NetworkServerNet.GetInstance().mNetworkRootGame = mNetworkRootGame; switch (SSGameCtrl.GetInstance().eGameMode) { case NetworkRootMovie.GameMode.Null: case NetworkRootMovie.GameMode.NoLink: { mSSGameDataManage.mGameData.SpawnPlayer(0); mSSGameDataManage.mGameData.SpawnNpc(1); mSSGameDataManage.mGameData.SpawnNpc(2); mSSGameDataManage.mGameData.SpawnNpc(3); mUIController.SetActiveUIRoot(true); break; } case NetworkRootMovie.GameMode.Link: { mUIController.SetActiveUIRoot(false); mSSTimeUpCom = gameObject.AddComponent <SSTimeUpCtrl>(); mSSTimeUpCom.OnTimeUpOverEvent += OnTimeUpOverNotConnectEvent; mSSTimeUpCom.Init(35f); break; } } NetworkEvent.GetInstance().OnServerInitializedEvent += OnServerInitializedEvent; NetworkEvent.GetInstance().OnPlayerConnectedEvent += OnPlayerConnectedEvent; NetworkEvent.GetInstance().OnConnectedToServerEvent += OnConnectedToServerEvent; NetworkEvent.GetInstance().OnFailedToConnectToMasterServerEvent += OnFailedToConnectToMasterServerEvent; }
void OnTimeUpOverServerWeiHuEvent() { if (mLoadingCom.mGameModeSelect.eGameMode == NetworkRootMovie.GameMode.Link) { Debug.Log("OnTimeUpOverServerWeiHuEvent..."); mLoadingCom.mGameModeSelect.eGameMode = NetworkRootMovie.GameMode.NoLink; //强制修改为单机模式. if (mLoadingCom.mLevelSelectUI != null) { Debug.Log("Reinit level select UI..."); mLoadingCom.mLevelSelectUI.Init(mLoadingCom); } else { //产生选择游戏场景UI. Debug.Log("spawn level select UI..."); mLoadingCom.SpawnLevelSelectUI(); } SetActiveUISeverWeiHu(false); if (NetworkServerNet.GetInstance().mRequestMasterServer != null) { NetworkServerNet.GetInstance().mRequestMasterServer.ClearMastServerHostList(); } } }
// Use this for initialization void Start() { _Instance = this; if (GlobalData.GetInstance().gameMode == GameMode.OnlineMode) { GameObject bikegamectrl = GameObject.Find(GlobalData.bikeGameCtrl); playerCreatScript = bikegamectrl.GetComponent <PlayerCreatNet>(); NetworkServerScript = NetworkServerNet.GetInstance(); netCtrlScript = NetCtrl.GetInstance(); if (NetworkServerScript != null && NetworkServerScript.GetIsServer()) { return; } else { SoureAudio = AudioManager.Instance.audio; } } else { SoureAudio = AudioManager.Instance.audio; ui = GetComponent <UISprite>(); scale = GetComponent <TweenScale>(); StartCoroutine("Gogo"); } }
/// <summary> /// 玩家链接到服务器(客户端消息). /// </summary> void OnConnectedToServerEvent() { int indexVal = NetworkServerNet.GetInstance().IndexSpawnPlayer; Debug.Log("SSGameRoot::OnConnectedToServerEvent -> creat client player, indexVal == " + indexVal); mSSGameDataManage.mGameData.SpawnPlayer(indexVal); //mUIController.SetActiveUIRoot(true); }
void Awake() { TimeLastYiWanChengVal = Time.time; if (NetworkServerNet.GetInstance() != null) { NetworkServerNet.GetInstance().mRequestMasterServer.SetMasterServerComment(RequestMasterServer.MasterServerComment.Movie); } }
void DelayResetIsLoadingLevel() { XkGameCtrl.ResetIsLoadingLevel(); if (NetworkServerNet.GetInstance() != null) { NetworkServerNet.GetInstance().TryToCreateServer(); } }
void RpcSendSpawnPlayerIndex(NetworkPlayer playerNet, int index) { NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie = index; if (playerNet != Network.player) { return; } NetworkServerNet.GetInstance().SetIndexSpawnPlayer(index); }
void Start() { _Instance = this; if (eNetState == GameNetType.Link) { //创建并且重置NetworkServerNet. NetworkServerNet.GetInstance().ResetInfo(); } }
void Update() { if (IsFailedToConnectMasterServer) { //链接主服务器失败(主服务器游戏可能没有打开). return; } if (Time.frameCount % 30 == 0) { if (!StartBtObj.activeSelf && !IsClickStartBt) { if (NetworkServerNet.GetInstance().mRequestMasterServer.GetMovieMasterServerNum() == 1 && NetworkServerNet.GetInstance().mRequestMasterServer.ServerIp == Network.player.ipAddress && Network.peerType == NetworkPeerType.Server) { TimeLastStartBt += (Time.deltaTime * 30); if (TimeLastStartBt >= 3f) { //循环动画场景主服务器有且只有1个动画服务端时,才允许显示开始按键. //SetAcitveStartBt(true); //产生选择游戏场景UI. mLoadingCom.SpawnLevelSelectUI(); //隐藏创建服务器的UI提示. SetActiveUICreateSever(false); } } else { TimeLastStartBt = 0f; } } if (NetworkServerNet.GetInstance() != null) { if (IndexPlayer != NetworkServerNet.GetInstance().IndexSpawnPlayer) { IndexPlayer = NetworkServerNet.GetInstance().IndexSpawnPlayer; Debug.Log("GameLinkPlayer::update -> IndexPlayer == " + IndexPlayer); if (!LinkNameParent.activeInHierarchy) { SetActiveLinkNameParent(true); } //ChangeUINameScale(IndexPlayer); SetUIPanelBeiJing(IndexPlayer); } if (PlayerLinkServerCount != NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie) { PlayerLinkServerCount = NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie; Debug.Log("GameLinkPlayer::update -> PlayerLinkServerCount == " + PlayerLinkServerCount); //SetPlayerUITexture(PlayerLinkServerCount); SetPlayerUIMesh(PlayerLinkServerCount); } } } }
void SendSpawnClientIndex(NetworkPlayer playerNet, int val) { LinkPlayerCtrl.GetInstance().DisplayLinkPlayerName(val); if (playerNet != Network.player) { return; } NetworkServerNet.GetInstance().SetIndexSpawnClient(val); }
IEnumerator DestroyNetNpcObj(GameObject obj, float timeVal = 0f) { if (timeVal > 0f) { yield return(new WaitForSeconds(timeVal)); } bool isTestHiddenObj = true; if (!isTestHiddenObj) { if (Network.peerType == NetworkPeerType.Disconnected) { Destroy(obj); } else { if (Network.peerType == NetworkPeerType.Server) { if (NetworkServerNet.GetInstance() != null) { int max = NpcMoveScript.Length; for (int i = 0; i < max; i++) { if (NpcMoveScript[i] != null) { NetworkServerNet.GetInstance().RemoveNetworkObj(NpcMoveScript[i].gameObject); } } NetworkServerNet.GetInstance().RemoveNetworkObj(obj); } } } } else { Transform npcChildTran = null; NpcMoveScript = NpcTran.GetComponentsInChildren <XKNpcMoveCtrl>(); int max = NpcMoveScript.Length; for (int i = 0; i < max; i++) { if (NpcMoveScript[i] != null) { NpcMoveScript[i].TriggerRemovePointNpc(0); npcChildTran = NpcMoveScript[i].transform; npcChildTran.parent = XkGameCtrl.NpcObjArray; } } //Debug.Log("Unity:"+"****max "+max+", fangZhenObj "+NpcObj.name); NpcTran.position = new Vector3(-18000f, -18000f, 0f); NpcTran.SetParent(XkGameCtrl.GetInstance().NpcObjHiddenArray); ResetFangZhenObjInfo(); IsHiddenNpcObj = true; IsActiveFangZhen = false; } }
public static void OnPlayerGameOver() { PlayerCreatNet.IsDisconnected = true; PlayerCreatNet.IsBackMoveScence = true; NetworkServerNet netScript = NetworkServerNet.GetInstance(); if (netScript != null) { netScript.SetIsDisconnect(); } }
void Start() { _Instance = this; camPosEvent = BikeCamEvent.Null; NetworkServerScript = NetworkServerNet.GetInstance(); if (mMotionBlur == null) { Debug.LogWarning("mMotionBlur is null"); } BlurEffectScript.enabled = false; float[] distances = new float[32]; for (int i = 0; i < 32; i++) { distances[i] = 400f; } distances[9] = 260; distances[15] = 100; distances[18] = 600; distances[19] = 50; distances[13] = 250; distances[20] = 50; distances[21] = 250; camera.layerCullDistances = distances; Random.seed = (int)(Time.realtimeSinceStartup * 100000f); RainObj.SetActive(false); if (NetworkServerScript != null && !NetworkServerScript.GetIsServer()) { Invoke("callBackgroundAudio", 3.5f); } mCamTran = transform; Screen.showCursor = false; smoothVal = mSmooth * 0.015f; //smoothValTmp = smoothVal; if (mBike != null) { mBikePlayer = mBike; } mMotionBlur = gameObject.GetComponent <MotionBlur>(); // if(mMotionBlur == null) // { // ScreenLog.Log("BikeCamera::Start -> mMotionBlur is null!"); // } }
/// <summary> /// 游戏场景里服务器被初始化. /// </summary> void OnServerInitializedEvent() { Debug.Log("SSGameRoot::OnServerInitializedEvent -> creat server player..."); if (NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie <= 0) { //没有其他玩家链接服务器. mSSGameDataManage.mGameData.SpawnPlayer(0); mSSGameDataManage.mGameData.SpawnNpc(1); mSSGameDataManage.mGameData.SpawnNpc(2); mSSGameDataManage.mGameData.SpawnNpc(3); mUIController.SetActiveUIRoot(true); } }
void CheckGameBtEvent() { // if (!ModeObj.activeSelf) { // return; // } ModeVal = GameMode.LianJi; // if (ModeVal == GameMode.Null) { // return; // } // if (!StartBtObj.activeSelf) { // return; // } XKGlobalData.GetInstance().PlayModeQueRenAudio(); if (ModeVal != GameMode.LianJi) { IsSelectDanJiMode = true; HiddenGameMode(); if (NetCtrl.GetInstance() != null) { NetCtrl.GetInstance().SendSubLinkCount(); } GameTypeCtrl.SetAppTypeVal(AppGameType.LianJiFeiJi); NetworkServerNet.GetInstance().MakeServerDisconnect(); //Close ServerNet. NetworkServerNet.GetInstance().MakeClientDisconnect(); //Close ClientNet. SetActiveLoading(true); } else { IsSelectDanJiMode = false; // if (NetworkServerNet.GetInstance() != null) { // NetworkServerNet.GetInstance().TryToLinkServer(); // } if (NetCtrl.GetInstance() != null) { NetCtrl.GetInstance().SendAddLinkCount(); //ServerPort. } else { //ClientPort. IsActiveClientPort = true; HiddenGameMode(); GameTypeCtrl.SetAppTypeVal(AppGameType.LianJiFeiJi); SetActiveLoading(true); } } SetActiveStartBt(false); }
void DelayResetIsLoadingLevel() { Debug.Log("Unity:!!!!!!DelayResetIsLoadingLevel2!!!!!!"); XkGameCtrl.ResetIsLoadingLevel(); if (NetworkServerNet.GetInstance() != null) { NetworkServerNet.GetInstance().TryToCreateServer(); } Debug.Log("Unity:!!!!!!DelayResetIsLoadingLevel3!!!!!!"); //InputEventCtrl.GetInstance().ClickStartBtOne(ButtonState.DOWN); //test. //InputEventCtrl.GetInstance().ClickStartBtOne(ButtonState.UP); //Debug.Log("Unity:!!!!!!DelayResetIsLoadingLevel4!!!!!!"); }
void OnFailedToConnectToMasterServerEvent() { if (!IsFailedToConnectMasterServer && SSGameCtrl.GetInstance().eGameMode == NetworkRootMovie.GameMode.Link) { Debug.Log("SSGameRoot -> OnFailedToConnectToMasterServerEvent..."); NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie = 0; NetworkServerNet.GetInstance().LinkServerPlayerNum_Game = 0; SSGameCtrl.GetInstance().eGameMode = NetworkRootMovie.GameMode.NoLink; //强制修改联机状态. //玩家链接主服务器失败. mSSGameDataManage.mGameData.SpawnPlayer(0); mSSGameDataManage.mGameData.SpawnNpc(1); mSSGameDataManage.mGameData.SpawnNpc(2); mSSGameDataManage.mGameData.SpawnNpc(3); mUIController.SetActiveUIRoot(true); } }
// Use this for initialization void Start() { if (GameLinkSt == GameLinkEnum.LINK) { NetworkServerNet.GetInstance(); } SetPanelUiRoot.YouMenSt = YouMenSt; AudioListener.volume = (float)GlobalData.GameAudioVolume / 10f; //if(_instance == null) { // _instance = this; // //DontDestroyOnLoad( gameObject ); // PlayMovie(); //} pcvr.DongGanState = 0; //Invoke("DelayCheckPcvr", Random.Range(5f, 15f)); }
void DestroyNetObj(GameObject obj) { if (Network.peerType == NetworkPeerType.Disconnected) { Destroy(obj); } else { if (Network.peerType == NetworkPeerType.Server) { if (NetworkServerNet.GetInstance() != null) { NetworkServerNet.GetInstance().RemoveNetworkObj(obj); } } } }
/// <summary> /// 发送Npc关闭喷气动画的网络消息. /// </summary> void SendNpcClosePenQiAni() { if (Network.peerType == NetworkPeerType.Client || Network.peerType == NetworkPeerType.Server) { if (IsNetControlPort) { if (Network.peerType == NetworkPeerType.Server && NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie <= 0) { //没有玩家选择链接服务器进行联机游戏. } else { mNetViewCom.RPC("RpcGetNpcClosePenQiAni", RPCMode.Others); } } } }
/// <summary> /// 发送Npc比赛运动路程的消息. /// </summary> void SendNpcDisMoveVal(float disVal) { if (Network.peerType == NetworkPeerType.Client || Network.peerType == NetworkPeerType.Server) { if (IsNetControlPort) { if (Network.peerType == NetworkPeerType.Server && NetworkServerNet.GetInstance().LinkServerPlayerNum_Movie <= 0) { //没有玩家选择链接服务器进行联机游戏. } else { mNetViewCom.RPC("RpcNpcDisMoveVal", RPCMode.Others, disVal); } } } }