Esempio n. 1
0
        public void New(MapSetting setting)
        {
            Init(new ResourceLoader());
            terrainRoot = new GameObject("TerrainRoot").transform;
            terrainRoot.SetParent(MapRoot, false);

            //Load(setting);
            ResizeMap(setting.CellCountX, setting.CellCountY);

            EventManager.Instance.Register(this, EditorEvent.MAP_LOAD, OnLoadMap);
            EventManager.Instance.Register(this, EditorEvent.MAP_UPDATE_PATHS, OnUpdatePaths);
            EventManager.Instance.Register(this, EditorEvent.MAP_UPDATE_PATH, OnUpdatePath);
            EventManager.Instance.Register(this, EditorEvent.MAP_TERRAIN_UPDATE, OnUpdateTerrain);
        }
Esempio n. 2
0
        public void Load(MapSetting setting)
        {
            CellCountX = setting.CellCountX;
            CellCountY = setting.CellCountY;
            UpdateMapSize();

            // Load map cells
            Cells = new Dictionary<int, MapCell>();
            foreach (MapCellSetting cellSetting in setting.Cells)
            {
                GameObject cellObject = Loader.LoadPrefab("Map/MapCell").Instantiate();
                cellObject.transform.SetParent(CellRoot, false);
                MapCell cell = cellObject.AddComponent<MapCell>();
                cell.Init(this, (short)cellSetting.X, (short)cellSetting.Y);
                cell.Load(cellSetting);
                Cells.Add(cell.Key, cell);
            }
            BuildNeighbours();

            // Load paths
            foreach (MapPathSetting pathSetting in setting.Paths)
            {
                List<Vector2> locations = new List<Vector2>(pathSetting.Waypoints.Length);
                foreach (var point in pathSetting.Waypoints)
                    locations.Add(new Vector2(point.X, point.Y));
                AddPath(locations, new Color(pathSetting.ColorR, pathSetting.ColorG, pathSetting.ColorB));
            }
            CalculatePaths();
            ToggleShowPaths(true);
        }