本文整理汇总了C#中ConvertOperation.TakeSuggestedResultName方法的典型用法代码示例。如果您正苦于以下问题:C# ConvertOperation.TakeSuggestedResultName方法的具体用法?C# ConvertOperation.TakeSuggestedResultName怎么用?C# ConvertOperation.TakeSuggestedResultName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConvertOperation
的用法示例。
在下文中一共展示了ConvertOperation.TakeSuggestedResultName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
public override bool Convert(ConvertOperation convert)
{
List<Component> availData = convert.Perform<Component>().ToList();
availData.Sort((Component a, Component b) => a.RequiresComponent(b.GetType()) ? 1 : 0);
// Generate objects
foreach (Component cmp in availData)
{
if (convert.IsObjectHandled(cmp)) continue;
Type cmpType = cmp.GetType();
// Create or retrieve GameObject
GameObject gameObj = null;
{
// First try to get one from the resultset that has an open slot for this kind of Component
if (gameObj == null)
gameObj = convert.Result.OfType<GameObject>().FirstOrDefault(g => g.GetComponent(cmpType) == null);
// Still none? Create a new GameObject
if (gameObj == null)
{
gameObj = new GameObject();
// Come up with a suitable name
string nameSuggestion = null;
{
// Be open for suggestions
if (nameSuggestion == null)
nameSuggestion = convert.TakeSuggestedResultName(cmp);
// Use a standard name
if (nameSuggestion == null)
nameSuggestion = cmpType.Name;
}
gameObj.Name = nameSuggestion;
}
}
// Make sure all requirements are met
foreach (Type t in Component.GetRequiredComponents(cmpType))
gameObj.AddComponent(t);
// Make sure no other Component of this Type is already added
gameObj.RemoveComponent(cmpType);
// Add Component
gameObj.AddComponent(cmp.GameObj == null ? cmp : cmp.Clone());
convert.AddResult(gameObj);
convert.MarkObjectHandled(cmp);
}
return false;
}