• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# UnityEngine.LayerMask类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UnityEngine.LayerMask的典型用法代码示例。如果您正苦于以下问题:C# LayerMask类的具体用法?C# LayerMask怎么用?C# LayerMask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LayerMask类属于UnityEngine命名空间,在下文中一共展示了LayerMask类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Awake

        private void Awake()
        {
            LayerOn = LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer);
            LayerOff = LayerMask.NameToLayer (KickStarter.settingsManager.deactivatedLayer);

            _Awake ();
        }
开发者ID:IJkeB,项目名称:Ekster_Final,代码行数:7,代码来源:NPC.cs


示例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;
 }
开发者ID:BiteMeInc,项目名称:bite-me,代码行数:27,代码来源:MovementUtility.cs


示例3: CheckGround

 bool CheckGround(Transform groundCheck, LayerMask whatIsGround, float groundedRadius)
 {
     if(groundCheck!=null)
         return Physics2D.OverlapCircle (groundCheck.position, groundedRadius, whatIsGround);
     else
         return true;
 }
开发者ID:kinlam,项目名称:RUN-SHOOT,代码行数:7,代码来源:MotionControlSystem.cs


示例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 ();
				}
			}
		}
开发者ID:amutnick,项目名称:CrackTheCode_Repo,代码行数:35,代码来源:ActionList.cs


示例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;
				}
			}
		}
开发者ID:voidserpent,项目名称:rpgbase,代码行数:27,代码来源:Chara2_Player.cs


示例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);
                }
            }
        }
开发者ID:fordream,项目名称:Hellikitty,代码行数:32,代码来源:RailgunAsset.cs


示例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;
        }
开发者ID:rammstein85,项目名称:Path-GPL,代码行数:26,代码来源:Inspector.cs


示例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;
        }
开发者ID:yzeal,项目名称:Weltenseele2,代码行数:45,代码来源:ObjectHelper.cs


示例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;
        }
开发者ID:jgirald,项目名称:ES2015F,代码行数:40,代码来源:EditorGUIx.cs


示例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;
        }
开发者ID:Leopotam,项目名称:LeopotamGroupLibraryUnity,代码行数:30,代码来源:GuiSystemInspector.cs


示例11: checkType

 public static bool checkType(IntPtr l, int p, out LayerMask lm)
 {
     int v;
     checkType(l, p, out v);
     lm = v;
     return true;
 }
开发者ID:huangkumao,项目名称:slua,代码行数:7,代码来源:LuaObject_overload.cs


示例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;
		}
开发者ID:pencilking2002,项目名称:TOF_Movement_Protype,代码行数:28,代码来源:Utilities.cs


示例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;
        }
开发者ID:PurpleKingdomGames,项目名称:UnityPathfinding,代码行数:59,代码来源:GridBuilder2D.cs


示例14: UpdateColliders

 public bool UpdateColliders(Vector2 topLeft, Vector2 bottomRight, LayerMask layerMask)
 {
     if (_updateOnFrame == Time.frameCount)
     {
         return collidersChangedOnLastUpdate;
     }
     collidersChangedOnLastUpdate = InnerUpdateColliders(topLeft, bottomRight, layerMask);
     return collidersChangedOnLastUpdate;
 }
开发者ID:mfagerlund,项目名称:Shadow2D,代码行数:9,代码来源:Collider2DTracker.cs


示例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;
        }
开发者ID:sethnel99,项目名称:HungerGame,代码行数:12,代码来源:GameObjectExtensions.cs


示例16: TeleportBuilder

 public TeleportBuilder(GameObject gameObject, InputActions input, string targetVariable, float timeout, LayerMask obstacles, float distance)
 {
     this.gameObject = gameObject;
       this.input = input;
       this.targetVariable = targetVariable;
       this.timeout = timeout;
       this.obstacles = obstacles;
       this.distance = distance;
 }
开发者ID:BrunoRomes,项目名称:UnityTests,代码行数:9,代码来源:TeleportBuilder.cs


示例17: CastRay

		public override RaycastHit2D CastRay(Vector2 relativeRayOrigin, Vector2 direction, float rayLength, LayerMask layers, LayerMask blockingLayers = default(LayerMask)) {
  		RaycastHit2D hit = base.CastRay(relativeRayOrigin, direction, rayLength, layers, blockingLayers);
  		if (hit.collider && hit.GameObject().IsInLayerMask(_oneWayGeometryLayer)) {
  			if (this.Constraints.FallThroughOneWayPlatforms || Mathf.Sign(direction.y) != -1) {
          // return empty hit instead of actual hit if we're allowed to go through the one way platform
  				return new RaycastHit2D();
  			}
  		}
  		return hit;
  	}
开发者ID:cupsster,项目名称:DTGameEngineModule,代码行数:10,代码来源:BaseController.cs


示例18: Awake

		private void Awake ()
		{
			GetSettingsManager ();
			LayerOn = LayerMask.NameToLayer (settingsManager.hotspotLayer);
			LayerOff = LayerMask.NameToLayer (settingsManager.deactivatedLayer);

			navigationManager = GameObject.FindWithTag (Tags.gameEngine).GetComponent <NavigationManager>();

			_Awake ();
		}
开发者ID:amutnick,项目名称:CrackTheCode_Repo,代码行数:10,代码来源:NPC.cs


示例19: init

        public void init(float angle)
        {
            colliders = entity == Entities.player ? player_owner_collide_layers : enemy_owner_collide_layers;

            this.angle = angle;

            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_seperation;

            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_seperation;
                pos.y += Mathf.Sin(angle) * particle_seperation;
                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_seperation, 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);
                }
            }
        }
开发者ID:kiwipxl,项目名称:Hellikitty,代码行数:31,代码来源:RailgunAsset.cs


示例20: Reset

 public override void Reset () {
     explosionPoint = new ConcreteVector3Var();
     explosionPosition = new ConcreteGameObjectVar(this.self);
     explosionForce = new ConcreteFloatVar();
     explosionRadius = new ConcreteFloatVar();
     layers = -1;
 }
开发者ID:xclouder,项目名称:godbattle,代码行数:7,代码来源:ExplosionForce2D.cs



注:本文中的UnityEngine.LayerMask类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.Light类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.Keyframe类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap