// Update is called once per frame
 void Update()
 {
     surface.BuildNavMesh();
 }
示例#2
0
 // Start is called before the first frame update
 void Start()
 {
     surface.BuildNavMesh();
     player.SetActive(true);
 }
示例#3
0
    // Start is called before the first frame update
    void Start()
    {
        List <ResourceSpawn> resourceSpawns       = mysql.ReadResourceSpawns();
        List <SerializableObjects.Trader> traders = mysql.ReadTraders();
        List <TradeBroker>       brokers          = mysql.ReadTradeBrokers();
        List <CraftingSpotSpawn> craftingSpots    = mysql.ReadCraftingSpots();
        List <NPCSpawn>          npcSpots         = mysql.ReadNPCSpawns();

        //create Chest prefab
        int        id    = NextId();
        GameObject chest = Instantiate(prefabs[GameObjectType.chest], new Vector3(-3.57f, -2f, -8.83f), Quaternion.identity);

        objects.Add(id, new Spawn()
        {
            id = id, type = GameObjectType.chest, gameObject = chest, objectType = ObjectType.CHEST
        });

        foreach (ResourceSpawn spawn in resourceSpawns)
        {
            id = NextId();
            GameObject go = Instantiate(prefabs[(GameObjectType)spawn.RESOURCE.RESOURCE_TYPE], new Vector3(spawn.X, spawn.Y, spawn.Z), Quaternion.identity);
            objects.Add(id, new Spawn()
            {
                id = id, type = (GameObjectType)spawn.RESOURCE.RESOURCE_TYPE, gameObject = go, objectType = ObjectType.RESOURCE
            });

            Item item = mysql.ReadItem(spawn.RESOURCE.ITEM_ID);

            Resource resource = go.GetComponent <Resource>();
            resource.maxHp         = spawn.RESOURCE.RESOURCE_HP;
            resource.resourceCount = spawn.RESOURCE.RESOURCE_COUNT;
            resource.respawnTime   = spawn.RESPAWN_TIME;
            resource.itemId        = spawn.RESOURCE.ITEM_ID;
            resource.skill_type    = (SkillType)spawn.RESOURCE.SKILL_TYPE;
            resource.experience    = spawn.RESOURCE.EXPERIENCE;
            resource.item          = item;

            resource.Initialize();
        }

        foreach (SerializableObjects.Trader trader in traders)
        {
            id = NextId();
            GameObject go = Instantiate(prefabs[(GameObjectType)trader.game_object_type], new Vector3(trader.x, trader.y, trader.z), Quaternion.identity);
            go.transform.eulerAngles = new Vector3(0, trader.y_rot, 0);
            objects.Add(id, new Spawn()
            {
                id = id, type = (GameObjectType)trader.game_object_type, gameObject = go, objectType = ObjectType.TRADER
            });

            Trader traderScript = go.GetComponent <Trader>();
            traderScript.id = trader.id;
        }

        foreach (TradeBroker broker in brokers)
        {
            id = NextId();
            GameObject go = Instantiate(prefabs[(GameObjectType)broker.game_object_type], new Vector3(broker.x, broker.y, broker.z), Quaternion.identity);
            go.transform.eulerAngles = new Vector3(0, broker.y_rot, 0);
            objects.Add(id, new Spawn()
            {
                id = id, type = (GameObjectType)broker.game_object_type, gameObject = go, objectType = ObjectType.TRADE_BROKER
            });
        }

        foreach (CraftingSpotSpawn craftingSpot in craftingSpots)
        {
            id = NextId();
            GameObject go = Instantiate(prefabs[(GameObjectType)craftingSpot.gameObjectType], new Vector3(craftingSpot.x, craftingSpot.y, craftingSpot.z), Quaternion.identity);
            go.transform.eulerAngles = new Vector3(0, craftingSpot.Y_rot, 0);
            objects.Add(id, new Spawn()
            {
                id = id, type = (GameObjectType)craftingSpot.gameObjectType, gameObject = go, objectType = ObjectType.CRAFTING_SPOT
            });

            CraftingSpot craftingSpotScript = go.GetComponent <CraftingSpot>();
            craftingSpotScript.skillType = craftingSpot.skillType;
        }

        land.BuildNavMesh();

        /*id = NextId();
         * GameObject palmTree = Instantiate(prefabs[GameObjectType.palmTree], new Vector3(32.62526f, 0.8707776f, 45.96268f), Quaternion.identity);
         * objects.Add(id, new Spawn() { id = id, type = GameObjectType.palmTree, gameObject = palmTree });
         *
         * id = NextId();
         * GameObject ironRock = Instantiate(prefabs[GameObjectType.ironRock], new Vector3(28.95738f, 0.64f, 48.02f), Quaternion.identity);
         * objects.Add(id, new Spawn() { id = id, type = GameObjectType.ironRock, gameObject = ironRock });
         *
         * id = NextId();
         * GameObject goldRock = Instantiate(prefabs[GameObjectType.goldRock], new Vector3(28.16f, 0.75f, 50.88757f), Quaternion.identity);
         * objects.Add(id, new Spawn() { id = id, type = GameObjectType.goldRock, gameObject = goldRock });*/
        /*
         * id = NextId();
         * GameObject ai = Instantiate(prefabs[GameObjectType.npcShip], new Vector3(0f, 0f, 0f), Quaternion.identity);
         * objects.Add(id, new Spawn() { id = id, type = GameObjectType.npcShip, gameObject = ai });
         * EnemyAI enemy = ai.GetComponent<EnemyAI>();
         * enemy.id = id;
         * Server.npcs.Add(id, enemy);*/


        /*foreach (NPCSpawn spawn in npcSpots)
         * {
         *  if (spawn.enabled)
         *  {
         *      id = NextId();
         *      GameObject go = Instantiate(prefabs[(GameObjectType)spawn.gameObjectType], new Vector3(spawn.x, spawn.y, spawn.z), Quaternion.identity);
         *      go.transform.eulerAngles = new Vector3(0, spawn.Y_rot, 0);
         *      objects.Add(id, new Spawn() { id = id, type = GameObjectType.dragon, objectType = ObjectType.NPC, gameObject = go });
         *      NPC npc = go.GetComponent<NPC>();
         *      npc.id = id;
         *      npc.npc_type = spawn.npc_type;
         *      npc.aggro_range = spawn.aggro_range;
         *      GameServer.npcs.Add(id, npc);
         *  }
         * }*/
    }
示例#4
0
 // Start is called before the first frame update
 void Start()
 {
     bakeNumber = 0;
     surface.BuildNavMesh();
 }
        private void Awake()
        {
            var levelSettings = SettingsSet.LevelSettings;


            // Input manager setup
            GameInputManager = new TankEternalGameInputManager
            {
                InputEnabled          = true,
                StandaloneInputModule = StandaloneInputModule,
                GameInputHandler      = StateMachine,
                Camera               = CameraHolder.Camera,
                CameraDistance       = levelSettings.CameraDistance,
                FireButtonName       = this.FireButtonName,
                NextWeaponButtonName = this.NextWeaponButtonName,
                PrevWeaponButtonName = this.PrevWeaponButtonName
            };
            GameInputManager.Init();

            // State Machine setup
            StateMachine.Init();

            // Level setup // todo Move to a separate class and call it each time Game Begins
            float levelWidth  = Random.Range(levelSettings.LevelMinWidth, levelSettings.LevelMaxWidth);
            float levelHeight = Random.Range(levelSettings.LevelMinHeight, levelSettings.LevelMaxHeight);

            LevelLeftBorder   = -levelWidth / 2f;
            LevelRightBorder  = levelWidth / 2f;
            LevelBottomBorder = -levelHeight / 2f;
            LevelTopBorder    = levelHeight / 2f;

            BackgroundRectangleSpawner.CuboidArea.Size.x = levelWidth * 1.5f;
            BackgroundRectangleSpawner.CuboidArea.Size.z = levelHeight * 1.5f;
            BackgroundRectangleSpawner.ObjectNumber      = (int)(levelWidth + levelHeight);

            BackgroundRectangleSpawner.Spawn(); // todo Rework Spawner so it will have ability to Shuffle Rectangles positions without recreating them
            Destroy(BackgroundRectangleSpawner);

            int obstaclesSpawnAmount = levelSettings.ObstaclesSpawnAmount;

            var obstaclePrefabs = levelSettings.ObstaclePrefabs;

            for (int index = 0; index < obstaclesSpawnAmount; index++)
            {
                var obstaclePrefab = obstaclePrefabs[Random.Range(0, obstaclePrefabs.Length)];
                var obstacle       = Instantiate(obstaclePrefab);

                var spawnPosition = new Vector3(Random.Range(LevelLeftBorder, LevelRightBorder), 0f,
                                                Random.Range(LevelBottomBorder, LevelTopBorder));

                obstacle.transform.localPosition = spawnPosition;
            }
            LevelNavMeshQuadTransform.localScale = new Vector3(levelWidth, levelHeight, 1f);
            NavMeshSurface.BuildNavMesh();

            // PlayerBullet Pawn setup
            PlayerPawn = Instantiate(playerPawnPrefab);

            PlayerPawn.GameController = this;

            PlayerPawn.Init();

            // Enemy Pawns setup
            var enemySettings = SettingsSet.EnemySettings;

            EnemyPawnObjectPool.InitialSize  = enemySettings.MaxEnemyAmount;
            EnemyPawnObjectPool.AbleToExpand = false;
            EnemyPawnObjectPool.Init();

            var enemies = EnemyPawnObjectPool.AvailableObjects;

            for (int index = 0; index < enemies.Count; index++)
            {
                var enemy = (TankEternalEnemyPawn)enemies[index];
                enemy.PlayerPawn = PlayerPawn;
                enemy.Init();
            }

            enemySpawnDelay        = enemySettings.SpawnDelay;
            enemySpawnCurrentDelay = enemySpawnDelay;

            var screenWorldBorders = GameInputManager.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height));

            ScreenWorldHalfWidth  = screenWorldBorders.x;
            ScreenWorldHalfHeight = -screenWorldBorders.y;

            // Camera setup
            CameraHolder.CameraOffset = new Vector3(0.0f, levelSettings.CameraDistance, 0.0f);

            CameraHolder.Init();

            // Ui setup
            UiController.GameController = this;

            UiController.Init();
        }
示例#6
0
    /*void OnValidate(){
     *  GenerateMesh();
     * }*/
    void GenerateMesh()
    {
        if (resolution == 0)
        {
            return;
        }

        //var verticesTwo = new List<Vector3>();
        var colors           = new List <Color>();
        var triangles        = new List <int>();
        var trianglesTwo     = new List <int>();
        var trianglesAll     = new List <int>();
        var vertices         = new List <Vector3>();
        var verticesCollider = new List <Vector3>();
        var axisA            = new Vector3(Vector3.up.y, Vector3.up.z, Vector3.up.x);
        var axisB            = Vector3.Cross(Vector3.up, axisA);

        noise            = new Noise(noiseSettings);
        circularGradient = new CircularGradient(new Vector3(size / 2, 0, size / 2), circularGradientSettings);
        colorGenerator   = new ColorGenerator(colorSettings);
        detailsGenerator = new DetailsGenerator(detailsSettings, size, new Vector2(0, -(size * 2)));
        detailPoints     = detailsGenerator.ComputedPoints();
        //Debug.Log(detailPoints[0].Length);

        int i = 0;

        for (int z = 0; z < size; z++)
        {
            for (int x = 0; x < size; x++)
            {
                Vector3 sercent             = new Vector3((float)x / size - 1, 0, (float)z / size - 1);
                float   elevation           = noise.Calculate(sercent.x + seed, sercent.z + seed) * circularGradient.Calculate(x, z);
                float   elevationNormalized = Mathf.Clamp01(elevation / (noiseSettings.rougness + circularGradientSettings.rougness));

                colors.Add(colorGenerator.Calculate(elevationNormalized));

                Vector3 point = Vector3.up + (x - .5f) * 2 * axisA + (z - .5f) * 2 * axisB;
                point.y = elevation;
                verticesCollider.Add(point);
                point.y += Random.Range(-1f, 1f) * lowPolyEffect;
                point.x += Random.Range(-1f, 1f) * lowPolyEffect;
                point.z += Random.Range(-1f, 1f) * lowPolyEffect;
                vertices.Add(point);
                //verticesTwo.Add(point);
                i++;
            }
        }

        i = 0;
        for (int z = 0; z < size; z++)
        {
            for (int x = 0; x < size; x++)
            {
                if (x != size - 1 && z != size - 1)
                {
                    triangles.Add(i);
                    triangles.Add(i + size + 1);
                    triangles.Add(i + size);

                    // triangles.Add(i);
                    // triangles.Add(i+1);
                    // triangles.Add(i+size+1);

                    trianglesTwo.Add(i);
                    trianglesTwo.Add(i + 1);
                    trianglesTwo.Add(i + size + 1);
                }

                i++;
            }
        }
        islandMesh.GenerateMesh(vertices.ToArray(), triangles.ToArray(), colors.ToArray());
        islandMesh2.GenerateMesh(vertices.ToArray(), trianglesTwo.ToArray(), colors.ToArray());

        trianglesAll.AddRange(triangles);
        trianglesAll.AddRange(trianglesTwo);
        if (!meshCollider.sharedMesh)
        {
            meshCollider.sharedMesh = new Mesh();
        }
        var colliderMesh = meshCollider.sharedMesh;

        colliderMesh.vertices = verticesCollider.ToArray();

        colliderMesh.triangles = trianglesAll.ToArray();
        colliderMesh.RecalculateNormals();
        meshCollider.sharedMesh = colliderMesh;

        navMeshSurface.BuildNavMesh();
    }
示例#7
0
 private void Start()
 {
     surface = GameObject.FindGameObjectWithTag("Navmesh").GetComponent <NavMeshSurface>();
     surface.BuildNavMesh();
 }
示例#8
0
 void Start()
 {
     nv.BuildNavMesh();
 }
