Exemplo n.º 1
0
    void LoadMap(int Worldx, int Worldy, int x, int y, YieldDirection yieldDirection)
    {
        String       saveMapPath = getMapPath(Worldx, Worldy, saveMapDataPath);
        MapBlockData mapdata     = mapfile.LoadFile(saveMapPath);

        if (mapdata == null)
        {
            String mapPath = getMapPath(Worldx, Worldy, mapDataPath);
            mapdata = mapfile.LoadFile(mapPath);
        }
        InstantiateMap(mapdata, Worldx, Worldy, x, y);
    }
Exemplo n.º 2
0
    void LoadMapThreaded(int Worldx, int Worldy, int x, int y, YieldDirection yieldDirection)
    {
        String      saveMapPath = getMapPath(Worldx, Worldy, saveMapDataPath);
        String      mapPath     = getMapPath(Worldx, Worldy, mapDataPath);
        LoadFileJob loadFileJob = new LoadFileJob();

        loadFileJob.Worldx         = Worldx;
        loadFileJob.Worldy         = Worldy;
        loadFileJob.x              = x;
        loadFileJob.y              = y;
        loadFileJob.input          = saveMapPath;
        loadFileJob.input2         = mapPath;
        loadFileJob.yieldDirection = yieldDirection;
        lfj.Add(loadFileJob);
        loadFileJob.Start();
    }
Exemplo n.º 3
0
    void InstantiateMap(MapBlockData mapData, int Worldx, int Worldy, int x, int y, YieldDirection yieldDirection)
    {
        GameObject world = GameObject.Find(getWorldName(Worldx, Worldy));

        if (world == null)
        {
            world      = (GameObject)Instantiate(prefabMapBlockView, new Vector3(0, 0, 0), Quaternion.identity, prefabParent.transform);
            world.name = getWorldName(Worldx, Worldy);
            world.transform.position = calculateTransformPosition(Worldx, Worldy);

            MapBlockView mapBlockView = world.GetComponent <MapBlockView> ();
            if (mapBlockView == null)
            {
                throw new MissingComponentException("Expected to find the MapBlockView Component");
            }
            mapBlockView.AutoSave = AutoSave;
            worlds [x, y]         = world;
            this.mapBlocks [x, y] = mapBlockView;
            StartCoroutine(mapBlockView.Initialize(Worldx, Worldy, mapData, getMapPath(Worldx, Worldy, saveMapDataPath), yieldDirection, resourceManager, this));
        }
    }
Exemplo n.º 4
0
        public IEnumerator Initialize(int blockX, int blockY, MapBlockData mapBlockData, String mapPath, YieldDirection yieldDirection, ResourceManager resourceManager, AsciiMapScript asciiMapScript)
        {
            this.blockX          = blockX;
            this.blockY          = blockY;
            this.mapBlockData    = mapBlockData;
            this.mapPath         = mapPath;
            this.resourceManager = resourceManager;
            this.asciiMapScript  = asciiMapScript;
            this.mapfile         = new MapFile();
            if (this.prefabWall == null)
            {
                this.prefabWall = resourceManager.getGameObject("Main/Wall");
            }
            if (this.prefabWorldWall == null)
            {
                this.prefabWorldWall = resourceManager.getGameObject("Main/worldwall");
            }

            if (mapBlockData == null)
            {
                // Empty map blocks will display as walls
                CreateMapObject((MapRows / 2), (MapCols / 2), prefabWorldWall, this.gameObject, "Main/WorldWall", 6, MapLayer.Floor);
            }
            else
            {
                if (yieldDirection == YieldDirection.YieldRight)
                {
                    for (int x = 0; x < mapBlockData.getRows(); x++)
                    {
                        if (this != null)
                        {
                            for (int y = 0; y < mapBlockData.getCols(); y++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
                else if (yieldDirection == YieldDirection.YieldLeft)
                {
                    for (int x = mapBlockData.getRows() - 1; x >= 0; x--)
                    {
                        if (this != null)
                        {
                            for (int y = 0; y < mapBlockData.getCols(); y++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
                else if (yieldDirection == YieldDirection.YieldDown)
                {
                    if (this != null)
                    {
                        for (int y = 0; y < mapBlockData.getCols(); y++)
                        {
                            for (int x = 0; x < mapBlockData.getRows(); x++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
                else if (yieldDirection == YieldDirection.YieldUp)
                {
                    for (int y = mapBlockData.getCols() - 1; y >= 0; y--)
                    {
                        if (this != null)
                        {
                            for (int x = 0; x < mapBlockData.getRows(); x++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
                else
                {
                    for (int x = 0; x < mapBlockData.getRows(); x++)
                    {
                        if (this != null)
                        {
                            for (int y = 0; y < mapBlockData.getCols(); y++)
                            {
                                if (x < 0 || x == mapBlockData.getRows() || y < 0 || y == mapBlockData.getCols())
                                {
                                    CreateMapObject(x, y, prefabWall, this.gameObject, "Main/Wall", 6, MapLayer.Floor);
                                }
                                else
                                {
                                    //GameObject floorObject = mapData.getFloor (x, y);
                                    GameObject floorObject = resourceManager.getGameObject(mapBlockData.getFloorResource(x, y));
                                    if (floorObject != null)
                                    {
                                        CreateMapObject(x, y, floorObject, this.gameObject, mapBlockData.getFloorResource(x, y), mapBlockData.getFloorInt(x, y), MapLayer.Floor);
                                    }
                                    //GameObject mainObject = mapData.getMain (x, y);
                                    GameObject mainObject = resourceManager.getGameObject(mapBlockData.getMainResource(x, y));
                                    if (mainObject != null)
                                    {
                                        CreateMapObject(x, y, mainObject, this.gameObject, mapBlockData.getMainResource(x, y), mapBlockData.getMainInt(x, y), MapLayer.Main);
                                    }
                                }
                            }
                        }
                        yield return(null);
                    }
                }
            }
            isInitialized = true;
            // Spawn a zombie
            if (blockX == 3 && blockY == 3 && this != null)
            {
                CreateMapObject(5, 10, resourceManager.getGameObject("main/zombie"), this.gameObject, "main/zombie", 7, MapLayer.Main);
                //	CreateMapObject (5, 5, resourceManager.getGameObject ("main/npc"), this.gameObject, "main/npc", 7, MapLayer.Main);
            }
        }