#region License /* FNA - XNA4 Reimplementation for Desktop Platforms * Copyright 2009-2016 Ethan Lee and the MonoGame Team * * Released under the Microsoft Public License. * See LICENSE for details. */ #endregion #region Using Statements using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; #endregion namespace Microsoft.Xna.Framework.Graphics { /// /// Represents a set of bones associated with a model. /// public class ModelBoneCollection : ReadOnlyCollection { #region Public Properties /// /// Retrieves a ModelBone from the collection, given the name of the bone. /// /// /// The name of the bone to retrieve. /// public ModelBone this[string boneName] { get { ModelBone ret; if (TryGetValue(boneName, out ret)) { return ret; } throw new KeyNotFoundException(); } } #endregion #region Public Constructor public ModelBoneCollection(IList list) : base(list) { } #endregion #region Public Methods /// /// Finds a bone with a given name if it exists in the collection. /// /// /// The name of the bone to find. /// /// /// [OutAttribute] The bone named boneName, if found. /// public bool TryGetValue(string boneName, out ModelBone value) { foreach (ModelBone bone in base.Items) { if (bone.Name == boneName) { value = bone; return true; } } value = null; return false; } #endregion #region Enumerator /// /// Returns a ModelMeshCollection.Enumerator that can iterate through a ModelMeshCollection. /// /// public new Enumerator GetEnumerator() { return new Enumerator(this); } /// /// Provides the ability to iterate through the bones in an ModelMeshCollection. /// public struct Enumerator : IEnumerator { private readonly ModelBoneCollection collection; private int position; internal Enumerator(ModelBoneCollection collection) { this.collection = collection; position = -1; } /// /// Gets the current element in the ModelMeshCollection. /// public ModelBone Current { get { return collection[position]; } } /// /// Advances the enumerator to the next element of the ModelMeshCollection. /// public bool MoveNext() { position += 1; return (position < collection.Count); } /// /// Immediately releases the unmanaged resources used by this object. /// public void Dispose() { } object IEnumerator.Current { get { return collection[position]; } } void IEnumerator.Reset() { position = -1; } } #endregion } }