示例#9
0
    private void GenerateMap()
    {
        m_map = new int[width, height];
        RandomFillMap();

        for (int i = 0; i < 5; i++)
        {
            SmoothMap();
        }

        ProcessMap();

        int borderSize = 1;

        int[,] borderedMap = new int[width + borderSize * 2, height + borderSize * 2];

        for (int x = 0; x < borderedMap.GetLength(0); x++)
        {
            for (int y = 0; y < borderedMap.GetLength(1); y++)
            {
                if (x >= borderSize && x < width + borderSize && y >= borderSize && y < height + borderSize)
                {
                    borderedMap[x, y] = m_map[x - borderSize, y - borderSize];
                }
                else
                {
                    borderedMap[x, y] = 1;
                }
            }
        }

        MeshGenerator meshGen = GetComponent <MeshGenerator>();

        meshGen.GenerateMesh(borderedMap, 1);
        NavMeshSurface navMeshSurface = GetComponent <NavMeshSurface>();

        navMeshSurface.BuildNavMesh();

        bool openSpace = false;

        System.Random pseudoRandom = new System.Random(seed.GetHashCode());

        while (!openSpace)
        {
            int x = pseudoRandom.Next(0, width);
            int y = pseudoRandom.Next(0, height);
            if (m_map[x, y] == 0)
            {
                openSpace = true;
                Vector3 position = CoordToWorldPoint(new Coord(x, y));
                position.y      = -4.3f;
                playerReference = Instantiate(playerPrefab, position, Quaternion.identity) as GameObject;
            }
        }

        for (int i = 0; i < spawnersAmount; i++)
        {
            openSpace = false;
            while (!openSpace)
            {
                int x = pseudoRandom.Next(0, width);
                int y = pseudoRandom.Next(0, height);
                if (m_map[x, y] == 0)
                {
                    openSpace = true;
                    Vector3 position = CoordToWorldPoint(new Coord(x, y));
                    position.y = -4.3f;
                    Instantiate(enemySpawner, position, Quaternion.identity);
                }
            }
        }
    }
