/// <summary> /// loads a effect file(.fx). /// </summary> /// <param name="fileName">effect file name in the content folder</param> /// <returns>resource element</returns> public GameResourceEffect LoadEffect(string fileName) { string keyName = Path.GetFileName(fileName); // Find the texture resource from ResourceManager by file name GameResourceEffect resource = GetEffect(keyName); // If can't find stored resource if (resource == null) { LoadContent <Effect>(keyName, fileName); resource = GetEffect(keyName); } // Can't get resource If loading failed! if (resource == null) { throw new ArgumentException("Fail to effect : " + fileName); } else if (resource.Effect.IsDisposed) { throw new InvalidOperationException( "Already disposed texture : " + fileName); } return(resource); }
/// <summary> /// loads a resource file in the content folder. /// </summary> /// <typeparam name="T">resource type (i.e. Model or Texture2D)</typeparam> /// <param name="key">resource key name</param> /// <param name="filePath">resource file name</param> /// <returns>resource element</returns> public GameResourceBase LoadContent <T>(string key, string filePath) { if (FrameworkCore.Game.GraphicsDevice == null) { throw new InvalidOperationException("No graphics device."); } GameResourceBase resource = FindResourceByKey(key); if (resource != null) { return(resource); } // loads a resource by content manager T obj = contentManager.Load <T>(filePath); if (obj == null) { throw new ArgumentException("Fail to load content (" + key + " : " + filePath + ")"); } if (obj is Texture2D) { resource = new GameResourceTexture2D(key, filePath, obj as Texture2D); } else if (obj is Model) { resource = new GameResourceModel(key, filePath, obj as Model); } else if (obj is AnimationSequence) { resource = new GameResourceAnimation(key, filePath, obj as AnimationSequence); } else if (obj is SpriteFont) { resource = new GameResourceFont(key, filePath, obj as SpriteFont); } else if (obj is Effect) { resource = new GameResourceEffect(key, filePath, obj as Effect); } else { throw new NotSupportedException("Not supported the resource"); } if (debugTrace) { System.Diagnostics.Debug.WriteLine( string.Format("Load Resource : {0} ({1})", filePath, resource.ToString())); } if (AddResource(resource)) { return(resource); } return(null); }