SHARE
TWEET

Unity Quick Sprites

a guest Feb 24th, 2014 49 Never
  1. class SpriteHandler extends EditorWindow {
  2.  
  3.     var selectedObject : Object;
  4.     var locPos : Vector3;
  5.  
  6.     @MenuItem ("Window/Sprite Handler")
  7.     static function ShowWindow () {
  8.         EditorWindow.GetWindow (SpriteHandler);
  9.     }
  10.  
  11.     function OnGUI () {
  12.  
  13.         var e : Event = Event.current;
  14.  
  15.         GUILayout.Label("Settings", EditorStyles.boldLabel);
  16.  
  17.                 if(Selection.activeGameObject) {
  18.             if(!selectedObject) {
  19.                 selectedObject = Selection.activeGameObject;
  20.             }
  21.             selectedObject.name = EditorGUILayout.TextField("Object Name: ", selectedObject.name);
  22.             locPos = selectedObject.transform.localPosition;
  23.                 }
  24.  
  25.         if(e.control && e.type == EventType.KeyUp && e.keyCode == KeyCode.UpArrow) {
  26.             CloneUp();
  27.         }
  28.         if(e.control && e.type == EventType.KeyUp && e.keyCode == KeyCode.DownArrow) {
  29.             CloneDown();
  30.         }
  31.         if(e.control && e.type == EventType.KeyUp && e.keyCode == KeyCode.LeftArrow) {
  32.             CloneLeft();
  33.         }
  34.         if(e.control && e.type == EventType.KeyUp && e.keyCode == KeyCode.RightArrow) {
  35.             CloneRight();
  36.         }
  37.  
  38.     }
  39.  
  40.     function OnInspectorUpdate() {
  41.         Repaint();
  42.     }
  43.  
  44.     function CloneUp() {
  45.         var newObject = Instantiate(selectedObject, Vector3(locPos.x, locPos.y + 1, locPos.z), selectedObject.transform.rotation);
  46.         selectedObject = newObject;
  47.     }
  48.     function CloneDown() {
  49.         var newObject = Instantiate(selectedObject, Vector3(locPos.x, locPos.y - 1, locPos.z), selectedObject.transform.rotation);
  50.         selectedObject = newObject;
  51.     }
  52.     function CloneLeft() {
  53.         var newObject = Instantiate(selectedObject, Vector3(locPos.x - 1, locPos.y, locPos.z), selectedObject.transform.rotation);
  54.         selectedObject = newObject;
  55.     }
  56.     function CloneRight() {
  57.         var newObject = Instantiate(selectedObject, Vector3(locPos.x + 1, locPos.y, locPos.z), selectedObject.transform.rotation);
  58.         selectedObject = newObject;
  59.     }
  60.  
  61.  
  62. }
RAW Paste Data
Top