示例#10
0
    void Start()
    {
        Vector3 nodecords(float x, float y)
        {
            return(new Vector3(x * 5, 0, -y * 5));
        }

        Vector3 endcords(float x, float y)
        {
            return(new Vector3(x * 5, 2.5f, -y * 5));
        }

        Vector3 wpcords(float x, float y)
        {
            return(new Vector3(x * 5, 1f, -y * 5));
        }

        void removenodeat(Node[] nodes, float x, float y)
        {
            foreach (Node n in nodes)
            {
                if (n.transform.position.x / 5 == x && -n.transform.position.z / 5 == y)
                {
                    n.gameObject.SetActive(false);
                    Destroy(n.gameObject);
                }
            }
        }

        void setpathnode(Node[] nodes, float x, float y)
        {
            removenodeat(nodes, x, y);
            GameObject ground = Instantiate(m_GroundPrefab, nodecords(x, y), Quaternion.identity, m_Environment.transform);

            ground.transform.localScale = new Vector3(4.9f, 1, 4.9f);
        }

        Territory territory = Territories.Get(GameManager.instance.TerritoryName);

        if (territory == null)
        {
            print("territory is null name='" + GameManager.instance.TerritoryName + "'");
        }

        m_Environment = new GameObject("Environment");
        m_Nodes       = new GameObject("Nodes");
        m_Waypoints   = new GameObject("Waypoints");

        BattleManager.instance.stats.Money = territory.startMoney;
        BattleManager.instance.stats.Lives = territory.startLives;

        /* SET UP A GROUND PLANE */
        GameObject gp = Instantiate(m_GroundPlanePrefab, new Vector3(0, -1, 0), Quaternion.identity, m_Environment.transform);

        gp.transform.localScale = new Vector3(1000, 1, 1000);

        /* SET UP A SMALL BACKGROUND */
        GameObject gp2 = Instantiate(m_GroundPlanePrefab, new Vector3(37.5f, -0.9f, -37.5f), Quaternion.identity, m_Environment.transform);

        gp2.transform.localScale = new Vector3(80, 1, 80);
        Renderer rend2 = gp2.GetComponent <Renderer>();

        rend2.material.color = new Color32(0, 32, 0, 255);

        /* SET UP TURRET NODES */
        // what's better? a map full of nodes, or a small number of nodes we can place at key points on the map?
        if (territory.turretnodes.Length == 0)
        {
            for (int y = 0; y < 16; y++)
            {
                for (int x = 0; x < 16; x++)
                {
                    GameObject node = Instantiate(m_NodePrefab, nodecords(x, y), Quaternion.identity, m_Nodes.transform);
                    node.transform.localScale = new Vector3(4, 1, 4);
                    foreach (MapPoint wp in territory.waypoints)
                    {
                        if (wp.x == x && wp.y == y)
                        {
                            Renderer rend = node.GetComponent <Renderer>();
                            rend.material.color = Color.black;
                        }
                    }
                }
            }
        }
        else
        {
            foreach (MapPoint np in territory.turretnodes)
            {
                GameObject node = Instantiate(m_NodePrefab, nodecords(np.x, np.y), Quaternion.identity, m_Nodes.transform);
                node.transform.localScale = new Vector3(4, 1, 4);
            }
        }
        /* SET UP START/END NODES */
        // crashes if no nodes are defined
        // the xml parser should be fixed to guarantee we have a valid map, or fail long before we reach this point
        if (territory.waypoints.Length < 1)
        {
            Debug.LogError("territory.waypoints for " + territory.name + " is empty - add some to the XML file");
        }
        GameObject startnode = Instantiate(m_StartPrefab, endcords(territory.waypoints[0].x, territory.waypoints[0].y), Quaternion.identity);

        startnode.transform.localScale = new Vector3(4, 4, 4);
        startnode.name = "Start";

        Node[] nl = m_Nodes.GetComponentsInChildren <Node>();

        for (int y = -2; y < 3; y++)
        {
            for (int x = -2; x < 3; x++)
            {
                removenodeat(nl, territory.waypoints[0].x + x, territory.waypoints[0].y + y);
            }
        }

        BGWaveManager.spawnPoint = startnode.transform;
        GameObject endnode = Instantiate(m_EndPrefab, endcords(territory.waypoints[territory.waypoints.Length - 1].x, territory.waypoints[territory.waypoints.Length - 1].y), Quaternion.identity);

        endnode.transform.localScale = new Vector3(4, 4, 4);
        endnode.name = "End";

        for (int y = -1; y < 2; y++)
        {
            for (int x = -1; x < 2; x++)
            {
                removenodeat(nl, territory.waypoints[territory.waypoints.Length - 1].x + x, territory.waypoints[territory.waypoints.Length - 1].y + y);
            }
        }

        /* SET UP WAYPOINTS */
        Waypoints.points = new Transform[territory.waypoints.Length];
        int i2 = 0;

        foreach (MapPoint wp in territory.waypoints)
        {
            GameObject waypoint = Instantiate(m_WaypointPrefab, wpcords(wp.x, wp.y), Quaternion.identity, m_Waypoints.transform);
            Waypoints.points[i2++] = waypoint.transform;
        }
        /* SET UP WAYPOINT PATH TILES */
        for (int i = 0; i < territory.waypoints.Length - 1; i++)
        {
            int minx = Mathf.Min((int)territory.waypoints[i].x, (int)territory.waypoints[i + 1].x);
            int maxx = Mathf.Max((int)territory.waypoints[i].x, (int)territory.waypoints[i + 1].x);
            int miny = Mathf.Min((int)territory.waypoints[i].y, (int)territory.waypoints[i + 1].y);
            int maxy = Mathf.Max((int)territory.waypoints[i].y, (int)territory.waypoints[i + 1].y);

            for (int x = minx; x <= maxx; x++)
            {
                for (int y = miny; y <= maxy; y++)
                {
                    setpathnode(nl, x, y);
                }
            }
        }
        // rebuild the nav mesh
        NavMeshSurface nms = m_Environment.AddComponent <NavMeshSurface>();

        nms.layerMask = 1 << LayerMask.NameToLayer("Environment");
        nms.BuildNavMesh();
        if (BattleManager.instance.attackMode)
        {
            AddAIDefenders();
        }
    }
示例#11
0
 // Use this for initialization
 void Start()
 {
     navMeshSurface.BuildNavMesh();
 }
