Esempio n. 1
0
        public void Generate()
        {
            parentInfo = this.transform.parent.GetComponent<Building>();
            if (floor == null)
            {
                floor = new GameObject();
                floor.name = "Floor";
                floor.transform.parent = this.transform;
                floor.transform.localPosition = Vector3.zero;
                floor.transform.localScale = Vector3.one;
                floor.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
                floor.AddComponent<MeshFilter>();
                floor.AddComponent<MeshRenderer>();

                floorAddOns = new GameObject();
                floorAddOns.name = "FloorAddOns";
                floorAddOns.transform.parent = this.transform;
                floorAddOns.transform.localPosition = Vector3.zero;
                floorAddOns.transform.localScale = Vector3.one;
                floorAddOns.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
                floorAddOns.AddComponent<MeshFilter>();
                floorAddOns.AddComponent<MeshRenderer>();
                Material floorAddOnsMat = Resources.Load("AddOnsMat", typeof(Material)) as Material;
                floorAddOns.GetComponent<MeshRenderer>().material = floorAddOnsMat;

                this.floorNumber = (parentInfo.transform.childCount) - 1;
            }

            ComputeBalconies();

            //Floor parameter checksum
            var newChecksum = floorHeight + windowBoxWidth + windowHeight + windowWidth +
                            sideWinBoxWidth + sideWindowWidth + sideWindowHeight + separatorOffset + separatorHeight;// + sumBalcony;

            GenerateFloor(); // Update tree mesh

            if (newChecksum != checksum)
            {
                checksum = newChecksum;
                parentInfo.CreateBuilding(parentInfo.transform.position, 0f, 0);
            }
        }
Esempio n. 2
0
        public Vector3 CreateFloor(Vector3 position)
        {
            GenerateFloor();
            floor = this.transform.FindChild("Floor").gameObject;
            floorAddOns = this.transform.FindChild("FloorAddOns").gameObject;
            parentInfo = this.transform.parent.GetComponent<Building>();

            floor.GetComponent<MeshRenderer>().material = this.transform.parent.GetComponent<Building>().chosenMat;
            Vector3 point = position;

            MeshOps.CreateParall(point, parentInfo.width, this.floorHeight, parentInfo.depth, vertexList, triangleList, uvList);
            CreateWindows(point, position.y, this.floorNumber, parentInfo.width, parentInfo.depth);
            point = new Vector3(point.x, position.y + this.floorHeight, point.z);

            if (parentInfo.separatorList[this.floorNumber])
            {
                //create separator
                MeshOps.CreateParall(point, parentInfo.width + this.separatorOffset * 2, this.separatorHeight, parentInfo.depth + this.separatorOffset * 2, vertexList2, triangleList2, uvList2);
                point = new Vector3(position.x, point.y + this.separatorHeight, position.z);
            }
            if (this.floorNumber == this.transform.parent.GetComponent<Building>().floors - 1)
            {
                //CreateRoof if needed
                if (parentInfo.hasRoof)
                    CreateRoof(point);
            }

            SetAndClearFloorMesh();
            SetAndClearFloorAddOnsMesh();

            if (floor.GetComponent<BoxCollider>() != null)
                DestroyImmediate(floor.gameObject.GetComponent<BoxCollider>());
            if (floorAddOns.GetComponent<BoxCollider>() != null)
                DestroyImmediate(floorAddOns.gameObject.GetComponent<BoxCollider>());
            floor.AddComponent<BoxCollider>();
            floorAddOns.AddComponent<BoxCollider>();
            return point;
        }