예제 #1
0
        // ##################################################################################



        // ##################################################################################
        /// <summary>
        /// Convert downloaded topography files to wavefront .obj files
        /// </summary>
        /// <param name="fullpath_source_folder"></param>
        /// <param name="fullpath_scenery_folder"></param>
        /// <param name="heli_x_scenery_setting_xml"></param>
        // ##################################################################################
        private static void Convert_Heli_X_Topography_To_Wavefront_Obj(string fullpath_source_folder, string fullpath_scenery_folder,
                                                                       ref Heli_X_Scenery_Setting_Xml heli_x_scenery_setting_xml)
        {
            // get heli-x main scenery settings file
            heli_x_scenery_setting_xml = Load_Heli_X_Skybox_Setup_File(fullpath_source_folder);

            // convert all collision/topography files to a single liste of triangles
            List <Heli_X_Triangle> heli_x_triangles = new List <Heli_X_Triangle>();

            foreach (string topography_file in heli_x_scenery_setting_xml.TopographyFile)
            {
                Load_Heli_X_Collision_Topography_Files(fullpath_source_folder + "\\" + topography_file, ref heli_x_triangles);
            }

            // after all collision/topography files are converted to one singe list of triangles, convert them to .obj
            Export_Heli_X_Collision_Object_As_Wavefront_Obj(fullpath_scenery_folder, heli_x_triangles);
        }
예제 #2
0
        // ##################################################################################



        // ##################################################################################
        // downloading zip-files from internet, unzip, copy and convert the collision files to .obj
        // https://forum.unity.com/threads/downloading-progress.184353/
        // ##################################################################################
        static IEnumerator Download_And_Import_Skybox(string url, string fullpath_scenery_folder, MonoBehaviour justToStartCoroutine, GameObject ui_canvas)
        {
            //UnityEngine.Debug.Log("Downloading file...");

            UnityWebRequest www = new UnityWebRequest(url);

            www.downloadHandler = new DownloadHandlerBuffer();

            justToStartCoroutine.StartCoroutine(Download_Progress(www, Path.GetFileName(fullpath_scenery_folder), justToStartCoroutine, ui_canvas));

            yield return(www.SendWebRequest());

            if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
            {
                //UnityEngine.Debug.Log(www.error);// TODO error handling
            }
            else
            {
                // The zip file has to be extracted temporaly, because we do not need every file. The rest is deleted again.
                string fullpath_temporary_folder = Path.GetTempPath();

                // Retrieve results as binary data
                byte[] results = www.downloadHandler.data;

                //Path.Combine(Application.streamingAssetsPath, "Skymaps\\" + filename_scenery_file);
                string scenery_name = Path.GetFileName(fullpath_scenery_folder);                 // heli-x uses foldername as name for setting file

                // (the data in the unziped files are stored in subfolders: i.e. \SkyBox\Ahornkopf\)
                string subfolder = Path.Combine("SkyBox", scenery_name);

                // because of too long path names (260 characters limit) the zip file is extracted to the temp directory
                //string fullpath_scenery_file_zipped = @"\\?\" + fullpath_scenery_folder + "\\" + filename_scenery_file + ".zip";
                if (!System.IO.Directory.Exists(fullpath_temporary_folder))
                {
                    System.IO.Directory.CreateDirectory(fullpath_temporary_folder);
                }

                //string fullpath_scenery_file_zipped = @"\\?\" + fullpath_temporary_folder + scenery_name + ".zip";
                //fullpath_scenery_file_zipped = @fullpath_scenery_file_zipped.Replace('/', '\\');
                string fullpath_scenery_file_zipped = Path.Combine(fullpath_temporary_folder, scenery_name + ".zip");

                string fullpath_scenery_file_unzipped = fullpath_temporary_folder;

                if (System.IO.Directory.Exists(Path.Combine(fullpath_temporary_folder, subfolder)))
                {
                    System.IO.Directory.Delete(Path.Combine(fullpath_temporary_folder, subfolder), true);
                }

                // store data from memory
                System.IO.File.WriteAllBytes(fullpath_scenery_file_zipped, results);

                //UnityEngine.Debug.Log("Download finished, unzipping file: " + fullpath_scenery_file_zipped);

                // use short path names to avoid 260 / 248 character limitation
                if (fullpath_scenery_file_zipped.Length > 247)
                {
                    UnityEngine.Debug.Log("Scenery's downloaded zipped file path is too long (" + fullpath_scenery_file_zipped.Length.ToString() + ")");
                }

                if (System.IO.File.Exists(fullpath_scenery_file_zipped))
                {
                    // unzip the downloaded file
                    // https://forum.unity.com/threads/extracting-zip-files.472537/
                    try
                    {
                        System.IO.Compression.ZipFile.ExtractToDirectory(fullpath_scenery_file_zipped, fullpath_scenery_file_unzipped);
                    }
                    catch (System.ArgumentException ex)
                    {
                        //UnityEngine.Debug.Log("\n" + "ZipFile Error\n" + ex.ToString());
                        //return;
                        // TODO handle error
                    }

                    // copy the skybox images
                    string sourceDirectory      = Path.Combine(Path.Combine(fullpath_scenery_file_unzipped, subfolder), "4096");
                    string destinationDirectory = Path.Combine(fullpath_scenery_folder, "4096");
                    if (System.IO.Directory.Exists(sourceDirectory))
                    {
                        Directory_Copy(sourceDirectory, destinationDirectory, true);
                    }

                    // copy eula german version
                    string sourceFileName = Path.Combine(Path.Combine(fullpath_scenery_file_unzipped, subfolder), "EULA.txt");
                    string destFileName   = Path.Combine(fullpath_scenery_folder, "EULA.txt");
                    if (System.IO.File.Exists(sourceFileName))
                    {
                        File.Copy(sourceFileName, destFileName, true);
                    }

                    // copy eula englisch
                    sourceFileName = Path.Combine(Path.Combine(fullpath_scenery_file_unzipped, subfolder), "EULA_en.txt");
                    destFileName   = Path.Combine(fullpath_scenery_folder, "EULA_en.txt");
                    if (System.IO.File.Exists(sourceFileName))
                    {
                        File.Copy(sourceFileName, destFileName, true);
                    }

                    // the collision files are formated to .obj and do not need to be copied
                    Heli_X_Scenery_Setting_Xml heli_x_scenery_setting_xml = new Heli_X_Scenery_Setting_Xml();
                    string filename_settings_file = Path.GetFileName(Path.Combine(fullpath_scenery_file_unzipped, subfolder)); // heli-x uses foldername as name for setting file
                    string fullpath_settings_file = Path.Combine(fullpath_scenery_file_unzipped, subfolder) + "\\" + filename_settings_file + ".xml";
                    if (System.IO.File.Exists(fullpath_settings_file))
                    {
                        Convert_Heli_X_Topography_To_Wavefront_Obj(Path.Combine(fullpath_scenery_file_unzipped, subfolder), fullpath_scenery_folder, ref heli_x_scenery_setting_xml);
                    }
                    //else
                    // scenery is not a heli-x scenery, therefore no need for conversion

                    // update the ui - TODO only if success
                    //Helicopter_Main.UI_Update_Helicopter_Or_Scenery_Selection_Panel_UI( Helicopter_Main.Ui_Selection_Type.scenery, ui_scenery_selection);
                    foreach (Transform transform in ui_canvas.transform.Find("UI Info Menu Scenery Selection/List Panel/Scroll View/Viewport/Content").GetComponentsInChildren <Transform>(true))
                    {
                        //if (transform.name == "Button Download " + scenery_name) { transform.gameObject.SetActive(false);} // hide Button Download
                        if (transform.name == "Button Select " + scenery_name)
                        {
                            transform.gameObject.SetActive(true);
                        }                                                                                               // reset Button Select
                        if (transform.name == "Image " + scenery_name)
                        {
                            Image image     = transform.GetComponent <Image>();
                            var   tempColor = image.color; tempColor.a = 1.0f; image.color = tempColor; // reset image alpha
                        }
                    }

                    if (System.IO.Directory.Exists(Path.Combine(fullpath_temporary_folder, subfolder)))
                    {
                        System.IO.Directory.Delete(Path.Combine(fullpath_temporary_folder, subfolder), true);
                    }
                }
            }

            yield return(null);
        }