Created
September 30, 2014 16:47
-
-
Save bcatcho/a2456f52ca2421b9752e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
namespace CatchCo.Diagram.EditorScripts | |
{ | |
public class SpriteHelperEditorWindow : EditorWindow | |
{ | |
[MenuItem ("CatchCo/Sprite Helper")] | |
private static void Init () | |
{ | |
EditorWindow.GetWindow (typeof(SpriteHelperEditorWindow)); | |
} | |
private void OnGUI () | |
{ | |
if (GUILayout.Button ("Truncate all rotations")) { | |
TruncateAllRotationsInScene (); | |
} | |
} | |
private void TruncateAllRotationsInScene () | |
{ | |
Undo.IncrementCurrentGroup (); | |
var transforms = Object.FindObjectsOfType<Transform> (); | |
Undo.RecordObjects (transforms, "Undo truncate all rotations"); | |
foreach (var tx in transforms) { | |
tx.localEulerAngles = TruncateRotation (tx.localEulerAngles); | |
EditorUtility.SetDirty (tx); | |
} | |
Undo.CollapseUndoOperations (Undo.GetCurrentGroup ()); | |
} | |
private Vector3 TruncateRotation (Vector3 localEulerAngles) | |
{ | |
localEulerAngles.x = Mathf.RoundToInt (localEulerAngles.x); | |
localEulerAngles.y = Mathf.RoundToInt (localEulerAngles.y); | |
localEulerAngles.z = Mathf.RoundToInt (localEulerAngles.z); | |
return localEulerAngles; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment