Beispiel #1
0
    public static LevelMapData Load()
    {
        if (data != null)
        {
            return(data);
        }
        string path = XGamePath.GetLevelDataJsonPath(LevelMap_FileName);

        //Debug.Log("LevelMapData.Load==>" + path);
        if (File.Exists(path))
        {
            try
            {
                StreamReader fs   = File.OpenText(path);
                string       json = fs.ReadToEnd();
                //ResMgr.Log(json);
                fs.Close();
                data = JsonMapper.ToObject <LevelMapData>(json);
                return(data);
            }
            catch (Exception e)
            {
                Debug.Log(e + "==>" + e.Data);
            }
        }
        else
        {
            Debug.Log("file not exist");
        }
        return(null);
    }
Beispiel #2
0
    public static void Save(LevelMapData data)
    {
        string FilePath = XGamePath.GetLevelDataJsonPath(LevelMap_FileName);

        //string FilePath = Path.Combine(Application.dataPath, "FakeResources/Data/LevelConfig/" + data.Name + ".json");
        LevelLoader.data = data;

        //Debug.Log("LevelMapData.Save==>" + FilePath);
        string json = JsonMapper.ToJson(data);
        string path = string.Format(FilePath, data.Name);

        try
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            byte[]     bytes = Encoding.UTF8.GetBytes(json);
            FileStream fs    = File.Create(path);
            fs.Write(bytes, 0, bytes.Length);
            fs.Flush();
            fs.Close();
        }
        catch (Exception e)
        {
            Debug.Log(e + "==>" + e.Data);
        }
    }
Beispiel #3
0
    public void AddScriptable(Vector2Int pPosition, GameScriptable pObject)
    {
        if (mActiveLevel.mLevelData == null)
        {
            mActiveLevel.mLevelData = new List <LevelMapData>();
            EditorUtility.SetDirty(mActiveLevel);
            EditorUtility.SetDirty(mAllLevels);
        }
        int aLIx = GetPositionIndex(pPosition);

        if (aLIx == -1)
        {
            aLIx = mActiveLevel.mLevelData.Count;
            LevelMapData aData = new LevelMapData();
            aData.mLayerTypes  = new List <Level.LayerTypes>();
            aData.mPosition    = pPosition;
            aData.mScriptables = new List <GameScriptable>();
            mActiveLevel.mLevelData.Add(aData);
            EditorUtility.SetDirty(mActiveLevel);
            EditorUtility.SetDirty(mAllLevels);
        }
        mActiveLevel.mLevelData[aLIx].mLayerTypes.Add(pObject.mRenderLayer);
        EditorUtility.SetDirty(mActiveLevel);
        EditorUtility.SetDirty(mAllLevels);
        mActiveLevel.mLevelData[aLIx].mScriptables.Add(pObject);
        EditorUtility.SetDirty(mActiveLevel);
        EditorUtility.SetDirty(mAllLevels);
    }
Beispiel #4
0
 protected override void Init()
 {
     m_config = ResBinReader.Read <LevelConfig_ARRAY>("LevelConfig");
     SortConfig();
     m_themeConfig = ResBinReader.Read <ThemeConfig_ARRAY>("ThemeConfig");
     m_value       = ResBinReader.Read <ValueConfig_ARRAY>("ValueConfig");
     m_data        = LevelLoader.Load();
     if (m_data == null)
     {
         Debuger.Log(Tag, string.Empty, "m_data == null");
     }
     CurPlayMode = GamePlayModule.Normal;
 }
