Пример #1
0
    public void GenerateLevel()
    {
        Vector3 position;

        if (m_playspaceManager.TryPlaceOnFloor(out position, 0.3f * Vector3.one, Vector3.zero, 0, 1000))
        {
            m_playspaceManager.SpawnObject(tankPrefab, position);
        }
        else
        {
            Debug.Log("FAILED TO PLACE TANK");
        }
        return;

        List <GameObject> tables = m_playspaceManager.GetPlatforms(PlayspaceManager.SortOrder.Descending);
        List <GameObject> floors = m_playspaceManager.GetFloors(PlayspaceManager.SortOrder.Descending);

        Debug.Log("GenerateLevel(): number of floors=" + floors.Count + ", number of tables=" + tables.Count);

        //TODO: check if empty and take corrective action
        if (tables.Count == 0 || floors.Count == 0)
        {
            // For now, place a big ugly gray cube if no tables found

            /*
             * GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
             * cube.transform.parent = gameObject.transform; // level manager will be parent
             * cube.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
             * cube.transform.position = new Vector3(0, 0, 2);
             * cube.GetComponent<Renderer>().material = flatMaterial;
             * cube.GetComponent<Renderer>().material.color = Color.grey;
             * cube.SetActive(true);
             */
            return;
        }

        // Place blocks representing a building on the largest table surface (for
        // now, until we have better assets, just place cubes :))

        /*
         * SurfacePlane cityPlane = floors[0].GetComponent<SurfacePlane>();
         * PlaceCube(0.25f, 0.75f, 0.25f, flatMaterial, Color.red, cityPlane, -0.25f + 0.0f, 0.1f);
         * PlaceCube(0.25f, 0.30f, 0.25f, flatMaterial, Color.green, cityPlane, -0.50f - 0.1f, 0.1f);
         * PlaceCube(0.25f, 0.40f, 0.25f, flatMaterial, Color.blue, cityPlane, 0.0f + 0.1f, 0.25f + 0.1f);
         */

        // Place two tanks on largest table and one more tank on each table
        SurfacePlane largestTable = tables[0].GetComponent <SurfacePlane>();

        m_playspaceManager.SpawnObject(tankPrefab, largestTable, 0, 0.2f);
        m_playspaceManager.SpawnObject(tankPrefab, largestTable, -0.25f, -0.2f);
        for (int i = 1; i < tables.Count; i++)
        {
            SurfacePlane table = tables[i].GetComponent <SurfacePlane>();
            m_playspaceManager.SpawnObject(tankPrefab, table, 0, 0);
        }

        // Place some tanks on the floor!
        foreach (GameObject floorObj in floors)
        {
            SurfacePlane   floor          = floorObj.GetComponent <SurfacePlane>();
            List <Vector2> spawnPoints    = m_playspaceManager.FindFloorSpawnPoints(new Vector3(0.25f, 0.5f, 0.25f), new Vector2(0.25f, 0.25f), 0.5f, floor);
            int            numSpawnPoints = spawnPoints.Count;
            List <int>     indexes        = new List <int>(numSpawnPoints);
            for (int i = 0; i < numSpawnPoints; i++)
            {
                indexes.Add(i);
            }
            int numTanks = System.Math.Min(3, numSpawnPoints);
            for (int i = 0; i < numTanks; i++)
            {
                int rand = Random.Range(0, indexes.Count);
                int idx  = indexes[rand];
                indexes.Remove(idx);
                m_playspaceManager.SpawnObject(tankPrefab, floor, spawnPoints[idx].x, spawnPoints[idx].y);
            }
        }
    }
Пример #2
0
    private void PlaceEnemies()
    {
        PlayspaceManager pm = PlayspaceManager.Instance;

        string placementName;

        Vector3 agent1Size  = Footprint.Measure(agentPrefab1);
        float   agent1Width = Mathf.Max(agent1Size.x, agent1Size.z);

        for (int i = 0; i < 3; i++)
        {
            TaskManager.Instance.Schedule(
                () =>
            {
                Vector3 position;
                if (pm.TryPlaceOnPlatform(out position, 0.25f, 1.5f, 1.5f * agent1Width))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab1, position, Quaternion.identity);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                return(null);
            });
        }

        Vector3 agent2Size  = Footprint.Measure(agentPrefab2);
        float   agent2Width = Mathf.Max(agent2Size.x, agent2Size.z);

        for (int i = 0; i < 2; i++)
        {
            TaskManager.Instance.Schedule(
                () =>
            {
                Vector3 position;
                Quaternion rotation;
                if (pm.TryPlaceOnPlatform(out position, 0.25f, 1.5f, 1.5f * agent2Width))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab2, position, Quaternion.identity);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                else if (pm.TryPlaceOnFloor(out placementName, out position, out rotation, agent2Size))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab2, position, rotation);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                return(null);
            });
        }

        Vector3 agent3Size  = Footprint.Measure(agentPrefab3);
        float   agent3Width = Mathf.Max(agent3Size.x, agent3Size.z);

        for (int i = 0; i < 1; i++)
        {
            TaskManager.Instance.Schedule(
                () =>
            {
                Vector3 position;
                Quaternion rotation;
                if (pm.TryPlaceOnPlatform(out position, 0.25f, 1.5f, 1.5f * agent3Width))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab3, position, Quaternion.identity);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                else if (pm.TryPlaceOnFloor(out placementName, out position, out rotation, agent3Size))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab3, position, rotation);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                return(null);
            });
        }

        Vector3 enemyHelicopter1Size = Footprint.Measure(enemyHelicopterPrefab1.gameObject);

        for (int i = 0; i < 1; i++)
        {
            TaskManager.Instance.Schedule(
                () =>
            {
                Vector3 position;
                Quaternion rotation;
                List <PlayspaceManager.Rule> rules = new List <PlayspaceManager.Rule>()
                {
                    PlayspaceManager.Rule.Nearby(m_besiegedBuildingPosition, 0f, 0.25f)
                };
                if (pm.TryPlaceInAir(out position, out rotation, enemyHelicopter1Size, rules))
                {
                    return(() =>
                    {
                        HelicopterEnemy enemyHelicopter = Instantiate(enemyHelicopterPrefab1, position, rotation);
                        SetTarget(enemyHelicopter.gameObject, playerHelicopter);
                    });
                }
                return(() => { Debug.Log("Failed to place enemy helicopter"); });
            });
        }
    }