Example #1
0
        void OnEnable()
        {
            var tile_map = GameObject.FindGameObjectWithTag("TileMap");

            if (tile_map != null)
            {
                mTilemap = tile_map.GetComponent <EditorData.TileMap>();
            }

            SpriteSheetManager.Instance.Load("tile");

            mMonsterList = new MonsterList();
            for (uint i = 1; i <= 31; ++i)
            {
                mMonsterList.Add(i);
            }

            mItemList = new ItemList();
            for (uint i = 1; i <= 7; ++i)
            {
                mItemList.Add(i);
            }

            mTerrainList = new TerrainList();
            for (uint i = 1; i <= 4; ++i)
            {
                mTerrainList.Add(i);
            }

            mPortalList = new PortalList();
            mPortalList.Add(0);
            mPortalList.Add(1);

            SceneView.onSceneGUIDelegate += TileMapUpdate;
        }
Example #2
0
        void OnGUI()
        {
            if (Application.isPlaying)
            {
                EditorGUILayout.LabelField("Please exit the play mode.");
                return;
            }

            if (mTilemap == null)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Level");
                mMapLevel = (uint)EditorGUILayout.IntField((int)mMapLevel);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("TileMap Width:");
                var width = (uint)EditorGUILayout.IntField(11);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("TileMap Height");
                var height = (uint)EditorGUILayout.IntField(11);
                EditorGUILayout.EndHorizontal();

                if (GUILayout.Button("Generate TileMap"))
                {
                    var tile_map_obj = new GameObject("TileMap");
                    mTilemap         = tile_map_obj.AddComponent <EditorData.TileMap>();
                    tile_map_obj.tag = "TileMap";

                    mTilemap.Level = mMapLevel;
                    mTilemap.Init(width, height);
                }

                if (GUILayout.Button("Load TileMap"))
                {
                    var asset = Resources.Load("level" + mMapLevel) as TextAsset;
                    Data.TileMapData tile_map_data = null;
                    using (var stream = new MemoryStream(asset.bytes))
                    {
                        var formatter = new BinaryFormatter();
                        tile_map_data = formatter.Deserialize(stream) as Data.TileMapData;
                    }

                    //var tile_map_data = AssetDatabase.LoadAssetAtPath("Assets/test.asset", typeof(Data.TileMapData)) as Data.TileMapData;

                    var tile_map_obj = new GameObject("TileMap");
                    mTilemap         = tile_map_obj.AddComponent <EditorData.TileMap>();
                    tile_map_obj.tag = "TileMap";

                    mTilemap.Level = tile_map_data.Level;
                    mTilemap.Init(tile_map_data.Width, tile_map_data.Height);

                    var floor_layer = tile_map_data.FloorLayer;
                    for (int r = 0; r < floor_layer.GetLength(0); ++r)
                    {
                        for (int c = 0; c < floor_layer.GetLength(1); ++c)
                        {
                            var tile = TerrainList.CreateTile((Logic.Tile.EType)floor_layer[r, c]);
                            mTilemap.SetTile(r, c, tile, ETileMapLayer.Floor);
                        }
                    }

                    foreach (var monster_data in tile_map_data.MonsterDatas)
                    {
                        var monster = MonsterList.CreateTile(monster_data.Id);
                        mTilemap.SetTile((int)monster_data.Pos.Row, (int)monster_data.Pos.Col, monster, ETileMapLayer.Collide);
                    }

                    foreach (var portal_data in tile_map_data.PortalDatas)
                    {
                        var portal = PortalList.CreateTile(portal_data.PortalType, portal_data.DestinationLevel, portal_data.DestinationPosition);
                        mTilemap.SetTile((int)portal_data.Pos.Row, (int)portal_data.Pos.Col, portal, ETileMapLayer.Collide);
                    }
                }

                return;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Level");
            mTilemap.Level = (uint)EditorGUILayout.IntField((int)mTilemap.Level);
            EditorGUILayout.EndHorizontal();

            mEditMode = (EEditMode)EditorGUILayout.EnumPopup("Edit Mode", mEditMode);
            if (mEditMode == EEditMode.Modify || mEditMode == EEditMode.Erase)
            {
                mEditRange = EditorGUILayout.IntSlider("Range", mEditRange, 1, 4);
            }

            mEditLayer = (ETileMapLayer)EditorGUILayout.EnumPopup("Edit Layer", mEditLayer);

            EditorGUILayout.LabelField("Terrain List", EditorStyles.boldLabel);
            if (mTerrainList.Draw())
            {
                Repaint();
            }

            EditorGUILayout.LabelField("Portal List", EditorStyles.boldLabel);
            if (mPortalList.Draw())
            {
                Repaint();
            }

            EditorGUILayout.LabelField("Monster List", EditorStyles.boldLabel);
            if (mMonsterList.Draw())
            {
                Repaint();
            }

            EditorGUILayout.LabelField("Item List", EditorStyles.boldLabel);
            if (mItemList.Draw())
            {
                Repaint();
            }

            if (GUILayout.Button("Save"))
            {
                mTilemap.Save(string.Format("Assets/Resources/level{0}.bytes", mTilemap.Level));
            }
        }