Esempio n. 1
0
    public void DrawContinueLine(LeanFinger finger)
    {
        if (Vector2.Distance(finger.GetWorldPosition(10, Camera.current),
                             CollidersPositions[CollidersPositions.Count - 1]) > DistanceBetweenDots)
        //Проверка на минимальное расстояние между точками
        {
            RecalculateFrequencyPoints(finger);
            Positions.Add(finger.GetWorldPosition(10, Camera.current)); // Добавляем точку касания.
            CalculateMainLine(finger);
            if (Positions.Count % 4 != 0)
            //Прорабатываем остаток.(если точек 6, то выше мы использовали формулу только для первых четырех точек, оставшиеся две имеют свою фомрулу безье)
            {
                CalculateRemainder(finger);
            }

            UpdateQuanityLines();
            CollidersPositions.Clear(); //Сброс листа точек для коллайдера
            for (int i = 0; i < dotsForDrawing.Count; i++)
            {
                // Все точки для отрисовки мы добавляем в лист точек коллайдера
                CollidersPositions.Add(dotsForDrawing[i]);
            }

            ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <LineRenderer>().positionCount
                = dotsForDrawing.ToArray().Length;
            ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <LineRenderer>()
            .SetPositions(dotsForDrawing.ToArray());
            ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <EdgeCollider2D>().points =
                CollidersPositions.ToArray();
            FrequencyPoints = temporedFrequencyPoints;
        }
    }
Esempio n. 2
0
 public void StartNewLine(LeanFinger finger)
 {
     if (quanityLines > 0)
     {
         GameObject lineRenderer = GameObject.Instantiate(LineRenderer);
         lineRenderer.transform.parent = transform;
         ListLineRenderers.Add(lineRenderer);                        //при каждом касании создавать новую линию.
         Positions.Add(finger.GetWorldPosition(10, Camera.current)); //Самая первая точка касания
         CollidersPositions.Clear();
         CollidersPositions.Add(finger.GetWorldPosition(10, Camera.current));
         // для коллайдера надо минимум две точки, поэтому создаем две!
         CollidersPositions.Add(finger.GetWorldPosition(10, Camera.current));
         ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <LineRenderer>().positionCount
             =
                 Positions.ToArray().Length;
         ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <LineRenderer>()
         .SetPositions(Positions.ToArray());
         ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <EdgeCollider2D>().points =
             CollidersPositions.ToArray();
         UpdateQuanityLines();
         MainFinger     = finger.Index;
         LastPoint      = 3;
         dotsForDrawing = new List <Vector3>();
     }
 }
Esempio n. 3
0
    /// <summary>
    /// ホールド中のチェック。
    /// </summary>
    public void Check_Holding(LeanFinger finger)
    {
        int mytouch_index = -1;                           //-1のままはおかしい

        for (int i = 0; i < LeanTouch.Fingers.Count; i++) //同時押しでも指を見分けるため
        {
            if (finger.Index == LeanTouch.Fingers[i].Index)
            {
                mytouch_index = i;
                break;
            }
        }

        if (my_Touch[mytouch_index].isHolding == true)        //ホールド中なら
        {
            //Debug.Log("a");
            if (judge.Is_hold_within_range(finger.GetWorldPosition(0), my_Touch[mytouch_index]))             //範囲内なら
            {
                //Debug.Log(finger.GetStartWorldPosition(0));
                //Debug.Log("ホールド範囲");
                //何もしないかホールド中のエフェクト再生
            }
            else
            {
                //Debug.Log("ホールド範囲外");
                my_Touch[mytouch_index].isHolding = false;
                judge.Hold_judge(my_Touch[mytouch_index], time_Manager.Get_time());
            }
        }
    }
