本文整理汇总了C#中X_UniTMX.MapObject.GetPropertyAsFloat方法的典型用法代码示例。如果您正苦于以下问题:C# MapObject.GetPropertyAsFloat方法的具体用法?C# MapObject.GetPropertyAsFloat怎么用?C# MapObject.GetPropertyAsFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类X_UniTMX.MapObject
的用法示例。
在下文中一共展示了MapObject.GetPropertyAsFloat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPrefabs
/// <summary>
/// Generate a prefab based in object colider layer
/// </summary>
/// <param name="obj">Object which properties will be used to generate a prefab.</param>
/// <param name="newColliderObject">if null add relative parent object,.</param>
/// <returns>Generated Game Object containing the Collider.</returns>
public void AddPrefabs(MapObject obj, GameObject newColliderObject = null, bool is2DColliders = false, bool addTileName = true)
{
int indexPrefab = 0;
while ("".Equals(obj.GetPropertyAsString(indexPrefab + "-prefab")) == false)
{
string prefabName = obj.GetPropertyAsString(indexPrefab + "-prefab");
string baseResourcePath = obj.GetPropertyAsString(indexPrefab + "-prefab path");
UnityEngine.Object resourceObject = Resources.Load(baseResourcePath + prefabName);
Resources.UnloadUnusedAssets();
if (resourceObject != null)
{
float zDepth = obj.GetPropertyAsFloat(indexPrefab + "-prefab z depth");
GameObject newPrefab = UnityEngine.Object.Instantiate(resourceObject) as GameObject;
//if (newColliderObject == null)
//{
// newPrefab.transform.parent = MapObject.transform;
// newPrefab.transform.localPosition = new Vector3(obj.Bounds.center.x, -obj.Bounds.center.y, zDepth);
//}
//else
//{
// newPrefab.transform.parent = newColliderObject.transform;
// newPrefab.transform.localPosition = new Vector3(0, 0, zDepth);
//}
newPrefab.transform.parent = MapObject.transform;
newPrefab.transform.localPosition = new Vector3(obj.Bounds.center.x, -obj.Bounds.center.y, zDepth);
// copy coliders from newColliderObject
// only copy if type of this object is diferent of "NoCollider"
if ("NoCollider".Equals(obj.Type) == false)
{
if (obj.GetPropertyAsBoolean(indexPrefab + "-prefab add collider"))
{
CopyCollider(obj, ref newColliderObject, ref newPrefab, is2DColliders);
}
}
newPrefab.name = (addTileName ? (_mapName + "_") : "") + obj.Name;
int indexMessage = 0;
string prefabMensage = obj.GetPropertyAsString(indexPrefab + "-prefab sendmessage " + indexMessage);
while ("".Equals(prefabMensage) == false)
{
string[] menssage = prefabMensage.Split(new[] { '|' }, StringSplitOptions.None);
if (menssage.Length == 2)
{
newPrefab.BroadcastMessage(menssage[0], menssage[1]);
}
indexMessage++;
prefabMensage = obj.GetPropertyAsString(indexPrefab + "-prefab sendmessage " + indexMessage);
}
}
else
{
Debug.LogError("Prefab doesn't exist at: Resources/" + baseResourcePath + prefabName);
}
indexPrefab++;
}
}
示例2: GeneratePrefab
/// <summary>
/// Generate a prefab based in object layer
/// </summary>
/// <param name="obj">Object which properties will be used to generate a prefab.</param>
/// <param name="parent">if null add relative parent object,.</param>
/// <param name="addMapName">true to add Map's name to the prefab name</param>
/// <returns>Generated GameObject from the Prefab.</returns>
public static GameObject GeneratePrefab(this Map map, MapObject obj, Vector2 anchorPointValue, GameObject parent = null, bool addMapName = true, bool setNameAsObjectName = false)
{
if (obj.HasProperty(Map.Property_PrefabName))
{
string prefabName = obj.GetPropertyAsString(Map.Property_PrefabName);
string baseResourcePath = obj.GetPropertyAsString(Map.Property_PrefabPath);
UnityEngine.Object resourceObject = Resources.Load(baseResourcePath + prefabName);
Resources.UnloadUnusedAssets();
if (resourceObject != null)
{
float zDepth = obj.GetPropertyAsFloat(Map.Property_PrefabZDepth);
GameObject newPrefab = UnityEngine.Object.Instantiate(resourceObject) as GameObject;
newPrefab.transform.parent = obj.ParentObjectLayer != null ? obj.ParentObjectLayer.LayerGameObject.transform : map.MapGameObject.transform;
newPrefab.transform.localPosition = map.TiledPositionToWorldPoint(
new Vector3(obj.Bounds.xMin + obj.Bounds.width * anchorPointValue.x,
obj.Bounds.yMin + obj.Bounds.height * anchorPointValue.y,
zDepth));
if (obj.HasProperty(Map.Property_PrefabAddCollider))
{
string colliderType = obj.GetPropertyAsString(Map.Property_PrefabAddCollider);
AddCollider(map, newPrefab, obj, !colliderType.Contains("3"));
}
// since custom properties are automatically added only when a collider is added, we must enforce them to be parsed
ApplyCustomProperties(newPrefab, obj);
if (parent)
newPrefab.transform.parent = parent.transform;
if (setNameAsObjectName)
newPrefab.name = obj.Name;
if (addMapName)
newPrefab.name = string.Concat(map.MapName, "_", newPrefab.name);
obj.LinkedGameObject = newPrefab;
return newPrefab;
}
else
{
Debug.LogError("Prefab doesn't exist at: Resources/" + baseResourcePath + prefabName);
}
}
return null;
}
示例3: AddPrefabs
/// <summary>
/// Generate a prefab based in object colider layer
/// </summary>
/// <param name="obj">Object which properties will be used to generate a prefab.</param>
/// <param name="newColliderObject">if null add relative parent object,.</param>
/// <param name="addTileName">true to add Map's name to the prefab name</param>
/// <param name="is2DColliders">true to generate 2D colliders</param>
/// <returns>Generated Game Object containing the Collider.</returns>
public void AddPrefabs(MapObject obj, GameObject newColliderObject = null, bool is2DColliders = false, bool addTileName = true)
{
int indexPrefab = 0;
while (obj.HasProperty(string.Concat(indexPrefab.ToString(), Property_PrefabName)))
{
string prefabName = obj.GetPropertyAsString(indexPrefab + Property_PrefabName);
string baseResourcePath = obj.GetPropertyAsString(indexPrefab + Property_PrefabPath);
UnityEngine.Object resourceObject = Resources.Load(baseResourcePath + prefabName);
Resources.UnloadUnusedAssets();
if (resourceObject != null)
{
float zDepth = obj.GetPropertyAsFloat(indexPrefab + Property_PrefabZDepth);
GameObject newPrefab = UnityEngine.Object.Instantiate(resourceObject) as GameObject;
newPrefab.transform.parent = obj.ParentObjectLayer != null ? obj.ParentObjectLayer.LayerGameObject.transform : MapObject.transform;
newPrefab.transform.localPosition = TiledPositionToWorldPoint(new Vector3(obj.Bounds.center.x, obj.Bounds.center.y, zDepth));
// copy coliders from newColliderObject
// only copy if type of this object is diferent of "NoCollider"
if (obj.Type.Equals(Object_Type_NoCollider) == false)
{
if (obj.GetPropertyAsBoolean(indexPrefab + Property_PrefabAddCollider))
{
//CopyCollider(obj, ref newColliderObject, ref newPrefab, is2DColliders);
AddCollider(newPrefab, obj, obj.Type.Equals(Object_Type_Trigger), is2DColliders, zDepth);
}
else
// since custom properties are automatically added when a collider is added but this prefab has no collider, we must enforce them to be parsed
ApplyCustomProperties(newPrefab, obj);
}
else
// since custom properties are automatically added when a collider is added but this prefab has no collider, we must enforce them to be parsed
ApplyCustomProperties(newPrefab, obj);
if (obj.GetPropertyAsBoolean(indexPrefab + Property_PrefabFixColliderPosition))
{
// Mario: Fixed wrong position in instantiate prefabs
if(newColliderObject != null && newPrefab != null)
newPrefab.transform.position = newColliderObject.transform.position;
}
newPrefab.name = (addTileName ? (_mapName + "_") : "") + obj.Name;
int indexMessage = 1;
string prefabMensage = obj.GetPropertyAsString(indexPrefab + Property_PrefabSendMessage + indexMessage);
while (string.IsNullOrEmpty(prefabMensage) == false)
{
string[] menssage = prefabMensage.Split(new[] { '|' }, StringSplitOptions.None);
if (menssage.Length == 2)
{
newPrefab.BroadcastMessage(menssage[0], menssage[1]);
}
if (menssage.Length == 1)
{
newPrefab.BroadcastMessage(menssage[0]);
}
indexMessage++;
prefabMensage = obj.GetPropertyAsString(indexPrefab + Property_PrefabSendMessage + indexMessage);
}
}
else
{
Debug.LogError("Prefab doesn't exist at: Resources/" + baseResourcePath + prefabName);
}
indexPrefab++;
}
}
示例4: Init
public void Init(MapObject door)
{
if (door.HasProperty("name")) name = door.GetPropertyAsString("name");
Out = Helper.TranslateDirection(door.GetPropertyAsString("out"));
In = Helper.TranslateDirection(door.GetPropertyAsString("in"));
ForceOut = door.HasProperty("force out") ? door.GetPropertyAsFloat("force out") : 1;
ForceIn = door.HasProperty("force in") ? door.GetPropertyAsFloat("force in") : 1;
GoTo = door.GetPropertyAsString("go to");
Scene = door.GetPropertyAsString("scene");
}