public void Draw(ref Texture2D2 texture) { DrawFloors(ref texture); DrawWalls(ref texture); DrawWindows(ref texture); DrawEntrances(ref texture); }
/// <summary> /// Add a new texture on top of the original ref 'texture'. /// </summary> /// <param name="original"></param> /// <param name="position"></param> /// <param name="to_add"></param> public static void AddToTexture(ref Texture2D2 original, Vector2 position, Sprite2 to_add) { position += new Vector2(DRAW_PAD, DRAW_PAD); // Perform operation for natural Color[] colors1 = original.natural.GetPixels((int)(position.x * PIXELS_PER_UNIT), (int)(position.y * PIXELS_PER_UNIT), to_add.natural.texture.width, to_add.natural.texture.height); Color[] colors2 = to_add.natural.texture.GetPixels(); Color[] new_colors = new Color[colors1.Length]; for (int i = 0; i < new_colors.Length; i++) { float r = Mathf.Clamp(colors1[i].r * (1 - colors2[i].a) + colors2[i].r * colors2[i].a, 0, 1); float g = Mathf.Clamp(colors1[i].g * (1 - colors2[i].a) + colors2[i].g * colors2[i].a, 0, 1); float b = Mathf.Clamp(colors1[i].b * (1 - colors2[i].a) + colors2[i].b * colors2[i].a, 0, 1); float a = Mathf.Clamp(colors1[i].a + colors2[i].a, 0, 1); new_colors[i] = new Color(r, g, b, a); } original.natural.SetPixels((int)(position.x * PIXELS_PER_UNIT), (int)(position.y * PIXELS_PER_UNIT), to_add.natural.texture.width, to_add.natural.texture.height, new_colors); // Perform operation for occluded colors1 = original.occluded.GetPixels((int)(position.x * PIXELS_PER_UNIT), (int)(position.y * PIXELS_PER_UNIT), to_add.occluded.texture.width, to_add.occluded.texture.height); colors2 = to_add.occluded.texture.GetPixels(); new_colors = new Color[colors1.Length]; for (int i = 0; i < new_colors.Length; i++) { float r = Mathf.Clamp(colors1[i].r * (1 - colors2[i].a) + colors2[i].r * colors2[i].a, 0, 1); float g = Mathf.Clamp(colors1[i].g * (1 - colors2[i].a) + colors2[i].g * colors2[i].a, 0, 1); float b = Mathf.Clamp(colors1[i].b * (1 - colors2[i].a) + colors2[i].b * colors2[i].a, 0, 1); float a = Mathf.Clamp(colors1[i].a + colors2[i].a, 0, 1); new_colors[i] = new Color(r, g, b, a); } original.occluded.SetPixels((int)(position.x * PIXELS_PER_UNIT), (int)(position.y * PIXELS_PER_UNIT), to_add.occluded.texture.width, to_add.occluded.texture.height, new_colors); }
private void DrawFloors(ref Texture2D2 texture) { BuildingModule module = GameObject.FindObjectOfType <BuildingModule>(); for (int x = 0; x < this.dimension.x; x++) { for (int y = 0; y < this.dimension.y; y++) { MapGenerator.AddToTexture(ref texture, this.Position(Depth.World) + new Point(x, y), module.building_floor); } } }
public override void OnStartClient() { base.OnStartClient(); MakeOccludedObject(); map = FindObjectOfType <MapGenerator>(); if (GetComponent <SpriteRenderer>() != null) { texture = MapGenerator.GetBlankTexture(map.dimension); } //StartCoroutine(WaitForDone()); }
private void DrawEntrance(Directional entrance, ref Texture2D2 texture) { BuildingModule module = GameObject.FindObjectOfType <BuildingModule>(); if (entrance.direction == Direction.North) { MapGenerator.AddToTexture(ref texture, entrance.Position(Depth.World), module.entrance_north); } else if (entrance.direction == Direction.East) { MapGenerator.AddToTexture(ref texture, entrance.Position(Depth.World), module.entrance_east); } else if (entrance.direction == Direction.South) { MapGenerator.AddToTexture(ref texture, entrance.Position(Depth.World), module.entrance_south); } else { MapGenerator.AddToTexture(ref texture, entrance.Position(Depth.World), module.entrance_west); } }
private void DrawEntrances(ref Texture2D2 texture) { List <DirectionalPair> all_entrances = new List <DirectionalPair>(); foreach (Room room in rooms) { foreach (Directional entrance in room.entrances) { if (!all_entrances.Any <DirectionalPair>(w => w == new DirectionalPair(entrance, entrance.OtherSide()))) { all_entrances.Add(new DirectionalPair(entrance, entrance.OtherSide())); } } } foreach (DirectionalPair entrance_pair in all_entrances) { DrawEntrance(entrance_pair.first, ref texture); DrawEntrance(entrance_pair.second, ref texture); } }
private void DrawWindow(Directional window, ref Texture2D2 texture) { BuildingModule module = GameObject.FindObjectOfType <BuildingModule>(); if (window.direction == Direction.North) { MapGenerator.AddToTexture(ref texture, window.Position(Depth.World), module.window_north); } else if (window.direction == Direction.East) { MapGenerator.AddToTexture(ref texture, window.Position(Depth.World), module.window_east); } else if (window.direction == Direction.South) { MapGenerator.AddToTexture(ref texture, window.Position(Depth.World), module.window_south); } else { MapGenerator.AddToTexture(ref texture, window.Position(Depth.World), module.window_west); } }
private void DrawWindows(ref Texture2D2 texture) { List <DirectionalPair> all_windows = new List <DirectionalPair>(); foreach (Room room in rooms) { foreach (Directional window in room.windows) { if (!all_windows.Any <DirectionalPair>(w => w == new DirectionalPair(window, window.OtherSide()))) { all_windows.Add(new DirectionalPair(window, window.OtherSide())); } } } foreach (DirectionalPair window_pair in all_windows) { DrawWindow(window_pair.first, ref texture); DrawWindow(window_pair.second, ref texture); } }
private void DrawWalls(ref Texture2D2 texture) { List <DirectionalPair> all_walls = new List <DirectionalPair>(); foreach (Room room in rooms) { foreach (Directional wall in room.walls) { if (!all_walls.Any <DirectionalPair>(w => w == new DirectionalPair(wall, wall.OtherSide()))) { all_walls.Add(new DirectionalPair(wall, wall.OtherSide())); } } } foreach (DirectionalPair wall_pair in all_walls) { DrawWall(wall_pair.first, ref texture); DrawWall(wall_pair.second, ref texture); } }