/// <summary> /// Loads a base <see cref="AudioClip"/> from disk /// </summary> /// <returns> /// A base <see cref="AudioClip"/> /// </returns> /// <param name='path'> /// Path to audio file /// </param> /// <param name='stream'> /// Whether or not the <see cref="AudioClip"/> should be fully loaded into memory or streamed from disk /// </param> private static AudioClip LoadAudioClip(string path, bool stream) { string filePath = SysPath.FindFile(path, SysPath.AudioExtensions); if (filePath == null) { Logger.Error(TAG, String.Format("Unable to find audio file: \"{0}\"", path)); return(null); } string url = SysPath.GetWwwPath(filePath); WWW www = new WWW(url); //while (!www.isDone); // FIXME: Is blocking here necessary? AudioClip clip; clip = www.GetAudioClip(false, stream); while (!clip.isReadyToPlay) { ; // Wait for buffer } www.Dispose(); // FIXME: What does this even do? Documentation is blank... if (clip == null) { Logger.Error(TAG, String.Format("Unable to load audio file: \"{0}\"", url)); } return(clip); }
/// <summary> /// Preload all audio from <see cref="AudioClips"/> /// </summary> private static void LoadAudioClips() { // Load default paths first foreach (AudioClips audio in Enum.GetValues(typeof(AudioClips))) { // Reflection magic! MemberInfo memberInfo = typeof(AudioClips).GetMember(audio.ToString()).FirstOrDefault(); AudioClipAttr audioClipAttr = (AudioClipAttr)Attribute.GetCustomAttribute(memberInfo, typeof(AudioClipAttr)); AudioInfo audioInfo = new AudioInfo(); audioInfo.path = audioClipAttr.path; audioInfo.loop = audioClipAttr.loop; audioInfo.stream = false; audioInfo.audio = null; _audioMap.Add(audioClipAttr.key, audio); _audioCache.Add(audio, audioInfo); } // Override default paths via settings // TODO: Implement // Load AudioClip objects // Note: No file existence check up until this step, aka no fallbacks foreach (AudioInfo audioInfo in _audioCache.Values.ToList()) { audioInfo.audio = LoadAudioClip(SysPath.GetDataPath(audioInfo.path), audioInfo.stream); } }
public static Texture2D LoadTexture(string path, bool repeat) { Texture2D texture; WWW www = new WWW(SysPath.GetWwwPath(path)); while (!www.isDone) { ; // FIXME: Blocks, thread this? } texture = www.texture; // Compare with www.LoadImageIntoTexture(texture)? texture.wrapMode = (repeat) ? TextureWrapMode.Repeat : TextureWrapMode.Clamp; texture.Compress(true); www.Dispose(); return(texture); }
/// <summary> /// Load a simfile /// </summary> /// <param name='path'> /// Path to simfile /// </param> /// <exception cref='ParserException'> /// Is thrown when the parser is unable to find the simfile /// </exception> public virtual void Load(string path) { if (!SysPath.FileExists(path)) { throw new ParserException(TAG, "Unable to find simfile: " + path); } _info.path = path; string parentFolder = SysPath.GetParentFolder(path); if (parentFolder == null) { throw new ParserException(TAG, "Unable to determine parent folder for path: " + path); } _info.folder = parentFolder; }
private static void PreloadSprites() { int numSprites = Enum.GetNames(typeof(Sprites)).Length; _textureCache = new Dictionary <Sprites, Texture2D>(numSprites); foreach (Sprites sprite in Enum.GetValues(typeof(Sprites))) { // Reflection magic! MemberInfo memberInfo = typeof(Sprites).GetMember(sprite.ToString()).FirstOrDefault(); SpriteInfo spriteInfo = (SpriteInfo)Attribute.GetCustomAttribute(memberInfo, typeof(SpriteInfo)); string path = SysPath.GetDataPath(spriteInfo.path); Texture2D texture = LoadTexture(path, spriteInfo.repeat); _textureCache.Add(sprite, texture); } }
/// <summary> /// Finds a file. Uses <see cref="SysPath.FindFile"/> /// </summary> /// <returns> /// The path to the file, null if not found /// </returns> /// <param name='name'> /// Name of key being parsed for /// </param> /// <param name='val'> /// Value string being parsed /// </param> /// <param name='fatal'> /// Whether or not a <see cref="ParserException"/> should be thrown upon parsing error /// </param> /// <param name='type'> /// Type of file /// </param> /// <param name='extensions'> /// List of file extensions to check with /// </param> public string FindFile(string name, string val, bool fatal, string type, string[] extensions) { string path = SysPath.FindFile(SysPath.GetPath(_info.folder, val), extensions); if (path == null) { string msg = String.Format("Unable to find {0} {1} file: {2}", name, type, val); if (fatal) { Error(msg); } else { Warning(msg); } } return(path); }
protected void InitAll() { // Order matters Logger.Init(); SettingsManager.Init(); StringsManager.Init(); Screens.Init(); SysInfo.Init(); SysPath.Init(); // Order doesn't matter Inputs.Init(); Rand.Init(); Score.Init(); Vibrator.Init(); Tracker.Init(); SpriteLoader.Init(); AudioLoader.Init(); }