Exemple #1
0
        /// <summary>
        /// 得到路径
        /// 结果可能返回NULL
        ///
        /// </summary>
        /// <param name="vForm"></param>
        /// <param name="vEnd"></param>
        /// <param name="bSimple"></param>
        /// <returns></returns>
        public List <NPoint> GetPath(Vector3 vForm, Vector3 vEnd, bool _bSimple = false)
        {
            if (map == null && GMap.instance != null)
            {
                map = GMap.instance;
            }

            if (map == null || map.bitMap == null)
            {
                Debug.Log("No Map Data");
                return(null);
            }

            bSimple = _bSimple;

            if (!bSimple)
            {
                iMaxFind = 200;
                iMaxStep = 200;
                return(CalcAStarPath(vForm, vEnd));
            }
            else
            {
                iMaxFind = 50;
                iMaxStep = 100;
                return(CalcSimplePath(vForm, vEnd));
            }
        }
Exemple #2
0
 public GMap()
 {
     // mask_wall = LayerMask.NameToLayer("Wall");
     // mask_def = LayerMask.NameToLayer("Default");
     mask_ground = 11;// LayerMask.NameToLayer("Ground");
     instance    = this;
 }
Exemple #3
0
        /// <summary>
        /// 初始化场景地图
        /// </summary>
        public void InitSceneMap(int _iX = -200, int _iY = -200, int _iWidth = 400, int _iHeight = 400)
        {
            iOffsetX = 0;
            iOffsetY = 0;
            iWidth   = _iWidth;
            iHeight  = _iHeight;

            if (_iX < 0)
            {
                iOffsetX = Math.Abs(_iX);
            }
            if (_iY < 0)
            {
                iOffsetY = Math.Abs(_iY);
            }
            if (_iX > 0)
            {
                iOffsetX = -_iX;
            }
            if (_iY > 0)
            {
                iOffsetY = -_iY;
            }

            InitializeArray(iWidth, iHeight, 0);

            for (int y = _iY; y < iHeight + _iY; y++)
            {
                for (int x = _iX; x < iWidth + _iX; x++)
                {
                    ray = new Ray(new Vector3(x, 5, y), Vector3.down * 10);
                    Debug.DrawLine(new Vector3(x, 3, y), new Vector3(x, -1, y));
                    //Debug.Break();

                    if (!Physics.Raycast(ray, out hitInfo, 10, (1 << mask_def)))
                    {
                        //GameObject gameObj = hitInfo.collider.gameObject;
                        //if (gameObj.tag == obstacleTag)
                        //{
                        bitMap[x + iOffsetX, y + iOffsetY] = 1;
                        //}
                    }
                }
            }

            GMap.instance = this;
        }
Exemple #4
0
        /// <summary>
        /// 导入外部地图数据
        /// </summary>
        /// <param name="data"></param>
        public void ImportMapData(ref sbyte[,] data, int _offsetX = 0, int _offsetY = 0)
        {
            iOffsetX = _offsetX;
            iOffsetY = _offsetY;

            iWidth  = data.GetLength(0);
            iHeight = data.GetLength(1);

            bitMap     = new sbyte[iWidth, iHeight];
            bitDynamic = new sbyte[iWidth, iHeight];   //值默认为0

            for (int y = 0; y < iHeight; y++)
            {
                for (int x = 0; x < iWidth; x++)
                {
                    bitMap[x, y] = data[x, y];
                }
            }

            GMap.instance = this;
        }