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 DrawParameterInspector()
     {
         SerializedProperty foldoutProperty = serializedObject.FindProperty("ShowParameterInspector");
         foldoutProperty.boolValue = PhotonGUI.ContainerHeaderFoldout("Synchronize Parameters", foldoutProperty.boolValue);

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

         float lineHeight = 20;
         Rect containerRect = PhotonGUI.ContainerBody(GetParameterCount()*lineHeight);

         for (int i = 0; i < GetParameterCount(); i++)
         {
             AnimatorControllerParameter parameter = null;

#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
             parameter = this.m_Controller.GetParameter(i);
#else
             parameter = m_Animator.parameters[ i ];
#endif

             string defaultValue = "";

             if (parameter.type == AnimatorControllerParameterType.Bool)
             {
                 defaultValue += parameter.defaultBool.ToString();
             }
             else if (parameter.type == AnimatorControllerParameterType.Float)
             {
                 defaultValue += parameter.defaultFloat.ToString();
             }
             else if (parameter.type == AnimatorControllerParameterType.Int)
             {
                 defaultValue += parameter.defaultInt.ToString();
             }

             if (this.m_Target.DoesParameterSynchronizeTypeExist(parameter.name) == false)
             {
                 this.m_Target.SetParameterSynchronized(parameter.name, (PhotonAnimatorView.ParameterType) parameter.type, PhotonAnimatorView.SynchronizeType.Disabled);
                 EditorUtility.SetDirty(this.m_Target);
             }

             PhotonAnimatorView.SynchronizeType value = this.m_Target.GetParameterSynchronizeType(parameter.name);

             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, parameter.name + " (" + defaultValue + ")");

             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 < GetParameterCount() - 1)
             {
                 Rect splitterRect = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1);
                 PhotonGUI.DrawSplitter(splitterRect);
             }

             if (value != this.m_Target.GetParameterSynchronizeType(parameter.name))
             {
                 Undo.RecordObject(target, "Modify Synchronize Parameter " + parameter.name);
                 this.m_Target.SetParameterSynchronized(parameter.name, (PhotonAnimatorView.ParameterType) parameter.type, value);

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