Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- /// <summary>
- /// Editor上でCameraをキーボード操作するためのコンポーネント
- /// </summary>
- public class EditorCamera : MonoBehaviour
- {
- const float Angle = 30f;
- const float Speed = 0.25f;
- bool IsShift { get { return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); } }
- bool shouldRotateLeft { get { return !IsShift && (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)); } }
- bool shouldRotateRight { get { return !IsShift && (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)); } }
- bool shouldMoveforwad { get { return !IsShift && (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)); } }
- bool shouldMoveBack { get { return !IsShift && (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S)); } }
- bool shouldMoveLeft { get { return IsShift && (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)); } }
- bool shouldMoveRight { get { return IsShift && (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)); } }
- bool shouldMoveUp { get { return IsShift && (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)); } }
- bool shouldMoveDown { get { return IsShift && (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S)); } }
- void Update()
- {
- // [←|A]キーで左回転
- if (shouldRotateLeft) { transform.Rotate(0, -Angle, 0); }
- // [→|D]キーで右回転
- if (shouldRotateRight) { transform.Rotate(0, Angle, 0); }
- // [↑|W]キーで前方移動
- if (shouldMoveforwad) { transform.position += transform.forward.normalized * Speed; }
- // [↓|S]キーで後方移動
- if (shouldMoveBack) { transform.position -= transform.forward.normalized * Speed; }
- // [Shift+(←|A)]キーで左方移動
- if (shouldMoveLeft) { transform.position -= transform.right.normalized * Speed; }
- // [Shift+(→|D)]キーで右方移動
- if (shouldMoveRight) { transform.position += transform.right.normalized * Speed; }
- // [Shift+(↑|W)]キーで上方移動
- if (shouldMoveUp) { transform.position += transform.up.normalized * Speed; }
- // [Shift+(↓|S)]キーで下方移動
- if (shouldMoveDown) { transform.position -= transform.up.normalized * Speed; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement