Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

     /// (byte)0 -> (int) ViewId (combined from actorNr and actor-unique-id)
     /// (byte)1 -> (short) prefix (level)
     /// (byte)5 -> (byte) method shortcut (alternative to name)
     internal void RPC(PhotonView view, string methodName, PhotonTargets target, bool encrypt, params object[] parameters)
     {
         if (this.blockSendingGroups.Contains(view.group))
         {
             return; // Block sending on this group
         }

         if (view.viewID < 1)
         {
             Debug.LogError("Illegal view ID:" + view.viewID + " method: " + methodName + " GO:" + view.gameObject.name);
         }

         if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
             Debug.Log("Sending RPC \"" + methodName + "\" to " + target);


         //ts: changed RPCs to a one-level hashtable as described in internal.txt
         Hashtable rpcEvent = new Hashtable();
         rpcEvent[(byte)0] = (int)view.viewID; // LIMITS NETWORKVIEWS&PLAYERS
         if (view.prefix > 0)
         {
             rpcEvent[(byte)1] = (short)view.prefix;
         }
         rpcEvent[(byte)2] = this.ServerTimeInMilliSeconds;


         // send name or shortcut (if available)
         int shortcut = 0;
         if (rpcShortcuts.TryGetValue(methodName, out shortcut))
         {
             rpcEvent[(byte)5] = (byte)shortcut; // LIMITS RPC COUNT
         }
         else
         {
             rpcEvent[(byte)3] = methodName;
         }

         if (parameters != null && parameters.Length > 0)
         {
             rpcEvent[(byte)4] = (object[])parameters;
         }

         // Check scoping
         if (target == PhotonTargets.All)
         {
             RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Encrypt = encrypt };
             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);

             // Execute local
             this.ExecuteRPC(rpcEvent, this.mLocalActor);
         }
         else if (target == PhotonTargets.Others)
         {
             RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Encrypt = encrypt };
             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
         }
         else if (target == PhotonTargets.AllBuffered)
         {
             RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);

             // Execute local
             this.ExecuteRPC(rpcEvent, this.mLocalActor);
         }
         else if (target == PhotonTargets.OthersBuffered)
         {
             RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
         }
         else if (target == PhotonTargets.MasterClient)
         {
             if (this.mMasterClient == this.mLocalActor)
             {
                 this.ExecuteRPC(rpcEvent, this.mLocalActor);
             }
             else
             {
                 RaiseEventOptions options = new RaiseEventOptions() { Receivers = ReceiverGroup.MasterClient, Encrypt = encrypt };
                 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
             }
         }
         else if (target == PhotonTargets.AllViaServer)
         {
             RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Receivers = ReceiverGroup.All, Encrypt = encrypt };
             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
             if (PhotonNetwork.offlineMode)
             {
                 this.ExecuteRPC(rpcEvent, this.mLocalActor);
             }
         }
         else if (target == PhotonTargets.AllBufferedViaServer)
         {
             RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Receivers = ReceiverGroup.All, CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
             if (PhotonNetwork.offlineMode)
             {
                 this.ExecuteRPC(rpcEvent, this.mLocalActor);
             }
         }
         else
         {
             Debug.LogError("Unsupported target enum: " + target);
         }
     }