示例#1
0
 public override void Dispose()
 {
     foreach (Action i in OnArrive.GetInvocationList())
     {
         OnArrive -= i;
     }
 }
    public void GoTo(Vector2Int dest)
    {
        List <Vector2Int> path = PathFinding.AStar.FindPath(levelInfo.tiles, m_characterMovement.coordinate, dest);

        if (path == null)
        {
            return;
        }

        m_path      = path;
        m_pathIndex = 0;

        // skip the first if already there
        if (m_path[m_pathIndex] == m_characterMovement.coordinate)
        {
            m_pathIndex++;
        }

        m_nextDir = TileDirectionEnum.Get_TD(m_characterMovement.coordinate, m_path[m_pathIndex]);

        destination = dest;

        if (m_characterMovement.coordinate == destination)
        {
            OnArrive?.Invoke(destination);
        }
    }
示例#3
0
    public void MoveToPos(Vector3 pos, OnArrive arrive = null)
    {
        Vector3 dir = (pos - mObj.mPosition).normalized;

        mAnimatorManager.SetRotation(dir);

        mTargetPos = pos;
        mOnArrive  = arrive;
    }
示例#4
0
 public void Arrive()
 {
     if (OnArrive.IsNotNull())
     {
         OnArrive();
     }
     Arrived = true;
     StopMove();
 }
示例#5
0
    public void MoveToTarget(IObject target, OnArrive arrive = null)
    {
        if (target == null)
        {
            return;
        }

        mMoveTarget = target;

        MoveToPos(mMoveTarget.mPosition, arrive);
    }
示例#6
0
        private void Arrive()
        {
            if (IsOn)
            {
                Log("Arrive");
                if (DebugMode)
                {
                    Debug.WriteLine("{0}:\t{1}\tArrive", ClockTime, this);
                }

                Count++;
                ScheduleToArrive();
                OnArrive.Invoke();
            }
        }
    public void GoTo(Vector2Int target)
    {
        if (levelManager.info.GetTile(target) == TileType.WALL)
        {
            return;
        }

        if (coordinate == target)
        {
            OnArrive?.Invoke(levelManager.GetTile(coordinate));
            return;
        }

        m_targetCoord = target;
        m_lerpFactor  = 0;
    }
示例#8
0
    void Update()
    {
        Vector2 dir   = toWhere - transform.position;
        float   angle = Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x);

        transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle - 90));
        transform.position = Vector2.MoveTowards(transform.position, toWhere, speed);
        if (Vector2.Distance(transform.position, toWhere) < 0.01f)
        {
            if (OnArrive != null)
            {
                OnArrive.Invoke(this, EventArgs.Empty);
            }
            Destroy(gameObject);
        }
    }
    private void UpdatePath(Tile t)
    {
        if (m_path == null)
        {
            return;
        }

        m_pathIndex++;

        if (m_pathIndex >= m_path.Count)
        {
            OnArrive?.Invoke(destination);
            return;
        }

        m_nextDir = TileDirectionEnum.Get_TD(m_characterMovement.coordinate, m_path[m_pathIndex]);
    }
示例#10
0
    private void UpdatePath(Tile t)
    {
        if (m_path == null)
        {
            return;
        }

        m_pathIndex++;

        if (m_pathIndex >= m_path.Count)
        {
            OnArrive?.Invoke(destination);
            return;
        }

        m_characterMovement.GoTo(m_path[m_pathIndex]);
    }
    private void Update()
    {
        if (!isMoving)
        {
            return;
        }

        m_lerpFactor += Time.deltaTime * speed;

        transform.position = Vector2.Lerp(coordinate, m_targetCoord, m_lerpFactor);

        // arrived
        if (!isMoving)
        {
            coordinate = m_targetCoord;
            OnArrive?.Invoke(levelManager.GetTile(coordinate));
        }
    }
示例#12
0
    private void Clickable_MouseUp(Clickable sender, UnityEngine.EventSystems.PointerEventData e)
    {
        this.dragging = false;
        if (Vector3.Distance(this.pathStart.position, this.closestPoint) <= ARRIVAL_DISTANCE)
        {
            if (OnArrive != null)
            {
                OnArrive.Invoke(this, 0f);
            }
        }
        else if (Vector3.Distance(this.pathEnd.position, this.closestPoint) <= ARRIVAL_DISTANCE)
        {
            if (OnArrive != null)
            {
                OnArrive.Invoke(this, 1f);
            }
        }

        if (StopDragging != null)
        {
            StopDragging.Invoke(this, GetPathPercentage(this.pathStart.position, this.pathEnd.position, this.closestPoint));
        }
    }