public LJMapObject GetPositionProperty(SerVector2Int position) { LJMapObject positionValue; if (m_PositionProperties.TryGetValue(position, out positionValue)) { } return(positionValue); }
private void ClearAllGirdObject(LJMapObjLayerData mapObjLayerData, List <Vector3Int> allLocations) { for (int i = 0, imax = allLocations.Count; i < imax; i++) { Vector3Int location = allLocations[i]; SerVector2Int serVector2Int = new SerVector2Int(location.x, location.y); mapObjLayerData.RemovePositionProperty(serVector2Int); } }
//[SerializeField] //private LJTestDict testDict; //public LJTestDict TestDict //{ // get { return testDict; } //} //public Dictionary<Vector3Int, LJGridObject> PositionProperties //{ // get { return serializationDictionary.ToDictionary(); } //} ////[SerializeField] //public List<Vector3Int> _keys = new List<Vector3Int> { }; ////[SerializeField] //public List<LJGridObject> _values = new List<LJGridObject> { }; //public void OnBeforeSerialize() //{ // _keys.Clear(); // _values.Clear(); // foreach (var kvp in m_PositionProperties) // { // _keys.Add(kvp.Key); // _values.Add(kvp.Value); // } //} //public void OnAfterDeserialize() //{ // m_PositionProperties.Clear(); // for (int i = 0; i != Math.Min(_keys.Count, _values.Count); i++) // { // m_PositionProperties[_keys[i]] = _values[i]; // } //} public bool SetPositionProperty(SerVector2Int position, LJMapObject positionProperty) { //Grid grid = GetComponentInParent<Grid>(); //if (grid != null && positionProperty != null) //{ if (positionProperty != null) { m_PositionProperties[position] = positionProperty; return(true); } return(false); }
private void EnsureCreateAllGirdObject(LJMapObjLayerData mapObjLayerData, List <Vector3Int> allLocations) { for (int i = 0, imax = allLocations.Count; i < imax; i++) { Vector3Int location = allLocations[i]; SerVector2Int serVector3Int = new SerVector2Int(location.x, location.y); //SerVector3Int serVector3Int = MapUtil.ConvertVec3Int2SerVec3Int(allLocations[i]); if (mapObjLayerData.ContainsPositionProperty(serVector3Int)) { continue; } mapObjLayerData.SetPositionProperty(serVector3Int, new LJMapObject(new Vector2Int(location.x, location.y))); } }
public override bool Equals(object obj) { if (obj == null) { return(false); } SerVector2Int other = obj as SerVector2Int; if (other == null) { return(false); } if (other.x == x && other.y == y) { return(true); } return(false); }
void OnDrawSceneGUI(SceneView sceneView) { LJMapObjLayerHolder mapObjLayerHolder = prefabBrush.LJMapObjLayerHolder; if (mapObjLayerHolder == null) { return; } Grid grid = mapObjLayerHolder.GetComponent <Grid>(); if (grid == null) { return; } LJMapObjLayerData mapObjLayerData = mapObjLayerHolder.mapObjLayerData; if (mapObjLayerData == null) { return; } if (!prefabBrush.showObjLayerBorder && !prefabBrush.showObjLayerInfo) { return; } Vector3 cellSize = grid.cellSize; //Debug.Log("we got cellSize : "+ cellSize); LJMapObjDict dict = mapObjLayerData.PositionProperties; StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair <SerVector2Int, LJMapObject> kvp in dict) { SerVector2Int serCellPosInt = kvp.Key; Vector2Int cellPosInt = MapUtil.ConvertSerVec2Int2Vec2Int(serCellPosInt); LJMapObject ljGridObject = kvp.Value; Vector3[] cellCorners = MapUtil.GetMapWorldCorners(new Vector3Int(cellPosInt.x, cellPosInt.y, 0), grid); Handles.color = Color.cyan; if (prefabBrush.showObjLayerBorder) { Handles.DrawLines(new Vector3[] { cellCorners[0], cellCorners[2], cellCorners[2], cellCorners[1], cellCorners[1], cellCorners[3], cellCorners[3], cellCorners[0], }); } //switch (ljGridObject.d) if (ljGridObject == null) { continue; } if (!prefabBrush.showObjLayerInfo) { continue; } stringBuilder.Remove(0, stringBuilder.Length); switch (ljGridObject.MainType) { case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.UNDEFINE: stringBuilder.Append("未定义"); break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.WONDER: stringBuilder.Append("域都"); break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.CITY: stringBuilder.Append("卫都"); break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.GATE: stringBuilder.Append("关隘"); break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.TOWN: stringBuilder.Append("城镇"); break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.RESOURCE: stringBuilder.Append("资源区"); break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.TREASURE: stringBuilder.Append("讨伐区"); break; } switch (ljGridObject.MainType) { case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.UNDEFINE: break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.WONDER: case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.CITY: case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.GATE: switch (ljGridObject.SubType) { case LJMapConst.MAP_OBJ_SUB_TYPE.UNDEFINE: stringBuilder.Append(" 未定义 "); break; case LJMapConst.MAP_OBJ_SUB_TYPE.WONDER_PART_OUTSIDE: stringBuilder.Append(" 外层 "); break; case LJMapConst.MAP_OBJ_SUB_TYPE.WONDER_PART_INNER: stringBuilder.Append(" 内层 "); break; case LJMapConst.MAP_OBJ_SUB_TYPE.WONDER_PART_KERNEL: stringBuilder.Append(" 核心 "); break; case LJMapConst.MAP_OBJ_SUB_TYPE.WONDER_PART_UNUSERD: stringBuilder.Append(" 阻塞 "); break; case LJMapConst.MAP_OBJ_SUB_TYPE.PART: break; } break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.TOWN: //stringBuilder.AppendFormat("id : {0}", ljGridObject.GetGridObjectId()); break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.RESOURCE: //stringBuilder.AppendFormat("id : {0}", ljGridObject.MainId); break; case LJTilemaps.LJMapConst.MAP_OBJ_MAIN_TYPE.TREASURE: //stringBuilder.AppendFormat("id : {0}", ljGridObject.MainId); break; } stringBuilder.AppendFormat("id : {0}", ljGridObject.GetGridObjectId()); Handles.color = Color.green; Handles.Label(cellCorners[4], stringBuilder.ToString(), GUI.skin.customStyles[4]); } }
private void DrawAllGirdObjectType(LJMapObjLayerData mapObjLayerData, LJMapObject currentGirdObject, List <Vector3Int> allLocations, ref bool isChanged) { int mainType = EditorGUILayout.IntPopup("组类型 : ", currentGirdObject.MainType, MAIN_NAMES, MAIN_INDEXS); if (currentGirdObject.MainType != mainType) //改变主类型 { isChanged = true; EnsureCreateAllGirdObject(mapObjLayerData, allLocations); for (int i = 0, imax = allLocations.Count; i < imax; i++) { Vector3Int location = allLocations[i]; SerVector2Int serVector2Int = new SerVector2Int(location.x, location.y); LJMapObject gridObject = mapObjLayerData.GetPositionProperty(serVector2Int); gridObject.MainType = mainType; switch (mainType) { case LJMapConst.MAP_OBJ_MAIN_TYPE.UNDEFINE: gridObject.SubType = LJMapConst.MAP_OBJ_SUB_TYPE.UNDEFINE; break; case LJMapConst.MAP_OBJ_MAIN_TYPE.WONDER: case LJMapConst.MAP_OBJ_MAIN_TYPE.CITY: case LJMapConst.MAP_OBJ_MAIN_TYPE.GATE: if (gridObject.SubType == LJMapConst.MAP_OBJ_SUB_TYPE.UNDEFINE) { gridObject.SubType = LJMapConst.MAP_OBJ_SUB_TYPE.WONDER_PART_OUTSIDE; } else if (gridObject.SubType == LJMapConst.MAP_OBJ_SUB_TYPE.PART) { gridObject.SubType = LJMapConst.MAP_OBJ_SUB_TYPE.WONDER_PART_OUTSIDE; } break; case LJMapConst.MAP_OBJ_MAIN_TYPE.TOWN: case LJMapConst.MAP_OBJ_MAIN_TYPE.RESOURCE: case LJMapConst.MAP_OBJ_MAIN_TYPE.TREASURE: gridObject.SubType = LJMapConst.MAP_OBJ_SUB_TYPE.PART; break; } } } switch (mainType) { case LJMapConst.MAP_OBJ_MAIN_TYPE.UNDEFINE: EditorGUILayout.LabelField("请先定义地块类型!"); break; case LJMapConst.MAP_OBJ_MAIN_TYPE.WONDER: case LJMapConst.MAP_OBJ_MAIN_TYPE.CITY: case LJMapConst.MAP_OBJ_MAIN_TYPE.GATE: int subType = EditorGUILayout.IntPopup("二级类型 : ", currentGirdObject.SubType, SUB_NAMES, SUB_INDEXS); if (currentGirdObject.SubType != subType) { //改变主类型 EnsureCreateAllGirdObject(mapObjLayerData, allLocations); for (int i = 0, imax = allLocations.Count; i < imax; i++) { Vector3Int location = allLocations[i]; SerVector2Int serVector2Int = new SerVector2Int(location.x, location.y); LJMapObject gridObject = mapObjLayerData.GetPositionProperty(serVector2Int); gridObject.SubType = subType; gridObject.MainType = mainType; } } break; case LJMapConst.MAP_OBJ_MAIN_TYPE.TOWN: case LJMapConst.MAP_OBJ_MAIN_TYPE.RESOURCE: case LJMapConst.MAP_OBJ_MAIN_TYPE.TREASURE: break; } }
public override void OnPaintInspectorGUI() { base.OnPaintInspectorGUI(); bool isChanged = false; EditorGUILayout.LabelField("蓝鲸图块编辑"); List <Vector3Int> allLocations = new List <Vector3Int>(); Vector3Int lastCellposition = lastBoundsInt.position; allLocations.Add(lastCellposition); foreach (Vector3Int location in lastBoundsInt.allPositionsWithin) { if (lastCellposition.Equals(location)) { continue; } allLocations.Add(location); } DrawInspectorAllLocation(allLocations); LJMapObjLayerHolder mapObjLayerHolder = prefabBrush.LJMapObjLayerHolder; if (mapObjLayerHolder == null) { EditorGUILayout.LabelField("未绑定 LJ Map Obj Layer Holder!"); return; } LJMapObjLayerData mapObjLayerData = mapObjLayerHolder.mapObjLayerData; if (mapObjLayerData == null) { EditorGUILayout.LabelField("未加载地图!"); return; } SerVector2Int lastCellVectPosition = new SerVector2Int(allLocations[0].x, allLocations[0].y); //SerVector3Int lastCellVectPosition = MapUtil.ConvertVec3Int2SerVec3Int(allLocations[0]); LJMapObject currentGirdObject = mapObjLayerData.GetPositionProperty(lastCellVectPosition); int drawSt = DrawInspectorEnableGirdObject(mapObjLayerData, currentGirdObject, allLocations); switch (drawSt) { case 1: //有修改 已关闭 SaveLJMapObjLayerData(mapObjLayerData); return; case 2: //有修改 已开启 currentGirdObject = mapObjLayerData.GetPositionProperty(lastCellVectPosition); isChanged = true; break; case 3: // 无修改 关闭 return; case 4: // 无修改 开启 break; } DrawAllGirdObjectType(mapObjLayerData, currentGirdObject, allLocations, ref isChanged); //switch (currentGirdObject.MainType) //{ // case LJMapConst.MAP_OBJ_MAIN_TYPE.UNDEFINE: // break; // case LJMapConst.MAP_OBJ_MAIN_TYPE.WONDER: // case LJMapConst.MAP_OBJ_MAIN_TYPE.CITY: // case LJMapConst.MAP_OBJ_MAIN_TYPE.GATE: // case LJMapConst.MAP_OBJ_MAIN_TYPE.TOWN: // case LJMapConst.MAP_OBJ_MAIN_TYPE.RESOURCE: // case LJMapConst.MAP_OBJ_MAIN_TYPE.TREASURE: // //DrawAllGirdObjectMainId(gridMapData, currentGirdObject, allLocations,ref isChanged); // break; //} //switch (currentGirdObject.MainType) //{ // case LJMapConst.MAP_OBJ_MAIN_TYPE.UNDEFINE: // break; // case LJMapConst.MAP_OBJ_MAIN_TYPE.WONDER: // case LJMapConst.MAP_OBJ_MAIN_TYPE.CITY: // case LJMapConst.MAP_OBJ_MAIN_TYPE.GATE: // DrawAllGirdObjectSubId(gridMapData, currentGirdObject, allLocations,ref isChanged); // break; // case LJMapConst.MAP_OBJ_MAIN_TYPE.TOWN: // case LJMapConst.MAP_OBJ_MAIN_TYPE.RESOURCE: // case LJMapConst.MAP_OBJ_MAIN_TYPE.TREASURE: // break; //} //EditorGUILayout.BeginHorizontal(); //EditorGUILayout.PrefixLabel("扩展信息 : "); //ljGridObject.ExtendMsg = EditorGUILayout.DelayedTextField(ljGridObject.ExtendMsg); //EditorGUILayout.EndHorizontal(); //EditorGUILayout.BeginHorizontal(); //EditorGUILayout.PrefixLabel("名字 : "); //ljGridObject.Name = EditorGUILayout.DelayedTextField(ljGridObject.Name); //EditorGUILayout.EndHorizontal(); //EditorGUILayout.BeginHorizontal(); //EditorGUILayout.PrefixLabel("备注 : "); //ljGridObject.Info = EditorGUILayout.DelayedTextField(ljGridObject.Info); //EditorGUILayout.EndHorizontal(); if (isChanged) { SaveLJMapObjLayerData(mapObjLayerData); } }
public bool RemovePositionProperty(SerVector2Int position) { return(m_PositionProperties.Remove(position)); }
public bool ContainsPositionProperty(SerVector2Int position) { return(m_PositionProperties.ContainsKey(position)); }
public bool TryGetPositionProperty(SerVector2Int position, out LJMapObject positionValue) { return(m_PositionProperties.TryGetValue(position, out positionValue)); }