本文整理汇总了C#中UnityEngine.LayerMask类的典型用法代码示例。如果您正苦于以下问题:C# LayerMask类的具体用法?C# LayerMask怎么用?C# LayerMask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LayerMask类属于UnityEngine命名空间,在下文中一共展示了LayerMask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
private void Awake()
{
LayerOn = LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer);
LayerOff = LayerMask.NameToLayer (KickStarter.settingsManager.deactivatedLayer);
_Awake ();
}
示例2: WithinSight2D
// Cast a circle with the desired distance. Check each collider hit to see if it is within the field of view. Set objectFound
// to the object that is most directly in front of the agent
public static GameObject WithinSight2D(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, LayerMask objectLayerMask, Vector3 targetOffset, LayerMask ignoreLayerMask)
{
GameObject objectFound = null;
var hitColliders = Physics2D.OverlapCircleAll(transform.position, viewDistance, objectLayerMask);
if (hitColliders != null)
{
float minAngle = Mathf.Infinity;
for (int i = 0; i < hitColliders.Length; ++i)
{
float angle;
GameObject obj;
// Call the 2D WithinSight function to determine if this specific object is within sight
if ((obj = WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, hitColliders[i].gameObject, targetOffset, true, out angle, ignoreLayerMask)) != null)
{
// This object is within sight. Set it to the objectFound GameObject if the angle is less than any of the other objects
if (angle < minAngle)
{
minAngle = angle;
objectFound = obj;
}
}
}
}
return objectFound;
}
示例3: CheckGround
bool CheckGround(Transform groundCheck, LayerMask whatIsGround, float groundedRadius)
{
if(groundCheck!=null)
return Physics2D.OverlapCircle (groundCheck.position, groundedRadius, whatIsGround);
else
return true;
}
示例4: Awake
private void Awake ()
{
SettingsManager settingsManager = AdvGame.GetReferences ().settingsManager;
LayerHotspot = LayerMask.NameToLayer (settingsManager.hotspotLayer);
LayerOff = LayerMask.NameToLayer (settingsManager.deactivatedLayer);
if (GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent <ActionListManager>())
{
actionListManager = GameObject.FindWithTag (Tags.gameEngine).GetComponent <ActionListManager>();
}
// If asset-based, download actions
if (source == ActionListSource.AssetFile)
{
actions.Clear ();
if (assetFile != null && assetFile.actions.Count > 0)
{
foreach (AC.Action action in assetFile.actions)
{
actions.Add (action);
}
useParameters = assetFile.useParameters;
parameters = assetFile.parameters;
}
}
if (useParameters)
{
// Reset all parameters
foreach (ActionParameter _parameter in parameters)
{
_parameter.Reset ();
}
}
}
示例5: Start
public override void Start()
{
base.Start();
floorLayerMask = 1 << UniRPGGlobal.DB.floorLayerMask;
if (UniRPGGlobal.Instance.state != UniRPGGlobal.State.InMainMenu)
{
if (clickMarkerPrefab)
{
clickMarker = (GameObject)GameObject.Instantiate(clickMarkerPrefab);
clickMarker.SetActive(false);
}
selectionRing = new GameObject[UniRPGGlobal.DB.selectionRingPrefabs.Length];
for (int i = 0; i < UniRPGGlobal.DB.selectionRingPrefabs.Length; i++)
{
if (UniRPGGlobal.DB.selectionRingPrefabs[i])
{
selectionRing[i] = (GameObject)GameObject.Instantiate(UniRPGGlobal.DB.selectionRingPrefabs[i]);
selectionRing[i].AddComponent<SimpleFollow>();
selectionRing[i].AddComponent<SimpleAutoHide>();
selectionRing[i].SetActive(false);
}
else selectionRing[i] = null;
}
}
}
示例6: init
public void init(float angle, float damage, float max_distance, LayerMask colliders)
{
this.angle = angle;
this.damage = damage;
this.max_distance = max_distance;
this.colliders = colliders;
RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)),
max_distance, colliders);
float dist = hit.transform == null ? max_distance : hit.distance;
float num_particles = dist / PARTICLE_SEP;
Vector3 pos = transform.position;
pos.z = -20;
GameObject railgun_particle = (GameObject)Resources.Load("particles/railgun_lightning");
for (int n = 0; n < num_particles; ++n)
{
pos.x += Mathf.Cos(angle) * PARTICLE_SEP;
pos.y += Mathf.Sin(angle) * PARTICLE_SEP;
GameObject obj = (GameObject)Instantiate(railgun_particle, pos, Quaternion.identity);
//check if any colliders are overlapping with a circle raycast
Collider2D col = Physics2D.OverlapCircle(pos, PARTICLE_SEP, colliders);
if (col)
{
//if the gameobject has a health component, deal damage to them
GenericHealth health = col.gameObject.GetComponent<GenericHealth>();
if (health != null) health.take_damage(damage);
}
}
}
示例7: Inspector
public Inspector()
{
if( instance != null )
{
Debug.LogError( "Creating extra instance of singleton Inspector" );
return;
}
instance = this;
blockingLayers = LayerMask.NameToLayer( "Default" );
meshReference = null;
showNetwork = true;
showNode = true;
showConnection = true;
networkTags = false;
nodeTags = false;
connectionTags = false;
bidirectionalConnect = false;
blockingLayers = -1;
connectionWidthNetwork = 1.0f;
connectionWidthNode = 1.0f;
instance = this;
}
示例8: IsObjectVisible
/// <summary>
/// Simple test for an object being visible. We test the field of view and the view distance.
/// Future version will check for objects blocking the view.
///
/// This version allows us to search for any object on a specific layer. If requested, we will
/// return the closest one.
/// </summary>
/// <param name="rPosition"></param>
/// <param name="rForward"></param>
/// <param name="rFOV"></param>
/// <param name="rDistance"></param>
/// <param name="rTargetLayerMask"></param>
/// <param name="rClosest"></param>
/// <returns></returns>
public static GameObject IsObjectVisible(Vector3 rPosition, Vector3 rForward, float rFOV, float rDistance, LayerMask rTargetLayerMask, bool rClosest)
{
GameObject lClosestObject = null;
// Grab all the object in a sphere around the center
Collider[] lColliders = UnityEngine.Physics.OverlapSphere(rPosition, rDistance, rTargetLayerMask);
if (lColliders != null)
{
// If we don't carea bout the closest one, just return the first one
if (!rClosest) { return lColliders[0].gameObject; }
// Test each of the objects to find the closest (with in the field of view
float lClosestDistance = float.MaxValue;
for (int i = 0; i < lColliders.Length; ++i)
{
GameObject lTargetObject = lColliders[i].gameObject;
if (lTargetObject != null)
{
// Test each object to ensure that it
float lDistance = IsObjectVisible(rPosition, rForward, rFOV, rDistance, lTargetObject.transform);
if (lDistance > 0f && lDistance < lClosestDistance)
{
lClosestDistance = lDistance;
lClosestObject = lTargetObject;
}
}
}
}
return lClosestObject;
}
示例9: LayerMaskField
/** Displays a LayerMask field.
* \param label Label to display
* \param showSpecial Use the Nothing and Everything selections
* \param selected Current LayerMask
* \note Unity 3.5 and up will use the EditorGUILayout.MaskField instead of a custom written one.
*/
public static LayerMask LayerMaskField(string label, LayerMask selected)
{
if (layers == null || (System.DateTime.UtcNow.Ticks - lastUpdateTick > 10000000L && Event.current.type == EventType.Layout)) {
lastUpdateTick = System.DateTime.UtcNow.Ticks;
if (layers == null) {
layers = new List<string>();
layerNames = new string[4];
} else {
layers.Clear ();
}
int emptyLayers = 0;
for (int i=0;i<32;i++) {
string layerName = LayerMask.LayerToName (i);
if (layerName != "") {
for (;emptyLayers>0;emptyLayers--) layers.Add ("Layer "+(i-emptyLayers));
layers.Add (layerName);
} else {
emptyLayers++;
}
}
if (layerNames.Length != layers.Count) {
layerNames = new string[layers.Count];
}
for (int i=0;i<layerNames.Length;i++) layerNames[i] = layers[i];
}
selected.value = EditorGUILayout.MaskField (label,selected.value,layerNames);
return selected;
}
示例10: LayerMaskField
static LayerMask LayerMaskField(string label, LayerMask layerMask)
{
var layers = UnityEditorInternal.InternalEditorUtility.layers;
_layerNumbers.Clear ();
for (int i = 0; i < layers.Length; i++) {
_layerNumbers.Add (LayerMask.NameToLayer (layers[i]));
}
var maskWithoutEmpty = 0;
var count = _layerNumbers.Count;
for (var i = 0; i < count; i++) {
if (((1 << _layerNumbers[i]) & layerMask.value) != 0) {
maskWithoutEmpty |= (1 << i);
}
}
maskWithoutEmpty = EditorGUILayout.MaskField (label, maskWithoutEmpty, layers);
var mask = 0;
for (int i = 0; i < count; i++) {
if ((maskWithoutEmpty & (1 << i)) != 0) {
mask |= (1 << _layerNumbers[i]);
}
}
layerMask.value = mask;
return layerMask;
}
示例11: checkType
public static bool checkType(IntPtr l, int p, out LayerMask lm)
{
int v;
checkType(l, p, out v);
lm = v;
return true;
}
示例12: LayerMaskField
public static LayerMask LayerMaskField(string label, LayerMask layerMask)
{
var layers = InternalEditorUtility.layers;
layerNumbers.Clear();
for(int i = 0; i < layers.Length; i++)
layerNumbers.Add(LayerMask.NameToLayer(layers[i]));
int maskWithoutEmpty = 0;
for(int i = 0; i < layerNumbers.Count; i++)
{
if(((1 << layerNumbers[i]) & layerMask.value) > 0)
maskWithoutEmpty |= (1 << i);
}
maskWithoutEmpty = UnityEditor.EditorGUILayout.MaskField(label, maskWithoutEmpty, layers);
int mask = 0;
for(int i = 0; i < layerNumbers.Count; i++)
{
if((maskWithoutEmpty & (1 << i)) > 0)
mask |= (1 << layerNumbers[i]);
}
layerMask.value = mask;
return layerMask;
}
示例13: BuildGrid
public static GridNode2D[,] BuildGrid(Rect bounds, float nodeSize, LayerMask layerMask, Dictionary<string, int> tagPenalties)
{
float xDistance = bounds.xMax - bounds.xMin;
float yDistance = bounds.yMax - bounds.yMin;
int gridX = (int) Mathf.Ceil(xDistance / nodeSize);
int gridY = (int) Mathf.Ceil(yDistance / nodeSize);
GridNode2D[,] returnVal = new GridNode2D[gridX, gridY];
int nodeY = 0;
for (float y = bounds.yMax; y > bounds.yMin; y -= nodeSize) {
// trace ray from left to right
float distanceSet = 0;
int nodeX = 0;
while (distanceSet <= xDistance) {
float distanceLeft = xDistance - distanceSet;
Vector2 origin = new Vector2(bounds.xMin + distanceSet, y);
RaycastHit2D rayCast = Physics2D.Raycast(origin, Vector2.right, distanceLeft, layerMask);
// If it hits something then mark each entry up to that point as passable
float hitPoint = Mathf.Floor(rayCast.distance / nodeSize) * nodeSize;
if (rayCast.collider == null) {
hitPoint = distanceLeft;
}
Debug.DrawRay(origin, Vector2.right * hitPoint);
for (float i = 0; i < hitPoint; i += nodeSize) {
returnVal[nodeX, nodeY] = new GridNode2D(new Point2D(origin.x + i, y)) {
Passable = true,
};
nodeX++;
}
// Mark the point it hit as impassable
distanceSet += (hitPoint + nodeSize);
if (distanceSet < xDistance && rayCast.collider != null) {
nodeX++;
bool passable = false;
int penalty = 0;
if (tagPenalties.ContainsKey(rayCast.collider.tag)) {
penalty = tagPenalties[rayCast.collider.tag];
passable = true;
}
returnVal[nodeX, nodeY] = new GridNode2D(new Point2D(bounds.xMin + distanceSet, y)) {
Passable = passable,
Penalty = penalty
};
}
// Repeat until there is no distance to go
}
nodeY++;
}
return returnVal;
}
示例14: UpdateColliders
public bool UpdateColliders(Vector2 topLeft, Vector2 bottomRight, LayerMask layerMask)
{
if (_updateOnFrame == Time.frameCount)
{
return collidersChangedOnLastUpdate;
}
collidersChangedOnLastUpdate = InnerUpdateColliders(topLeft, bottomRight, layerMask);
return collidersChangedOnLastUpdate;
}
示例15: IsAnyPartVisible
/** Check if this GameObject's renderer or any child renderer that matches `mask`
* is currently visible on screen.
*/
public static bool IsAnyPartVisible(this GameObject go, LayerMask mask)
{
var renderers =
from r in go.GetComponentsInChildren<Renderer> ()
where (mask & r.gameObject.layer) != 0 && r.isVisible
select r;
return renderers.Count () > 0;
}