暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompensateRotationProcessor.cs 1.3KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.ComponentModel;
  2. using UnityEngine.InputSystem.LowLevel;
  3. namespace UnityEngine.InputSystem.Processors
  4. {
  5. [DesignTimeVisible(false)]
  6. internal class CompensateRotationProcessor : InputProcessor<Quaternion>
  7. {
  8. public override Quaternion Process(Quaternion value, InputControl control)
  9. {
  10. if (!InputSystem.settings.compensateForScreenOrientation)
  11. return value;
  12. const float kSqrtOfTwo = 1.4142135623731f;
  13. var q = Quaternion.identity;
  14. switch (InputRuntime.s_Instance.screenOrientation)
  15. {
  16. case ScreenOrientation.PortraitUpsideDown: q = new Quaternion(0.0f, 0.0f, 1.0f /*sin(pi/2)*/, 0.0f /*cos(pi/2)*/); break;
  17. case ScreenOrientation.LandscapeLeft: q = new Quaternion(0.0f, 0.0f, kSqrtOfTwo * 0.5f /*sin(pi/4)*/, -kSqrtOfTwo * 0.5f /*cos(pi/4)*/); break;
  18. case ScreenOrientation.LandscapeRight: q = new Quaternion(0.0f, 0.0f, -kSqrtOfTwo * 0.5f /*sin(3pi/4)*/, -kSqrtOfTwo * 0.5f /*cos(3pi/4)*/); break;
  19. }
  20. return value * q;
  21. }
  22. public override string ToString()
  23. {
  24. return "CompensateRotation()";
  25. }
  26. public override CachingPolicy cachingPolicy => CachingPolicy.EvaluateOnEveryRead;
  27. }
  28. }