public void CopyFrom(SpriteMarker m) { IsDummy = true; MapSprite = m.MapSprite; GetComponent <SpriteRenderer>().flipX = m.GetComponent <SpriteRenderer>().flipX; GetComponent <SpriteRenderer>().color = m.GetComponent <SpriteRenderer>().color; }
SpriteMarker make_sprite(Vector3 pos, ConnectionSprite cs, Vector3 offset) { pos.z = -3f; GameObject g = GameObject.Instantiate(MapSpritePrefab); SpriteMarker sm = g.GetComponent <SpriteMarker>(); sm.SetSprite(cs); sm.transform.position = pos + offset; m_sprites.Add(sm); //m_sprites.AddRange(sm.CreateMirrorSprites()); return(sm); }
SpriteMarker make_bridge_sprite(Vector3 pos, ConnectionSprite cs, Vector3 offset, bool force, bool flip_x) { pos.z = -3f; GameObject g = GameObject.Instantiate(MapSpritePrefab); SpriteMarker sm = g.GetComponent <SpriteMarker>(); sm.SetSprite(cs); sm.SetFlip(force, flip_x); sm.transform.position = pos + offset; m_sprites.Add(sm); m_sprites.AddRange(sm.CreateMirrorSprites(m_forced_max, m_forced_min, m_force_mirror)); return(sm); }
/// <summary> /// 削除マーカーの生成 /// </summary> private SpriteMarker InstantiateRemoveMarker(string markerName, Vector2 point) { if (!marker) { return(null); } //マーカーの取得 SpriteMarker m = marker.PopMarker(removeMarker, point); m.gameObject.name = markerName; m.gameObject.SetActive(true); //コールバックの設定 m.onDown.RemoveListener(OnRemoveMarkerDown); m.onDown.AddListener(OnRemoveMarkerDown); return(m); }
SpriteMarker create_sprite(Vector3 pos, bool flip) { GameObject g = GameObject.Instantiate(MapSpritePrefab); SpriteMarker sm = g.GetComponent <SpriteMarker>(); sm.CopyFrom(this); sm.transform.position = pos; int max_y = Mathf.RoundToInt((MapBorder.s_map_border.Maxs.y + 1.0f) * 100f); int y = max_y - Mathf.RoundToInt(pos.y * 100f); sm.SetOrder(y); sm.SetFlip(true, flip); return(sm); }
/// <summary> /// 追加マーカーの生成 /// </summary> private SpriteMarker InstantiateAddMarker(string markerName, Vector2 p1, Vector2 p2) { if (!marker) { return(null); } Vector2 point = (p2 - p1) * 0.5f + p1; //マーカーの取得 SpriteMarker m = marker.PopMarker(addMarker, point); m.gameObject.name = markerName; m.gameObject.SetActive(true); //コールバックの設定 m.onDown.RemoveListener(OnAddMarkerDown); m.onDown.AddListener(OnAddMarkerDown); return(m); }
public List <SpriteMarker> PlaceSprites() { if (m_sprites != null) { foreach (SpriteMarker sm in m_sprites) { GameObject.Destroy(sm.gameObject); } } m_sprites = new List <SpriteMarker>(); List <SpriteMarker> all = new List <SpriteMarker>(); foreach (ConnectionWrapMarker m in m_wraps) { //all.AddRange(m.PlaceSprites()); } if (PolyBorder != null) { Vector3 max = MapBorder.s_map_border.Maxs; Vector3 min = MapBorder.s_map_border.Mins; bool p1 = false; bool p2 = false; if (PolyBorder.P1.x < min.x || PolyBorder.P1.y < min.y || PolyBorder.P1.x > max.x || PolyBorder.P1.y > max.y) { m_force_mirror = true; m_forced_min = PolyBorder.P1; m_forced_max = PolyBorder.P1; p1 = true; } if (PolyBorder.P2.x < min.x || PolyBorder.P2.y < min.y || PolyBorder.P2.x > max.x || PolyBorder.P2.y > max.y) { m_force_mirror = true; m_forced_min = PolyBorder.P2; m_forced_max = PolyBorder.P2; p2 = true; } if (p1 && p2) { m_forced_max = max + new Vector3(0.02f, 0.02f); m_forced_min = max - new Vector3(0.02f, 0.02f); } } if (m_connection.ConnectionType == ConnectionType.MOUNTAIN) { if (PolyBorder == null) { return(m_sprites); } Vector3 last = new Vector3(-900, -900, 0); ConnectionSprite cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); ConnectionSprite bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); if (cs == null) { return(m_sprites); } int ct = 0; make_sprite(PolyBorder.P1, cs, Vector3.zero); make_sprite(PolyBorder.P1, bottom, new Vector3(0, 0.01f)); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); make_sprite(PolyBorder.P2, cs, Vector3.zero); make_sprite(PolyBorder.P2, bottom, new Vector3(0, 0.01f)); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); foreach (Vector3 pt in PolyBorder.OrderedFinePoints) { if (Vector3.Distance(last, pt) < cs.Size && ct < PolyBorder.OrderedFinePoints.Count - 3) { ct++; continue; } ct++; last = pt; make_sprite(pt, cs, Vector3.zero); make_sprite(pt, bottom, new Vector3(0, 0.01f)); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); } } else if (m_connection.ConnectionType == ConnectionType.MOUNTAINPASS) { if (PolyBorder == null) { return(m_sprites); } Vector3 last = new Vector3(-900, -900, 0); ConnectionSprite cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); ConnectionSprite bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); PolyBorder other = PolyBorder.Reversed(); make_sprite(PolyBorder.P1, cs, Vector3.zero); make_sprite(PolyBorder.P1, bottom, new Vector3(0, 0.01f)); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); make_sprite(PolyBorder.P2, cs, Vector3.zero); make_sprite(PolyBorder.P2, bottom, new Vector3(0, 0.01f)); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); make_sprite(other.OrderedFinePoints[0], cs, Vector3.zero); make_sprite(other.OrderedFinePoints[0], bottom, new Vector3(0, 0.01f)); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); make_sprite(other.OrderedFinePoints[1], cs, Vector3.zero); make_sprite(other.OrderedFinePoints[1], bottom, new Vector3(0, 0.01f)); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); make_sprite(other.OrderedFinePoints[2], cs, Vector3.zero); make_sprite(other.OrderedFinePoints[2], bottom, new Vector3(0, 0.01f)); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); Vector3 endpt = other.OrderedFinePoints[2]; cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); bool is_mountain = true; foreach (Vector3 pt in PolyBorder.OrderedFinePoints) { if (Vector3.Distance(pt, endpt) < 0.05f) { break; } if (Vector3.Distance(last, pt) < cs.Size) { continue; } last = pt; if (!is_mountain) { make_sprite(pt, cs, new Vector3(0, 0.01f)); } else { make_sprite(pt, cs, Vector3.zero); make_sprite(pt, bottom, new Vector3(0, 0.01f)); } if (Vector3.Distance(pt, endpt) < 0.6f) { cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAINPASS); is_mountain = false; } else { cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.MOUNTAIN); is_mountain = true; } bottom = ArtManager.s_art_manager.GetMountainSpecSprite(); } } else if (m_connection.ConnectionType == ConnectionType.SHALLOWRIVER) { int mid = Mathf.RoundToInt(PolyBorder.OrderedPoints.Count * 0.25f); if (UnityEngine.Random.Range(0, 2) == 0) { mid = Mathf.RoundToInt(PolyBorder.OrderedPoints.Count * 0.75f); } Vector3 pos = PolyBorder.OrderedPoints[mid]; Vector3 pos2 = PolyBorder.OrderedPoints[mid + 1]; Vector3 actual = (pos - pos2).normalized;//(PolyBorder.P2 - PolyBorder.P1).normalized; Vector3 dir = new Vector3(-0.05f, 1f); if (Mathf.Abs(actual.y) < 0.3f) { ConnectionSprite cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.RIVER); SpriteMarker s = make_sprite(pos, cs, Vector3.zero); } else { ConnectionSprite cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.SHALLOWRIVER); if ((actual.y < 0 && actual.x > 0) || (actual.y > 0 && actual.x < 0)) { make_bridge_sprite(pos, cs, Vector3.zero, true, true); dir = new Vector3(1f, 0.3f); } else { make_bridge_sprite(pos, cs, Vector3.zero, true, false); dir = new Vector3(1f, -0.3f); } } float cull = 0.05f; List <Vector3> positions = new List <Vector3>(); while (cull < 0.35f) { positions.Add(pos + (dir * cull)); positions.Add(pos + (dir * -cull)); cull += 0.05f; } m_culling_points = positions; } else if (m_connection.ConnectionType == ConnectionType.ROAD) { if (PolyBorder == null) { return(m_sprites); } ConnectionSprite cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.ROAD); if (cs == null) { return(m_sprites); } foreach (Vector3 pt in m_poly) { make_sprite(pt, cs, new Vector3(UnityEngine.Random.Range(-0.01f, 0.01f), UnityEngine.Random.Range(-0.01f, 0.01f))); cs = ArtManager.s_art_manager.GetConnectionSprite(ConnectionType.ROAD); } } all.AddRange(m_sprites); return(all); }
public List <SpriteMarker> PlaceSprites() { MapSpriteSet set = ArtManager.s_art_manager.GetMapSpriteSet(m_node.ProvinceData.Terrain); if (!set.MapSprites.Any()) { return(m_sprites); } int valid_ct = set.MapSprites.Where(x => m_node.ProvinceData.Terrain.IsFlagSet(x.ValidTerrain)).Count(); if (valid_ct == 0) { return(m_sprites); } while (m_sprite_points.Any()) { Vector3 pos = m_sprite_points[0]; ProvinceSprite ps = ArtManager.s_art_manager.GetProvinceSprite(m_node.ProvinceData.Terrain); if (ps == null) { m_sprite_points.Remove(pos); continue; } while (UnityEngine.Random.Range(0f, 1f) > ps.SpawnChance) { ps = ArtManager.s_art_manager.GetProvinceSprite(m_node.ProvinceData.Terrain); if (ps == null) { break; } } if (ps == null) { m_sprite_points.Remove(pos); continue; } List <Vector3> remove = m_sprite_points.Where(x => Vector3.Distance(x, pos) < ps.Size).ToList(); foreach (Vector3 p in remove) { m_sprite_points.Remove(p); } //m_sprite_points.Remove(pos); pos.z = -3f; GameObject g = GameObject.Instantiate(MapSpritePrefab); SpriteMarker sm = g.GetComponent <SpriteMarker>(); sm.SetSprite(ps); sm.transform.position = pos; m_sprites.Add(sm); m_sprites.AddRange(sm.CreateMirrorSprites(Vector3.zero, Vector3.zero)); } return(m_sprites); }