/**
     * 製作基座欄杆
     */
    private List <GameObject> CreateRingBorderColumn(BorderModelStruct borderModelStruct, GameObject parentObj, List <Vector3> posList)
    {
        float borderColumnWidth  = borderModelStruct.fenceModelStruct.bound.size.x;       //欄杆柱子長度
        float borderColumnHeight = borderModelStruct.fenceModelStruct.bound.size.y;       //欄杆柱子長度
        float borderColumnLengh  = borderModelStruct.fenceModelStruct.bound.size.z;       //欄杆柱子深度

        List <GameObject> borderColumnList = new List <GameObject>();

        for (int i = 0; i < posList.Count; i++)
        {
            Vector3 dir         = posList[(i + 1) % posList.Count] - posList[i];
            Vector3 dirFormer   = posList[i] - posList[(i - 1 + posList.Count) % posList.Count];
            float   dis         = Vector3.Distance(posList[i], posList[(i + 1) % posList.Count]);
            float   width       = dis / (Mathf.Max(borderColumnNumber - 1, 1));
            float   rotateAngle = (Vector3.Dot(Vector3.right, dir) > 0 ? Vector3.Angle(dir, Vector3.forward) : (180 - Vector3.Angle(dir, Vector3.forward)));
            for (int j = 0; j < Mathf.Max(borderColumnNumber - 1, 1); j++)
            {
                //borderColumn
                Vector3    pos   = posList[i] + borderColumnHeight / 2.0f * Vector3.up + dir.normalized * (j * width) - dirFormer.normalized * (borderColumnLengh / 2.0f) + ((j == 0) ? (borderColumnWidth / 2.0f * dir.normalized) : Vector3.zero);
                GameObject clone = Instantiate(borderModelStruct.fenceModelStruct.model, pos, borderModelStruct.fenceModelStruct.model.transform.rotation) as GameObject;
                clone.transform.rotation = Quaternion.AngleAxis(rotateAngle, Vector3.up) * Quaternion.Euler(borderModelStruct.fenceModelStruct.rotation);

                clone.transform.parent = parentObj.transform;

                borderColumnList.Add(clone);
            }
        }
        return(borderColumnList);
    }
Exemple #2
0
    void Awake()
    {
        //*** Border ***
        fenceModelStruct     = new ModelStruct(fenceModel, fenceModelRotation, fenceModelScale);
        fenceWallModelStruct = new ModelStruct(fenceWallModel, fenceWallModelRotation, fenceWallModelScale);
        borderModelStruct    = new BorderModelStruct(fenceModelStruct, fenceWallModelStruct);

        //*** 欄杆 ***
        friezeModelStruct       = new ModelStruct(friezeModel, friezeModelRotation, friezeModelScale);
        balustradeModelStruct   = new ModelStruct(balustradeModel, balustradeModelRotation, balustradeModelScale);
        sparrowBraceModelStruct = new ModelStruct(sparrowBraceModel, sparrowBraceModelRotation, sparrowBraceModelScale);
        eaveColumnModelStruct   = new EaveColumnModelStruct(friezeModelStruct, balustradeModelStruct, sparrowBraceModelStruct);

        windowModelStruct     = new ModelStruct(windowModel, windowModelRotation, windowModelScale);
        doorModelStruct       = new ModelStruct(doorModel, doorModelRotation, doorModelScale);
        windowWallModelStruct = new ModelStruct(windowWallModel, windowWallModelRotation, windowWallModelScale);
        goldColumnModelStruct = new GoldColumnModelStruct(windowModelStruct, doorModelStruct, windowWallModelStruct);

        //*** 瓦片結構 : 設定好筒瓦、平瓦、簷瓦模組與個別的旋轉與尺寸向量
        roundTileModelStruct    = new ModelStruct(roundTileModel, roundTileModelRotation, roundTileModelScale);
        flatTileModelStruct     = new ModelStruct(flatTileModel, flatTileModelRotation, flatTileModelScale);
        eaveTileModelStruct     = new ModelStruct(eaveTileModel, eaveTileModelRotation, eaveTileModelScale);
        flyingRafterModelStruct = new ModelStruct(flyingRafterModel, flyingRafterModelRotation, flyingRafterModelScale);
        roofSurfaceModelStruct  = new RoofSurfaceModelStruct(roundTileModelStruct, flatTileModelStruct, eaveTileModelStruct, flyingRafterModelStruct);

        //*** 主瘠結構 : 設定好主脊模組跟旋轉、尺寸向量
        mainRidgeTileModelStruct = new ModelStruct(mainRidgeTileModel, mainRidgeTileModelRotation, mainRidgeTileModelScale);
        mainRidgeModelStruct     = new MainRidgeModelStruct(mainRidgeTileModelStruct);
    }
    private List <GameObject> CreateRingBorderWall(BorderModelStruct borderModelStruct, GameObject parentObj, List <Vector3> columnList)
    {
        float borderWallWidth  = borderModelStruct.fenceWallModelStruct.bound.size.x;     //欄杆柱子長度
        float borderWallHeight = borderModelStruct.fenceWallModelStruct.bound.size.y;     //欄杆柱子長度
        float borderWallLengh  = borderModelStruct.fenceWallModelStruct.bound.size.z;     //欄杆柱子深度

        float borderColumnWidth  = borderModelStruct.fenceModelStruct.bound.size.x;       //欄杆柱子長度
        float borderColumnHeight = borderModelStruct.fenceModelStruct.bound.size.y;       //欄杆柱子長度
        float borderColumnLengh  = borderModelStruct.fenceModelStruct.bound.size.z;       //欄杆柱子深度

        List <GameObject> borderWallList = new List <GameObject>();

        for (int i = 0; i < columnList.Count; i++)
        {
            if (i % (borderColumnNumber - 1) == ((int)(borderColumnNumber - 1) / 2) && entraneIndexList.Contains(i / (borderColumnNumber - 1)))
            {
                continue;
            }
            float   width   = borderWallWidth;
            float   dis     = Vector3.Distance(columnList[i], columnList[(i + 1) % columnList.Count]) - borderColumnWidth / 2.0f - borderColumnLengh / 2.0f;
            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   = columnList[i] + dir.normalized * (width / 2.0f + j * width + borderColumnWidth / 2.0f) - (borderColumnHeight / 2.0f - borderWallHeight / 2.0f) * Vector3.up;
                GameObject clone = Instantiate(borderModelStruct.fenceWallModelStruct.model, pos, borderModelStruct.fenceWallModelStruct.model.transform.rotation) as GameObject;
                clone.transform.rotation = Quaternion.AngleAxis(rotateAngle, Vector3.up) * Quaternion.Euler(borderModelStruct.fenceWallModelStruct.rotation);
                clone.transform.GetChild(0).localScale = new Vector3(clone.transform.GetChild(0).localScale.x *(width) / borderWallWidth, clone.transform.GetChild(0).localScale.y, (clone.transform.GetChild(0).localScale.z));
                clone.transform.parent = parentObj.transform;
                borderWallList.Add(clone);
            }
        }
        return(borderWallList);
    }