Esempio n. 4
0
        private void OnFingerTap(LeanFinger finger)
        {
            if (finger.StartedOverGui)
            {
                return;
            }
            if (!Data.IsRoadActive)
            {
                return;
            }
            if (Data.RoadGuid == GridDataContainer.RoadInTownGuid)//это значит что это дорога под городом и не должна нажиматься вообще
            {
                LeanTouch.OnFingerTap -= OnFingerTap;
                return;
            }

            var roadController = GetComponentInParent <RoadController>();
            var tappedObj      = finger.GetRay().GetRayHitWithMask("RoadTile");

            if (!tappedObj?.gameObject)
            {
                roadController.UpdateAnimatorState(false);
                return;
            }
            var tilemapPos = TilemapsDataContainer.Instance.WorldToCell(finger.GetWorldPosition(10));

            if (GridDataContainer.Instance.RoadTilesData.TryGetValue(tilemapPos, out var roadTileData))
            {
                roadController.UpdateAnimatorState(roadTileData.RoadGuid == Data.RoadGuid);
            }
            else
            {
                roadController.UpdateAnimatorState(false);
            }
        }
Esempio n. 5
0
    public void Select(LeanFinger finger)
    {
        var point = finger.GetWorldPosition(0);

        point.z = 0;
        var        localMask = LayerMask.GetMask("Enemy");
        var        hits      = Physics2D.OverlapCircleAll(point, radius, localMask);
        GameObject target    = null;
        float      distance  = 999f;

        foreach (var hit in hits)
        {
            var targettable = hit.GetComponent <ITarget>();
            if (targettable != null)
            {
                var dist = (point - hit.transform.position).magnitude;
                if (dist < distance)
                {
                    target = hit.gameObject;
                }
            }
        }
        if (target != null)
        {
            target.GetComponent <ITarget>().SetTarget();
        }
    }
Esempio n. 6
0
 public void RecalculateFrequencyPoints(LeanFinger finger)
 {
     temporedFrequencyPoints = FrequencyPoints;
     FrequencyPoints         = Vector2.Distance(finger.GetWorldPosition(10, Camera.current),
                                                CollidersPositions[CollidersPositions.Count - 1]) - DistanceBetweenDots;
     FrequencyPoints /= distancePerDot;
     FrequencyPoints  = (int)FrequencyPoints + temporedFrequencyPoints;
 }
Esempio n. 7
0
 void Set_My_touch(float touchTime, LeanFinger finger, int mytouch_index)
 {
     my_Touch[mytouch_index].fingerID      = finger.Index;
     my_Touch[mytouch_index].touchTime     = touchTime;
     my_Touch[mytouch_index].touchPos      = finger.GetWorldPosition(0);
     my_Touch[mytouch_index].isTouching    = true;
     my_Touch[mytouch_index].mytouch_index = mytouch_index;
     //Debug.Log("Set_My_touch " + my_Touch.touchPos);
 }
Esempio n. 8
0
        private Component FindComponentUnder(LeanFinger finger)
        {
            var component = default(Component);
            // Find the position under the current finger
            var point = finger.GetWorldPosition(1.0f);

            // Find the collider at this position
            component = Physics2D.OverlapPoint(point, LayerMask);
            return(component);
        }
Esempio n. 9
0
    public void OnTapItemButton(LeanFinger finger)
    {
        Vector3    fingerPos  = finger.GetWorldPosition(10f, Camera.main);
        GameObject buttonItem = GeneralTools.Instance.ItemButtonAt(fingerPos);

        if (buttonItem != null)
        {
            overallDirector.Instance._selectedItemName = buttonItem.GetComponent <ShowDescription>().itemName;
        }
    }
Esempio n. 10
0
    public void SetReference(LeanFinger finger)
    {
        referenceRotation = rotationTarget.localRotation.eulerAngles.z;
        var   pos      = finger.GetWorldPosition(0);
        float AngleRad = Mathf.Atan2(pos.y - transform.position.y, pos.x - transform.position.x);
        // Get Angle in Degrees
        float AngleDeg = (180 / Mathf.PI) * AngleRad;

        referenceAngle = AngleDeg /* + transform.localRotation.eulerAngles.z*/;
    }
Esempio n. 11
0
        private void OnFingerTap(LeanFinger finger)
        {
            if (finger.StartedOverGui)
            {
                return;
            }

            var tilemapPos = TilemapsDataContainer.Instance.WorldToCell(finger.GetWorldPosition(10));

            animator.SetBool(ShowParameterName, tilemapPos == Position);
        }
    public void OnFingerDown(LeanFinger finger)
    {
        if (this.finger == null)
        {
            this.finger = finger;

            slingPositionOnDown = transform.localPosition;

            Camera camera = overrideCamera != null ? overrideCamera : Camera.main;
            touchPositionOnDown = finger.GetWorldPosition(Mathf.Abs(camera.transform.position.z), camera);
        }
    }
