123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- using UnityEngine.AI;
- using UnityEngine.EventSystems;
- using System;
- public class SwipeMove : MonoBehaviour {
- public float MaxSpeed = 10;
- public float DefoultSpeed = 10;
- public float SPEED = 10;
- public float SwipeMoveSide = 0.5f;
- public float SwipeMoveForward = 0.5f;
- public float SwipeMoveBack = 0.5f;
- public RunnersController RunnerController;
- private NavMeshAgent Agent;
-
- public void Start()
- {
- RunnerController = GetComponent<RunnersController>();
- Agent = GetComponent<NavMeshAgent>();
- }
- void UpdateDestination()
- {
- //Agent.SetDestination(Core.Instance.GetComponent<LevelTargets>().ListLevelTargets[Core.Instance.GetComponent<LevelTargets>().CurTarget].position);
- RunnerController.Destination();
- }
- public void SlideBackward()
- {
- timer = defaultTimerValue;
- DirSwipe = DirectionSwipe.Back;
- Agent.speed -= 0.5f;
- }
- public void SlideForward()
- {
- timer = defaultTimerValue;
- DirSwipe = DirectionSwipe.Forward;
- Agent.speed += 0.5f;
-
- }
- public void SlideLeft()
- {
- timer = defaultTimerValue;
- DirSwipe = DirectionSwipe.Left;
-
- }
- public void SlideRight()
- {
- timer = defaultTimerValue;
- DirSwipe = DirectionSwipe.Right;
- }
- public enum DirectionSwipe
- {
- Left,
- Right,
- Forward,
- Back,
- None
- }
- public void SlideNone()
- {
- DirSwipe = DirectionSwipe.None;
- }
- public DirectionSwipe DirSwipe = DirectionSwipe.None;
- private float defaultTimerValue = 0.3f;
- private float timer;
- private bool GettingControlPlayer;
- private void Update()
- {
- if(Core.Instance.IsGameMode != Core.StateModeGame.IsGameMode )
- {
- return;
- }
- if(Agent.speed <=0)
- {
- UIManager.Instance.GameOverPanel.gameObject.SetActive(true);
- UIManager.Instance.GameOverPanel.DOFade(1, 0.5f);
- return;
- }
- Agent.speed -= Time.deltaTime * 0.1f;
- if(UIManager.Instance.RacePanel.gameObject.activeSelf && Core.Instance.IsGameMode== Core.StateModeGame.IsGameMode && RunnerController.gameObject.activeSelf)
- {
- timer -= Time.deltaTime;
- //switch(DirSwipe)
- //{
- // case DirectionSwipe.Left:
- // if(timer>0)
- // {
- // this.transform.position = Vector3.Slerp(this.transform.position, SwipeMoveSide * -transform.right + this.transform.position, 3f * Time.fixedDeltaTime);
- // return;
- // }
- // //this.transform.Translate(SPEED * Vector3.right * Time.deltaTime, Space.Self);
- // break;
- // case DirectionSwipe.Right:
- // if (timer > 0)
- // {
- // this.transform.position = Vector3.Slerp(this.transform.position, SwipeMoveSide * transform.right + this.transform.position, 3f * Time.fixedDeltaTime);
- // return;
- // }
- // //this.transform.Translate(SPEED * Vector3.left * Time.deltaTime, Space.Self);
- // break;
- // case DirectionSwipe.Forward:
- // if (timer > 0)
- // {
- // this.transform.position = Vector3.Slerp(this.transform.position, SwipeMoveForward * transform.forward + this.transform.position, 3f * Time.fixedDeltaTime);
- // return;
- // }
- // //this.transform.Translate(SPEED * Vector3.forward * Time.deltaTime, Space.Self);
- // break;
- // case DirectionSwipe.Back:
- // if (timer > 0)
- // {
- // this.transform.position = Vector3.Slerp(this.transform.position, SwipeMoveBack * -transform.forward + this.transform.position, 3f * Time.fixedDeltaTime);
- // return;
- // }
- // //this.transform.Translate(SPEED * Vector3.back * Time.deltaTime, Space.Self);
- // break;
- //}
- //UpdateDestination();
- //DirSwipe = DirectionSwipe.None;
- }
- if (Core.Instance.IsGameMode != Core.StateModeGame.Kiss && Core.Instance.IsGameMode != Core.StateModeGame.StartLevel)
- {
- if (RunnerController.IsPlayer)
- {
- if (Input.GetMouseButtonDown(0))
- {
- this.OnMouseDown();
- this.GettingControlPlayer = true;
- }
- if (Input.GetMouseButtonUp(0))
- {
- this.GettingControlPlayer = false;
- }
- if (GettingControlPlayer)
- {
- this.OnMouseDrag();
- }
- }
- }
-
- //if (Input.touchCount > 0)
- //{
- // Touch touch = Input.GetTouch(0); // get first touch since touch count is greater than zero
- // if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
- // {
- // // get the touch position from the screen touch to world point
- // Vector3 touchedPos = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10));
- // // lerp and set the position of the current object to that of the touch, but smoothly over time.
- // transform.position = Vector3.Lerp(transform.position, touchedPos, Time.deltaTime);
- // }
- //}
- }
- private Vector3 screenPoint;
- private Vector3 offset;
- void OnMouseDown()
- {
- screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
- offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, screenPoint.y, screenPoint.z));
- }
- void OnMouseDrag()
- {
- Vector3 cursorPoint = new Vector3(Input.mousePosition.x, screenPoint.y, screenPoint.z);
- Vector3 cursorPosition = Camera.main.ScreenToWorldPoint(cursorPoint) + offset;
- transform.position = Vector3.Lerp(transform.position,cursorPosition, 2* Time.deltaTime);
- //GetComponent<Animator>().SetFloat("Blend", 0.0f + );
- }
- private enum DraggedDirection
- {
- Up,
- Down,
- Right,
- Left
- }
- private DraggedDirection GetDragDirection(Vector3 dragVector)
- {
- float positiveX = Mathf.Abs(dragVector.x);
- float positiveY = Mathf.Abs(dragVector.y);
- DraggedDirection draggedDir;
- draggedDir = (dragVector.x > 0) ? DraggedDirection.Right : DraggedDirection.Left;
- //if (positiveX > positiveY)
- //{
-
- //}
- //else
- //{
- // draggedDir = (dragVector.y > 0) ? DraggedDirection.Up : DraggedDirection.Down;
- //}
- Debug.Log(draggedDir);
- return draggedDir;
- }
- public void OnEndDrag(PointerEventData eventData)
- {
- Debug.Log("Press position + " + eventData.pressPosition);
- Debug.Log("End position + " + eventData.position);
- Vector3 dragVectorDirection = (eventData.position - eventData.pressPosition).normalized;
- Debug.Log("norm + " + dragVectorDirection);
- GetDragDirection(dragVectorDirection);
- }
- }
|