本文整理汇总了C#中UnityEngine.Collider.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Collider.GetType方法的具体用法?C# Collider.GetType怎么用?C# Collider.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Collider
的用法示例。
在下文中一共展示了Collider.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawWireCollider
public static void DrawWireCollider(Collider c)
{
if (c == null) throw new System.ArgumentNullException("c");
if (c is BoxCollider)
{
var box = c as BoxCollider;
DrawWireRectoid(box.transform.TransformPoint(box.center), box.transform.rotation, Vector3.Scale(box.size, box.transform.lossyScale));
}
else if (c is SphereCollider)
{
var sphereGeom = com.spacepuppy.Geom.Sphere.FromCollider(c as SphereCollider);
DrawWireSphere(sphereGeom.Center, c.transform.rotation, sphereGeom.Radius);
}
else if (c is CapsuleCollider)
{
var capGeom = com.spacepuppy.Geom.Capsule.FromCollider(c as CapsuleCollider);
DrawWireCapsule(capGeom.Start, capGeom.End, capGeom.Radius);
}
else if (c is CharacterController)
{
var capGeom = com.spacepuppy.Geom.Capsule.FromCollider(c as CharacterController);
DrawWireCapsule(capGeom.Start, capGeom.End, capGeom.Radius);
}
else if (c is MeshCollider)
{
//not supported
throw new System.ArgumentException("Unsupported collider type '" + c.GetType().Name + "'.", "c");
}
else
{
//not supported
throw new System.ArgumentException("Unsupported collider type '" + c.GetType().Name + "'.", "c");
}
}
示例2: GetSurfaceIndex
int GetSurfaceIndex(Collider col, Vector3 worldPos) {
string textureName = "";
// Case when the ground is a terrain.
if(col.GetType() == typeof(TerrainCollider)) {
Terrain terrain = col.GetComponent<Terrain>();
TerrainData terrainData = terrain.terrainData;
float[] textureMix = GetTerrainTextureMix(worldPos, terrainData, terrain.GetPosition());
int textureIndex = GetTextureIndex(worldPos, textureMix);
textureName = terrainData.splatPrototypes[textureIndex].texture.name;
}
// Case when the ground is a normal mesh.
else {
textureName = GetMeshMaterialAtPoint(worldPos);
}
// Searching for the found texture / material name in registered materials.
foreach(var material in registeredTextures) {
if(material.texture.name == textureName) {
return material.surfaceIndex;
}
}
return -1;
}
示例3: IsMeshCollider
/// <summary>
/// Determines whether [is mesh collider] [the specified collider].
/// </summary>
/// <param name="collider">The collider.</param>
/// <returns>
/// <c>true</c> if [is mesh collider] [the specified collider]; otherwise, <c>false</c>.
/// </returns>
public static bool IsMeshCollider(Collider collider)
{
return collider.GetType() == typeof(MeshCollider);
}
示例4: OnTriggerEnter
private void OnTriggerEnter(Collider other)
{
Console.WriteLine(other.GetType());
DoActivateTrigger();
}
示例5: UpdateAreaRange
/// <summary>
/// Overload to skip the need for an Area to exist so this can be used during setup.
/// </summary>
protected void UpdateAreaRange(Collider col, Component col2D) // Component is for 4.0 compatability
{
Vector3 normRange = this.GetNormalizedRange();
if (col is SphereCollider)
{
var collider = (SphereCollider)col;
collider.radius = normRange.x;
}
else if (col is BoxCollider)
{
var collider = (BoxCollider)col;
collider.size = normRange;
}
else if (col is CapsuleCollider)
{
var collider = (CapsuleCollider)col;
collider.radius = normRange.x;
collider.height = normRange.y;
}
else if (col2D is CircleCollider2D)
{
var collider = (CircleCollider2D)col2D;
collider.radius = normRange.x;
}
else if (col2D is BoxCollider2D)
{
var collider = (BoxCollider2D)col2D;
collider.size = new Vector2(normRange.x, normRange.y);
}
else
{
string colType;
string colName;
if (col != null)
{
colType = col.GetType().Name;
colName = col.name;
}
else if (col2D != null)
{
colType = col2D.GetType().Name;
colName = col2D.name;
}
else
{
throw new System.NullReferenceException("No Collider Found!");
}
Debug.LogWarning
(
string.Format
(
"Unsupported collider type '{0}' for collider '{1}'.",
colType,
colName
)
);
}
}