示例#12
0
 void Start()
 {
     randomCurrent = randomMax;
     GenerateDungeon();
     surface.BuildNavMesh();
 }
 void Start()
 {
     surface.RemoveData();
     surface.BuildNavMesh();
 }
    void Awake()
    {
        int numberOfStartRooms  = 1;
        int numberOfRandomRooms = 1;
        int numberOfPuzzleRooms = 1;

        // Can of course be different
        if (currentLevel == "tutorial")
        {
            numberOfStartRooms  = 1;
            numberOfRandomRooms = 1;
            numberOfPuzzleRooms = 1;
        }
        else if (currentLevel == "ice")
        {
            numberOfStartRooms  = 1;
            numberOfRandomRooms = 19;
            numberOfPuzzleRooms = 1;
        }
        else if (currentLevel == "fire")
        {
            numberOfStartRooms  = 1;
            numberOfRandomRooms = 15;
            numberOfPuzzleRooms = 1;
        }
        else if (currentLevel == "michael_test")
        {
            numberOfStartRooms  = 1;
            numberOfRandomRooms = 2;
            numberOfPuzzleRooms = 1;
        }
        numberOfRooms = ArturGameManager.numberOfRooms;

        if (currentLevel == "tutorial")
        {
            numberOfRooms = 0;
        }

        allEnemyPositions = new List <Vector3>();
        string roomPath = "Rooms/" + currentLevel + "/";

        System.Random rand      = new System.Random();
        GameObject    firstRoom = Resources.Load <GameObject>(roomPath + "start" + (rand.Next(1, numberOfStartRooms)));

        firstRoom.GetComponent <LevelMetaInf>().instantiatedAt = Vector3.zero;

        Instantiate(firstRoom);
        Vector3 roomPosition = new Vector3(firstRoom.GetComponent <LevelMetaInf>().lastBlock.x,
                                           firstRoom.GetComponent <LevelMetaInf>().lastBlock.y, 0);
        List <GameObject> gameRooms = new List <GameObject>();

        gameRooms.Add(firstRoom);

        for (int i = 0; i < firstRoom.GetComponent <LevelMetaInf>().enemyPositions.Count; i++)
        {
            allEnemyPositions.Add(firstRoom.GetComponent <LevelMetaInf>().enemyPositions[i] + firstRoom.GetComponent <LevelMetaInf>().instantiatedAt);
        }


        if (testSpecificRoom != 0)
        {
            GameObject nextRoom = Resources.Load <GameObject>(roomPath + testSpecificRoom);
            nextRoom.GetComponent <LevelMetaInf>().respawnLocation = roomPosition;
            nextRoom.GetComponent <LevelMetaInf>().instantiatedAt  = roomPosition;
            Instantiate(nextRoom, roomPosition, Quaternion.identity);

            gameRooms.Add(nextRoom);

            roomPosition.x += nextRoom.GetComponent <LevelMetaInf>().lastBlock.x + 1;
            roomPosition.y += nextRoom.GetComponent <LevelMetaInf>().lastBlock.y;

            for (int j = 0; j < nextRoom.GetComponent <LevelMetaInf>().enemyPositions.Count; j++)
            {
                allEnemyPositions.Add(nextRoom.GetComponent <LevelMetaInf>().enemyPositions[j] + nextRoom.GetComponent <LevelMetaInf>().instantiatedAt);
            }
        }



        List <int> roomsOrder = Enumerable.Range(1, numberOfRandomRooms).ToList();


        int extraRooms = 0;

        if (numberOfRooms > numberOfRandomRooms)
        {
            extraRooms = numberOfRooms - numberOfRandomRooms;
        }

        for (int i = 0; i < extraRooms; i++)
        {
            roomsOrder.Add(rand.Next(1, numberOfRandomRooms));
        }

        int[] randomRoomsOrder = ArturHelper.Shuffle <int>(new System.Random(), roomsOrder.ToArray());



        for (int i = 0; i < numberOfRooms; i++)
        {
            /*
             * Controlling the random generation a bit.
             * GameObject nextRoom;
             * if (i % 3 == 0)
             * {
             *      // Generate bigger room with a puzzle.
             *      GameObject nextRoom = Resources.Load<GameObject>(roomPath + "puzzles/" + rand.Next(1, numberOfPuzzleRooms));
             * }
             * else
             * {
             *      // Random room.
             *      GameObject nextRoom = Resources.Load<GameObject>(roomPath + rand.Next(1, numberOfRandomRooms));
             * }
             */



            //GameObject nextRoom = Resources.Load<GameObject>(roomPath + rand.Next(1, numberOfRandomRooms)); // TODO
            GameObject nextRoom = Resources.Load <GameObject>(roomPath + randomRoomsOrder[i]); //
            nextRoom.GetComponent <LevelMetaInf>().respawnLocation = roomPosition;
            nextRoom.GetComponent <LevelMetaInf>().instantiatedAt  = roomPosition;
            Instantiate(nextRoom, roomPosition, Quaternion.identity);

            gameRooms.Add(nextRoom);

            roomPosition.x += nextRoom.GetComponent <LevelMetaInf>().lastBlock.x + 1;
            roomPosition.y += nextRoom.GetComponent <LevelMetaInf>().lastBlock.y;


            for (int j = 0; j < nextRoom.GetComponent <LevelMetaInf>().enemyPositions.Count; j++)
            {
                allEnemyPositions.Add(nextRoom.GetComponent <LevelMetaInf>().enemyPositions[j] + nextRoom.GetComponent <LevelMetaInf>().instantiatedAt);
            }
        }

        GameObject endRoom = Resources.Load <GameObject>(roomPath + "end");

        endRoom.GetComponent <LevelMetaInf>().instantiatedAt = roomPosition;

        Instantiate(endRoom, roomPosition, Quaternion.identity);

        string playerOnePath = "Prefabs/Main/PlayerCharacters/ArturMainCharacter1";
        string playerTwoPath = "Prefabs/Main/PlayerCharacters/ArturMainCharacter2";

        GameObject playerOne = Resources.Load <GameObject>(playerOnePath);
        GameObject playerTwo = Resources.Load <GameObject>(playerTwoPath);

        Instantiate(playerOne, firstRoom.GetComponent <LevelMetaInf>().respawnLocation, Quaternion.identity);
        Instantiate(playerTwo, firstRoom.GetComponent <LevelMetaInf>().respawnLocation + new Vector3(2, 0, 0), Quaternion.identity);

        gameRooms.Add(endRoom);
        surface.BuildNavMesh();
        string enemyPath = "Prefabs/Main/Enemies/Enemy";

        foreach (Vector3 enemyPos in allEnemyPositions)
        {
            GameObject enemy = Resources.Load <GameObject>(enemyPath);
            Instantiate(enemy, enemyPos, Quaternion.identity);
        }
    }
