public void AddTile(Vector2Int position, int height) { if (!Cordination.ContainsKey(position)) { Debug.LogError("Cordination doesn't have key : " + position); return; } //step 1. 타일 생성 GameObject addTile = new GameObject("HexaTile_Normal"); addTile.transform.SetParent(this.gameObject.transform); //step 2. 기본 타일 컴포넌트 추가. HexaTileInfo cp = addTile.AddComponent <HexaTileInfo_Normal>(); cp.faceModel = GameObject.Instantiate(faceModelPrefabDic[555555]); cp.faceModel.transform.SetParent(addTile.transform); cp.bodyModel = GameObject.Instantiate(bodyModelPrefab); cp.bodyModel.transform.SetParent(addTile.transform); //step 3. 위치정보 설정 cp.tilePosition = position; cp.tileHeight = 5; //step 4. 이웃정보 추가 try { cp.neighborTile[0] = this.Cordination[position + new Vector2Int(0, 2)];//null이면 그냥 null이 들어가면 된다. cp.neighborTile[1] = this.Cordination[position + new Vector2Int(1, 1)]; cp.neighborTile[2] = this.Cordination[position + new Vector2Int(1, -1)]; cp.neighborTile[3] = this.Cordination[position + new Vector2Int(0, -2)]; cp.neighborTile[4] = this.Cordination[position + new Vector2Int(-1, -1)]; cp.neighborTile[5] = this.Cordination[position + new Vector2Int(-1, 1)]; } catch { Debug.LogError("HexaGridTileMap addTile, set neighborTiles Error"); GameObject.Destroy(addTile); return; } //step 5. 기타 필요한 참조 확보 및 정보 추가 cp.map = this; cp.type = TileType.Normal; //step 6. 좌표계에 등록 try { Cordination[position] = cp; } catch { Debug.LogError("HexaGridTileMap addTile, set Cordination Error"); GameObject.Destroy(addTile); return; } }
public void ImportCommonAttributes(HexaTileInfo source) { this.tilePosition = source.tilePosition; this.tileHeight = source.tileHeight; this.userImportTextureUsage = source.userImportTextureUsage; this.faceModel = source.faceModel; this.bodyModel = source.bodyModel; this.tileContents = source.tileContents; this.map = source.map; this.neighborTile = source.neighborTile; this.type = source.type; this.resource = source.resource; }
public static HexaTileInfo ExportCommonAttributes(HexaTileInfo source) { HexaTileInfo ret = new HexaTileInfo(); ret.tilePosition = source.tilePosition; ret.tileHeight = source.tileHeight; ret.userImportTextureUsage = source.userImportTextureUsage; ret.faceModel = source.faceModel; ret.bodyModel = source.bodyModel; ret.tileContents = source.tileContents; ret.map = source.map; ret.neighborTile = source.neighborTile; ret.type = source.type; ret.resource = source.resource; return(ret); }
public void ChangeTileType(Vector2Int position, TileType type) { if (!Cordination.ContainsKey(position)) { Debug.LogError("Cordination doesn't have key : " + position); return; } TileType beforeType = Cordination[position].type; if (beforeType == type) { Debug.Log("ChangeTileType report. type is same."); return; } if (beforeType == TileType.Suburbs) { Debug.LogError(L.T("Suburbs타입의 타일은 타입을 전환할 수 없습니다.")); return; } if (Cordination[position].tileHeight != 5 && type == TileType.City) { Debug.LogError(L.T("높이가 기본값(5)이 아닌 타일은 도시로 지정할 수 없습니다.")); return; } //타일 타입을 바꾸면, 공통속성(HexaTileInfo클래스의 속성)만 보존된다. //step 1. 기존 컴포넌트의 공통 속성값 복사 HexaTileInfo copiedCommonAttributes = HexaTileInfo.ExportCommonAttributes(Cordination[position]); //step 2. 해당 컴포넌트의 게임 오브젝트에 대한 임시 참조 확보 GameObject temp = Cordination[position].gameObject; //step 3. 해당 컴포넌트 제거 Destroy(temp.GetComponent <HexaTileInfo>()); //step 4. 컴포넌트 추가 HexaTileInfo cp = null; //City는 Normal로만 바꿀 수 있다. City 주위 6타일은 무조건 Suburbs기 때문에, City를 Normal로 바꾸면 인접 6개타일도 전부 Normal이 된다. switch (type) //Normal을 City로 바꾸려면 자기 인접 타일이 전부 Normal이어야 한다. 그리고 이들은 전부 Suburbs로 바뀐다. { case TileType.City: //Suburbs타입의 타일은 타입을 전환할 수 없다. cp = temp.AddComponent <HexaTileInfo_City>(); break; case TileType.Suburbs: cp = temp.AddComponent <HexaTileInfo_Suburbs>(); break; case TileType.Normal: cp = temp.AddComponent <HexaTileInfo_Normal>(); break; default: Debug.LogError("ChangeTileType Error. strange Tile type : " + type); break; } //step 5. 추가한 컴포넌트에 속성값 추가 if (cp != null) { cp.ImportCommonAttributes(copiedCommonAttributes); } else { Debug.LogError("ChangeTileType Error. change target component is null"); } }