/// <summary> /// Used to clone a texture layer. Mainly used during a call to Clone on a Material. /// </summary> /// <returns></returns> public void CopyTo( TextureUnitState target ) { var props = target.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Instance ); // save parent from target, since it will be overwritten by the following loop var tmpParent = target.parent; for ( var i = 0; i < props.Length; i++ ) { var prop = props[ i ]; var srcVal = prop.GetValue( this ); prop.SetValue( target, srcVal ); } // restore correct parent target.parent = tmpParent; target.frames = new string[MaxAnimationFrames]; // copy over animation frame texture names for ( var i = 0; i < MaxAnimationFrames; i++ ) { target.frames[ i ] = this.frames[ i ]; } // must clone these references target.colorBlendMode = this.colorBlendMode.Clone(); target.alphaBlendMode = this.alphaBlendMode.Clone(); target.effectList = new TextureEffectList(); // copy effects foreach ( var effect in this.effectList ) { target.effectList.Add( effect.Clone() ); } // dirty the hash of the parent pass target.parent.DirtyHash(); }