Advertisement
napland

CustomTransformComponent part 3-2

Jul 30th, 2016
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1.     private bool showLocalAxisToggle = false;
  2.     private void ShowLocalAxisComponentToggle()
  3.     {
  4.         EditorGUILayout.Space();
  5.         EditorGUILayout.Space();
  6.         ShowLocalAxis showLocalAxis = _transform.gameObject.GetComponent<ShowLocalAxis>();
  7.  
  8.        
  9.         if (showLocalAxis == null)
  10.             showLocalAxisToggle = false;
  11.         else
  12.             showLocalAxisToggle = true;
  13.  
  14.         EditorGUILayout.BeginHorizontal();
  15.         EditorGUILayout.LabelField("Show local rotation handles", EditorStyles.boldLabel);
  16.         EditorGUI.BeginChangeCheck();
  17.         // We use GUILayout.Toggle here instead of EditorGUI toggle because they cause horizontal overflow
  18.         showLocalAxisToggle = GUILayout.Toggle(showLocalAxisToggle, (showLocalAxisToggle ? "on" : "off" ));
  19.         if (EditorGUI.EndChangeCheck())
  20.         {
  21.             if (showLocalAxisToggle == true)
  22.             {
  23.                 showLocalAxis = _transform.gameObject.AddComponent<ShowLocalAxis>();
  24.                 int componentCount = _transform.GetComponents<Component>().Length;
  25.                 for (int i = 1; i < componentCount; i++)
  26.                 {
  27.                     UnityEditorInternal.ComponentUtility.MoveComponentUp(showLocalAxis);
  28.                 }
  29.             }
  30.             else
  31.             {
  32.                 showLocalAxis.destroyWhenSafe = true;
  33.             }
  34.         }
  35.         EditorGUILayout.EndHorizontal();
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement