Beispiel #1
0
        /// <summary>
        /// Loads the specified animation from the local content manager.
        /// </summary>
        /// <param name="animation">The identifier of the animation to load.</param>
        /// <returns>The animation that was loaded.</returns>
        public SpriteAnimation LoadLocalContent(SpriteAnimationID animation)
        {
            if (!animation.IsValid || localContent == null)
            {
                return(null);
            }

            return(localContent.Load(animation));
        }
        /// <summary>
        /// Loads the specified animation from the local content manager.
        /// </summary>
        /// <param name="animation">The identifier of the animation to load.</param>
        /// <returns>The animation that was loaded.</returns>
        public SpriteAnimation LoadLocalContent(SpriteAnimationID animation)
        {
            if (!animation.IsValid || localContent == null)
            {
                return(null);
            }

            var density = Display?.DensityBucket ?? ScreenDensityBucket.Desktop;

            return(localContent.Load(animation, density));
        }
        /// <summary>
        /// Loads the specified sprite animation.
        /// </summary>
        /// <remarks>Content managers maintain a cache of references to all loaded assets, so calling <see cref="ContentManager.Load{T}(String, Boolean)"/> multiple
        /// times on a content manager with the same parameter will return the same object rather than reloading the source file.</remarks>
        /// <param name="contentManager">The <see cref="ContentManager"/> with which to load the animation's associated sprite asset.</param>
        /// <param name="id">The identifier that represents the sprite animation to load.</param>
        /// <param name="cache">A value indicating whether to add the sprite asset to the manager's cache.</param>
        /// <returns>The sprite animation that was loaded.</returns>
        public static SpriteAnimation Load(this ContentManager contentManager, SpriteAnimationID id, Boolean cache = true)
        {
            Contract.Require(contentManager, nameof(contentManager));
            Contract.Ensure<ArgumentException>(id.IsValid, nameof(id));
            Contract.EnsureNotDisposed(contentManager, contentManager.Disposed);

            var sprite = contentManager.Load<Sprite>(SpriteAnimationID.GetSpriteAssetIDRef(ref id), cache);

            var name = SpriteAnimationID.GetAnimationNameRef(ref id);
            if (!String.IsNullOrEmpty(name))
            {
                var value = sprite[name];
                if (value == null)
                    throw new ArgumentException(UltravioletStrings.InvalidSpriteAnimationReference.Format(id));

                return value;
            }

            var index = SpriteAnimationID.GetAnimationIndexRef(ref id);
            if (index < 0 || index >= sprite.AnimationCount)
                throw new ArgumentException(UltravioletStrings.InvalidSpriteAnimationReference.Format(id));

            return sprite[index];
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SourcedSpriteAnimationID"/> class.
 /// </summary>
 /// <param name="spriteAnimationID">The sprite animation's identifier.</param>
 /// <param name="spriteSource">The sprite asset's source.</param>
 public SourcedSpriteAnimationID(SpriteAnimationID spriteAnimationID, AssetSource spriteSource)
 {
     this.spriteAnimationID = spriteAnimationID;
     this.spriteSource      = spriteSource;
 }
        /// <summary>
        /// Reads a <see cref="SpriteAnimationID"/> value.
        /// </summary>
        private static Object ReadJson_SpriteAnimationID(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
        {
            var value = (String)serializer.Deserialize(reader, typeof(String));

            return(SpriteAnimationID.Parse(value));
        }