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:

     static int ConvertNetworkView(NetworkView[] netViews, bool isScene)
     {
         for (int i = netViews.Length - 1; i >= 0; i--)
         {
             NetworkView netView = netViews[i];
             PhotonView view = netView.gameObject.AddComponent();
             if (isScene)
             {
                 //Get scene ID
                 string str = netView.viewID.ToString().Replace("SceneID: ", "");
                 int firstSpace = str.IndexOf(" ");
                 str = str.Substring(0, firstSpace);
                 int oldViewID = int.Parse(str);

                 view.viewID = oldViewID;
                 EditorUtility.SetDirty(view);
                 EditorUtility.SetDirty(view.gameObject);
             }
             view.observed = netView.observed;
             if (netView.stateSynchronization == NetworkStateSynchronization.Unreliable)
             {
                 view.synchronization = ViewSynchronization.Unreliable;
             }
             else if (netView.stateSynchronization == NetworkStateSynchronization.ReliableDeltaCompressed)
             {
                 view.synchronization = ViewSynchronization.ReliableDeltaCompressed;
             }
             else
             {
                 view.synchronization = ViewSynchronization.Off;
             }
             DestroyImmediate(netView, true);
         }
         AssetDatabase.Refresh();
         AssetDatabase.SaveAssets();

         return netViews.Length;
     }