Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public AxisFlag rotationAxisFlag;
- private void RandomRotatationInspector()
- {
- EditorGUILayout.LabelField("Random Rotation", EditorStyles.boldLabel, layoutMaxWidth);
- rotationAxisFlag = (AxisFlag)EditorGUILayout.EnumMaskField("Rotation Axis", rotationAxisFlag, layoutMaxWidth);
- Transform[] selectedTransforms = Selection.transforms;
- string label = "Rotate " + _transform.name;
- if (selectedTransforms.Length > 1)
- label = "Rotate selected";
- if (Button(label))
- {
- RandomRotate(rotationAxisFlag , selectedTransforms);
- }
- }
- private void RandomRotate(AxisFlag axis , Transform[] selected)
- {
- for (int i = 0; i < selected.Length; i++)
- {
- Vector3 temp = selected[i].localEulerAngles;
- if ((axis & AxisFlag.X) == AxisFlag.X)
- temp.x = RdmDeg();
- if ((axis & AxisFlag.Y) == AxisFlag.Y)
- temp.y = RdmDeg();
- if ((axis & AxisFlag.Z) == AxisFlag.Z)
- temp.z = RdmDeg();
- Undo.RecordObject(_transform, "random rotate " + selected[i].name);
- selected[i].localEulerAngles = temp;
- }
- }
- private float RdmDeg()
- {
- return Random.Range(0f, 360f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement