// ################################################################################## // ################################################################################## // setup prefab instance // ################################################################################## void Setup_Selection_Element_Instance(ref GameObject prefab_instance, Ui_Selection_Type ui_Selection_Type, int selection_id, string selection_name, stru_selection_content selection_content, stru_skymap_paths stru_skymap_path) { // object's favourite toggle Toggle favourite_toggle = prefab_instance.transform.Find("Toggle_Favourite").GetComponent <Toggle>(); Texture2D texture2D; // setup favourite toggle state if (ui_Selection_Type == Ui_Selection_Type.scenery) { favourite_toggle.isOn = PlayerPrefs.GetInt("SavedSetting____" + selection_name + "____is_scenery_favourite", 0) == 0 ? false : true; // load preview image texture2D = Load_Image(list_skymap_paths[selection_id].fullpath_preview_image); if (texture2D != null) { prefab_instance.transform.Find("Image").GetComponent <Image>().sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0, 0), 1); } } if (ui_Selection_Type == Ui_Selection_Type.helicopter) { favourite_toggle.isOn = PlayerPrefs.GetInt("SavedSetting____" + selection_name + "____is_helicopter_favourite", 0) == 0 ? false : true; // load preview image texture2D = (Texture2D)Resources.Load(selection_name + "_preview_image", typeof(Texture2D)); if (texture2D != null) { prefab_instance.transform.Find("Image").GetComponent <Image>().sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0, 0), 1); } } // add listener to favourite toggle favourite_toggle.onValueChanged.AddListener(delegate { Listener_UI_Toggle_Selection_Favourite_OnValueChanged(ui_Selection_Type, selection_name, favourite_toggle); }); // fill ui-prefab instance with information prefab_instance.transform.Find("Text_Name").GetComponent <Text>().text = selection_content.name; prefab_instance.transform.Find("Text_Author").GetComponent <Text>().text = selection_content.author; prefab_instance.transform.Find("Text_Date").GetComponent <Text>().text = selection_content.date; prefab_instance.transform.Find("Text_Version").GetComponent <Text>().text = selection_content.version; prefab_instance.transform.Find("Text_Info").GetComponent <Text>().text = selection_content.info; Button open_link_button = prefab_instance.transform.Find("Button Open Link").GetComponent <Button>(); if (selection_content.homepagelink != "-") { open_link_button.gameObject.SetActive(true); open_link_button.onClick.AddListener(delegate { Application.OpenURL(selection_content.homepagelink); }); } else { open_link_button.gameObject.SetActive(false); } if (ui_Selection_Type == Ui_Selection_Type.scenery) { string scenery_name = selection_name; string fullpath_scenery_folder; if (((Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)) && helicopter_ODE.par_temp.simulation.storage.sceneries_file_location.val == 0) { fullpath_scenery_folder = Path.Combine(Path.Combine(Application.streamingAssetsPath, "Skymaps"), scenery_name); // Windows } else { fullpath_scenery_folder = Path.Combine(Path.Combine(Application.persistentDataPath, "Skymaps"), scenery_name); // Only choice on MacIO, ... } Button download_button = prefab_instance.transform.Find("Button Download").GetComponent <Button>(); Button select_button = prefab_instance.transform.Find("Button Select").GetComponent <Button>(); Image image = prefab_instance.transform.Find("Image").GetComponent <Image>(); // add unique name to be able to select it by name in static coroutine Download_And_Import_Skybox() download_button.name = "Button Download " + scenery_name; select_button.name = "Button Select " + scenery_name; image.name = "Image " + scenery_name; // if a download link is given in i.e. 'Ahornkopf_information_file.xml' ... //if (selection_content.downloadlink != "not downloadable" && // !IO_Heli_X.Heli_X_Import.Check_Local_Scenery_Files(fullpath_scenery_folder)) if (stru_skymap_path.is_downloadable && !stru_skymap_path.is_downloaded) { //... then show download button download_button.gameObject.GetComponentInChildren <Text>().text = "Download"; download_button.gameObject.SetActive(true); // and add button listener with download function download_button.onClick.AddListener(delegate { IO_Heli_X.Heli_X_Import.Get_Skybox(selection_content.downloadlink, fullpath_scenery_folder, this, download_button, ui_canvas, stru_skymap_path); }); // change preview image appearance, to show that scenery is not available (change alpha) var tempColor = image.color; tempColor.a = 0.2f; image.color = tempColor; // we also do not need the selection button prefab_instance.transform.Find("Button Select " + scenery_name).GetComponent <Button>().gameObject.SetActive(false); } if (stru_skymap_path.is_downloadable && stru_skymap_path.is_downloaded) { // hide download button download_button.gameObject.GetComponentInChildren <Text>().text = "Download Again"; download_button.gameObject.SetActive(true); // and add button listener with download function download_button.onClick.AddListener(delegate { IO_Heli_X.Heli_X_Import.Get_Skybox(selection_content.downloadlink, fullpath_scenery_folder, this, download_button, ui_canvas, stru_skymap_path); }); } // add listener to button prefab_instance.transform.Find("Button Select " + scenery_name).GetComponent <Button>().onClick.AddListener(delegate { Listener_UI_Button_Selection_Select_OnClick(ui_Selection_Type, selection_id); }); } if (ui_Selection_Type == Ui_Selection_Type.helicopter) { // selected object from list prefab_instance.transform.Find("Button Select").GetComponent <Button>().onClick.AddListener(delegate { Listener_UI_Button_Selection_Select_OnClick(ui_Selection_Type, selection_id); }); } //prefab_instance.transform.Find("Text_Mass").GetComponent<Text>().text = helicopter_ODE.par.transmitter_and_helicopter.helicopter.mass_total.val + " kg"; //prefab_instance.transform.Find("Text_Rotor_Diameter").GetComponent<Text>().text = helicopter_ODE.par.transmitter_and_helicopter.helicopter.mainrotor.R.val + " m"; }
// ############################################################################ // ############################################################################ // search for available skymaps in the streamingassets "Skymaps" folder // ############################################################################ private void Get_Skymaps_Paths(ref List <stru_skymap_paths> list_skymap_paths) { // On many platforms, the streaming assets folder location is read - only; // you can not modify or write new files there at runtime. Use Application.persistentDataPath // for a folder location that is writable. Therefore all scenery files (folder with all // neccessary images and also partial empty folder with downloadable content) are copied to // Application.persistentDataPath. string fullpath_skymap_folder; if (((Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)) && helicopter_ODE.par_temp.simulation.storage.sceneries_file_location.val == 0) { fullpath_skymap_folder = Path.Combine(Application.streamingAssetsPath, "Skymaps"); // Windows // On Windows we can use (read and write) Application.streamingAssetsPath. We can leave the "installed" files there. } else { fullpath_skymap_folder = Path.Combine(Application.persistentDataPath, "Skymaps"); // Only choice on MacIO, ... // On other systems (MacOS, ...) copy everthing from Application.streamingAssetsPath to Application.persistentDataPath string SourcePath = Path.Combine(Application.streamingAssetsPath, "Skymaps"); string DestinationPath = fullpath_skymap_folder; if (!Directory.Exists(DestinationPath) || first_start_flag == 1) // if new version, then also copy the files { Directory.CreateDirectory(DestinationPath); Helper.Directory_Copy(SourcePath, DestinationPath, true); } } List <string> list_fullpath_skymap_folder = new List <string>(Directory.GetDirectories(fullpath_skymap_folder)); // check if necessary files are available foreach (string each_fullpath_skymap_folder in list_fullpath_skymap_folder) { bool flag_folder_ok = false, flag_images_ok = false; bool flag_preview_image_found_ok = false, flag_parameter_file_found_ok = false, flag_collision_file_found_ok = false; bool flag_collision_landing_file_found_ok = false, flag_information_file_found_ok = false, flag_information_file_url_found_ok = false; //bool flag_ambient_audio_file_found_ok = false, // create skymap struct to store information about skymap stru_skymap_paths skymap_paths_temp = new stru_skymap_paths(); // get skymap name skymap_paths_temp.name = Path.GetFileNameWithoutExtension(each_fullpath_skymap_folder); // get fullpath to Path.Combine(Application.streamingAssetsPath, "Skymaps"); or Path.Combine(Application.persistentDataPath, "Skymaps")) skymap_paths_temp.fullpath_skymap_folder = each_fullpath_skymap_folder; // find images if (Directory.Exists(Path.Combine(each_fullpath_skymap_folder, "4096"))) { flag_folder_ok = true; //UnityEngine.Debug.Log("each_skymap " + each_skymap + "/4096/"); // find images //string supportedExtensions = "*.bmp,*.exr,*.gif,*.hdr,*.iff,*.jpeg,*.jpg,*.pict,*.png,*.psd,*.tga,*.tif,*.tiff"; string supportedExtensions = ".jpeg,*.jpg,*.png"; IEnumerable <string> image_files = Directory.GetFiles(Path.Combine(each_fullpath_skymap_folder, "4096"), "*.*", SearchOption.TopDirectoryOnly).Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower())); // check images int number_of_textures_found = 0; foreach (string each_image_path in image_files) { //UnityEngine.Debug.Log(each_image_path); string filename = Path.GetFileNameWithoutExtension(each_image_path); //UnityEngine.Debug.Log(filename); if (filename.Substring(filename.Length - 5).ToLower().CompareTo("front") == 0) { skymap_paths_temp.fullpath_front_texture = each_image_path; number_of_textures_found++; } if (filename.Substring(filename.Length - 4).ToLower().CompareTo("back") == 0) { skymap_paths_temp.fullpath_back_texture = each_image_path; number_of_textures_found++; } if (filename.Substring(filename.Length - 4).ToLower().CompareTo("left") == 0) { skymap_paths_temp.fullpath_right_texture = each_image_path; // left flipped with right ! number_of_textures_found++; } if (filename.Substring(filename.Length - 5).ToLower().CompareTo("right") == 0) { skymap_paths_temp.fullpath_left_texture = each_image_path; // right flipped with left ! number_of_textures_found++; } if (filename.Substring(filename.Length - 2).ToLower().CompareTo("up") == 0 || filename.Substring(filename.Length - 3).ToLower().CompareTo("top") == 0) { skymap_paths_temp.fullpath_up_texture = each_image_path; number_of_textures_found++; } if (filename.Substring(filename.Length - 4).ToLower().CompareTo("down") == 0 || filename.Substring(filename.Length - 6).ToLower().CompareTo("bottom") == 0) { skymap_paths_temp.fullpath_down_texture = each_image_path; number_of_textures_found++; } } if (number_of_textures_found == 6) { flag_images_ok = true; } } else { Directory.CreateDirectory(Path.Combine(each_fullpath_skymap_folder, "4096")); flag_folder_ok = false; } // find preview image string fullpath_preview_image = Path.Combine(each_fullpath_skymap_folder, "preview.jpg"); if (File.Exists(fullpath_preview_image)) { skymap_paths_temp.fullpath_preview_image = fullpath_preview_image; flag_preview_image_found_ok = true; } // find settings file string fullpath_parameter_file = Path.Combine(each_fullpath_skymap_folder, skymap_paths_temp.name + "_parameter_file.xml"); if (File.Exists(fullpath_parameter_file)) { skymap_paths_temp.fullpath_parameter_file = fullpath_parameter_file; skymap_paths_temp.fullpath_parameter_file_used = fullpath_parameter_file; // set it here only as default flag_parameter_file_found_ok = true; } // find information file string fullpath_information_file = Path.Combine(each_fullpath_skymap_folder, skymap_paths_temp.name + "_information_file.xml"); if (File.Exists(fullpath_information_file)) { skymap_paths_temp.fullpath_information_file = fullpath_information_file; flag_information_file_found_ok = true; // import xml for checking at the end of this method: if for downloadble sceneries a url is given stru_selection_content scenery_selection_content = Common.Helper.IO_XML_Deserialize <stru_selection_content>(skymap_paths_temp.fullpath_information_file); if (scenery_selection_content.downloadlink != "not downloadable") // TODO also check if url is valid { flag_information_file_url_found_ok = true; } } // find collision object string fullpath_collision_object = Path.Combine(each_fullpath_skymap_folder, "collision_object.obj"); if (File.Exists(fullpath_collision_object)) { skymap_paths_temp.fullpath_collision_object = fullpath_collision_object; flag_collision_file_found_ok = true; } // find collision object for landing string fullpath_collision_landing_object = Path.Combine(each_fullpath_skymap_folder, "collision_landing_object.obj"); if (File.Exists(fullpath_collision_landing_object)) { skymap_paths_temp.fullpath_collision_landing_object = fullpath_collision_landing_object; flag_collision_landing_file_found_ok = true; } // find ambient audio file string fullpath_ambient_audio_file = Path.Combine(each_fullpath_skymap_folder, "ambient_audio.ogg"); if (File.Exists(fullpath_ambient_audio_file)) { skymap_paths_temp.fullpath_ambient_audio_file = fullpath_ambient_audio_file; //flag_ambient_audio_file_found_ok = true; } // if a minium neccessary files have been found, then assign thhis skymap to the skymap list //UnityEngine.Debug.Log("flag_images_ok " + flag_images_ok + " flag_folder_ok " + flag_folder_ok); if (flag_folder_ok && flag_preview_image_found_ok && flag_images_ok && flag_collision_file_found_ok && flag_collision_landing_file_found_ok && flag_parameter_file_found_ok && flag_information_file_found_ok) { list_skymap_paths.Add(skymap_paths_temp); list_skymap_paths[list_skymap_paths.Count - 1].is_downloadable = false; list_skymap_paths[list_skymap_paths.Count - 1].is_downloaded = false; if (flag_information_file_url_found_ok) { list_skymap_paths[list_skymap_paths.Count - 1].is_downloadable = true; list_skymap_paths[list_skymap_paths.Count - 1].is_downloaded = true; } } // some sceneries are downloadable, and thus not included in the basic installation. These sceneries must have some files included and are checked here for them: //if (flag_preview_image_found_ok && !flag_images_ok && !flag_collision_file_found_ok && flag_collision_landing_file_found_ok && flag_parameter_file_found_ok && flag_information_file_found_ok && flag_information_file_url_found_ok) if (flag_preview_image_found_ok && !flag_images_ok && flag_collision_landing_file_found_ok && flag_parameter_file_found_ok && flag_information_file_found_ok && flag_information_file_url_found_ok) { list_skymap_paths.Add(skymap_paths_temp); list_skymap_paths[list_skymap_paths.Count - 1].is_downloadable = true; list_skymap_paths[list_skymap_paths.Count - 1].is_downloaded = false; } //UnityEngine.Debug.Log("each_fullpath_skymap_folder " + each_fullpath_skymap_folder + " skymap_paths_temp.name " + skymap_paths_temp.name); //UnityEngine.Debug.Log("flag_folder_ok " + flag_folder_ok + // " flag_preview_image_found_ok " + flag_preview_image_found_ok + // " flag_images_ok " + flag_images_ok + // " flag_collision_file_found_ok " + flag_collision_file_found_ok + // " flag_collision_landing_file_found_ok " + flag_collision_landing_file_found_ok + // " flag_parameter_file_found_ok " + flag_parameter_file_found_ok + // " flag_information_file_found_ok " + flag_information_file_found_ok + // " flag_information_file_url_found_ok " + flag_information_file_url_found_ok); } }
// ################################################################################## #endregion // ################################################################################## // dddddddd // UUUUUUUU UUUUUUUUIIIIIIIIII hhhhhhh d::::::dlllllll iiii // U::::::U U::::::UI::::::::I h:::::h d::::::dl:::::l i::::i // U::::::U U::::::UI::::::::I h:::::h d::::::dl:::::l iiii // UU:::::U U:::::UUII::::::II h:::::h d:::::d l:::::l // U:::::U U:::::U I::::I h::::h hhhhh aaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d l::::l iiiiiiinnnn nnnnnnnn ggggggggg ggggg // U:::::D D:::::U I::::I h::::hh:::::hhh a::::::::::::a n:::nn::::::::nn dd::::::::::::::d l::::l i:::::in:::nn::::::::nn g:::::::::ggg::::g // U:::::D D:::::U I::::I h::::::::::::::hh aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d l::::l i::::in::::::::::::::nn g:::::::::::::::::g // U:::::D D:::::U I::::I h:::::::hhh::::::h a::::ann:::::::::::::::nd:::::::ddddd:::::d l::::l i::::inn:::::::::::::::ng::::::ggggg::::::gg // U:::::D D:::::U I::::I h::::::h h::::::h aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d l::::l i::::i n:::::nnnn:::::ng:::::g g:::::g // U:::::D D:::::U I::::I h:::::h h:::::h aa::::::::::::a n::::n n::::nd:::::d d:::::d l::::l i::::i n::::n n::::ng:::::g g:::::g // U:::::D D:::::U I::::I h:::::h h:::::h a::::aaaa::::::a n::::n n::::nd:::::d d:::::d l::::l i::::i n::::n n::::ng:::::g g:::::g // U::::::U U::::::U I::::I h:::::h h:::::ha::::a a:::::a n::::n n::::nd:::::d d:::::d l::::l i::::i n::::n n::::ng::::::g g:::::g // U:::::::UUU:::::::U II::::::II h:::::h h:::::ha::::a a:::::a n::::n n::::nd::::::ddddd::::::ddl::::::li::::::i n::::n n::::ng:::::::ggggg:::::g // UU:::::::::::::UU I::::::::I h:::::h h:::::ha:::::aaaa::::::a n::::n n::::n d:::::::::::::::::dl::::::li::::::i n::::n n::::n g::::::::::::::::g // UU:::::::::UU I::::::::I h:::::h h:::::h a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::dl::::::li::::::i n::::n n::::n gg::::::::::::::g // UUUUUUUUU IIIIIIIIII hhhhhhh hhhhhhh aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd dddddlllllllliiiiiiii nnnnnn nnnnnn gggggggg::::::g // g:::::g // gggggg g:::::g // g:::::gg gg:::::g // g::::::ggg:::::::g // gg:::::::::::::g // ggg::::::ggg // ################################################################################## gggggg #region ui_handling // ################################################################################## // update every parameter prefab on ui // ################################################################################## public void UI_Update_Helicopter_Or_Scenery_Selection_Panel_UI(Ui_Selection_Type ui_Selection_Type, UI_Helicopter_Or_Scenery_Selection ui_selection) { // remove all children form Scroll View Content UI foreach (Transform child in ui_selection.ui_scroll_view_content) { GameObject.Destroy(child.gameObject); } // helicopter: get information xml and fill list on ui if (ui_Selection_Type == Ui_Selection_Type.helicopter) { helicopter__prefabs_vertical_position_on_scroll_view_ui = 0; int selection_id = 0; foreach (Transform each_helicopter in helicopters_available.transform) { string selection_name = each_helicopter.name; // only show helicopter in list, which are marked as favourit when filter toggle "ui_toggle_show_only_favourites.isOn == true" is active if (!(ui_selection.ui_toggle_show_only_favourites.isOn == true && (PlayerPrefs.GetInt("SavedSetting____" + selection_name + "____is_helicopter_favourite", 0) == 0 ? false : true) == false)) { // import xml helicopter_selection_content = new stru_selection_content(); TextAsset txtAsset = (TextAsset)Resources.Load(each_helicopter.name + "_information_file", typeof(TextAsset)); if (txtAsset != null) { helicopter_selection_content = Common.Helper.IO_XML_Deserialize <stru_selection_content>(txtAsset); } //Common.Helper.IO_XML_Serialize(txtAsset,"c:/Temp/test1.txt"); // create ui-prefab instance GameObject prefab_instance = Instantiate_Selection_Element_Prefab(ui_selection, ref helicopter__prefabs_vertical_position_on_scroll_view_ui); // setup instanced prefab (settings and listeners) Setup_Selection_Element_Instance(ref prefab_instance, ui_Selection_Type, selection_id, selection_name, helicopter_selection_content, null); } selection_id++; } // resize rect-transform area now to fit all UI-prefabs into ui_selection.ui_scroll_view_content.GetComponent <RectTransform>().sizeDelta = new Vector2(0, helicopter__prefabs_vertical_position_on_scroll_view_ui + 20); } // scenery: get information xml and fill list on ui if (ui_Selection_Type == Ui_Selection_Type.scenery) { scenery__prefabs_vertical_position_on_scroll_view_ui = 0; for (int selection_id = 0; selection_id < list_skymap_paths.Count; selection_id++) { string selection_name = list_skymap_paths[selection_id].name; // only show scenery in list, which are marked as favourit when filter toggle "ui_toggle_show_only_favourites.isOn == true" is active if (!(ui_selection.ui_toggle_show_only_favourites.isOn == true && (PlayerPrefs.GetInt("SavedSetting____" + selection_name + "____is_scenery_favourite", 0) == 0 ? false : true) == false)) { // import xml scenery_selection_content = new stru_selection_content(); if (File.Exists(list_skymap_paths[selection_id].fullpath_information_file)) { scenery_selection_content = Common.Helper.IO_XML_Deserialize <stru_selection_content>(list_skymap_paths[selection_id].fullpath_information_file); } //Common.Helper.IO_XML_Serialize(scenery_selection_content, "c:/Temp/test2.txt"); // create ui-prefab instance GameObject prefab_instance = Instantiate_Selection_Element_Prefab(ui_selection, ref scenery__prefabs_vertical_position_on_scroll_view_ui); // setup instanced prefab (settings and listeners) Setup_Selection_Element_Instance(ref prefab_instance, ui_Selection_Type, selection_id, selection_name, scenery_selection_content, list_skymap_paths[selection_id]); } } // resize rect-transform area now to fit all UI-prefabs into ui_selection.ui_scroll_view_content.GetComponent <RectTransform>().sizeDelta = new Vector2(0, scenery__prefabs_vertical_position_on_scroll_view_ui + 20); } }