GameD









How do I use Game D
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: NetworkingPeer.cs Copy
822     private void GameEnteredOnGameServer(OperationResponse operationResponse)
823     {
824         if (operationResponse.ReturnCode != 0)
825         {
826             switch (operationResponse.OperationCode)
827             {
828                 case OperationCode.CreateGame:
829                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
830                     {
831                         Debug.Log("Create failed on GameServer. Changing back to MasterServer. Msg: " + operationResponse.DebugMessage);
832                     }
833                     SendMonoMessage(PhotonNetworkingMessage.OnPhotonCreateRoomFailed, operationResponse.ReturnCode, operationResponse.DebugMessage);
834                     break;
835                 case OperationCode.JoinGame:
836                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
837                     {
838                         Debug.Log("Join failed on GameServer. Changing back to MasterServer. Msg: " + operationResponse.DebugMessage);
839                         if (operationResponse.ReturnCode == ErrorCode.GameDoesNotExist)
840                         {
841                             Debug.Log("Most likely the game became empty during the switch to GameServer.");
842                         }
843                     }
844                     SendMonoMessage(PhotonNetworkingMessage.OnPhotonJoinRoomFailed, operationResponse.ReturnCode, operationResponse.DebugMessage);
845                     break;
846                 case OperationCode.JoinRandomGame:
847                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
848                     {
849                         Debug.Log("Join failed on GameServer. Changing back to MasterServer. Msg: " + operationResponse.DebugMessage);
850                         if (operationResponse.ReturnCode == ErrorCode.GameDoesNotExist)
851                         {
852                             Debug.Log("Most likely the game became empty during the switch to GameServer.");
853                         }
854                     }
855                     SendMonoMessage(PhotonNetworkingMessage.OnPhotonRandomJoinFailed, operationResponse.ReturnCode, operationResponse.DebugMessage);
856                     break;
857             }
858
859             this.DisconnectToReconnect();
860             return;
861         }
862
863         this.State = global::PeerState.Joined;
864         this.mRoomToGetInto.isLocalClientInside = true;
865
866         Hashtable actorProperties = (Hashtable)operationResponse[ParameterCode.PlayerProperties];
867         Hashtable gameProperties = (Hashtable)operationResponse[ParameterCode.GameProperties];
868         this.ReadoutProperties(gameProperties, actorProperties, 0);
869
870         // the local player's actor-properties are not returned in join-result. add this player to the list
871         int localActorNr = (int)operationResponse[ParameterCode.ActorNr];
872
873         this.ChangeLocalID(localActorNr);
874         this.CheckMasterClient(-1);
875
876         if (this.mPlayernameHasToBeUpdated)
877         {
878             this.SendPlayerName();
879         }
880
881         switch (operationResponse.OperationCode)
882         {
883             case OperationCode.CreateGame:
884                 SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom);
885                 break;
886             case OperationCode.JoinGame:
887             case OperationCode.JoinRandomGame:
888                 // the mono message for this is sent at another place
889                 break;
890         }
891     }
File name: GameController.cs Copy
42  void InitializeGameVariables(){
43   Load ();
44
45   if (data != null) {
46    isGameStartedFirstTime = data.GetIsGameStartedFirstTime ();
47   } else {
48    isGameStartedFirstTime = true;
49   }
50
51   if (isGameStartedFirstTime) {
52    isGameStartedFirstTime = false;
53    isMusicOn = true;
54    coins = 0;
55    weaponLevel = 1;
56    data = new GameData ();
57    data.SetIsGameStartedFirstTime (isGameStartedFirstTime);
58    data.SetIsMusicOn (isMusicOn);
59    data.SetCoins (coins);
60    data.SetWeaponLevel (weaponLevel);
61    Save ();
62
63    Load ();
64   } else {
65    isGameStartedFirstTime = data.GetIsGameStartedFirstTime ();
66    isMusicOn = data.GetIsMusicOn ();
67    coins = data.GetCoins ();
68    weaponLevel = data.GetWeaponLevel ();
69   }
70  }
File name: GameController.cs Copy
97  public void Load(){
98   FileStream file = null;
99
100   try{
101    BinaryFormatter bf = new BinaryFormatter();
102    file = File.Open(Application.persistentDataPath + "/data.dat", FileMode.Open);
103    data = bf.Deserialize(file) as GameData;
104   }catch(Exception e){
105    Debug.LogException (e, this);
106   }finally{
107    if(file != null){
108     file.Close ();
109    }
110   }
111  }
File name: GameController.cs Copy
38  void InitializeGameVariables(){
39   Load ();
40
41
42   if (data != null) {
43    isGameStartedFirstTime = data.GetIsGameStartedFirstTime ();
44   } else {
45    isGameStartedFirstTime = true;
46   }
47
48   if (isGameStartedFirstTime) {
49    isGameStartedFirstTime = false;
50    isMusicOn = true;
51    levels = new bool[15];
52    highscore = new int[levels.Length];
53
54    levels [0] = true;
55    for (int i = 1; i < levels.Length; i++) {
56     levels [i] = false;
57    }
58
59    for (int i = 0; i < highscore.Length; i++) {
60     highscore [i] = 0;
61    }
62
63    data = new GameData ();
64
65    data.SetIsMusicOn (isMusicOn);
66    data.SetIsGameStartedFirstTime (isGameStartedFirstTime);
67    data.SetHighScore (highscore);
68    data.SetLevels (levels);
69
70    Save ();
71
72    Load ();
73   } else {
74    isGameStartedFirstTime = data.GetIsGameStartedFirstTime ();
75    isMusicOn = data.GetIsMusicOn ();
76    highscore = data.GetHighScore ();
77    levels = data.GetLevels ();
78   }
79
80  }
File name: GameController.cs Copy
106  public void Load(){
107   FileStream file = null;
108
109   try{
110    BinaryFormatter bf = new BinaryFormatter();
111    file = File.Open(Application.persistentDataPath + "/data.dat", FileMode.Open);
112    data = bf.Deserialize(file) as GameData;
113
114   }catch(Exception e){
115    Debug.LogException (e, this);
116   }finally{
117    if(file != null){
118     file.Close ();
119    }
120   }
121  }

Download file with original file name:GameD

GameD 111 lượt xem

Gõ tìm kiếm nhanh...