示例#15
0
    private void GenerateMap(bool loadFromTxt)
    {
        level      = Instantiate(level);
        level.name = "Level";
        if (loadFromTxt)
        {
            for (int i = 0; i < asciiMap.Length; i++)
            {
                LoadMap(asciiMap[i], i);
            }
        }
        else
        {
            // procedurally generate map
            mapGrid = new int[mapSize, mapSize];
            // set map digger start position to middle of map
            xPos  = mapSize / 2;
            yPos  = mapSize / 2;
            steps = mapSize * mapSize / 4;
            for (int i = 0; i < steps; i++)
            {
                //move digger
                if (Random.Range(0f, 1f) > 0.75f)
                {
                    dir = Random.Range(0, 4);
                }
                switch (dir)
                {
                case 0:
                    xPos++;
                    break;

                case 1:
                    yPos++;
                    break;

                case 2:
                    xPos--;
                    break;

                case 3:
                    yPos--;
                    break;
                }
                // prevent digger from out of bounds
                xPos = Mathf.Clamp(xPos, 1, mapSize - 2);
                yPos = Mathf.Clamp(yPos, 1, mapSize - 2);
                mapGrid[xPos, yPos] = 1; // set current position to floor
            }
            for (int y = 1; y < mapSize - 1; y++)
            {
                for (int x = 1; x < mapSize - 1; x++)
                {
                    if ((mapGrid[x, y] == 0) && (mapGrid[x + 1, y] == 1) && (mapGrid[x - 1, y] == 1) && (mapGrid[x, y + 1] == 1) && (mapGrid[x, y - 1] == 1))
                    {
                        mapGrid[x, y] = 1;
                    }
                }
            }
            for (int y = 1; y < mapSize - 1; y++)
            {
                for (int x = 1; x < mapSize - 1; x++)
                {
                    if (mapGrid[x, y] == 1)
                    {
                        if (mapGrid[x + 1, y] == 0)
                        {
                            mapGrid[x + 1, y] = 2;
                        }
                        if (mapGrid[x - 1, y] == 0)
                        {
                            mapGrid[x - 1, y] = 2;
                        }
                        if (mapGrid[x, y + 1] == 0)
                        {
                            mapGrid[x, y + 1] = 2;
                        }
                        if (mapGrid[x, y - 1] == 0)
                        {
                            mapGrid[x, y - 1] = 2;
                        }
                    }
                }
            }
            for (int y = 0; y < mapSize; y++)
            {
                for (int x = 0; x < mapSize; x++)
                {
                    switch (mapGrid[x, y])
                    {
                    case 0:
                        proceduralMap += "H";
                        break;

                    case 1:
                        if (!hasSpawn)
                        {
                            proceduralMap += "C";
                            hasSpawn       = true;
                        }
                        else
                        {
                            proceduralMap += "O";
                        }
                        break;

                    case 2:
                        proceduralMap += "X";
                        break;
                    }
                }
                proceduralMap += "\n";
            }
            mapWidth = mapSize + 1;
            ParseMap(proceduralMap, 1);
        }
        surface = level.GetComponent <NavMeshSurface>();
        surface.BuildNavMesh();
    }
示例#16
0
 public void RunTimeBake()
 {
     NMSurface.BuildNavMesh();
 }
示例#17
0
 public void BakeNavMesh()
 {
     navMesh.BuildNavMesh();
 }
示例#18
0
 // Use this for initialization
 void Start()
 {
     GenerateLevel();
     NavMesh.BuildNavMesh();
 }
示例#19
0
 // Use this for initialization
 void Start()
 {
     GenerateLevel();
     // UPDATE NAVMESH
     surface.BuildNavMesh();
 }
