public static void Load(string _path, TileWorldCreator _creator)
        {
            if (_path == "")
            {
                return;
            }

            isLoading = true;

            FileStream   _file = new FileStream(_path, FileMode.Open, FileAccess.Read);
            StreamReader _sr   = new StreamReader(_file);


            saveMapContent = _sr.ReadToEnd();


            //split file in several xml maps
            string[] _sp   = new string[] { "---" };
            string[] lines = saveMapContent.Split(_sp, System.StringSplitOptions.None); //("---"[0]);

            _creator.configuration.worldMap = new List <TileWorldConfiguration.WorldMap>();

            _creator.configuration.global.layerCount = lines.Length - 1;

            //clear all settings except presets
            _creator.ClearSettings(false, lines.Length - 1);

            //load back map for each layer
            for (int l = 0; l < lines.Length - 1; l++)
            {
                SaveMap _map = GetData <SaveMap>(lines[l]);

                _creator.configuration.global.width  = _map.width;
                _creator.configuration.global.height = _map.height;



                _creator.configuration.worldMap.Add(new TileWorldConfiguration.WorldMap(_creator.configuration.global.width, _creator.configuration.global.height, false, _map.useMask, _map.selectedMask));


                //Load back multidimensional array from single dim array
                _creator.configuration.worldMap[l].cellMap = new bool[_creator.configuration.global.width, _creator.configuration.global.height];
                //_creator.configuration.worldMap[l].tileInformation = new TileWorldConfiguration.TileInformation[_creator.configuration.global.width, _creator.configuration.global.height];
                _creator.configuration.worldMap[l].tileObjects = new GameObject[_creator.configuration.global.width, _creator.configuration.global.height];
                _creator.configuration.worldMap[l].tileTypes   = new TileWorldConfiguration.TileInformation.TileTypes[_creator.configuration.global.width, _creator.configuration.global.height];
                _creator.configuration.worldMap[l].maskMap     = new bool[_creator.configuration.global.width, _creator.configuration.global.height];
                _creator.configuration.worldMap[l].oldCellMap  = new bool[_creator.configuration.global.width, _creator.configuration.global.height];

                //for (int i = 0; i < _creator.configuration.global.height; i++)
                //{
                //    for (int j = 0; j < _creator.configuration.global.width; j++)
                //    {

                //        _creator.configuration.worldMap[l].tileInformation[j, i] = new TileWorldConfiguration.TileInformation();
                //    }
                //}

                int _index = 0;



                for (int y = 0; y < _creator.configuration.global.height; y++)
                {
                    for (int x = 0; x < _creator.configuration.global.width; x++)
                    {
                        _creator.configuration.worldMap[l].cellMap[x, y] = _map.map[_index]; // creator.worldMap[l].mapSingle[_index];

                        if (_map.maskMap.Length > 0)
                        {
                            _creator.configuration.worldMap[l].maskMap[x, y] = _map.maskMap[_index];
                        }


                        _index++;
                    }
                }

                _creator.ResizeIntArray(false, 0);
            }

            _sr.Close();

            isLoading = false;
        }
Esempio n. 2
0
        public static void Load(string _path, TileWorldCreator _creator)
        {
            if (_path == "")
            {
                return;
            }

            isLoading = true;


            byte[] bytes = File.ReadAllBytes(_path);
            saveMapContent = SerializationUtility.DeserializeValue <string>(bytes, DataFormat.Binary);

            //split file in several xml maps
            string[] _sp   = new string[] { "---" };
            string[] lines = saveMapContent.Split(_sp, System.StringSplitOptions.None); //("---"[0]);

            _creator.configuration.worldMap = new List <TileWorldConfiguration.WorldMap>();

            _creator.configuration.global.layerCount = lines.Length - 1;

            //clear all settings except presets
            _creator.ClearSettings(false, lines.Length - 1);

            //load back map for each layer
            for (int l = 0; l < lines.Length - 1; l++)
            {
                SaveMap _map = GetData <SaveMap>(lines[l]);

                _creator.configuration.global.width  = _map.width;
                _creator.configuration.global.height = _map.height;
                _creator.configuration.global.layerPresetIndex[l] = _map.preset;


                _creator.configuration.worldMap.Add(new TileWorldConfiguration.WorldMap(_creator.configuration.global.width, _creator.configuration.global.height, false, _map.useMask, _map.selectedMask));


                //Load back multidimensional array from single dim array
                _creator.configuration.worldMap[l].cellMap     = new bool[_creator.configuration.global.width, _creator.configuration.global.height];
                _creator.configuration.worldMap[l].tileObjects = new GameObject[_creator.configuration.global.width, _creator.configuration.global.height];
                _creator.configuration.worldMap[l].tileTypes   = new TileWorldConfiguration.TileInformation.TileTypes[_creator.configuration.global.width, _creator.configuration.global.height];
                _creator.configuration.worldMap[l].maskMap     = new bool[_creator.configuration.global.width, _creator.configuration.global.height];
                _creator.configuration.worldMap[l].oldCellMap  = new bool[_creator.configuration.global.width, _creator.configuration.global.height];


                int _index = 0;



                for (int y = 0; y < _creator.configuration.global.height; y++)
                {
                    for (int x = 0; x < _creator.configuration.global.width; x++)
                    {
                        _creator.configuration.worldMap[l].cellMap[x, y] = _map.map[_index]; // creator.worldMap[l].mapSingle[_index];

                        if (_map.maskMap.Length > 0)
                        {
                            _creator.configuration.worldMap[l].maskMap[x, y] = _map.maskMap[_index];
                        }


                        _index++;
                    }
                }

                _creator.ResizeIntArray(false, 0);
            }

            //_sr.Close();

            isLoading = false;
        }