void Awake() { currentBrush = PenBrush; //默认笔刷 drawableSprite = this.GetComponent <SpriteRenderer>().sprite; drawableTexture = drawableSprite.texture; cleanColorArray = new Color[(int)drawableSprite.rect.width * (int)drawableSprite.rect.height]; //重置时Texture2D的颜色 for (int x = 0; x < cleanColorArray.Length; x++) { cleanColorArray[x] = resetColour; } }
//设置画笔绑定的绘制函数 public void SetPenBrush() { currentBrush = PenBrush; }
public static void Build <T>(List <Segment> segments, int mask, float samplingStep, int strokeSize, BrushFunction <T> brushFunction, int mapSize, WorldToMapCoords worldToMapCoords, T[,] map) { Stroke stroke = new Stroke(); stroke.halfSize = Mathf.CeilToInt(strokeSize * 0.5f); stroke.halfSize2 = stroke.halfSize * stroke.halfSize; HashSet <Segment> visited = new HashSet <Segment>(); foreach (var segment in segments) { RoadNetworkTraversal.PreOrder(segment, (s0) => { stroke.segment = s0; stroke.segmentDirection = (s0.End - s0.Start) / s0.Length; int numSteps = Mathf.CeilToInt(s0.Length / samplingStep); var segmentStep = 1.0f / numSteps; var positionIncrement = s0.Length / numSteps * stroke.segmentDirection; stroke.segmentStep = 0; stroke.segmentCoords = s0.Start; int x, y; for (int step = 0; step < numSteps; step++, stroke.segmentCoords += positionIncrement, stroke.segmentStep += segmentStep) { if (!worldToMapCoords(stroke.segmentCoords.x, stroke.segmentCoords.y, out x, out y)) { break; } stroke.x = x; stroke.y = y; brushFunction(stroke, mapSize, map); } return(true); }, mask, ref visited); } }