public void Load(TerrainFlagInfo info) { ColorField.color = info.Color; NameField.text = info.Name; FlagField.text = info.FlagName; Flag = info.Flag; }
public static string GetNameByFlag(MapCellFlag flag) { TerrainFlagInfo info = GetInfoByFlag(flag); if (info != null) return info.Name; return "未知地形"; }
public static Color GetColorByFlag(MapCellFlag flag) { TerrainFlagInfo info = GetInfoByFlag(flag); if (info != null) return info.Color; return Color.black; }
public TerrainFlagInfo(MapCellFlag flag, string name, Color color) { Flag = flag; Name = name; FlagName = Enum.GetName(typeof(MapCellFlag), flag); Color = color; }
public static TerrainFlagInfo GetInfoByFlag(MapCellFlag flag) { foreach (TerrainFlagInfo info in Infos) { if (info.Flag == flag) return info; } return null; }
public void Load(TerrainFlagInfo info) { Flag = info.Flag; Color = Color.FromRgb((byte)(info.Color.r * 255), (byte)(info.Color.g * 255), (byte)(info.Color.b * 255)); ColorBlock.Background = new SolidColorBrush(Color); NameField.Content = info.Name; TypeField.Content = info.FlagName; int visibleFlags = Properties.Settings.Default.TerrainVisibleFlags; CheckField.IsChecked = EditorUtils.HasFlag(visibleFlags, (int)Flag); }
public void SetTerrainFlag(int x, int y, int radius, MapCellFlag flag, bool apply) { Dictionary<int, MapCellSetting> cellSettings = MapUtils.ArrayToDict(MapData.Cells); EditorMap map = GameEditor.Instance.Map; Vector2[] locations = MapUtils.Circle(x, y, radius); foreach (Vector2 location in locations) { MapCell cell = map.GetCell(location); if (cell == null) continue; if (apply) { MapCellSetting cellSetting; if (!cellSettings.TryGetValue(cell.Key, out cellSetting)) { cellSetting = new MapCellSetting(); cellSetting.X = cell.X; cellSetting.Y = cell.Y; cellSettings.Add(cell.Key, cellSetting); } EditorUtils.SetFlag(ref cellSetting.Flags, (int)flag, apply); } else { MapCellSetting cellSetting; if (cellSettings.TryGetValue(cell.Key, out cellSetting)) { EditorUtils.SetFlag(ref cellSetting.Flags, (int)flag, apply); if (cellSetting.Flags == 0) cellSettings.Remove(cell.Key); } } } MapData.Cells = MapUtils.DictToArray(cellSettings); InfoMap infos = new InfoMap(); infos["flag"] = flag; Modify(EditorEvent.MAP_TERRAIN_UPDATE, infos); }
public void SetFlag(MapCellFlag flag, bool value) { if (value) Flags = Flags | (int)flag; else Flags = Flags & (~(int)flag); }
public bool HasFlag(MapCellFlag flag) { return (Flags & (int)flag) != 0; }
public void ToggleShowTerrain(MapCellFlag flag, bool show) { Transform root; if (show) { int markIndex; if (!terrainRoots.TryGetValue(flag, out root)) { root = new GameObject("Terrain_" + Enum.GetName(typeof(MapCellFlag), flag)).transform; root.SetParent(terrainRoot, false); terrainRoots.Add(flag, root); List<int> indices = terrainMaskIndices.Values.ToList(); for (markIndex = 0; ; ++markIndex) { if (indices.IndexOf(markIndex) < 0) break; } terrainMaskIndices[flag] = markIndex; } else { markIndex = terrainMaskIndices[flag]; } root.localPosition = new Vector3(0, 0, markIndex * -0.1f); float scale = Mathf.Max(0.2f, 1 - markIndex * 0.2f); Color color = TerrainFlagInfo.GetColorByFlag(flag); List<MapCell> cells = GetCellsByFlag(flag); int cellCount = cells.Count; int childCount = root.childCount; for (int i = 0; i < cellCount; ++i) { MapCell cell = cells[i]; Transform terrainMark; if (i >= childCount) { GameObject terrainMarkObj = Loader.LoadPrefab("Map/TerrainMark").Instantiate(); terrainMarkObj.GetComponent<SpriteRenderer>().color = color; terrainMark = terrainMarkObj.transform; terrainMark.SetParent(root, false); } else { terrainMark = root.GetChild(i); } terrainMark.position = cell.Position; terrainMark.Translate(0, 0, -terrainMark.localPosition.z); terrainMark.localScale = new Vector3(scale, scale); } for (int i = cellCount; i < childCount; ++i) Destroy(root.GetChild(i).gameObject); } else { if (terrainRoots.TryGetValue(flag, out root)) { Destroy(root.gameObject); terrainRoots.Remove(flag); terrainMaskIndices.Remove(flag); } } }
private List<MapCell> GetCellsByFlag(MapCellFlag flag) { List<MapCell> ret = new List<MapCell>(); foreach (MapCell cell in Cells.Values) { if (cell.HasFlag(flag)) ret.Add(cell); } return ret; }