Example #1
0
        private void OnImportMapPath(string path)
        {
            string extension = Path.GetExtension(path);

            switch (extension.ToLower())
            {
            case ".vol":
                List <string> fileNames = new List <string>();

                // Get list of map names from the archive
                VolFile vol = new VolFile(path);
                for (int i = 0; i < vol.GetCount(); ++i)
                {
                    string name = vol.GetName(i);
                    if (Path.GetExtension(name).ToLower() == ".map")
                    {
                        fileNames.Add(name);
                    }
                }

                // Open list of map names for selection
                ListSelectDialog.Create(fileNames, "Select Map", "Import", (string mapName) => OnImportMapSelected(vol, mapName), () =>
                {
                    interactable = true;
                    vol.Dispose();
                });

                break;

            default:
                CreateNew_NoRefresh();

                interactable = true;

                if (UserData.current.ImportMap(path))
                {
                    interactable = false;

                    m_MapRenderer.Refresh(() =>
                    {
                        interactable = true;
                        Debug.Log("Import Complete.");
                    });
                }
                else
                {
                    // Import failed
                    interactable = false;

                    m_MapRenderer.Refresh(() =>
                    {
                        interactable = true;
                        Debug.LogError("Failed to read map: " + path);
                    });
                }
                break;
            }
        }
Example #2
0
        private static IEnumerator LoadSoundsRoutine(string archivePath)
        {
            float startTime = Time.realtimeSinceStartup;
            float curTime   = startTime;

            // Get file names from legacy sound archive.
            // We do this to cache the sounds used by the game engine.
            List <string> soundFileNames = new List <string>();

            try
            {
                VolFile soundArchive = new VolFile(archivePath);
                int     count        = soundArchive.GetCount();
                for (int i = 0; i < count; ++i)
                {
                    soundFileNames.Add(Path.GetFileNameWithoutExtension(soundArchive.GetName(i)));
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogWarning(ex);
            }

            // Load sounds
            foreach (string soundFileName in soundFileNames)
            {
                AudioClip soundClip = GetAssetFromModBundle <AudioClip>(soundFileName);

                if (soundClip != null)
                {
                    _SoundLookup[soundFileName] = soundClip;
                }
                else if (_LegacyAssets != null)
                {
                    // Load legacy sound
                    try
                    {
                        byte[] wavData = _LegacyAssets.GetResource(soundFileName + ".wav");
                        if (wavData != null)
                        {
                            _SoundLookup[soundFileName] = WavUtility.ToAudioClip(wavData, 0, soundFileName);
                        }
                        else
                        {
                            Debug.LogWarning("Could not find resource with name: " + soundFileName);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogException(ex);
                        Debug.LogError("Sound File: " + soundFileName);
                    }
                }
                else
                {
                    // Could not find sound!
                    Debug.LogWarning("Could not find sound with name: " + soundFileName);
                }

                // Every X seconds, take a break to render the screen
                if (curTime + 0.25f < Time.realtimeSinceStartup)
                {
                    yield return(null);

                    curTime = Time.realtimeSinceStartup;
                }
            }

            Debug.Log("Sounds Load Time: " + (Time.realtimeSinceStartup - startTime).ToString("N2") + " seconds");
        }