Exemplo n.º 1
0
    void OnSceneGUI()
    {
        FormationManager _target = (FormationManager)target;

        if (_target.leaderAgent != null)
        {
            Handles.color = Color.red;
            Handles.ArrowCap(0, _target.leaderAgent.transform.position, _target.leaderAgent.transform.rotation, 4f);
        }


        switch (_target.formation)
        {
        case FormationManager.Formations.SemiCircle:
            _target.theta = Mathf.PI / (_target.agentsNum * 2);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetSemiCirclePos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        case FormationManager.Formations.Circle:
            _target.theta = Mathf.PI / (_target.agentsNum);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetCirclePos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        case FormationManager.Formations.V:
            _target.separation = new Vector2(_target._separation, _target._separation);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetVPosition(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        case FormationManager.Formations.Triangle:
            for (int i = 0; i < 3; ++i)
            {
                _target.agentsPerSide [i] = _target.agentsNum / 3 + (_target.agentsNum % 3 > i ? 1 : 0);
            }
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetTrianglePos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        case FormationManager.Formations.Wedge:
            _target.separation = new Vector2(_target._separation, _target._separation);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetWedgePos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        case FormationManager.Formations.Column:
            _target.separation = new Vector2(_target._separation, _target._separation);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetColumnPos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }

            break;


        case FormationManager.Formations.Diamond:

            _target.separation = new Vector2(_target._separation, _target._separation);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetDiamondPos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        case FormationManager.Formations.Diagonal:

            _target.separation = new Vector2(_target._separation, _target._separation);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetDiagonalPos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        case FormationManager.Formations.Grid:

            _target.separation = new Vector2(_target._separation, _target._separation);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetGridPos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        case FormationManager.Formations.Line:

            _target.separation = new Vector2(_target._separation, _target._separation);
            for (int i = 0; i < _target.agentsNum; i++)
            {
                var pos = _target.GetLinePos(i, _target.zLookAhead);
                if (_target.leaderAgent != null)
                {
                    pos = pos + _target.leaderAgent.transform.position;
                }
                Handles.color = Color.red;
                Handles.SphereCap(i, pos, Quaternion.identity, 0.5f);
            }
            break;

        default:
            break;
        }
    }