Ejemplo n.º 1
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);
    }
    /**
     * 建造整圈牆(columnList為bottom位置)
     */
    public void CreateRingWall(GameObject parentObj, GoldColumnModelStruct goldColumnModelStruct, List <Vector3> columnList, float columnRadius, int unit, int goldColumnbayNumber, int doorNumber)
    {
        float wallHeight = goldColumnHeight;                                       //牆長度
        float wallLengh  = columnRadius * 2.0f;                                    //牆深度

        float windowWidth  = goldColumnModelStruct.windowModelStruct.bound.size.x; //裝飾物長度
        float windowHeight = goldColumnModelStruct.windowModelStruct.bound.size.y; //裝飾物長度
        float windowLengh  = goldColumnModelStruct.windowModelStruct.bound.size.z; //裝飾物深度


        float doorWidth  = goldColumnModelStruct.doorModelStruct.bound.size.x;       //裝飾物長度
        float doorHeight = goldColumnModelStruct.doorModelStruct.bound.size.y;       //裝飾物長度
        float doorLengh  = goldColumnModelStruct.doorModelStruct.bound.size.z;       //裝飾物深度


        float windowWallWidth  = goldColumnModelStruct.windowWallModelStruct.bound.size.x;       //裝飾物長度
        float windowWallHeight = goldColumnModelStruct.windowWallModelStruct.bound.size.y;       //裝飾物長度
        float windowWallLengh  = goldColumnModelStruct.windowWallModelStruct.bound.size.z;       //裝飾物深度

        float doorMidIndex = ((float)goldColumnbayNumber / 2);

        doorNumber = Mathf.Clamp(doorNumber, 0, Mathf.CeilToInt(doorMidIndex));
        int doorMaxIndex = (int)((goldColumnbayNumber % 2 == 1) ? (doorMidIndex + (doorNumber - 1)) : (doorMidIndex + (doorNumber - 1) + 0.5f));
        int doorMinIndex = (int)((goldColumnbayNumber % 2 == 1) ? (doorMidIndex - (doorNumber - 1)) : (doorMidIndex - (doorNumber - 1) - 0.5f));

        for (int i = 0; i < columnList.Count; i++)
        {
            float dis = Vector3.Distance(columnList[i], columnList[(i + 1) % columnList.Count]) - columnRadius * 2;

            Vector3 dir = columnList[(i + 1) % columnList.Count] - columnList[i];
            //門
            if (((i % (goldColumnbayNumber)) <= doorMaxIndex) && (i % (goldColumnbayNumber) >= doorMinIndex))
            {
                float width = dis;
                for (int j = 0; j < 1; j++)
                {
                    float   rotateAngle     = (Vector3.Dot(Vector3.forward, dir) < 0 ? Vector3.Angle(dir, Vector3.right) : -Vector3.Angle(dir, Vector3.right));
                    Vector3 pos             = dir.normalized * (width / 2.0f + j * width + columnRadius) + columnList[i] + goldColumnHeight / 2.0f * Vector3.up;
                    float   disDiff         = doorWidth - width;
                    float   doorWidthScale  = (width) / (doorWidth);
                    float   doorHeightScale = wallHeight / (doorHeight);
                    //door
                    GameObject clone = Instantiate(goldColumnModelStruct.doorModelStruct.model, pos, goldColumnModelStruct.doorModelStruct.model.transform.rotation) as GameObject;
                    clone.transform.rotation = Quaternion.AngleAxis(rotateAngle, Vector3.up) * Quaternion.Euler(goldColumnModelStruct.doorModelStruct.rotation);
                    clone.transform.GetChild(0).localScale = new Vector3(clone.transform.GetChild(0).localScale.x *doorWidthScale, clone.transform.GetChild(0).localScale.y *doorHeightScale, (clone.transform.GetChild(0).localScale.z));
                    clone.transform.parent = parentObj.transform;
                    doorObjList.Add(clone);
                }
            }
            else            //窗
            {
                float width = dis / unit;
                for (int j = 0; j < unit; j++)
                {
                    #region windowWall
                    float   rotateAngle           = (Vector3.Dot(Vector3.forward, dir) < 0 ? Vector3.Angle(dir, Vector3.right) : -Vector3.Angle(dir, Vector3.right));
                    Vector3 pos                   = dir.normalized * (width / 2.0f + j * width + columnRadius) + columnList[i] + goldColumnHeight / 2.0f * Vector3.up;
                    float   disDiff               = windowWallWidth - width;
                    float   windowWallWidthScale  = (width) / (windowWallWidth);
                    float   windowWallHeightScale = wallHeight / (windowWallHeight);
                    //windowWall
                    GameObject clone = Instantiate(goldColumnModelStruct.windowWallModelStruct.model, pos, goldColumnModelStruct.windowWallModelStruct.model.transform.rotation) as GameObject;
                    clone.transform.rotation = Quaternion.AngleAxis(rotateAngle, Vector3.up) * Quaternion.Euler(goldColumnModelStruct.windowWallModelStruct.rotation);
                    clone.transform.GetChild(0).localScale = new Vector3(clone.transform.GetChild(0).localScale.x *windowWallWidthScale, clone.transform.GetChild(0).localScale.y *windowWallHeightScale, (clone.transform.GetChild(0).localScale.z));

                    clone.transform.parent = parentObj.transform;
                    windowObjList.Add(clone);
                    #endregion
                }
            }
        }
    }