public void SetNode(NodeBase node) { this.node = node; node.container = this; }
public void updateTerrainTexture(Terrain terr) { if (terr != null) { List <SplatPrototype> prototypes = new List <SplatPrototype>(); List <TextureOutput> textureOutputs = new List <TextureOutput>(); for (int i = 0; i < nodeContainers.Count; i++) { if (nodeContainers[i].node is TextureOutput) { textureOutputs.Add((TextureOutput)nodeContainers[i].node); } } textureOutputs.Sort((TextureOutput left, TextureOutput right) => { return(left.paintOrder - right.paintOrder); }); for (int i = 0; i < textureOutputs.Count; i++) { TextureOutput texNode = textureOutputs[i]; if (texNode.texture != null) { SplatPrototype p = new SplatPrototype(); p.texture = texNode.texture; p.normalMap = texNode.normal; p.tileSize = new Vector2(texNode.texSizeX, texNode.texSizeY); prototypes.Add(p); } } terr.terrainData.splatPrototypes = prototypes.ToArray(); int w = terr.terrainData.alphamapWidth; int h = terr.terrainData.alphamapHeight; float realWidth = terr.terrainData.size.x; float realHeight = terr.terrainData.size.z; float[,] totalAlpha = new float[w, h]; int layers = terr.terrainData.alphamapLayers; float[,,] alphaDatas = new float[w, h, layers]; for (int ly = layers - 1; ly >= 0; ly--) { NodeBase tempNode = null; for (int i = 0; i < textureOutputs.Count; i++) { if (textureOutputs[i].paintOrder == ly) { tempNode = textureOutputs[i]; } } if (tempNode != null) { float[,] values = tempNode.update(seed, w, h, new Rect(baseX, baseY, realWidth, realHeight)); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (totalAlpha[i, j] + values[i, j] <= 1.00001f) { alphaDatas[i, j, ly] = values[i, j]; totalAlpha[i, j] += values[i, j]; } else { alphaDatas[i, j, ly] = 1f - totalAlpha[i, j]; totalAlpha[i, j] = 1f; } } } } } terr.terrainData.SetAlphamaps(0, 0, alphaDatas); } }