Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if UNITY_EDITOR && UNITY_STANDALONE_WIN
- #if UNITY_ANDROID
- Update(){}
- #if UNITY_STANDALONE_WIN
- 10000 строк кода
- #endif
- #if UNITY_ANDROID
- 10000 строк кода
- #endif
- public interface IInputController {
- List<Vector3> OnTouch();
- bool IsCursorMoving();
- bool IsTouchEnd();
- }
- public class WinController : MonoBehaviour, IInputController {
- public List<Vector3> OnTouch() {
- List<Vector3> list = new List<Vector3>();
- if (Input.GetMouseButton(0))
- list.Add(Input.mousePosition);
- return list;
- }
- public bool IsCursorMoving() {
- if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
- return true;
- return false;
- }
- public bool IsTouchEnd() {
- if (Input.GetMouseButtonUp(0)) {
- return true;
- }
- return false;
- }
- }
- public class AndroidController : MonoBehaviour, IInputController {
- private const int MAX_COUNT_TOUCHES = 2;
- public List<Vector3> OnTouch() {
- List<Vector3> list = new List<Vector3>();
- for (var i = 0; i < Input.touchCount; ++i) {
- var phase = Input.GetTouch(i).phase;
- if (phase == TouchPhase.Stationary || phase == TouchPhase.Moved) {
- list.Add(Input.GetTouch(i).position);
- }
- if (list.Count >= MAX_COUNT_TOUCHES)
- break;
- }
- return list;
- }
- public bool IsCursorMoving() {
- if (Input.GetTouch(0).phase == TouchPhase.Moved)
- return true;
- return false;
- }
- public bool IsTouchEnd() {
- for (var i = 0; i < Input.touchCount; ++i) {
- var phase = Input.GetTouch(i).phase;
- if (phase == TouchPhase.Ended)
- return true;
- }
- return false;
- }
- }
- class ControlScript : MonoBehaviour {
- public IInputController inputController;
- void Start() {
- inputController = GetInputController();
- }
- private IInputController GetInputController() {
- IInputController controller = GetComponent<WinController>();
- #if UNITY_STANDALONE_WIN
- IInputController controller = GetComponent<WinController>();
- #endif
- #if UNITY_ANDROID
- IInputController controller = GetComponent<AndroidController>();
- #endif
- return controller;
- }
- }
- void Update() {
- if (inputController.IsTouchEnd())
- Debug.Log("Пожалуюсь в спец органы на тебя!");
- if (inputController.OnTouch().Count > 0)
- Debug.Log("Че тыкаешь?");
- if (inputController.IsCursorMoving())
- Debug.Log("А-а-а, помогите, спасите, меня тошнит!");
- }
- RuntimePlatform platform = Application.platform;
- if(platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer) {
- // do smth
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement