Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. /// <summary>
  4. /// Editor上でCameraをキーボード操作するためのコンポーネント
  5. /// </summary>
  6. public class EditorCamera : MonoBehaviour
  7. {
  8. const float Angle = 30f;
  9. const float Speed = 0.25f;
  10.  
  11. bool IsShift { get { return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); } }
  12. bool shouldRotateLeft { get { return !IsShift && (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)); } }
  13. bool shouldRotateRight { get { return !IsShift && (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)); } }
  14. bool shouldMoveforwad { get { return !IsShift && (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)); } }
  15. bool shouldMoveBack { get { return !IsShift && (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S)); } }
  16. bool shouldMoveLeft { get { return IsShift && (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)); } }
  17. bool shouldMoveRight { get { return IsShift && (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)); } }
  18. bool shouldMoveUp { get { return IsShift && (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)); } }
  19. bool shouldMoveDown { get { return IsShift && (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S)); } }
  20.  
  21. void Update()
  22. {
  23. // [←|A]キーで左回転
  24. if (shouldRotateLeft) { transform.Rotate(0, -Angle, 0); }
  25. // [→|D]キーで右回転
  26. if (shouldRotateRight) { transform.Rotate(0, Angle, 0); }
  27. // [↑|W]キーで前方移動
  28. if (shouldMoveforwad) { transform.position += transform.forward.normalized * Speed; }
  29. // [↓|S]キーで後方移動
  30. if (shouldMoveBack) { transform.position -= transform.forward.normalized * Speed; }
  31. // [Shift+(←|A)]キーで左方移動
  32. if (shouldMoveLeft) { transform.position -= transform.right.normalized * Speed; }
  33. // [Shift+(→|D)]キーで右方移動
  34. if (shouldMoveRight) { transform.position += transform.right.normalized * Speed; }
  35. // [Shift+(↑|W)]キーで上方移動
  36. if (shouldMoveUp) { transform.position += transform.up.normalized * Speed; }
  37. // [Shift+(↓|S)]キーで下方移動
  38. if (shouldMoveDown) { transform.position -= transform.up.normalized * Speed; }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement