Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Created March 5, 2015 15:09
Show Gist options
  • Save kyubuns/49fa73bdf808049c0aec to your computer and use it in GitHub Desktop.
Save kyubuns/49fa73bdf808049c0aec to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(CanvasRenderer))]
public class CanvasRendererMover : Editor
{
static int hint = "WidgetHash".GetHashCode();
void OnSceneGUI()
{
if(UnityEditor.Tools.current != Tool.Rect) return;
var e = Event.current;
int id = GUIUtility.GetControlID(hint, FocusType.Keyboard);
var type = e.GetTypeForControl(id);
if(type != EventType.keyDown) return;
if(e.keyCode == KeyCode.UpArrow) Move(target, new Vector3(0.0f, 1.0f), e);
else if(e.keyCode == KeyCode.RightArrow) Move(target, new Vector3(1.0f, 0.0f), e);
else if(e.keyCode == KeyCode.DownArrow) Move(target, new Vector3(0.0f, -1.0f), e);
else if(e.keyCode == KeyCode.LeftArrow) Move(target, new Vector3(-1.0f, 0.0f), e);
}
void Move(object obj, Vector3 v, Event e)
{
var g = obj as CanvasRenderer;
g.transform.localPosition += v;
e.Use();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment