示例#1
0
    // Returns the info of the radar. The visible tanks are returned with this method
    public ViewInfo GetViewInfo()
    {
        ViewInfo vi = new ViewInfo();

        List <Tank> tanks = TankManager.Instance.GetTanks();

        Vector3 pos = turretTransform.position;

        for (int i = 0; i < tanks.Count; i++)
        {
            if (tank == tanks[i])
            {
                continue;
            }

            // 1. Check the distance
            if (Vector3.Distance(pos, tanks[i].transform.position) < tank.prop.viewDistance)
            {
                // 2. Check the angle
                Vector3 p1 = tanks[i].transform.position - pos;
                if (Vector3.Angle(p1, turretTransform.forward) <= tank.prop.viewAngle / 2.0f)
                {
                    vi.AddTankInfo(tanks[i]);
                }
            }
        }

        MapObstacle[] obstacles = Map.Instance.GetObstacles();

        for (int i = 0; i < obstacles.Length; i++)
        {
            // 1. Check the distance
            if (Vector3.Distance(pos, obstacles[i].transform.position) < tank.prop.viewDistance)
            {
                // 2. Check the angle
                Vector3 p1 = obstacles[i].transform.position - pos;
                if (Vector3.Angle(p1, turretTransform.forward) <= tank.prop.viewAngle / 2.0f)
                {
                    vi.AddObstacleInfo(obstacles[i]);
                }
            }
        }

        Debug.LogFormat("Visible {0} of {1} tanks and {2} obstacles", vi.GetTankCount(), tanks.Count, vi.GetEntityCount() - vi.GetTankCount());

        return(vi);
    }