Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. #if UNITY_EDITOR && UNITY_STANDALONE_WIN
  2. #if UNITY_ANDROID
  3.  
  4. Update(){}
  5.  
  6. #if UNITY_STANDALONE_WIN
  7. 10000 строк кода
  8. #endif
  9. #if UNITY_ANDROID
  10. 10000 строк кода
  11. #endif
  12.  
  13. public interface IInputController {
  14.  
  15. List<Vector3> OnTouch();
  16.  
  17. bool IsCursorMoving();
  18.  
  19. bool IsTouchEnd();
  20. }
  21.  
  22. public class WinController : MonoBehaviour, IInputController {
  23.  
  24. public List<Vector3> OnTouch() {
  25. List<Vector3> list = new List<Vector3>();
  26.  
  27. if (Input.GetMouseButton(0))
  28. list.Add(Input.mousePosition);
  29.  
  30. return list;
  31. }
  32.  
  33.  
  34. public bool IsCursorMoving() {
  35. if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
  36. return true;
  37.  
  38. return false;
  39. }
  40.  
  41.  
  42. public bool IsTouchEnd() {
  43. if (Input.GetMouseButtonUp(0)) {
  44. return true;
  45. }
  46.  
  47. return false;
  48. }
  49. }
  50.  
  51. public class AndroidController : MonoBehaviour, IInputController {
  52.  
  53. private const int MAX_COUNT_TOUCHES = 2;
  54.  
  55. public List<Vector3> OnTouch() {
  56. List<Vector3> list = new List<Vector3>();
  57.  
  58. for (var i = 0; i < Input.touchCount; ++i) {
  59. var phase = Input.GetTouch(i).phase;
  60. if (phase == TouchPhase.Stationary || phase == TouchPhase.Moved) {
  61. list.Add(Input.GetTouch(i).position);
  62. }
  63. if (list.Count >= MAX_COUNT_TOUCHES)
  64. break;
  65. }
  66.  
  67. return list;
  68. }
  69.  
  70.  
  71. public bool IsCursorMoving() {
  72. if (Input.GetTouch(0).phase == TouchPhase.Moved)
  73. return true;
  74.  
  75. return false;
  76. }
  77.  
  78.  
  79. public bool IsTouchEnd() {
  80. for (var i = 0; i < Input.touchCount; ++i) {
  81. var phase = Input.GetTouch(i).phase;
  82. if (phase == TouchPhase.Ended)
  83. return true;
  84. }
  85.  
  86. return false;
  87. }
  88. }
  89.  
  90. class ControlScript : MonoBehaviour {
  91. public IInputController inputController;
  92.  
  93. void Start() {
  94. inputController = GetInputController();
  95. }
  96.  
  97. private IInputController GetInputController() {
  98. IInputController controller = GetComponent<WinController>();
  99.  
  100. #if UNITY_STANDALONE_WIN
  101. IInputController controller = GetComponent<WinController>();
  102. #endif
  103. #if UNITY_ANDROID
  104. IInputController controller = GetComponent<AndroidController>();
  105. #endif
  106.  
  107. return controller;
  108. }
  109. }
  110.  
  111. void Update() {
  112. if (inputController.IsTouchEnd())
  113. Debug.Log("Пожалуюсь в спец органы на тебя!");
  114.  
  115. if (inputController.OnTouch().Count > 0)
  116. Debug.Log("Че тыкаешь?");
  117.  
  118. if (inputController.IsCursorMoving())
  119. Debug.Log("А-а-а, помогите, спасите, меня тошнит!");
  120. }
  121.  
  122. RuntimePlatform platform = Application.platform;
  123. if(platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer) {
  124. // do smth
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement