示例#1
0
    // Use this for initialization
    void OnGUI()
    {
        EditorGUILayout.PrefixLabel("Map Settings", EditorStyles.boldLabel);
        // Add Width, height controls
        m_Width = (int)EditorGUILayout.IntField("Width", m_Width);
        m_Height = (int)EditorGUILayout.IntField("Height", m_Height);

        if(GUILayout.Button("Create"))
        {
            var level_manager = GameObject.Find("LevelManager").GetComponent<he.script.LevelManager>();
            // If we got some terrain already created, destroy it
            if (level_manager.terrainManager != null)
                ClearTerrain(level_manager.terrainManager);

            // Get current scene path
            string current_scene = EditorApplication.currentScene;
            string current_scene_path = current_scene.Substring(0, current_scene.LastIndexOf('/'));
            current_scene_path = current_scene_path.Substring(current_scene_path.LastIndexOf('/') + 1);
            // Material manager
            var material_manager = new he.TerrainMaterialManager(Application.dataPath);

            string asset_parent_path = "Assets/Scenes";
            string asset_path = GetCurrentScenePath();
            // Be sure asset path exist
            string asset_path_guid = AssetDatabase.AssetPathToGUID(asset_path);
            if(asset_path_guid.Length == 0)
                AssetDatabase.CreateFolder(asset_parent_path, current_scene_path);
            // Create terrain manager and all partitions
            var tile_set = material_manager.GetTerrainSet("summer");
            level_manager.terrainManager.This((ushort)m_Width, (ushort)m_Height, tile_set);
            // Create all assets
            level_manager.CreateAssets(asset_path + "/", new AssetDatabaseCustom());

            // Terrain manager has changed
            EditorUtility.SetDirty(level_manager.terrainManager);
            // Refresh asset database because of terrain were added there
            AssetDatabase.Refresh();
        }
    }
示例#2
0
        //! Load xml.
        public void LoadXml(XmlReader Reader, IEditor AssetDatabase)
        {
            // Material manager
            var material_manager = new he.TerrainMaterialManager(Application.dataPath);
            // Create terrain manager and all partitions
            var tile_set = material_manager.GetTerrainSet("summer");

            Reader.ReadToDescendant("terrain");

            m_Width = ushort.Parse(Reader.GetAttribute("width"));
            m_Height = ushort.Parse(Reader.GetAttribute("height"));

            m_Partitions = new TerrainPartition[m_Width * m_Height];
            for (int i = 0; i < m_Height; ++i)
            {
                for (int j = 0; j < m_Width; ++j)
                {
                    Reader.ReadToFollowing("partition");

                    TerrainPartition terrain_comp = CreateTerrainPartition(j, i);
                    // Add to list of partitions
                    m_Partitions[j + i * m_Width] = terrain_comp;
                    // Load the terrain partition data
                    terrain_comp.LoadXml(Reader, AssetDatabase);
                    // Create mesh
                    terrain_comp.CreateMesh(tile_set);
                }
            }
        }