Beispiel #5
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (Application.isPlaying)
        {
            mapMaker = MapMaker.Instance;
            //mapDataList = mapMaker.mapDataList;
            allGrid = mapMaker.allGrid;
            //LevelMapDataMgr levelMgr = Resources.Load<LevelMapDataMgr>("AssetData/LevelMapData");
            ////如果路径存在,先读取文件
            //if (levelMgr != null)
            //{
            //    mapDataList = levelMgr.leveMapDataList;
            //}

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("搜集地图数据"))
            {
                md               = new LevelMapData();
                md.levelID       = mapMaker.levelID;
                md.gridStateList = new List <GridPoint.GridState>();
                foreach (GridPoint gp in allGrid)
                {
                    if (gp.gridState.isTowerPoint)
                    {
                        md.gridStateList.Add(gp.gridState);
                    }
                }
                mapMaker.mapData = md;
            }
            if (GUILayout.Button("保存当前地图"))
            {
                //如果是新关卡 则添加
                LevelMapDataMgr mgrP = Resources.Load <LevelMapDataMgr>("AssetData/LevelMapData");
                if (md.levelID > mgrP.leveMapDataList.Count)
                {
                    //mapDataList.Add(md);
                    mgrP.leveMapDataList.Add(md);
                }
                else
                {
                    mgrP.leveMapDataList[md.levelID - 1] = md;
                }
                LevelMapDataMgr mgr = ScriptableObject.CreateInstance <LevelMapDataMgr>();
                //LevelMapDataMgr mgr = new LevelMapDataMgr();
                mgr.leveMapDataList = new List <LevelMapData>();
                for (int i = 0; i < mgrP.leveMapDataList.Count; i++)
                {
                    mgr.leveMapDataList.Add(mgrP.leveMapDataList[i]);
                }
                UnityEditor.AssetDatabase.CreateAsset(mgr, "Assets/Resources/AssetData/LevelMapData.asset");
                UnityEditor.AssetDatabase.SaveAssets();
                UnityEditor.AssetDatabase.Refresh();
                Debug.Log("保存成功");
            }

            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("读取当前关卡"))
            {
                foreach (GridPoint gp in allGrid)
                {
                    gp.InitGrid();
                }

                foreach (GridPoint.GridState gs in LevelMapDataMgr.Instance.leveMapDataList[mapMaker.levelID - 1].gridStateList)
                {
                    allGrid[gs.id].gridState = gs;
                    allGrid[gs.id].UpdateGrid();
                }

                mapMaker.roadSR.sprite = Resources.Load <Sprite>("Pictures/Game/Map/Map_" + mapMaker.levelID);
            }
            if (GUILayout.Button("重置操作"))
            {
                foreach (GridPoint gp in allGrid)
                {
                    gp.InitGrid();
                    gp.UpdateGrid();
                }
            }
            EditorGUILayout.EndHorizontal();
        }
    }
Beispiel #6
0
    public static void OnGui(MapEditor wind)
    {
        m_deletegroup.Clear();
        LevelMapData data = wind.Level_Data;

        m_scroll = GUILayout.BeginScrollView(m_scroll);
        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        GUILayout.Label(data.Name, GUILayout.Width(200));
        GUILayout.Label("关卡数:" + data.Configs.Count, GUILayout.Width(300));
        GUILayout.EndHorizontal();


        GUILayout.BeginHorizontal();
        bool isadd = false;

        if (isaddmode)
        {
            string temp = "0";
            isadd = GUILayout.Button("确认");
            GUILayout.Label("关卡ID", GUILayout.Width(50));
            temp = GUILayout.TextField(id.ToString());
            id   = uint.Parse(temp);
            if (GUILayout.Button("取消"))
            {
                isaddmode = false;
            }
        }
        else
        {
            isaddmode = GUILayout.Button("添加关卡", GUILayout.Width(75));
            GUILayout.Label("筛选关卡:", GUILayout.Width(50));
            if (GUILayout.Button("清空", GUILayout.Width(40)))
            {
                wind.selectedLevel = string.Empty;
            }
            wind.selectedLevel = GUILayout.TextField(wind.selectedLevel, GUILayout.Width(50));
            GUILayout.Space(10);
            if (GUILayout.Button("关卡类型", MapEditor.toolbarDropdown, GUILayout.Width(75)))
            {
                GenericMenu menu = new UnityEditor.GenericMenu();
                //menu.AddSeparator("");
                menu.AddItem(new GUIContent("全部"), false, () => { wind.selectedLevel_Type = 0; });
                menu.AddItem(new GUIContent("冒险关卡"), false, () => { wind.selectedLevel_Type = 1; });
                menu.AddItem(new GUIContent("签到关卡"), false, () => { wind.selectedLevel_Type = 2; });
                //menu.DropDown(new Rect(0, 0, 20, 30));
                menu.ShowAsContext();
            }
        }
        if (isadd)
        {
            AddConfig(wind, id);
            isaddmode = false;
        }
        if (GUILayout.Button("编辑工具格子", GUILayout.Width(150)))
        {
            wind.Pagetype = MapEditor.PageType.EditorSub;
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("地图ID", GUILayout.Width(200));
        GUILayout.Label("对应的关卡ID", GUILayout.Width(250));
        GUILayout.Label("规格:", GUILayout.Width(200));
        GUILayout.EndHorizontal();

        foreach (var k in data.Configs)
        {
            ConfigItem.OnGui(k, wind);
        }
        GUILayout.EndVertical();
        GUILayout.EndScrollView();
        if (m_deletegroup.Count > 0)
        {
            wind.Level_Data.DeleteConfig(m_deletegroup);
        }
    }
Beispiel #7
0
 /// <summary>
 /// Create a new Graph from here
 /// </summary>
 /// <param name="l">The level map</param>
 /// <returns>A new level map graph</returns>
 public static LevelMapGraph NewGraphFromMap(LevelMapData l)
 {
     return new LevelMapGraph(l);
 }
Beispiel #8
0
 /// <summary>
 /// Construct a new graph for a level
 /// </summary>
 /// <param name="level"></param>
 public LevelMapGraph(LevelMapData level)
 {
     LoadData(level);
 }
Beispiel #9
0
        /// <summary>
        /// Build level graph
        /// </summary>
        /// <param name="l"></param>
        public void LoadData(LevelMapData l)
        {
            level = l;
            //make graph based on map

            try
            {
                MapGraph = new Graph();

                MapNodes = new Node[level.Height * level.Width];

                // put nodes in graph and array
                for (int i = 0; i < level.Height * level.Width; i++)
                {
                    if (level.GetSquareAt(i % level.Width, i / level.Width).type == MapSquareType.Open)
                    {
                        MapNodes[i] = MapGraph.AddNode((i % level.Width) * 16 -8, (i / level.Width) * 16 -8, 0);
                    }
                }

                for (int i = 0; i < level.Height * level.Width; i++)
                {
                    //updown
                    if (i / level.Width > 0)
                    {
                        if (MapNodes[i - level.Width] != null && MapNodes[i] != null)
                            MapGraph.Add2Arcs(MapNodes[i], MapNodes[i - level.Width], 1);
                    }
                    //leftright
                    if (i % level.Width > 0)
                    {
                        if (MapNodes[i - 1] != null && MapNodes[i] != null)
                            MapGraph.Add2Arcs(MapNodes[i], MapNodes[i - 1], 1);
                    }
                    //top left diag
                    if (i % level.Width > 0 && i / level.Width > 0)
                    {
                        if (MapNodes[i - level.Width - 1] != null && MapNodes[i] != null && MapNodes[i - level.Width] != null && MapNodes[i - 1] != null)
                            MapGraph.Add2Arcs(MapNodes[i], MapNodes[i - level.Width - 1], 1);
                    }
                    //top right diag
                    if (i % level.Width < level.Width - 1 && i / level.Width > 0)
                    {
                        if (MapNodes[i - level.Width + 1] != null && MapNodes[i] != null && MapNodes[i + 1] != null && MapNodes[i - level.Width] != null)
                            MapGraph.Add2Arcs(MapNodes[i], MapNodes[i - level.Width + 1], 1);
                    }
                }
            }
            catch (Exception e) { throw e; }
        }
Beispiel #10
0
 /// <summary>
 /// Loads the game config from a config file
 /// This will also load the default level
 /// </summary>
 /// <param name="filename">The name of the config file to load</param>
 public void LoadConfigFromFile(string filename)
 {
     WriteDebugLine("BEGIN LOADING CONFIG FILE",true);
     //Load config and default level
     mCurrentConfiguration = GeneralConfig.LoadFromFile(filename);
     WriteDebugLine("Loaded Config from " + filename);
     mLevel = LevelData.Load(mCurrentConfiguration.DefaultLevel);
     WriteDebugLine("Loaded Level from " + mCurrentConfiguration.DefaultLevel);
     mMap = LevelMapData.LoadFromFile(mLevel.LevelMapFileName);
     WriteDebugLine("Loaded Map from " + mLevel.LevelMapFileName);
     //Create pathfinding graph for level
     mGraph = LevelMapGraph.NewGraphFromMap(mMap);
     WriteDebugLine("Created pathfinding graph from map");
     //Add config to scripting
     mScripter.LoadAndImportFromInstance(mCurrentConfiguration,out mBuffer);
     WriteDebugLine("Imported Config into Scripting Engine: " + mBuffer);
     WriteDebugLine("END LOADING CONFIG FILE");
 }
Beispiel #11
0
 /// <summary>
 /// Generate and initialise a new random square map and graph.
 /// </summary>
 /// <param name="Dimention">The side length of the square map.</param>
 public void GenerateNewRandomSquareMap(int Dimention, int wallstobreak)
 {
     mMap = RandomMapGenerator.RandomSquareLevelMap(Dimention, null, wallstobreak);
     mGraph = LevelMapGraph.NewGraphFromMap(mMap);
 }
Beispiel #12
0
        /// <summary>
        /// Get a new square random level map.
        /// </summary>
        /// <param name="dimention">The length of a side of the map.</param>
        /// <param name="rand">The random number provider.</param>
        /// <returns>A new Level Map.</returns>
        public static LevelMapData RandomSquareLevelMap(int dimention, Random rand, int wallstobreak)
        {
            //Make a new random square maze of the given dimention.
            Maze sourceMaze = new Maze(dimention);
            sourceMaze.Generate();

            //Generate level map based on maze.
            int yoffset = 1;
            LevelMapSquare topleft = new LevelMapSquare(MapSquareType.Open);
            LevelMapSquare topright = new LevelMapSquare(MapSquareType.Open);
            LevelMapSquare bottomleft = new LevelMapSquare(MapSquareType.Open);
            LevelMapSquare bottomright = new LevelMapSquare(MapSquareType.Open);
            LevelMapData MyLevel = new LevelMapData(sourceMaze.kDimension * 2 + 1, sourceMaze.kDimension * 2 + 1);

            for (int i = 0; i < sourceMaze.kDimension * sourceMaze.kDimension; i++)
            {
                topleft = new LevelMapSquare(MapSquareType.Open);
                topright = new LevelMapSquare(MapSquareType.Open);
                bottomleft = new LevelMapSquare(MapSquareType.Open);
                bottomright = new LevelMapSquare(MapSquareType.Open);

                //Do the west and south walls.
                //west
                if (sourceMaze.Cells[i % sourceMaze.kDimension, i / sourceMaze.kDimension].Walls[1] == 1)
                {
                    topleft.type = MapSquareType.Closed;
                    bottomleft.type = MapSquareType.Closed;
                }
                if (sourceMaze.Cells[i % sourceMaze.kDimension, i / sourceMaze.kDimension].Walls[2] == 1)
                {
                    bottomleft.type = MapSquareType.Closed;
                    bottomright.type = MapSquareType.Closed;
                }

                // maze x = map x*2
                MyLevel.SetSquareAt((i % sourceMaze.kDimension) * 2, (i / sourceMaze.kDimension) * 2 + yoffset, topleft);
                MyLevel.SetSquareAt(((i % sourceMaze.kDimension) * 2) + 1, (i / sourceMaze.kDimension) * 2 + yoffset, topright);
                MyLevel.SetSquareAt(((i % sourceMaze.kDimension) * 2) + 1, ((i / sourceMaze.kDimension) * 2) + 1 + yoffset, bottomright);
                MyLevel.SetSquareAt((i % sourceMaze.kDimension) * 2, ((i / sourceMaze.kDimension) * 2) + 1 + yoffset, bottomleft);

                //This method misses out corner bits - so if a square has both a right and up wall, fill the corner.
                if (i / sourceMaze.kDimension > 0 && i % sourceMaze.kDimension < sourceMaze.kDimension - 1)
                {
                    if (sourceMaze.Cells[i % sourceMaze.kDimension, i / sourceMaze.kDimension].Walls[0] == 1
                        && sourceMaze.Cells[i % sourceMaze.kDimension, i / sourceMaze.kDimension].Walls[3] == 1)
                    {
                        MyLevel.SetSquareAt(((i % sourceMaze.kDimension) * 2) + 2, ((i / sourceMaze.kDimension) * 2) - 1 + yoffset, new LevelMapSquare(MapSquareType.Closed));
                    }
                }
            }

            //Break down a few walls.
            Vector2 walltobreak;
            List<Vector2> exclusion = new List<Vector2>();
            for (int i = 0; i < MyLevel.Width; i++)
            {
                exclusion.Add(new Vector2(i, 0));//don't break down top north wall
                exclusion.Add(new Vector2(i, MyLevel.Height - 1));//or south wall
                exclusion.Add(new Vector2(0, i));//or east wall
                exclusion.Add(new Vector2(MyLevel.Width - 1, i));//or west wall
            }
            for (int i = 0; i < wallstobreak; i++)
            {
                walltobreak = MyLevel.GetRandomSquareCoordsByType(MapSquareType.Closed, null, exclusion, 0);
                MyLevel.SetSquareAt((int)walltobreak.X, (int)walltobreak.Y, new LevelMapSquare(MapSquareType.Open));
            }

            MyLevel.ComputeQuads();
            return MyLevel;
        }
Beispiel #13
0
 /// <summary>
 /// Load this level's current map.
 /// </summary>
 public void LoadMap()
 {
     if (m_levelmapfilename.Length > 0 && m_levelmapfilename != "<none>")
     {
         m_levelmap = LevelMapData.LoadFromFile(m_levelmapfilename);
     }
 }