void GenMap0() { Map map = new Map(); map.Init(); //扰乱边缘 NoisyEdges noisyEdge = new NoisyEdges(); noisyEdge.BuildNoisyEdges(map); new MapTexture(TextureScale).AttachTexture(GameObject.Find("Map"), map, noisyEdge); }
private void GenMap() { Random.seed = 1; _txtTexture = GetTextTexture(); Map.Width = Width; Map.Height = Height; Map map = new Map(); map.SetPointNum(_pointNum); map.Init(CheckIsland()); //扰乱边缘 NoisyEdges noisyEdge = new NoisyEdges(); noisyEdge.BuildNoisyEdges(map); new MapTexture(TextureScale).AttachTexture(_showMap, map, noisyEdge); }
// void Update() // { // if (_map != null && _map.SelectedCenter != null) // { // _selector.transform.localPosition = new Vector3(_map.SelectedCenter.point.x, _map.SelectedCenter.point.y, 1); // } // } void Awake () { _selector = GameObject.Find("Selector"); //Random.seed = 1; _map = new Map(); _map.Init(); GameObject.Find("Main MyCamera").GetComponentInChildren<MyCamera>().Map = _map; //ÈÅÂÒ±ßÔµ NoisyEdges noisyEdge = new NoisyEdges(); noisyEdge.BuildNoisyEdges(_map); new MapTexture(_textureScale).AttachTexture(GameObject.Find("Map"), _map,noisyEdge); }
// void Update() // { // if (_map != null && _map.SelectedCenter != null) // { // _selector.transform.localPosition = new Vector3(_map.SelectedCenter.point.x, _map.SelectedCenter.point.y, 1); // } // } void Awake() { _selector = GameObject.Find("Selector"); //Random.seed = 1; _map = new Map(); _map.Init(); GameObject.Find("Main MyCamera").GetComponentInChildren <MyCamera>().Map = _map; //ÈÅÂÒ±ßÔµ NoisyEdges noisyEdge = new NoisyEdges(); noisyEdge.BuildNoisyEdges(_map); new MapTexture(_textureScale).AttachTexture(GameObject.Find("Map"), _map, noisyEdge); }
public void AttachTexture(GameObject plane, Map map, NoisyEdges noisyEdge) { int textureWidth = (int) Map.Width*_textureScale; int textureHeight = (int) Map.Height*_textureScale; Texture2D texture = new Texture2D(textureWidth, textureHeight,TextureFormat.RGB565, true); texture.SetPixels(Enumerable.Repeat(BiomeProperties.Colors[Biome.Ocean], textureWidth * textureHeight).ToArray()); //绘制扰乱的边缘 foreach (Center p in map.Graph.centers) { foreach (var r in p.neighbors) { Edge edge = map.Graph.lookupEdgeFromCenter(p, r); if (!noisyEdge.path0.ContainsKey(edge.index) || !noisyEdge.path1.ContainsKey(edge.index)) { // It's at the edge of the map, where we don't have // the noisy edges computed. TODO: figure out how to // fill in these edges from the voronoi library. continue; } //绘制扰乱后的形状 DrawNoisyPolygon(texture, p, noisyEdge.path0[edge.index]); DrawNoisyPolygon(texture, p, noisyEdge.path1[edge.index]); } } //绘制扰乱后的河流 foreach (var line in map.Graph.edges.Where(p => p.river > 0 && !p.d0.water && !p.d1.water)) { //绘制扰乱后的边缘 List<Vector2> edge0 = noisyEdge.path0[line.index]; for (int i = 0; i < edge0.Count - 1; i++) DrawLine(texture, edge0[i].x, edge0[i].y, edge0[i + 1].x, edge0[i + 1].y, Color.blue); List<Vector2> edge1 = noisyEdge.path1[line.index]; for (int i = 0; i < edge1.Count - 1; i++) DrawLine(texture, edge1[i].x, edge1[i].y, edge1[i + 1].x, edge1[i + 1].y, Color.blue); } texture.Apply(); plane.GetComponent<Renderer>().material.mainTexture = texture; }
public void AttachTexture(GameObject plane, Map map, NoisyEdges noisyEdge) { Texture2D texture = GetTexture(map, noisyEdge); plane.GetComponent<Renderer>().material.mainTexture = texture; }