Exemplo n.º 1
0
    public static void UpdateMovePosition(Vector3 position)
    {
        if (_selectedShips.Count == 0)
        {
            return;
        }

        List <Vector3> formation = FormationManager.Get(position, _selectedShips[0].transform.forward, _selectedShips.Count).ToList();

        //move to closest position in formation
        for (int i = 0; i < _selectedShips.Count; i++)
        {
            Vector3 np = formation
                         .OrderByDescending(v => Vector3.Distance(v, _selectedShips[i].transform.position))
                         .First();

            formation.Remove(np);

            _selectedShips[i].UpdateMovePosition(np);
        }
    }
Exemplo n.º 2
0
    public static void AddMove(Vector3?position, bool clearQueue)
    {
        if (_selectedShips.Count == 0)
        {
            return;
        }

        List <Vector3> formation = FormationManager.Get((Vector3)position, _selectedShips[0].transform.forward, _selectedShips.Count).ToList();

        //need to map the closest ship to the closest point
        for (int i = 0; i < _selectedShips.Count; i++)
        {
            if (position != null)
            {
                int closestIndex = -1;

                float distance = Mathf.Infinity;

                for (int j = 0; j < formation.Count; j++)
                {
                    float d = Vector3.Distance(_selectedShips[i].transform.position, formation[j]);

                    if (closestIndex == -1 || d < distance)
                    {
                        closestIndex = j;
                    }
                }

                _selectedShips[i].AddMove(new Move(formation[closestIndex], _selectedShips[i]), clearQueue);
                formation.RemoveAt(closestIndex);
            }
            else
            {
                _selectedShips[i].AddMove(new Move(position, _selectedShips[i]), clearQueue);
            }
        }
    }