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:

         SerializedProperty gizmoSizeProperty )
     {
         float height = EditorGUIUtility.singleLineHeight;
         float flexibleWidth = Mathf.Max( 40, position.width - EditorGUIUtility.labelWidth - 20 - 75 - 5 - 40 - 5 );

         Rect labelRect = new Rect( position.xMin, position.yMin, EditorGUIUtility.labelWidth, height );
         GUI.Label( labelRect, label );

         Rect enabledRect = new Rect( labelRect.xMax, labelRect.yMin, 20, height );
         EditorGUI.PropertyField( enabledRect, gizmoEnabledProperty, GUIContent.none );

         bool oldGUIEnabled = GUI.enabled;
         GUI.enabled = gizmoEnabledProperty.boolValue;

         Rect colorRect = new Rect( enabledRect.xMax + 5, labelRect.yMin, 70, height );
         EditorGUI.PropertyField( colorRect, gizmoColorProperty, GUIContent.none );

         Rect typeRect = new Rect( colorRect.xMax + 5, labelRect.yMin, flexibleWidth * 0.7f, height );
         EditorGUI.PropertyField( typeRect, gizmoTypeProperty, GUIContent.none );

         Rect sizeLabelRect = new Rect( typeRect.xMax + 10, labelRect.yMin, 30, height );
         GUI.Label( sizeLabelRect, "Size" );

         Rect sizeRect = new Rect( sizeLabelRect.xMax + 5, labelRect.yMin, flexibleWidth * 0.3f, height );
         EditorGUI.PropertyField( sizeRect, gizmoSizeProperty, GUIContent.none );

         GUI.enabled = oldGUIEnabled;
     }