Advertisement
napland

CustomTransformInspector Random Rotation

Aug 19th, 2016
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1.     public AxisFlag rotationAxisFlag;
  2.     private void RandomRotatationInspector()
  3.     {
  4.         EditorGUILayout.LabelField("Random Rotation", EditorStyles.boldLabel, layoutMaxWidth);
  5.         rotationAxisFlag = (AxisFlag)EditorGUILayout.EnumMaskField("Rotation Axis", rotationAxisFlag, layoutMaxWidth);
  6.  
  7.         Transform[] selectedTransforms = Selection.transforms;
  8.  
  9.         string label = "Rotate " + _transform.name;
  10.         if (selectedTransforms.Length > 1)
  11.             label = "Rotate selected";
  12.  
  13.         if (Button(label))
  14.         {
  15.             RandomRotate(rotationAxisFlag , selectedTransforms);
  16.         }
  17.     }
  18.  
  19.     private void RandomRotate(AxisFlag axis , Transform[] selected)
  20.     {
  21.         for (int i = 0; i < selected.Length; i++)
  22.         {
  23.             Vector3 temp = selected[i].localEulerAngles;
  24.  
  25.             if ((axis & AxisFlag.X) == AxisFlag.X)
  26.                 temp.x = RdmDeg();
  27.  
  28.             if ((axis & AxisFlag.Y) == AxisFlag.Y)
  29.                 temp.y = RdmDeg();
  30.  
  31.             if ((axis & AxisFlag.Z) == AxisFlag.Z)
  32.                 temp.z = RdmDeg();
  33.  
  34.             Undo.RecordObject(_transform, "random rotate " + selected[i].name);
  35.             selected[i].localEulerAngles = temp;
  36.         }
  37.     }
  38.  
  39.     private float RdmDeg()
  40.     {
  41.         return Random.Range(0f, 360f);
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement