IEnumerator OnLevelWasLoaded(int mapID) { if(mapID == this.playingMapID) { readyStartPlay = false; isDraw = true; this.playGameSkin = Resources.Load("Skin/CarInsanity", typeof(GUISkin)) as GUISkin; if(PlayerPrefs.GetString("GameType", "Single") == "Network") { this.processState = PlayGameController.ProcessState.CONNECTING; Network.Connect(gameServerIP, gameServerPort); enabled = true; } else { Room room = this.matchRoom.GetComponent<Room>(); for(int i = 0; i < 4; i++) { GameUserPlayer targetPlayer = room.GetPlayer(i); CarInsanityPlayer playerCarInfo = targetPlayer.GetComponent<CarInsanityPlayer>(); GameObject[] startPositionArray = GameObject.FindGameObjectsWithTag("StartPosition"); foreach(GameObject position in startPositionArray ) { if(Convert.ToInt32(position.name) == i + 1) { // foreach(Transform cp in carPrefabs) { // if(cp.name == ((Definition.eCarID)(targetPlayer.GetComponent<CarInsanityPlayer>().selectedCar.carID)).ToString()) { // playerCar = cp; // } // } CarProperty tf = Instantiate(Resources.Load(((Definition.eCarID)(playerCarInfo.selectedCar.carID)).ToString(), typeof(CarProperty)), position.transform.position, position.transform.rotation) as CarProperty; tf.ownerGUPID = targetPlayer.GUPID; tf.playerName = targetPlayer.playerName; if(playerCarInfo.selectedCar.isTalentOpened) { switch(((Definition.eCarID)(playerCarInfo.selectedCar.carID)).ToString()) { case "POLICE_CAR" : tf.gameObject.AddComponent<PolicePassiveSkill>(); break; case "LORRY_TRUCK" : tf.gameObject.AddComponent<TruckPassiveSkill>(); break; case "AMBULANCE" : tf.gameObject.AddComponent<AmbulancePassiveSkill>(); break; case "FIRE_FIGHTING_TRUCK" : tf.gameObject.AddComponent<FireFightPassiveSkill>(); break; case "GARBAGE_TRUCK" : case "MASCOT_TRUCK" : tf.gameObject.AddComponent<GarbagePassiveSkill>(); break; case "OLDCLASS_TRUCK" : case "GODOFWEALTH_TRUCK" : OldclassPassiveSkill passiveSkill = tf.gameObject.AddComponent<OldclassPassiveSkill>(); if(targetPlayer.GUPID == playingGUPID) { passiveSkill.PassiveSkillInit(); } break; case "HUMMER_TRUCK" : tf.gameObject.AddComponent<HummerPassiveSkill>(); break; } } // tf.networkView.viewID = viewID; if(playingIsCreator == 1) { if(targetPlayer.isAI) { if(tf.GetComponent<CarAI>()) tf.GetComponent<CarAI>().enabled = true; // Debug.Log("SendToGameServer_Ready - GUPID:"+targetGUPID+" (target is AI)"); // networkView.RPC("SendToGameServer_Ready", RPCMode.Server, playingRoomIndex, targetGUPID, tf.networkView.viewID, position.transform.position, position.transform.rotation); } } if(targetPlayer.GUPID == playingGUPID) { // Debug.Log("SendToGameServer_Ready - GUPID:"+targetGUPID+"(i m the target)"); // networkView.RPC("SendToGameServer_Ready", RPCMode.Server, playingRoomIndex, targetGUPID, tf.networkView.viewID, position.transform.position, position.transform.rotation); } else { // Debug.Log("SendToGameServer_ReplyInitialData - GUPID:"+targetGUPID); // networkView.RPC("SendToGameServer_ReplyInitialData", RPCMode.Server, playingRoomIndex, targetGUPID); } break; } } } Resources.UnloadUnusedAssets(); ReceiveByClientPortal_StartPlayCountDown(5); // if(OnLoadSuccess != null) // { // OnLoadSuccess(); // } enabled = true; for(int i = 5; i >= 0; i--) { startPlayCountDown = i; if(i != 0) { AudioSource.PlayClipAtPoint(start1Audio, Camera.main.transform.position); } else { AudioSource.PlayClipAtPoint(start2Audio, Camera.main.transform.position); } yield return new WaitForSeconds(1); } enabled = false; ReceiveByClientPortal_StartPlay(); } }else{ this.processState = PlayGameController.ProcessState.FREE; this.isGameInitialized = false; this.isCountDownAnimaitonStarted = false; this.isFinishPlayCountDown = false; isDraw = false; this.playGameSkin = null; enabled = false; } }
// private void drawLoadingScreenWindow(int id) { // GUILayout.BeginHorizontal(); // foreach(GameUserPlayer driver in this.matchRoom.GetComponent<Room>().playersInRoom) { // // GUILayout.BeginVertical(); // GUILayout.Label(driver.playerName, Font_White); // GUILayout.Label(strEmpty, CarIcon_+((Definition.eCarID)driver.GetComponent<CarInsanityPlayer>().selectedCar.carID).ToString(), GUILayout.Height(Screen.height * 0.2f), GUILayout.Width(Screen.height * 0.2f)); // GUILayout.EndVertical(); // } // GUILayout.EndHorizontal(); // // GUILayout.Label(strTheGameIsLoading); // GUILayout.Space(10); // GUILayout.Label(strLoadingEstimatedTime); // GUILayout.Label(strLoadingElapsedTime + strColon+strSpace + elapsedTime + strSpace+strSeconds); // // } // private void drawArrivedRecordWindow(int id) { // int c = 1; // foreach(KeyValuePair<int, String> kvp in this.matchRoom.GetComponent<CarInsanityRecorder>().GetRecordDic()) { // // GUILayout.BeginHorizontal(); // GUILayout.Label(c.ToString() + strSpace+strName+strColon + this.matchRoom.GetComponent<Room>().GetPlayer(kvp.Key).playerName + strSpace + strRecord + strColon + kvp.Value); // GUILayout.EndHorizontal(); // } // // GUILayout.Label(strWaitingForOtherPlayers); // } // private void drawBalanceRecordWindow(int id) { // int c = 1; // if(this.matchRoom) // { // foreach(KeyValuePair<int, String> kvp in this.matchRoom.GetComponent<CarInsanityRecorder>().GetRecordDic()) { // GUILayout.BeginHorizontal(); // GUILayout.Label(c.ToString() + strSpace+strName+strColon + this.matchRoom.GetComponent<Room>().GetPlayer(kvp.Key).playerName + strSpace + strRecord + strColon + kvp.Value); // GUILayout.EndHorizontal(); // } // } // // if(GUILayout.Button(strClose)) { // // Destroy(this.matchRoom.gameObject); // //this.matchRoom = null; // redirectController.RedirectStart(); // } // // } void OnCompletedAMatch() { processState = PlayGameController.ProcessState.MATCHCOMPLETED; Destroy(this.matchRoom.gameObject); }
void OnConnectedToServer() { if(this.processState == PlayGameController.ProcessState.CONNECTING) { // networkView.RPC("SendToGameServer_JoinMatch", RPCMode.Server, playingRoomIndex, playingGUPID, playingCarID, playingPlayerName, playingIsCreator, playingPlayerNumber, playingMapID, playingMatchType, playingIsAI, Network.AllocateViewID()); networkView.RPC("SendToGameServer_JoinMatch", RPCMode.Server, playingRoomIndex, playingGUPID, playingPlayerID, playingPlayerCarID, playingCarID, playingPlayerName, playingIsCreator, playingPlayerNumber, playingMapID, playingMatchType, playingIsAI, Network.AllocateViewID()); processState = ProcessState.CONNECTEDTOGAMESERVER; //for ai if(playingIsCreator == 1) { // i am creator foreach(GameUserPlayer d in this.matchRoom.GetComponent<Room>().playersInRoom) { if(d.isAI) { // networkView.RPC("SendToGameServer_JoinMatch", RPCMode.Server, playingRoomIndex, d.GUPID, 0, d.playerName, 0, playingPlayerNumber, playingMapID, playingMatchType, 1, Network.AllocateViewID()); networkView.RPC("SendToGameServer_JoinMatch", RPCMode.Server, playingRoomIndex, d.GUPID, 0, 0, 0, d.playerName, 0, playingPlayerNumber, playingMapID, playingMatchType, 1, Network.AllocateViewID()); } } } } }
public void SendWin(float driftTime, float useSkill, int beHitTime, int gupid) { // Debug.Log("SendWin.GUPID:"+gupid); networkView.RPC("SendToGameServer_FinishPlay", RPCMode.Server, playingRoomIndex, driftTime, useSkill, beHitTime, gupid); if(playingGUPID == gupid) { //may be ai win if(this.processState != PlayGameController.ProcessState.BALANCE) { this.processState = PlayGameController.ProcessState.ARRIVED; // OnShowRecord(); } } }
public void ReceiveByClientPortal_TimeUp() { // Debug.Log("TimeUp"); StopAllCarAndNetworkSynchron(); this.processState = PlayGameController.ProcessState.BALANCE; OnShowRecord(); }
public void ReceiveByClientPortal_StartPlayCountDown(float second) { if(!readyStartPlay) { readyStartPlay = true; if(OnLoadSuccess != null) { OnLoadSuccess(); } } this.processState = PlayGameController.ProcessState.STARTPLAYCOUNTDOWN; this.startPlayCountDown = second; if(PlayerPrefs.GetString("GameType", "Single") == "Network") { if(second == 0) { AudioSource.PlayClipAtPoint(start2Audio, Camera.main.transform.position); } else { AudioSource.PlayClipAtPoint(start1Audio, Camera.main.transform.position); } } isGameInitialized = true; if(!isCountDownAnimaitonStarted) { if(countDownBat == null) { countDownBat = Camera.main.GetComponentInChildren<CountDownBat>(); } // countDownBat.SetStartFlyIn(); isCountDownAnimaitonStarted = true; } if(dynamicMaterial == null) { dynamicMaterial = Camera.main.GetComponentInChildren<DynamicMaterial>(); } // dynamicMaterial.SetCountdownRender((int)this.startPlayCountDown); // if(!isOpenMapCamera) // { // LittleMap mapCamera = FindObjectOfType(typeof(LittleMap)) as LittleMap; // mapCamera.SetCars(); // isOpenMapCamera = true; // } }
public void ReceiveByClientPortal_StartPlay() { // Debug.Log("ReceiveByClientPortal_StartPlay"); this.matchRoom.isMatchStart = true; readyStartPlay = false; if(countDownBat == null) { countDownBat = Camera.main.GetComponentInChildren<CountDownBat>(); } // countDownBat.SetStartFlyOut(); LittleMap mapCamera = FindObjectOfType(typeof(LittleMap)) as LittleMap; mapCamera.SetCars(); RankManager rankManager = FindObjectOfType(typeof(RankManager)) as RankManager; rankManager.SetRanksCar(); this.processState = PlayGameController.ProcessState.PLAY; if(OnGameStart != null) { OnGameStart(); } }
public void ReceiveByClientPortal_FinishPlay(int GUPID, string timeRecord, int gainGold) { // Debug.Log ("ReceiveByClientPortal_FinishPlay - GUPID:"+GUPID+", Record:"+timeRecord); // Debug.Log("FinishPlay"); if(!isFinishPlayCountDown) { StartCoroutine(FinishPlayCountDown()); } // isShowFinishCountDown = true; this.matchRoom.GetComponent<CarInsanityRecorder>().AddRecord(GUPID, timeRecord); // Debug.Log ("OnCarArrived - GUPID:"+GUPID+", Record:"+timeRecord+", rank:"+this.matchRoom.GetComponent<CarInsanityRecorder>().GetRecordCount()+", isOwned:" + (playingGUPID == GUPID).ToString() ); OnCarArrived(this.matchRoom.GetCarInsanityPlayer(GUPID), timeRecord, this.matchRoom.GetComponent<CarInsanityRecorder>().GetRecordCount(), playingGUPID == GUPID); if(GUPID == playingGUPID) { // i m finish // isShowFinishCountDown = false; this.processState = PlayGameController.ProcessState.ARRIVED; // OnShowRecord(); OnShowGainGold(gainGold, this.matchRoom.GetComponent<CarInsanityRecorder>().GetRecordCount()); int c = 0; foreach(KeyValuePair<int, string> kp in this.matchRoom.GetComponent<CarInsanityRecorder>().GetRecordDic()) { c++; if(kp.Key == playingGUPID) { Camera.main.BroadcastMessage("ShowCup", c, SendMessageOptions.DontRequireReceiver); break; } } // //stop synchronize // CarProperty[] cars = FindObjectsOfType(typeof(CarProperty)) as CarProperty[] ; // foreach(CarProperty cp in cars) { // if(cp.ownerGUPID == playingGUPID) { // cp.networkView.enabled = false; // break; // } // } } //start balance when all player arrived if(this.matchRoom.GetComponent<CarInsanityRecorder>().GetRecordCount() == this.matchRoom.GetComponent<Room>().maxPlayerNumber) { // Debug.Log("ReceiveByClientPortal_FinishPlay - GetRecordCount():" + this.tvcMatchRoom.GetRecordCount() + ", GetMaxPlayerNumber():"+ this.tvcMatchRoom.GetMaxPlayerNumber()); StopAllCarAndNetworkSynchron(); this.processState = PlayGameController.ProcessState.BALANCE; OnShowRecord(); } }