Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
        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);
            }
        }