示例#20
0
 // Start is called before the first frame update
 void Start()
 {
     //build nav mesh on runtime
     surface.BuildNavMesh();
 }
示例#21
0
 private void DestroyClosestTarget(Collider closestTarget)
 {
     closestTarget.gameObject.SetActive(false);
     surface.BuildNavMesh();
 }
示例#22
0
 // Update is called once per frame
 void LateUpdate()
 {
     //Nave Mesh is updating
     surface.BuildNavMesh();
 }
示例#23
0
 /// <summary>
 /// 烘焙路径
 /// </summary>
 private void BakePath()
 {
     agent.enabled = false;
     surface.BuildNavMesh();
     path = new NavMeshPath();
 }
示例#24
0
 /// <summary>
 /// generate navmesh for npcs
 /// </summary>
 /// <remarks>For some strange reason you only need to have 1 navmeshsurface.</remarks>
 public void GenerateNavMesh()
 {
     mesh.BuildNavMesh();
 }
示例#25
0
 public void BuildNavMeshAfterLevel()
 {
     surface.BuildNavMesh();
     Debug.Log("navmesh built, supposedly");
 }
 public void NavMeshIsAvailableAfterBuild()
 {
     surface.BuildNavMesh();
     Assert.IsTrue(HasNavMeshAtOrigin());
 }
示例#27
0
 // Start is called before the first frame update
 public void Bake()
 {
     surface.BuildNavMesh();
 }
示例#28
0
 // Start is called before the first frame update
 void Start()
 {
     surface.BuildNavMesh();
 }
示例#29
0
 void Start()
 {
     GenerateLevel();
     surface.BuildNavMesh();
 }
示例#30
0
    void Start()
    {
        //*** Init from Json
        m_nbColor_min      = OptionsManager.m_options.lvl2_nbColors;
        m_random_steps_max = OptionsManager.m_options.lvl2_randomSteps;
        m_rate_side        = OptionsManager.m_options.lvl2_sideSteps;
        m_steps_min        = OptionsManager.m_options.lvl2_steps;
        m_random_color_max = OptionsManager.m_options.lvl2_random_color_max;

        m_nbColor = m_nbColor_min + Random.Range(0, m_random_color_max);
        //size of the ground where the player start
        m_ground.transform.localScale = new Vector3(m_ground.transform.localScale.x, m_ground.transform.localScale.y, 4f * m_nbColor);
        m_ground.transform.position   = new Vector3(m_ground.transform.position.x, m_ground.transform.position.y, (4f * m_nbColor) / 2);


        //Randomly improve number of steps


        m_steps = m_steps_min + Random.Range(0, m_random_steps_max);
        m_list  = new GameObject[m_steps, m_nbColor];
        Queue <Material> shuffleColor = new Queue <Material>();


        for (int i = 0; i < m_steps; i++)
        {
            //reload color
            Shuffle(m_color, m_nbColor);
            for (int r = 0; r < m_nbColor; r++)
            {
                shuffleColor.Enqueue(m_color[r]);
            }

            for (int j = 0; j < m_nbColor; j++)
            {
                GameObject cgenerated = Instantiate(m_shape);
                cgenerated.transform.parent   = this.transform; //inside this game object
                cgenerated.transform.position = m_shape.transform.position + new Vector3(i * m_gape, 0, j * m_gape);
                cgenerated.GetComponent <Renderer>().material = shuffleColor.Dequeue();

                NavMeshLink north = cgenerated.AddComponent <NavMeshLink>();
                north.startPoint = new Vector3(-m_gape, 1, 0);
                north.endPoint   = new Vector3(0, 1, 0);

                NavMeshLink east = cgenerated.AddComponent <NavMeshLink>();
                east.startPoint = new Vector3(0, 1, 0);
                east.endPoint   = new Vector3(0, 1, m_gape);

                NavMeshLink ne = cgenerated.AddComponent <NavMeshLink>();
                ne.startPoint = new Vector3(0, 1, 0);
                ne.endPoint   = new Vector3(m_gape, 1, m_gape);

                NavMeshLink nw = cgenerated.AddComponent <NavMeshLink>();
                nw.startPoint = new Vector3(0, 1, 0);
                nw.endPoint   = new Vector3(m_gape, 1, -m_gape);

                m_list[i, j] = cgenerated;
            }
        }
        Destroy(m_shape);
        m_surfaces.BuildNavMesh();
        m_path = new List <GameObject>();
        makePath(m_path);
        updateColorIcons();

        //Show all the cube map from the cam
        m_cam.orthographicSize += m_path.Count * 1.4f;

        //Sounds
        FindObjectOfType <OptionsManager>().PlaySound("bgm_action_4");
    }