Esempio n. 1
0
        //---------------------------------------------------------------------
        // unity3d top 视图,坐标原点Terrain左下,而png原点在左上,应用层将坐标转换好传进来
        public void load(IEbPixelLoader pixel_loader, float xmin_world, float zmin_world,
                         float width_world, float height_world)
        {
            mPixelLoader = pixel_loader;

            WidthWorld  = width_world;
            HeightWorld = height_world;
            XMinWorld   = xmin_world;
            ZMinWorld   = zmin_world;
            WidthGrid   = mPixelLoader.width;
            HeightGrid  = mPixelLoader.height;

            mGridRegions = new EbGridRegion[WidthGrid, HeightGrid];
            mPixelNav    = new EbPixelNav((uint)(WidthGrid * HeightGrid));

            mPixelNav.blockStart(mPixelLoader.width, mPixelLoader.height);
            mPixelLoader.foreachPixel(
                (bool is_block, int w, int h) =>
            {
                if (is_block)
                {
                    mGridRegions[w, h] = null;
                    mPixelNav.setBlock(w, h);
                }
                else
                {
                    mGridRegions[w, h] = new EbGridRegion(mEntityMgr);
                }
            }
                );
            mPixelNav.blockEnd();
        }
Esempio n. 2
0
        //---------------------------------------------------------------------
        public void entityMove(Entity entity, EbVector3 pos_world)
        {
            EbVector2    pos_grid = _world2gird(pos_world);
            EbGridRegion region   = mGridRegions[(int)pos_grid.x, (int)pos_grid.y];

            if (region == null)
            {
                return;
            }

            EbGridRegion region_last = entity.getUserData <EbGridRegion>();

            if (region.Equals(region_last))
            {
                region.entityMove(entity);
            }
            else
            {
                if (region_last != null)
                {
                    region_last.entityLeaveRegion(entity);
                }
                region.entityEnterRegion(entity);
            }
        }
Esempio n. 3
0
        //---------------------------------------------------------------------
        public void entityLeaveRegion(Entity entity, EbVector3 pos_world)
        {
            EbVector2    pos_grid = _world2gird(pos_world);
            EbGridRegion region   = mGridRegions[(int)pos_grid.x, (int)pos_grid.y];

            if (region == null)
            {
                return;
            }

            region.entityLeaveRegion(entity);
        }