public void OnSceneGUI() { MapResourceItem s = (MapResourceItem)target; if (GUI.changed) { EditorUtility.SetDirty(s); } }
/// <summary> /// Handles ResourceManager ResourceInit event /// </summary> protected void ResourceManager_ResourceInit(object sender, EventArgs e) { if (DesignMode) { return; } ResourceManager manager = sender as ResourceManager; if (!manager.FailureOnInitialize) { return; } if (manager is MapResourceManager) { MapResourceManager mapManager = manager as MapResourceManager; for (int i = 0; i < mapManager.ResourceItems.Count; i++) { MapResourceItem item = mapManager.ResourceItems[i]; if (item != null && item.FailedToInitialize) { mapManager.ResourceItems[i] = null; } } } else if (manager is GeocodeResourceManager) { GeocodeResourceManager gcManager = manager as GeocodeResourceManager; for (int i = 0; i < gcManager.ResourceItems.Count; i++) { GeocodeResourceItem item = gcManager.ResourceItems[i]; if (item != null && item.FailedToInitialize) { gcManager.ResourceItems[i] = null; } } } else if (manager is GeoprocessingResourceManager) { GeoprocessingResourceManager gpManager = manager as GeoprocessingResourceManager; for (int i = 0; i < gpManager.ResourceItems.Count; i++) { GeoprocessingResourceItem item = gpManager.ResourceItems[i]; if (item != null && item.FailedToInitialize) { gpManager.ResourceItems[i] = null; } } } }
public void ClearGrid(Vector2 grid) { for (int i = 3; i > -1; i--) { int index = layers.IndexOf((MapEditorSortLayer)i); if (index != -1) { int n = layerItems[index].posList.IndexOf((int)grid.x * 10000 + (int)grid.y); if (n != -1) { MapResourceItem item = layerItems[index].items[n]; layerItems[index].posList.RemoveAt(n); layerItems[index].items.RemoveAt(n); UpdateMap(); break; } } } }
public void AddGrid(int pos, MapResourceItem selectedTile) { int index = layers.IndexOf(selectedTile.layer); if (index != -1) { int i = layerItems[index].posList.IndexOf(pos); if (i != -1) { layerItems[index].items[i] = selectedTile; } else { layerItems[index].posList.Add(pos); layerItems[index].items.Add(selectedTile); } } else { layers.Add(selectedTile.layer); layerItems.Add(new MapLayerItem()); layerItems[layerItems.Count - 1].posList.Add(pos); layerItems[layerItems.Count - 1].items.Add(selectedTile); } if (selectedTile.layer == MapEditorSortLayer.Floor1) { if (mapGird.ContainsKey(pos)) { mapGird[pos] = selectedTile; } else { mapGird.Add(pos, selectedTile); } } }
public void OnGUI() { GUILayout.BeginVertical(); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); worldType = (WorldType)EditorGUILayout.EnumPopup(worldType, GUILayout.Width(100)); if (GUILayout.Button("创建新的地图块", GUILayout.Width(100), GUILayout.Height(30))) { currMapScene = new GameObject("Map" + (mapSceneList.Count + 1)).AddComponent <MapScene>(); currMapScene.offsetX = offsetX; currMapScene.offsetY = offsetY; currMapScene.mapSizeX = mapSizeX; currMapScene.mapSizeY = mapSizeY; currMapScene.worldType = worldType; mapSceneList.Add(currMapScene); FreshResource(); } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("地图宽度:", GUILayout.Width(60)); mapSizeX = EditorGUILayout.IntField(mapSizeX, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("地图高度:", GUILayout.Width(60)); mapSizeY = EditorGUILayout.IntField(mapSizeY, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("地图偏移X:", GUILayout.Width(60)); offsetX = EditorGUILayout.IntField(offsetX, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("地图偏移Y:", GUILayout.Width(60)); offsetY = EditorGUILayout.IntField(offsetY, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); GUILayout.Label("当前选中的地图块: " + (currMapScene == null ? "无" : currMapScene.name), GUILayout.Width(200)); if (currMapScene != null) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("地图宽度:" + currMapScene.mapSizeX, GUILayout.Width(100)); GUILayout.Label("地图高度:" + currMapScene.mapSizeY, GUILayout.Width(100)); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("地图偏移X:", GUILayout.Width(60)); currMapScene.offsetX = EditorGUILayout.IntField(currMapScene.offsetX, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("地图偏移Y:", GUILayout.Width(60)); currMapScene.offsetY = EditorGUILayout.IntField(currMapScene.offsetY, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.Space(20); GUILayout.BeginHorizontal(); if (GUILayout.Button("更新物理碰撞", GUILayout.Width(90), GUILayout.Height(30))) { for (int i = 0; i < mapSceneList.Count; i++) { mapSceneList[i].UpdateCollider(); } } if (GUILayout.Button("清除当前地图块", GUILayout.Width(90), GUILayout.Height(30))) { if (currMapScene != null) { currMapScene.Clear(); } mapSceneList.Remove(currMapScene); currMapScene = null; if (mapSceneList.Count > 0) { currMapScene = mapSceneList[0]; } } if (GUILayout.Button("保存世界地图", GUILayout.Width(90), GUILayout.Height(30))) { EditorApplication.SaveScene(EditorApplication.currentScene); SaveSceneAsset(); } if (GUILayout.Button("加载世界地图", GUILayout.Width(90), GUILayout.Height(30))) { LoadSceneAsset(); } GUILayout.EndHorizontal(); toolSelected = (MapTool)GUILayout.Toolbar((int)toolSelected, toolIcons, GUILayout.Width(160), GUILayout.Height(30)); if (currMapScene != null && mapResouceList != null) { GUILayout.BeginVertical(); int count = 0; for (int i = 0; i < mapResouceList.Count; i++) { if (mapResouceList[i].worldType != WorldType.None && mapResouceList[i].worldType != currMapScene.worldType) { continue; } if (count % 7 == 0) { GUILayout.BeginHorizontal(); } Sprite sprite = (mapResouceList[i].isPrefab ? (mapResouceList[i].GetComponentInChildren <SpriteRenderer>().sprite) : ((mapResouceList[i].isNine ? mapResouceList[i].center[0] : mapResouceList[i].normalList[0]).sprite)); var croppedTexture = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height); var pixels = sprite.texture.GetPixels((int)sprite.textureRect.x, (int)sprite.textureRect.y, (int)sprite.textureRect.width, (int)sprite.textureRect.height); croppedTexture.SetPixels(pixels); croppedTexture.Apply(); if (GUILayout.Button(croppedTexture, GUILayout.Width(60), GUILayout.Height(60))) { selectedTile = mapResouceList[i]; if (toolSelected == MapTool.Clear) { toolSelected = MapTool.Draw; } } if ((count + 1) % 7 == 0) { GUILayout.EndHorizontal(); } count++; } GUILayout.EndVertical(); } GUILayout.EndVertical(); }
void GenerateStoneWallAndEdge() { int index = currMapScene.layers.IndexOf(MapEditorSortLayer.Floor1); MapLayerItem mapLayerItem = currMapScene.layerItems[index]; for (int i = 0; i < mapLayerItem.items.Count; i++) { if (mapLayerItem.items[i].itemType == MapEditorItemType.Wall) { int x = mapLayerItem.posList[i] / 10000; int y = mapLayerItem.posList[i] % 10000; if (y == 0) { continue; } index = mapLayerItem.posList.IndexOf(x * 10000 + y - 1); if (index != -1 && (mapLayerItem.items[index].itemType != MapEditorItemType.Wall && mapLayerItem.items[index].itemType != MapEditorItemType.StoneWall)) { mapLayerItem.items[i] = mapLayerItem.items[i].replaceItem; } } } for (int i = 0; i < mapLayerItem.items.Count; i++) { if (mapLayerItem.items[i].itemType != MapEditorItemType.Wall && mapLayerItem.items[i].itemType != MapEditorItemType.StoneWall) { int x = mapLayerItem.posList[i] / 10000; int y = mapLayerItem.posList[i] % 10000; int index1 = mapLayerItem.posList.IndexOf(x * 10000 + y + 1); int index2 = mapLayerItem.posList.IndexOf((x - 1) * 10000 + y); int index3 = mapLayerItem.posList.IndexOf((x + 1) * 10000 + y); bool wall1 = index1 != -1 && (mapLayerItem.items[index1].itemType == MapEditorItemType.Wall || mapLayerItem.items[index1].itemType == MapEditorItemType.StoneWall); bool wall2 = index2 != -1 && (mapLayerItem.items[index2].itemType == MapEditorItemType.Wall || mapLayerItem.items[index2].itemType == MapEditorItemType.StoneWall); bool wall3 = index3 != -1 && (mapLayerItem.items[index3].itemType == MapEditorItemType.Wall || mapLayerItem.items[index3].itemType == MapEditorItemType.StoneWall); MapResourceItem edge = null; if (wall1 && wall2 && wall3) { edge = mapLayerItem.items[index1].replaceEdgeSingleUp; } else if (wall1 && wall2 && !wall3) { edge = mapLayerItem.items[index1].replaceEdgeLeftUp; } else if (wall1 && !wall2 && wall3) { edge = mapLayerItem.items[index1].replaceEdgeRightUp; } else if (wall1 && !wall2 && !wall3) { edge = mapLayerItem.items[index1].replaceEdgeUp; } else if (!wall1 && wall2 && wall3) { edge = mapLayerItem.items[index2].replaceEdgeVer; } else if (!wall1 && wall2 && !wall3) { edge = mapLayerItem.items[index2].replaceEdgeLeft; } else if (!wall1 && !wall2 && wall3) { edge = mapLayerItem.items[index3].replaceEdgeRight; } else { edge = null; } if (edge != null) { index = currMapScene.layers.IndexOf(MapEditorSortLayer.Floor2); MapLayerItem mapLayerEdgeItem = null; if (index == -1) { currMapScene.layers.Add(MapEditorSortLayer.Floor2); mapLayerEdgeItem = new MapLayerItem(); currMapScene.layerItems.Add(mapLayerEdgeItem); } else { mapLayerEdgeItem = currMapScene.layerItems[index]; } index = mapLayerEdgeItem.posList.IndexOf(x * 10000 + y); if (index == -1) { mapLayerEdgeItem.posList.Add(x * 10000 + y); mapLayerEdgeItem.items.Add(edge); } else { mapLayerEdgeItem.items[index] = edge; } } } } }
void AddTile(Vector2 pos, MapResourceItem selectedTile) { currMapScene.AddGrid(((int)pos.x - currMapScene.offsetX) * 10000 + (int)pos.y - currMapScene.offsetY, selectedTile); currMapScene.UpdateMap(); }
void OnEnable() { resourceItem = (MapResourceItem)target; }
private MapResourceItem CreateMapResourceItem(MapService mapService) { Logger.Debug("Creating map resource item for service=" + mapService.ServiceName); GISResourceItemDefinition definition = new GISResourceItemDefinition(); definition.DataSourceType = Properties.DataSourceType; definition.DataSourceDefinition = Properties.DataSourceDefinition; definition.Identity = Properties.Identity; definition.ResourceDefinition = "(default)@" + mapService.ServiceName; definition.DataSourceShared = true; MapResourceItem resourceItem = new MapResourceItem(); resourceItem.Definition = definition; resourceItem.Name = mapService.DisplayName; resourceItem.DisplaySettings = new DisplaySettings(); resourceItem.DisplaySettings.Visible = mapService.Visible; resourceItem.Parent = MapResourceManager; return resourceItem; }
/// <summary> /// Creates a GraphicsResource in the MapResourceManager. /// This must be the first layer to be created on the web-tier. /// </summary> public void AddGraphicsLayer() { GISResourceItemDefinition graphicsDefinition = new GISResourceItemDefinition(); graphicsDefinition.ResourceDefinition = "GraphicsResource"; graphicsDefinition.DataSourceDefinition = "In Memory"; graphicsDefinition.DataSourceType = "GraphicsLayer"; graphicsDefinition.DataSourceShared = true; MapResourceItem graphicsResourceItem = new MapResourceItem(); graphicsResourceItem.Definition = graphicsDefinition; graphicsResourceItem.Name = Properties.GraphicsResourceName; graphicsResourceItem.DisplaySettings = new DisplaySettings(); graphicsResourceItem.DisplaySettings.Visible = true; graphicsResourceItem.DisplaySettings.DisplayInTableOfContents = false; graphicsResourceItem.Parent = MapResourceManager; MapResourceManager.ResourceItems.Add(graphicsResourceItem); MapResourceManager.CreateResource(graphicsResourceItem); MapResourceManager.Refresh(); }
private List <MapSprite> GetSpriteList(int i, int j, Dictionary <int, MapResourceItem> girdInfo) { MapResourceItem item = girdInfo[i * 10000 + j]; bool grid1 = girdInfo.ContainsKey((i - 1) * 10000 + j); bool grid2 = girdInfo.ContainsKey((i + 1) * 10000 + j); bool grid3 = girdInfo.ContainsKey(i * 10000 + (j - 1)); bool grid4 = girdInfo.ContainsKey(i * 10000 + (j + 1)); bool grid5 = girdInfo.ContainsKey((i - 1) * 10000 + (j + 1)); bool grid6 = girdInfo.ContainsKey((i + 1) * 10000 + (j + 1)); bool grid7 = girdInfo.ContainsKey((i - 1) * 10000 + (j - 1)); bool grid8 = girdInfo.ContainsKey((i + 1) * 10000 + (j - 1)); bool wall1 = item.itemType == MapEditorItemType.Wall && !grid1; bool wall2 = item.itemType == MapEditorItemType.Wall && !grid2; bool wall3 = item.itemType == MapEditorItemType.Wall && !grid3; bool wall4 = item.itemType == MapEditorItemType.Wall && !grid4; bool wall5 = item.itemType == MapEditorItemType.Wall && !grid5; bool wall6 = item.itemType == MapEditorItemType.Wall && !grid6; bool wall7 = item.itemType == MapEditorItemType.Wall && !grid7; bool wall8 = item.itemType == MapEditorItemType.Wall && !grid8; bool left = wall1 || grid1 && (girdInfo[(i - 1) * 10000 + j].itemType == item.itemType); bool right = wall2 || grid2 && (girdInfo[(i + 1) * 10000 + j].itemType == item.itemType); bool down = wall3 || grid3 && (girdInfo[i * 10000 + (j - 1)].itemType == item.itemType); bool up = wall4 || grid4 && (girdInfo[i * 10000 + (j + 1)].itemType == item.itemType); bool leftUp = wall5 || grid5 && (girdInfo[(i - 1) * 10000 + (j + 1)].itemType == item.itemType); bool rightUp = wall6 || grid6 && (girdInfo[(i + 1) * 10000 + (j + 1)].itemType == item.itemType); bool leftDown = wall7 || grid7 && (girdInfo[(i - 1) * 10000 + (j - 1)].itemType == item.itemType); bool rightDown = wall8 || grid8 && (girdInfo[(i + 1) * 10000 + (j - 1)].itemType == item.itemType); if (item.isNine) { if (!left && !right && !down && !up) { //单个 return(item.single); } else if (!left && right && !down && !up) { //向左单个 return(item.singleLeft); } else if (left && !right && !down && !up) { //向右单个 return(item.singleRight); } else if (!left && !right && down && !up) { //向上单个 return(item.singleUp); } else if (!left && !right && !down && up) { //向下单个 return(item.singleDown); } else if (left && right && !down && !up) { //横向双通 return(item.pass1_1); } else if (!left && !right && down && up) { //竖向双通 return(item.pass1_2); } else if (left && right && !down && up && !leftUp && !rightUp) { //上三通 return(item.pass2_1); } else if (left && right && down && !up && !leftDown && !rightDown) { //下三通 return(item.pass2_2); } else if (left && !right && down && up && !leftUp && !leftDown) { //左三通 return(item.pass2_3); } else if (!left && right && down && up && !rightUp && !rightDown) { //右三通 return(item.pass2_4); } else if (left && right && down && up && !leftUp && !rightUp && !leftDown && !rightDown) { //上下左右四通 return(item.passAll); } else if (!left && right && down && !up && !rightDown) { //左上拐角 return(item.corner1_1); } else if (left && !right && down && !up && !leftDown) { //右上拐角 return(item.corner1_2); } else if (!left && right && !down && up && !rightUp) { //左下拐角 return(item.corner1_3); } else if (left && !right && !down && up && !leftUp) { //右下拐角 return(item.corner1_4); } else if (!left && right && down && !up && rightDown) { //左外上角 return(item.out_1); } else if (left && !right && down && !up && leftDown) { //右外上角 return(item.out_2); } else if (!left && right && !down && up && rightUp) { //左外下角 return(item.out_3); } else if (left && !right && !down && up && leftUp) { //右外下角 return(item.out_4); } else if (leftDown && left && leftUp && down && up && !rightDown && right && rightUp) { //左上内角 return(item.in_1); } else if (!leftDown && left && leftUp && down && up && rightDown && right && rightUp) { //右上内角 return(item.in_2); } else if (leftDown && left && leftUp && down && up && rightDown && right && !rightUp) { //左下内角 return(item.in_3); } else if (leftDown && left && !leftUp && down && up && rightDown && right && rightUp) { //右下内角 return(item.in_4); } else if (left && right && down && !up && rightDown && leftDown) { //上边 return(item.up); } else if (left && right && !down && up && rightUp && leftUp) { //下边 return(item.down); } else if (!left && right && down && up && rightDown && rightUp) { //左边 return(item.left); } else if (left && !right && down && up && leftDown && leftUp) { //右边 return(item.right); } else if (!leftDown && left && leftUp && down && up && rightDown && right && !rightUp) { //左上右下对角 return(item.angle1_1); } else if (leftDown && left && !leftUp && down && up && !rightDown && right && rightUp) { //左下右上对角 return(item.angle1_2); } else if (leftDown && left && !leftUp && down && up && rightDown && right && !rightUp) { //上凸 return(item.pass3_1); } else if (!leftDown && left && leftUp && down && up && !rightDown && right && rightUp) { //下凸 return(item.pass3_2); } else if (!leftDown && left && !leftUp && down && up && rightDown && right && rightUp) { //左凸 return(item.pass3_3); } else if (leftDown && left && leftUp && down && up && !rightDown && right && !rightUp) { //右凸 return(item.pass3_4); } else if (!left && down && up && rightDown && right && !rightUp) { //上凸靠左 return(item.pass4_1); } else if (leftDown && left && !leftUp && down && up && !right) { //上凸靠右 return(item.pass4_2); } else if (!left && down && up && !rightDown && right && rightUp) { //下凸靠左 return(item.pass4_3); } else if (!leftDown && left && leftUp && down && up && !right) { //下凸靠右 return(item.pass4_4); } else if (!leftDown && left && down && !up && rightDown && right) { //左凸靠上 return(item.pass4_5); } else if (left && !down && up && right && rightUp) { //左凸靠下 return(item.pass4_6); } else if (leftDown && left && down && !up && !rightDown && right) { //右凸靠上 return(item.pass4_7); } else if (left && leftUp && !down && up && right && !rightUp) { //右凸靠下 return(item.pass4_8); } else if (!leftDown && left && !leftUp && !down && up && right && rightDown && !rightUp) { //左上通两路 return(item.pass5_1); } else if (leftDown && left && !leftUp && down && up && right && !rightDown && !rightUp) { //右上通两路 return(item.pass5_2); } else if (!leftDown && left && !leftUp && down && up && right && !rightDown && rightUp) { //左下通两路 return(item.pass5_3); } else if (!leftDown && left && leftUp && down && up && right && !rightDown && !rightUp) { //右下通两路 return(item.pass5_4); } else { //中心 return(item.center); } } else { return(item.normalList); } }