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:

     private void DrawWeightInspector()
     {
         SerializedProperty foldoutProperty = serializedObject.FindProperty("ShowLayerWeightsInspector");
         foldoutProperty.boolValue = PhotonGUI.ContainerHeaderFoldout("Synchronize Layer Weights", foldoutProperty.boolValue);

         if (foldoutProperty.boolValue == false)
         {
             return;
         }

         float lineHeight = 20;
         Rect containerRect = PhotonGUI.ContainerBody(this.m_Animator.layerCount*lineHeight);

         for (int i = 0; i < this.m_Animator.layerCount; ++i)
         {
             if (this.m_Target.DoesLayerSynchronizeTypeExist(i) == false)
             {
                 this.m_Target.SetLayerSynchronized(i, PhotonAnimatorView.SynchronizeType.Disabled);
                 EditorUtility.SetDirty(this.m_Target);
             }

             PhotonAnimatorView.SynchronizeType value = this.m_Target.GetLayerSynchronizeType(i);

             Rect elementRect = new Rect(containerRect.xMin, containerRect.yMin + i*lineHeight, containerRect.width, lineHeight);

             Rect labelRect = new Rect(elementRect.xMin + 5, elementRect.yMin + 2, EditorGUIUtility.labelWidth - 5, elementRect.height);
             GUI.Label(labelRect, "Layer " + i);

             Rect popupRect = new Rect(elementRect.xMin + EditorGUIUtility.labelWidth, elementRect.yMin + 2, elementRect.width - EditorGUIUtility.labelWidth - 5, EditorGUIUtility.singleLineHeight);
             value = (PhotonAnimatorView.SynchronizeType) EditorGUI.EnumPopup(popupRect, value);

             if (i < this.m_Animator.layerCount - 1)
             {
                 Rect splitterRect = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1);
                 PhotonGUI.DrawSplitter(splitterRect);
             }

             if (value != this.m_Target.GetLayerSynchronizeType(i))
             {
                 Undo.RecordObject(target, "Modify Synchronize Layer Weights");
                 this.m_Target.SetLayerSynchronized(i, value);

                 EditorUtility.SetDirty(this.m_Target);
             }
         }
     }