123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using Assets.Scripts.Models;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- public class TouchScript : MonoBehaviour
- {
-
- public enum Tools { Move = 0, Rotate = 1, Scale = 2, Rectangle = 3 }
- public static Tools tools = Tools.Scale;
-
- void Start()
- {
- }
- void Update()
- {
- if (Input.touchCount > 0)
- {
- Debug.Log("Global touch!");
- }
- }
- private Vector3 screenPoint;
- private Vector3 offset;
- private Vector3 curScreenPoint;
- private Vector3 curPosition;
- public float horizontalSpeed = 1.0F;
- public float verticalSpeed = 1.0F;
- private Vector3 scaleChange = new Vector3(-0.001f, -0.001f, -0.001f);
- private Vector3 positionChange = new Vector3(0.0f, -0.0005f, 0.0f);
- private bool increase = false;
- public GameObject panel;
-
- void OnMouseDown()
- {
-
- switch (tools)
- {
- case Tools.Move:
- screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
- offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
-
- break;
- case Tools.Rotate:
-
- break;
- case Tools.Scale:
- increase = !increase;
-
- break;
-
-
-
- }
- }
-
- void OnMouseDrag()
- {
- float h = horizontalSpeed * Input.GetAxis("Mouse X");
- float v = verticalSpeed * Input.GetAxis("Mouse Y");
- switch (tools)
- {
- case Tools.Move:
- curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
- curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
- transform.position = curPosition;
- panel.transform.position = transform.position;
- break;
- case Tools.Rotate:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- break;
- case Tools.Scale:
-
-
-
- if (increase)
- {
- scaleChange = new Vector3(0.01f, 0, 0.01f);
- positionChange = new Vector3(0.05f, 0, 0.05f);
- }
- else
- {
- scaleChange = new Vector3(-0.01f, 0, -0.01f);
- positionChange = new Vector3(-0.05f, 0, -0.05f);
- }
- transform.transform.localScale += scaleChange;
- transform.transform.position += positionChange;
-
-
- if (transform.transform.localScale.y < 0.01f || transform.transform.localScale.y > 10.0f)
- {
- increase = !increase;
- }
-
- panel.transform.localScale = transform.localScale;
- break;
- case Tools.Rectangle:
-
-
-
-
-
- break;
- }
- }
- void OnMouseUp()
- {
- }
- }
|