Beispiel #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 CreateRingFrieze(GameObject parentObj, EaveColumnModelStruct eaveColumnModelStruct, List <Vector3> columnList, float columnRadius, float heightOffset)
    {
        float friezeWidth  = eaveColumnModelStruct.friezeModelStruct.bound.size.x;       //裝飾物長度
        float friezeHeight = eaveColumnModelStruct.friezeModelStruct.bound.size.y;       //裝飾物長度
        float friezeLengh  = eaveColumnModelStruct.friezeModelStruct.bound.size.z;       //裝飾物深度

        for (int i = 0; i < columnList.Count; i++)
        {
            float   width   = friezeWidth;
            float   height  = friezeHeight;
            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.friezeModelStruct.model, pos, eaveColumnModelStruct.friezeModelStruct.model.transform.rotation) as GameObject;
                clone.transform.rotation = Quaternion.AngleAxis(rotateAngle, Vector3.up) * Quaternion.Euler(eaveColumnModelStruct.friezeModelStruct.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) / friezeWidth);

                clone.transform.parent = parentObj.transform;
                friezeObjList.Add(clone);
            }

            //FriezeWall(frieze上方裝飾牆)
            GameObject   friezeWall   = new GameObject("FriezeWall");
            MeshFilter   meshFilter   = friezeWall.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = friezeWall.AddComponent <MeshRenderer>();
            friezeWall.transform.parent = parentObj.transform;
            meshRenderer.material.color = Color.yellow;
            float   rotateAngleZ     = (Vector3.Dot(Vector3.forward, dir) < 0 ? Vector3.Angle(dir, Vector3.right) :  -Vector3.Angle(dir, Vector3.right));
            float   friezeWallHeight = (eaveColumnHeight - heightOffset - friezeHeight / 2.0f);
            Vector3 posZ             = (columnList[i] + columnList[(i + 1) % columnList.Count]) / 2.0f + (heightOffset + friezeHeight / 2.0f + friezeWallHeight / 2.0f) * Vector3.up;
            MeshCenter.Instance.CreateCubeMesh(posZ, dis, friezeWallHeight, 0.5f, rotateAngleZ, meshFilter);
            friezeObjList.Add(friezeWall);


            //sparrowBrace雀替
            Vector3    posX         = dir.normalized * (columnRadius) + columnList[i] + (heightOffset - friezeHeight / 2.0f) * Vector3.up;
            float      rotateAngleX = (Vector3.Dot(Vector3.forward, dir) < 0 ? Vector3.Angle(dir, Vector3.right) : -Vector3.Angle(dir, Vector3.right));
            GameObject sparrowBrace = Instantiate(eaveColumnModelStruct.sparrowBraceModelStruct.model, posX, eaveColumnModelStruct.sparrowBraceModelStruct.model.transform.rotation) as GameObject;
            sparrowBrace.transform.rotation = Quaternion.AngleAxis(rotateAngleX, Vector3.up) * Quaternion.Euler(eaveColumnModelStruct.sparrowBraceModelStruct.rotation);

            sparrowBrace.transform.parent = parentObj.transform;
            friezeObjList.Add(sparrowBrace);

            posX         = -dir.normalized * (columnRadius) + columnList[(i + 1) % columnList.Count] + (heightOffset - friezeHeight / 2.0f) * Vector3.up;
            rotateAngleX = (Vector3.Dot(Vector3.forward, -dir) < 0 ? Vector3.Angle(-dir, Vector3.right) : -Vector3.Angle(-dir, Vector3.right));
            sparrowBrace = Instantiate(eaveColumnModelStruct.sparrowBraceModelStruct.model, posX, eaveColumnModelStruct.sparrowBraceModelStruct.model.transform.rotation) as GameObject;
            sparrowBrace.transform.rotation = Quaternion.AngleAxis(rotateAngleX, Vector3.up) * Quaternion.Euler(eaveColumnModelStruct.sparrowBraceModelStruct.rotation);

            sparrowBrace.transform.parent = parentObj.transform;
            friezeObjList.Add(sparrowBrace);
        }
    }
        /**
         * 建造整欄杆
         */
        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);
                }
            }
        }