Exemple #1
0
    // ############################################################################



    // ############################################################################
    // load the collision object "collision_object.obj" from streamingassets folder
    // ############################################################################
    private void Change_Skybox_Collision_Object(stru_skymap_paths skymap_paths)
    {
        // collision object for reseting model (collision with blades)
        Mesh holder_mesh = new Mesh();

        //ObjImporter newMesh = new ObjImporter();
        holder_mesh = ObjImporter.ImportFile(skymap_paths.fullpath_collision_object);

        MeshFilter collision_object_mesh_filter = GameObject.Find("Collision Object").transform.Find("collisionobject").gameObject.GetComponent <MeshFilter>();

        collision_object_mesh_filter.mesh = holder_mesh;

        MeshCollider collision_object_mesh_collider = GameObject.Find("Collision Object").transform.Find("collisionobject").gameObject.GetComponent <MeshCollider>();

        collision_object_mesh_collider.sharedMesh = holder_mesh;

        collision_object_mesh_filter.mesh.RecalculateNormals();
        collision_object_mesh_collider.sharedMesh.RecalculateNormals();

        // collision object for landig
        Mesh holder_mesh2 = new Mesh();

        holder_mesh2 = ObjImporter.ImportFile(skymap_paths.fullpath_collision_landing_object);
        // this is calulated in the helicopter_ODE-thread at high update frequency
        helicopter_ODE.Set_AABB_Skybox_Collision_Landing_Mesh(holder_mesh2);
    }
Exemple #2
0
    // ############################################################################



    // ############################################################################
    // change the skybox material textures
    // ############################################################################
    private void Change_Skybox_Material(stru_skymap_paths skymap_paths)
    {
        Change_Skybox_Material_Subfunction(skymap_paths.fullpath_front_texture, "_FrontTex", CubemapFace.PositiveZ, true);  // left -> front
        Change_Skybox_Material_Subfunction(skymap_paths.fullpath_back_texture, "_BackTex", CubemapFace.NegativeZ, false);   // right -> back
        Change_Skybox_Material_Subfunction(skymap_paths.fullpath_left_texture, "_LeftTex", CubemapFace.NegativeX, false);   // back -> right
        Change_Skybox_Material_Subfunction(skymap_paths.fullpath_right_texture, "_RightTex", CubemapFace.PositiveX, false); // front -> left
        Change_Skybox_Material_Subfunction(skymap_paths.fullpath_up_texture, "_UpTex", CubemapFace.PositiveY, false);       // top
        Change_Skybox_Material_Subfunction(skymap_paths.fullpath_down_texture, "_DownTex", CubemapFace.NegativeY, false);   // bottom

        skybox_cubemap.Apply();

        Resources.UnloadUnusedAssets();
        DynamicGI.UpdateEnvironment();
    }
Exemple #3
0
    // ############################################################################



    // ############################################################################
    // 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);
        }
    }
Exemple #4
0
    // ############################################################################



    // ############################################################################
    // change the ambient sound to "ambient_audio.ogg" from streamingassets folder "Skymaps"
    // ############################################################################
    private void Change_Skybox_Ambient_Sound(stru_skymap_paths skymap_paths)
    {
        AudioSource myAudioSource = GameObject.Find("Ambient Sound").gameObject.GetComponent <AudioSource>();

        Play_Audio(myAudioSource, skymap_paths.fullpath_ambient_audio_file);
    }
Exemple #5
0
 public stru_skymap()
 {
     skymap_paths = new stru_skymap_paths();
 }
Exemple #6
0
    // ##################################################################################



    // ##################################################################################
    // 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";
    }