예제 #1
0
    void Start()
    {
        Swipeable swipeable = GetComponent <Swipeable>();

        swipeable.onSwipe   = OnSwipe;
        swipeable.onTouched = OnTouched;
    }
예제 #2
0
    void Resolve(Vector2 touchPos, int fingerID)
    {
        TouchInfo touchInfo = touchInfos.Find(t => t.touchID == fingerID);

        if (touchInfo == null)
        {
            return;
        }

        Vector3 startPosition = touchInfo.touchPos;
        Vector3 newPosition   = touchPos;

        float distance  = Vector3.Distance(startPosition, newPosition);
        float deltaTime = Time.time - touchInfo.time;

        Vector3 direction = newPosition - startPosition;

        direction.Normalize();

        TouchResult touchResult = new TouchResult(distance, deltaTime, direction);

        Swipeable swipeable = touchInfo.touchedObject.GetComponent <Swipeable>();

        if (distance < clickDistanceThreshold)
        {
            swipeable.Touched(touchResult);
        }
        else
        {
            swipeable.Swipe(touchResult);
        }

        touchInfos.Remove(touchInfo);
    }
예제 #3
0
    // -------------------------------------------------------------------------------

    public void OnDrag(PointerEventData eventData)
    {
        if (Swipeable.CheckForSwipe(eventData, SwipeCheckData))
        {
            Hide();
            SlidingPanel.Show();
        }
    }
예제 #4
0
    // -------------------------------------------------------------------------------

    public void OnDrag(PointerEventData eventData)
    {
        if (Swipeable.CheckForSwipe(eventData, SwipeToCloseData))
        {
            SlideOff();
        }
        else if (Swipeable.CheckForSwipe(eventData, SwipeToOpenData))
        {
            SlideOn();
        }
    }
예제 #5
0
 private static void PerformTap(Ray ray)
 {
     if (Physics.Raycast(ray, out RaycastHit hitInfo, float.MaxValue, sm_raycastMask))
     {
         Swipeable component = hitInfo.transform.gameObject.GetComponent <Swipeable>();
         if (component != null)
         {
             component.SwipeEntered();
         }
     }
 }
예제 #6
0
        void Awake()
        {
            if (!Util.DontDestroyOnLoad <Player>(gameObject))
            {
                return;
            }

            Instance   = this;
            _swipeable = GetComponent <Swipeable>();
            SetSwipeEvent();
            _level = Level.Instance;
        }
예제 #7
0
    void AddTouch(Touch touch)
    {
        Ray ray = Camera.main.ScreenPointToRay(touch.position);

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            GameObject hitGameObject = hit.collider.gameObject;
            Swipeable  swipeable     = hitGameObject.GetComponent <Swipeable>();

            if (swipeable)
            {
                touchInfos.Add(new TouchInfo(touch.position, touch.fingerId, hitGameObject, Time.time));
            }
        }
    }
예제 #8
0
    void AddMouse()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            GameObject hitGameObject = hit.collider.gameObject;
            Swipeable  swipeable     = hitGameObject.GetComponent <Swipeable>();

            if (swipeable)
            {
                touchInfos.Add(new TouchInfo(Input.mousePosition, -1, hitGameObject, Time.time));
            }
        }
    }
예제 #9
0
    private void onTap(Transform tapTarget)
    {
        if (tapTarget == null)
        {
            return;
        }

        Debug.Log($"Tap on {tapTarget.name}");

        Tappable tappable = tapTarget.GetComponent <Tappable>();

        tappable?.onTap();

        Swipeable swipeable = tapTarget.GetComponent <Swipeable>();

        if (swipeable != null)
        {
            currentSwipe = swipeable.onSwipeStart();
        }
    }
예제 #10
0
    private void CheckSwipe(Touch touch)
    {
        touchPositions[touch.fingerId].Add(touch.position);

        Vector3 firstPosition = touchPositions[touch.fingerId][0];
        Vector3 lastPosition  = touchPositions[touch.fingerId][touchPositions[touch.fingerId].Count - 1];

        Vector3 firstPoint = Camera.main.ScreenToWorldPoint(new Vector3(firstPosition.x, firstPosition.y, Camera.main.nearClipPlane));
        Vector3 lastPoint  = Camera.main.ScreenToWorldPoint(new Vector3(lastPosition.x, lastPosition.y, Camera.main.nearClipPlane));

        Vector3 direction = lastPoint - firstPoint;

        swipeDirections.Add(direction);
        // Check if the touch hit a swipable
        Swipeable swipeable = GetSwipeable(raycastHits[touch.fingerId].Value);

        if (swipeable)
        {
            swipeable.OnSwipe(raycastHits[touch.fingerId].Value, direction);
            touchPositions[touch.fingerId].Clear();
            touchPositions[touch.fingerId].Add(touch.position);
        }
    }
예제 #11
0
    void Update()
    {
        if (IsInit || !unitID.IsReady())
        {
            return;
        }
        IsInit = true;

        GameObject player = GameSharedData.GetLocalPlayer();

        // don't do it for other players

        /*    if (player.GetComponent<Unit_ID>().GetPlayerIndex() != GetComponent<Unit_ID>().GetPlayerIndex())
         *  {
         *      enabled = false;
         *      return;
         *  }*/

        Swipeable swipeable = GetComponent <Swipeable>();

        swipeable.onSwipe   = OnSwipe;
        swipeable.onTouched = OnTouched;
    }
예제 #12
0
 public VerticalSwipe(Swipeable target, float completePixelLength) : base(target)
 {
     this.completePixelLength = completePixelLength;
 }
예제 #13
0
 public HorizontalSwipe(Swipeable target, float completePixelLength) : base(target)
 {
     this.completePixelLength = completePixelLength;
 }
예제 #14
0
 protected Swipe(Swipeable target)
 {
     this.target = target;
 }
예제 #15
0
 public DiagonalSwipe(Swipeable target, float length) : base(target)
 {
     this.length = length;
 }