| 1234567891011121314151617181920212223242526 |
- import { _decorator, Component, Size, Rect, Vec2, Vec3 } from 'cc';
- const { ccclass, property } = _decorator;
- // 画网格,个工具类
- export class GridDraw {
- // 默认右下角,是0,0,返回的坐标,为网格中点
- drawGrid(rect:Rect,size:Size,offset:Vec2 =new Vec2(0.5,0.5)):Vec3[][]{
- let w = rect.width / size.width;
- let h = rect.height / size.height;
- let offset_x = w*offset.x+rect.x
- let offset_y = h*offset.y+rect.y
- let res :Vec3[][] = [[]]
- for (let i = 0; i < size.height; i++) {
- for (let j = 0; j < size.width; j++) {
- if(!res[i]){
- res[i] = [];
- }
- res[i][j] = new Vec3(j *w +offset_x, i * h + offset_y , 0);
- }
- }
- return res;
- }
-
- }
- export const gridDraw = new GridDraw()
|