Esempio n. 13
0
 private void OnFingerSet(LeanFinger finger)
 {
     if (lastTappedTownPosition != null)
     {
         var currentHoveredCell = TownTilemap.WorldToCell(finger.GetWorldPosition(10));
         if (lastHoveredCell != currentHoveredCell && currentHoveredCell != lastTappedTownPosition)
         {
             var path = BresenhamLine.GetPath(lastTappedTownPosition.Value, currentHoveredCell);
             RedrawPath(lastPath, path);
             lastPath = path;
         }
         lastHoveredCell = currentHoveredCell;
     }
 }
Esempio n. 14
0
        private void OnTap(LeanFinger finger)
        {
            var screenPos = finger.ScreenPosition;
            var worldPos  = finger.GetWorldPosition(10, Camera.current);

            Utils.LogConditional($"{nameof(InputManager)} + tap " +
                                 $"| {nameof(screenPos)} = {screenPos} " +
                                 $"| {nameof(worldPos)} = {worldPos}");

            if (Physics2D.OverlapPoint(worldPos, _selectableLayer.AsMask))
            {
                Tapped?.Invoke(worldPos);
            }
        }
Esempio n. 15
0
    public void Rotate(LeanFinger finger)
    {
        if (menu.activeSlot != null)
        {
            menu.activeSlot.Unselect();
            menu.activeSlot = null;
        }
        var   pos      = finger.GetWorldPosition(0);
        float AngleRad = Mathf.Atan2(pos.y - transform.position.y, pos.x - transform.position.x);
        // Get Angle in Degrees
        float AngleDeg = (180 / Mathf.PI) * AngleRad;

        // Rotate Object
        rotationTarget.localRotation = Quaternion.Euler(0, 0, AngleDeg - referenceAngle + referenceRotation);
    }
Esempio n. 16
0
    public void OnFingerUp(LeanFinger finger)
    {
        if (isOnCooldownAfterChangeTool)
        {
            return;
        }

        if (finger.Index == MainFinger)
        {
            float temporalDistance = DistanceBetweenDots; // Переменная для временного хранения дистанции между точек.
            DistanceBetweenDots = 0;
            //Чтобы формула была применима к последней точки касания, мы устанавливаем дистанцию временно равной 0.
            OnFingerSet(finger);                    //имитируем касание в точке отрыва пальца
            DistanceBetweenDots = temporalDistance; // Возвращаем значение дистанции между точек.

            Vector2 PosNow           = finger.GetWorldPosition(10, Camera.current);
            float   minDistance      = DistanceBetweenDots + 1;
            string  FoundDescription = FoundLinesEndsNear(ref minDistance, PosNow, true);
            if (minDistance <= DistanceForContinueLine)
            {
                Vector2[] ExpectLine = DeleteAndTakeLine(FoundDescription, true);
                for (int i = 0; i < ExpectLine.Length; i++)
                {
                    Positions.Add(ExpectLine[i]);
                    CollidersPositions.Add(ExpectLine[i]);
                }
                ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <LineRenderer>().positionCount =
                    Positions.ToArray().Length;
                ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <LineRenderer>()
                .SetPositions(Positions.ToArray());
                ListLineRenderers[ListLineRenderers.Count - 1].GetComponent <EdgeCollider2D>().points =
                    CollidersPositions.ToArray();

                MainFinger     = finger.Index;
                LastPoint      = 3;
                lastDots       = 0;
                dotsForDrawing = new List <Vector3>();
            }


            Positions          = new List <Vector3>();
            CollidersPositions = new List <Vector2>();
            LastPoint          = 3;
            lastDots           = 0;
            MainFinger         = -1;
            dotsForDrawing     = new List <Vector3>();
        }
    }
Esempio n. 17
0
    private void Update()
    {
        if (finger != null)
        {
            Camera camera = overrideCamera ? overrideCamera : Camera.main;

            Vector3 lastPosition    = finger.GetLastWorldPosition(Mathf.Abs(camera.transform.position.z), camera);
            Vector3 currentPosition = finger.GetWorldPosition(Mathf.Abs(camera.transform.position.z), camera);
            float   swipeSpeed      = (currentPosition - lastPosition).magnitude / Time.deltaTime;

            if (swipeSpeed >= minSlashSpeed)
            {
                OnSlash(lastPosition, currentPosition);
            }
        }
    }
Esempio n. 18
0
 public void OnFingerSetWriter(LeanFinger finger)
 {
     if (isEnabled)
     {
         if (Positions.Count == 0) // Когда только что поставили палец на экран
         {
             if (MainFinger == -1)
             {
                 if (!finger.IsOverGui && !isOverDragableObject(finger))
                 {
                     Vector2 PosNow           = finger.GetWorldPosition(10, Camera.current);
                     float   minDistance      = DistanceBetweenDots + 1;
                     string  FoundDescription = FoundLinesEndsNear(ref minDistance, PosNow, false);
                     if (minDistance <= DistanceForContinueLine)
                     {
                         ContinueAnotherLine(finger, FoundDescription);
                     }
                     else
                     {
                         StartNewLine(finger);
                     }
                 }
             }
         }
         else //Движение пальца на экране
         {
             if (finger.Index == MainFinger)
             {
                 if (quanityLines > 0)
                 {
                     if (!finger.IsOverGui)
                     {
                         DrawContinueLine(finger);
                     }
                     else
                     {
                         Positions          = new List <Vector3>();
                         MainFinger         = -1;
                         LastPoint          = 3;
                         lastDots           = 0;
                         CollidersPositions = new List <Vector2>();
                     }
                 }
             }
         }
     }
 }
Esempio n. 19
0
        private void OnFingerDown(LeanFinger finger)
        {
            var tappedCell   = TownTilemap.WorldToCell(finger.GetWorldPosition(10));
            var objectOnTile = TownTilemap.GetTile(tappedCell);

            if (objectOnTile != null)
            {
                var town = objectOnTile as TownCell;
                if (town != null)
                {
                    GetComponent <AudioManager>().PlayPop(false);
                    lastTappedTownPosition = tappedCell;
                    LeanTouch.OnFingerSet += OnFingerSet;
                    LeanTouch.OnFingerUp  += OnFingerUp;
                }
            }
        }
Esempio n. 20
0
    public void OnFingerDown(LeanFinger finger)
    {
        Vector2 touchWorldPosition = finger.GetWorldPosition(10);

        print(touchWorldPosition);

        Collider2D[] touchedObjects = Physics2D.OverlapCircleAll(touchWorldPosition, .1f);
        for (int i = 0; i < touchedObjects.Length; i++)
        {
            if (touchedObjects[i].GetInstanceID() == GetComponent <Collider2D>().GetInstanceID())
            {
                GetComponent <LeanSelectable>().IsSelected = true;
                return;
            }
        }
        GetComponent <LeanSelectable>().IsSelected = false;
    }
Esempio n. 21
0
    public void OnFingerDown(LeanFinger finger)
    {
        var ray = finger.GetWorldPosition(1.0f);
        var hit = Physics2D.OverlapPoint(ray, LayerMask);

        consoleTouch = false;

        if (hit != null)
        {
            if (hit.gameObject.tag == "Console")
            {
                consoleTouch = true;
            }
        }
        else
        {
        }
    }
    private void Update()
    {
        if (finger != null)
        {
            Camera  camera        = overrideCamera != null ? overrideCamera : Camera.main;
            Vector3 touchPosition = finger.GetWorldPosition(Mathf.Abs(camera.transform.position.z), camera);
            Vector3 delta         = touchPosition - touchPositionOnDown;
            transform.localPosition = slingPositionOnDown + delta;
            if (transform.localPosition.magnitude > maxStretchDistance)
            {
                transform.localPosition = transform.localPosition.normalized * maxStretchDistance;
            }
            jiggleVelocity = Vector3.zero;
        }
        else
        {
            float tension = GetTension();
            if (tension > 0f)
            {
                jiggleVelocity -= transform.localPosition.normalized * tension * projectileLaunchForce * jiggleIntensity * Time.deltaTime;
            }

            float decceleration = projectileLaunchForce * jiggleDamping;

            if (jiggleVelocity.magnitude > decceleration * Time.deltaTime)
            {
                jiggleVelocity -= jiggleVelocity.normalized * decceleration * Time.deltaTime;
            }
            else
            {
                jiggleVelocity = Vector3.zero;
            }

            transform.position += jiggleVelocity * Time.deltaTime;
        }

        if (currentProjectile != null)
        {
            currentProjectile.transform.position = transform.position;
        }
    }
Esempio n. 23
0
    public void OnFingerTap(LeanFinger finger)
    {
        var ray = finger.GetWorldPosition(1.0f);
        var hit = Physics2D.OverlapPoint(ray, LayerMask);

        if (hit != null)
        {
            if (hit.gameObject.tag == "InventoryCell" || hit.gameObject.tag == "SkillCell")
            {
                if (cellNotEmpty)
                {
                    if (hit.gameObject == this.gameObject)
                    {
                        if (this.itemEventVisible == false)
                        {
                            itemEventVisible = true;
                            itemEvent.SetActive(true);
                        }
                        else
                        {
                            itemEventVisible = false;
                            itemEvent.SetActive(false);
                        }
                    }
                    else
                    {
                        itemEventVisible = false;
                        itemEvent.SetActive(false);
                    }
                }
            }
        }
        else
        {
            if (gameObject.tag != "DailyRewardCell" && gameObject.tag != "ShopCell")
            {
                itemEvent.SetActive(false);
                itemEventVisible = false;
            }
        }
    }
Esempio n. 24
0
    private void OnFingerDown(LeanFinger finger)
    {
        var lastNote = game.Chart.Model.note_list.FindLast(it => it.start_time - 0.5f < game.Time);
        var error    = game.Time - lastNote.start_time;

        game.effectController.PlayRippleEffect(finger.GetWorldPosition(0, game.camera));
        beatPulseVisualizer.StartPulsing();
        Debug.Log($"{calibratedFourMeasures} - Offset: {error}s");
        offsets.Add(error);
        if (offsets.Count > 1 && Math.Abs(offsets.Last() - offsets.GetRange(0, offsets.Count - 1).Average()) > 0.080)
        {
            retries++;
            needRetry = true;
            calibratedFourMeasures = false;
            offsets.Clear();
            progressIndicator.Progress = 0;
            progressIndicator.Text     = "";
            return;
        }

        var progress = calibratedFourMeasures ? 4 + offsets.Count : offsets.Count;

        progressIndicator.Progress = progress * 1f / 8f;
        progressIndicator.Text     = $"{progress} / 8";

        if (offsets.Count == 4)
        {
            if (calibratedFourMeasures)
            {
                LeanTouch.OnFingerDown = _ => { };
                PromptComplete();
            }
            else
            {
                calibratedFourMeasures = true;
                offsets.Clear();
            }
        }
    }
Esempio n. 25
0
    public void Check_Swipe(LeanFinger finger)
    {
        int mytouch_index = -1;                           //-1のままはおかしい

        for (int i = 0; i < LeanTouch.Fingers.Count; i++) //同時押しでも指を見分けるため
        {
            if (finger.Index == LeanTouch.Fingers[i].Index)
            {
                mytouch_index = i;
                break;
            }
        }

        float distance = Get_distance(finger.GetWorldPosition(0), finger.GetLastWorldPosition(0));

        //Debug.Log("distance  " + distance);
        if (distance >= Swipe_distance)
        {
            Set_My_touch(time_Manager.Get_time(), finger, mytouch_index);
            judge.Main_judge(1, my_Touch[mytouch_index]);
        }
    }
Esempio n. 26
0
        private void OnFingerUp(LeanFinger finger)
        {
            LeanTouch.OnFingerSet -= OnFingerSet;
            LeanTouch.OnFingerUp  -= OnFingerUp;
            var currentHoveredCell = TownTilemap.WorldToCell(finger.GetWorldPosition(10));
            var town = TownTilemap.GetTile(currentHoveredCell) as TownCell;

            if (town != null && lastTappedTownPosition != currentHoveredCell) //check if we hit a different town
            {
                if (lastPath != null && lastPath.Any())
                {
                    if (FixateRoad())
                    {
                        GetComponent <AudioManager>().PlayPop(true);
                        EstablishPath();
                        return;
                    }
                }
            }

            pathDrawer.ClearPath(lastPath); // убираем весь путь ибо не получилось зафиксировать его
            lastPath = new List <Vector3Int>();
        }
Esempio n. 27
0
    public void OnFingerTap(LeanFinger finger)
    {
        var ray = finger.GetWorldPosition(1.0f);
        var hit = Physics2D.OverlapPoint(ray, LayerMask);

        if (hit != null)
        {
            if (blockRaycast.value == false)
            {
                if (hit.gameObject.tag == "BattleCell" && selectable == true)
                {
                    if (hit.gameObject == this.gameObject)
                    {
                        if (battlePhase.value == "move")
                        {
                            PlayerMoveOnCell();
                        }
                        else if (battlePhase.value == "attack")
                        {
                            for (int i = 0; i < EnemiesArray.array.Count; i++)
                            {
                                if (heightIndex == EnemiesArray.array[i].enemyHeightIndex && widthIndex == EnemiesArray.array[i].enemyWidthIndex)
                                {
                                    selectedEnemy.value = EnemiesArray.array[i].gameObject;
                                    useSkill.Raise();
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
        }
    }
Esempio n. 28
0
    public void OnFingerTap(LeanFinger finger)
    {
        var ray = finger.GetWorldPosition(1.0f);
        var hit = Physics2D.OverlapPoint(ray, LayerMask);

        Debug.Log("hit " + hit);

        if (hit != null)
        {
            if (hit.gameObject.tag == "Button")
            {
                if (blockRaycastConsole.value == false)
                {
                    if (hit.gameObject == this.gameObject)
                    {
                        Debug.Log("Button");
                        Raise();
                    }
                }
            }
            else if (hit.gameObject.tag == "ButtonUI")
            {
                if (blockRaycast.value == false && blockRaycastConsole.value == false)
                {
                    if (hit.gameObject == this.gameObject)
                    {
                        Debug.Log("ButtonUI");
                        Raise();
                    }
                }
            }
        }
        else
        {
        }
    }
Esempio n. 29
0
    public void OnFingerTap(LeanFinger finger)
    {
        var ray = finger.GetWorldPosition(1.0f);
        var hit = Physics2D.OverlapPoint(ray, LayerMask);

        playerOnCell = false;

        if (hit != null)
        {
            if (blockRaycast.value == false)
            {
                if (hit.gameObject.tag == "Cell" && CellDisplay.cellIsActive)
                {
                    if (hit.gameObject == this.gameObject)
                    {
                        playerOnCell = true;

                        playerPosition.value.x = CellDisplay.heightPos;
                        playerPosition.value.y = CellDisplay.widthPos;

                        CheckAvailableCells();

                        moves.ParameterValue -= 1;

                        if (moves.ParameterValue == 0)
                        {
                            if (food.ParameterValue == 0)
                            {
                                health.ParameterValue -= 3;
                            }
                            else
                            {
                                food.ParameterValue -= 1;

                                if (food.ParameterValue == 0)
                                {
                                    helpTipIndex.value = 0;
                                    callHelpTip.Raise();
                                }
                            }

                            string cellType = hit.gameObject.GetComponent <CellDisplay>().cellType;

                            if (cellType == "Event")
                            {
                                cellGameEventList.CellGameEventsList[0].Raise();
                            }
                            else if (cellType == "Standart")
                            {
                                cellGameEventList.CellGameEventsList[9].Raise();
                            }
                            else if (cellType == "Shop")
                            {
                                cellGameEventList.CellGameEventsList[1].Raise();
                            }
                        }
                        else
                        {
                        }
                    }
                }
            }
        }
        else
        {
        }
    }
Esempio n. 30
0
 void OnFingerDown(LeanFinger finger)
 {
     Instantiate(Prefab, finger.GetWorldPosition(Distance), Quaternion.Euler(-90, 0, 0));
 }