本文整理汇总了C#中IContentManager.Unload方法的典型用法代码示例。如果您正苦于以下问题:C# IContentManager.Unload方法的具体用法?C# IContentManager.Unload怎么用?C# IContentManager.Unload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContentManager
的用法示例。
在下文中一共展示了IContentManager.Unload方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
/// <summary>
/// Updates all of the automaticly added GrhDatas.
/// </summary>
/// <param name="cm"><see cref="IContentManager"/> to use for new GrhDatas.</param>
/// <param name="rootGrhDir">Root Grh texture directory.</param>
/// <param name="sender">The <see cref="Control"/> that is invoking this event.</param>
/// <returns>
/// IEnumerable of all of the new GrhDatas created.
/// </returns>
public static IEnumerable<GrhData> Update(IContentManager cm, string rootGrhDir, Control sender = null)
{
var senderForm = GetRootForm(sender);
// Clear the temporary content to make sure we have plenty of working memory
cm.Unload(ContentLevel.Temporary, true);
// Get the tasks
var tasks = GetStationaryTasks(rootGrhDir).Concat(GetAnimatedTasks(rootGrhDir)).ToArray();
// If we have a lot of tasks, show a "busy" form
GrhDataUpdaterProgressForm frm = null;
if (tasks.Length > _minTaskToShowTaskForm)
{
frm = new GrhDataUpdaterProgressForm(tasks.Length);
if (senderForm != null)
frm.Show(senderForm);
else
frm.Show();
frm.Focus();
}
var createdGrhDatas = new List<GrhData>();
if (senderForm != null)
{
senderForm.Enabled = false;
senderForm.Visible = false;
}
try
{
// Start processing the tasks
for (var i = 0; i < tasks.Length; i++)
{
if (frm != null)
frm.UpdateStatus(i);
var newGD = tasks[i].Add(cm);
if (newGD != null)
{
createdGrhDatas.Add(newGD);
if (log.IsInfoEnabled)
log.InfoFormat("Created automatic GrhData `{0}` ({1} of {2} in batch).", newGD, i, tasks.Length);
}
}
}
finally
{
// Dispose of the form, if needed
if (frm != null)
frm.Dispose();
if (senderForm != null)
{
senderForm.Enabled = true;
senderForm.Visible = true;
}
}
if (log.IsInfoEnabled)
log.WarnFormat("Automatic GrhData creation update resulted in `{0}` new GrhData(s).", createdGrhDatas.Count);
return createdGrhDatas;
}
示例2: Update
/// <summary>
/// Updates all of the automaticly added GrhDatas.
/// </summary>
/// <param name="cm"><see cref="IContentManager"/> to use for new GrhDatas.</param>
/// <param name="rootGrhDir">Root Grh texture directory.</param>
/// <param name="added">The GrhDatas that were added (empty if none were added).</param>
/// <param name="deleted">The GrhDatas that were deleted (empty if none were added).</param>
/// <param name="grhDataFileTags">The file tags for the corresponding GrhDatas.</param>
/// <returns>
/// IEnumerable of all of the new GrhDatas created.
/// </returns>
public static void Update(IContentManager cm, string rootGrhDir, out GrhData[] added, out GrhData[] deleted, out Dictionary<GrhData, GrhData.FileTags> grhDataFileTags)
{
if (!rootGrhDir.EndsWith("\\") && !rootGrhDir.EndsWith("/"))
rootGrhDir += "/";
// Clear the temporary content to make sure we have plenty of working memory
cm.Unload(ContentLevel.Temporary, true);
// Get the relative file path for all files up-front (only do this once since it doesn't scale well)
var relFilePaths = Directory.GetFiles(rootGrhDir, "*", SearchOption.AllDirectories)
.Select(x => x.Replace('\\', '/').Substring(rootGrhDir.Length))
.ToArray();
// Also grab the existing GrhDatas
var existingGrhDatas = GrhInfo.GrhDatas.ToDictionary(x => x.Categorization.ToString(), x => x);
// Go through each file and do the adds
grhDataFileTags = new Dictionary<GrhData, GrhData.FileTags>();
HashSet<GrhData> addedGrhDatas = new HashSet<GrhData>();
HashSet<GrhData> deletedGrhDatas = new HashSet<GrhData>();
HashSet<GrhData> grhDatasToDelete = new HashSet<GrhData>(existingGrhDatas.Values);
HashSet<string> checkedAnimationRelDirs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var relFilePath in relFilePaths)
{
// Before doing anything else, ensure it is a valid file type to handle
string fileExtension = Path.GetExtension(relFilePath);
if (!_graphicFileSuffixes.Contains(fileExtension, StringComparer.OrdinalIgnoreCase))
continue;
string absFilePath = rootGrhDir + relFilePath;
// Grab some stuff based on the file path
string absDir = Path.GetDirectoryName(absFilePath);
if (rootGrhDir.Length >= absDir.Length)
continue;
string relDir = absDir.Substring(rootGrhDir.Length);
string parentDirName = absDir.Substring(Path.GetDirectoryName(absDir).Length + 1);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(relFilePath);
bool isAnimationFrame = parentDirName.StartsWith("_");
if (!isAnimationFrame)
{
// ** Stationary **
var fileTags = GrhData.FileTags.Create(fileNameWithoutExtension);
// Build the categorization info
string category = relDir.Replace("/", SpriteCategorization.Delimiter).Replace("\\", SpriteCategorization.Delimiter);
SpriteCategorization cat = new SpriteCategorization(category, fileTags.Title);
// Get existing
GrhIndex? grhIndex = null;
GrhData grhData;
if (existingGrhDatas.TryGetValue(cat.ToString(), out grhData))
{
grhDatasToDelete.Remove(grhData);
}
// If already exists as animated, delete first
if (grhData != null && (grhData is AnimatedGrhData || grhData is AutomaticAnimatedGrhData))
{
grhIndex = grhData.GrhIndex; // We will re-use this GrhIndex
GrhInfo.Delete(grhData);
deletedGrhDatas.Add(grhData);
grhData = null;
}
// Add new
string texturePath = "/" + relFilePath.Substring(0, relFilePath.Length - Path.GetExtension(absFilePath).Length);
if (grhData == null)
{
grhData = GrhInfo.CreateGrhData(cm, cat, texturePath, grhIndex);
addedGrhDatas.Add(grhData);
}
else
{
// Make sure the texture is correct
string currTextureName = "/" + ((StationaryGrhData)grhData).TextureName.ToString().TrimStart('/', '\\');
if (currTextureName != texturePath)
{
((StationaryGrhData)grhData).ChangeTexture(texturePath);
}
}
// Ensure set to auto-size
StationaryGrhData stationaryGrhData = (StationaryGrhData)grhData;
//.........这里部分代码省略.........