/** * 計算簷柱位置 */ public List <Vector3> CalculateColumnPos(List <Vector3> posList, EntraneIndexList entranceIndexList, int bayNumber) { List <Vector3> newPosList = new List <Vector3>(); for (int i = 0; i < posList.Count; i++) { Vector3 columnPos = posList[i]; newPosList.Add(columnPos); if (!entranceIndexList.Contains(i)) { //eaveBayColumn int nextIndex = (i + 1) % posList.Count; Vector3 posNext = posList[nextIndex]; float disBetweenColumn = Vector3.Distance(columnPos, posNext); float bayWidth = disBetweenColumn / bayNumber; Vector3 bayDir = posNext - columnPos; for (int j = 1; j < bayNumber; j++) { Vector3 bayColumnPos = bayDir.normalized * (j * bayWidth) + columnPos; newPosList.Add(bayColumnPos); } } } return(newPosList); }
/** * 建造整欄杆 */ public void CreateRingBalustrade(GameObject parentObj, int sides, EntraneIndexList entraneIndexList, EaveColumnModelStruct eaveColumnModelStruct, List <Vector3> columnList, float columnRadius, float heightOffset) { float balustradeWidth = eaveColumnModelStruct.balustradeModelStruct.bound.size.x; //欄杆長度 float balustradeHeight = eaveColumnModelStruct.balustradeModelStruct.bound.size.y; //欄杆長度 float balustradeLengh = eaveColumnModelStruct.balustradeModelStruct.bound.size.z; //欄杆深度 for (int i = 0; i < columnList.Count; i++) { float width = balustradeWidth; float dis = Vector3.Distance(columnList[i], columnList[(i + 1) % columnList.Count]) - columnRadius * 2; int number = Mathf.Max(Mathf.FloorToInt(dis / width), 1); Vector3 dir = columnList[(i + 1) % columnList.Count] - columnList[i]; float disDiff = (dis - width * number) / number; width = dis / number; float rotateAngle = (Vector3.Dot(Vector3.forward, dir) < 0 ? Vector3.Angle(dir, Vector3.right) : -Vector3.Angle(dir, Vector3.right)); for (int j = 0; j < number; j++) { Vector3 pos = dir.normalized * (width / 2.0f + j * width + columnRadius) + columnList[i] + heightOffset * Vector3.up; GameObject clone = Instantiate(eaveColumnModelStruct.balustradeModelStruct.model, pos, eaveColumnModelStruct.balustradeModelStruct.model.transform.rotation) as GameObject; clone.transform.rotation = Quaternion.AngleAxis(rotateAngle, Vector3.up) * Quaternion.Euler(eaveColumnModelStruct.balustradeModelStruct.rotation); clone.transform.GetChild(0).localScale = new Vector3(clone.transform.GetChild(0).localScale.x, clone.transform.GetChild(0).localScale.y, (clone.transform.GetChild(0).localScale.z) * (width) / balustradeWidth); clone.transform.parent = parentObj.transform; balusObjList.Add(clone); } } }
private void CreateBody(GameObject parentObj, int sides, EntraneIndexList entraneIndexList, float bodyWidth, float bodyLength, float bodyHeight, Vector3 bodyCenter) { Debug.Log("CreateBody"); eaveCornerColumnList.Clear(); goldCornerColumnList.Clear(); goldColumnList.Clear(); eaveColumnList.Clear(); List <Vector3> eaveColumnPosList; List <Vector3> goldColumnPosList; eaveColumnPosList = CalculateColumnPos(bodyLength, bodyWidth, bodyHeight, eaveColumnbayNumber, bodyCenter); goldColumnPosList = CalculateColumnPos(bodyLength * 0.9f, bodyWidth * 0.9f, bodyHeight, goldColumnbayNumber, bodyCenter); eaveColumnList = CreateRingColumn(parentObj, eaveColumnPosList, eaveColumnRadius, eaveColumnRadius, eaveColumnHeight, eaveColumnRadius * 1.2f, columnFundationHeight, "EaveColumn"); if (isGoldColumn) { goldColumnList = CreateRingColumn(parentObj, goldColumnPosList, goldColumnRadius, goldColumnRadius, goldColumnHeight, goldColumnRadius * 1.2f, columnFundationHeight, "GoldColumn"); } //角柱計算 if (eaveColumnbayNumber <= 0) { eaveColumnbayNumber = 1; } for (int i = 0, count = 0; i < sides; i++) { eaveCornerColumnList.Add(eaveColumnList[count]); if (entraneIndexList.Contains(i)) { count++; } else { count += eaveColumnbayNumber; } } if (isGoldColumn) { if (goldColumnbayNumber <= 0) { goldColumnbayNumber = 1; } for (int i = 0, count = 0; i < sides; i++) { goldCornerColumnList.Add(goldColumnList[count]); count += goldColumnbayNumber; } } }
private void CreateBody(GameObject parentObj, int sides, EntraneIndexList entranceIndexList, List <Vector3> eaveCornerColumnPosList, List <Vector3> goldCornerColumnPosList) { Debug.Log("CreateBody"); eaveCornerColumnList.Clear(); goldCornerColumnList.Clear(); goldColumnList.Clear(); eaveColumnList.Clear(); //CreateBody List <Vector3> eaveColumnPosList = CalculateColumnPos(eaveCornerColumnPosList, entranceIndexList, eaveColumnbayNumber); List <Vector3> goldColumnPosList = CalculateColumnPos(goldCornerColumnPosList, entranceIndexList, goldColumnbayNumber); eaveColumnPosList = MainController.Instance.Vector3ListAddVector3(eaveColumnPosList, Vector3.up * eaveColumnHeight / 2.0f); goldColumnPosList = MainController.Instance.Vector3ListAddVector3(goldColumnPosList, Vector3.up * goldColumnHeight / 2.0f); eaveColumnList = CreateRingColumn(parentObj, eaveColumnPosList, eaveColumnRadius, eaveColumnRadius, eaveColumnHeight, eaveColumnRadius * 1.2f, columnFundationHeight, "TingEaveCol"); goldColumnList = CreateRingColumn(parentObj, goldColumnPosList, goldColumnRadius, goldColumnRadius, goldColumnHeight, goldColumnRadius * 1.2f, columnFundationHeight, "TingGoldCol"); //建築牆面 CreateRingWall(parentObj, ModelController.Instance.goldColumnModelStruct, GetColumnStructBottomPosList(goldColumnList), goldColumnRadius, unitNumberInBay, goldColumnbayNumber, doorNumber); //建立欄杆 CreateRingBalustrade(parentObj, (int)sides, entranceIndexList, ModelController.Instance.eaveColumnModelStruct, GetColumnStructBottomPosList(eaveColumnList), eaveColumnRadius, 0.1f * eaveColumnHeight); //建立楣子 CreateRingFrieze(parentObj, ModelController.Instance.eaveColumnModelStruct, GetColumnStructBottomPosList(eaveColumnList), eaveColumnRadius, 0.7f * eaveColumnHeight); //角柱計算 for (int i = 0; i < eaveColumnList.Count; i++) { foreach (Vector3 pos in eaveCornerColumnPosList) { if (eaveColumnList[i].bottomPos == pos) { eaveCornerColumnList.Add(eaveColumnList[i]); } } } if (isGoldColumn) { for (int i = 0; i < goldColumnList.Count; i++) { foreach (Vector3 pos in goldCornerColumnPosList) { if (goldColumnList[i].bottomPos == pos) { goldCornerColumnList.Add(goldColumnList[i]); } } } } }
/** * 初始化基座 */ public void InitFunction(BuildingObj buildingObj, float platformFrontWidth, float platformFrontLength, float platformHeight, bool isStair, float rotateAngle = 0) { this.buildingObj = buildingObj; this.platWidth = platformFrontWidth; this.platLength = platformFrontLength; this.platHeight = platformHeight; this.isStair = isStair; stairHeight = platformHeight; this.parentObj = buildingObj.platform; this.sides = (int)buildingObj.sides; this.entraneIndexList = buildingObj.entraneIndexList; //*********************************************************************** platFormStruct = CreatePlatform(buildingObj.platform, (int)buildingObj.sides, buildingObj.platformCenter, rotateAngle); StartCreateBorder(isBorder); StartCreateStair(isStair); }