本文整理汇总了C#中PropertyCollection.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyCollection.TryGetValue方法的具体用法?C# PropertyCollection.TryGetValue怎么用?C# PropertyCollection.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyCollection
的用法示例。
在下文中一共展示了PropertyCollection.TryGetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyCustomProperties
/// <summary>
/// Applies to a GameObject any custom property found in PropertyCollection
/// </summary>
/// <param name="gameObject">GameObject to apply custom properties to</param>
/// <param name="properties">PropertyCollection to read custom properties from</param>
public static void ApplyCustomProperties(GameObject gameObject, PropertyCollection properties)
{
// nothing to do here...
if (gameObject == null || properties == null)
return;
// Set a layer number for gameObject
if (properties.HasProperty(Map.Property_Layer))
gameObject.layer = properties.GetPropertyAsInt(Map.Property_Layer);
if (properties.HasProperty(Map.Property_LayerName))
gameObject.layer = LayerMask.NameToLayer(properties.GetPropertyAsString(Map.Property_LayerName));
// Add a tag for gameObject
if (properties.HasProperty(Map.Property_Tag))
gameObject.tag = properties.GetPropertyAsString(Map.Property_Tag);
int c = 1;
// Unity 5 Removed AddComponent("string")...
#if !UNITY_5
// Add Components for this gameObject
while (properties.HasProperty(Map.Property_AddComponent + c))
{
try
{
gameObject.AddComponent(properties.GetPropertyAsString(Map.Property_AddComponent + c));
}
catch (System.Exception e)
{
Debug.LogError(e);
}
c++;
}
c = 1;
#else
// Add Components for this gameObject
while (properties.HasProperty(Map.Property_AddComponent + c))
{
try
{
//gameObject.AddComponent(System.Type.GetType(properties.GetPropertyAsString(Map.Property_AddComponent + c)));
//gameObject.AddComponent(System.Type.GetType("Door")) as Door;
if(properties.GetPropertyAsString(Map.Property_AddComponent + c) == "Door"){
gameObject.AddComponent<Door>();
}else if(properties.GetPropertyAsString(Map.Property_AddComponent + c) == "CollisionLevel"){
gameObject.AddComponent<CollisionLevel>();
}else if(properties.GetPropertyAsString(Map.Property_AddComponent + c) == "HidePlayer"){
gameObject.AddComponent<HidePlayer>();
}
}
catch (System.Exception e)
{
Debug.LogError(e);
}
c++;
}
c = 1;
//Set variables for Component Door
Door door;
if(door = gameObject.GetComponent<Door>()){
Debug.Log("HAS DOOR");
Property force;
//Debug.Log(gameObject.name+" FORCE "+force.RawValue.ToString());
if(properties.TryGetValue(Map.Property_ForceIn, out force)){
door.ForceIn = float.Parse(force.RawValue);
Debug.Log("ForceIn "+force.RawValue);
}
if(properties.TryGetValue(Map.Property_ForceOut, out force)){
door.ForceOut = float.Parse(force.RawValue);
Debug.Log("ForceOut "+force.RawValue);
}
if(properties.TryGetValue(Map.Property_Goto, out force)){
door.GoTo = force.RawValue;
Debug.Log("Goto "+force.RawValue);
}
if(properties.TryGetValue(Map.Property_In, out force)){
door.In = (Direction) System.Enum.Parse(typeof(Direction), force.RawValue, true);
Debug.Log("In "+force.RawValue);
}
if(properties.TryGetValue(Map.Property_Out, out force)){
door.Out = (Direction) System.Enum.Parse(typeof(Direction), force.RawValue, true);
Debug.Log("Out "+force.RawValue);
}
//.........这里部分代码省略.........