Пример #1
0
        public override void OnInspectorGUI()
        {
            CSAdvertising bm = (CSAdvertising)target;

            GUILayout.Box(banner, GUILayout.ExpandWidth(true));



            if (GUILayout.Button("Update Template"))
            {
                bm.AwakeMe();
                bm.UpdateElements();
            }
            bm.useAdvertising = EditorGUILayout.Toggle("Use Advertising Panels", bm.useAdvertising);
            bm.lodDistance    = EditorGUILayout.Slider("Culling Distance", bm.lodDistance, 0f, 1f);
            bm.instancesX     = EditorGUILayout.IntField("Advertising density", bm.instancesX);
            bm.randomScaleMin = EditorGUILayout.FloatField("Scale Min", bm.randomScaleMin);
            bm.randomScaleMax = EditorGUILayout.FloatField("Scale Max", bm.randomScaleMax);
            bm.randomSeed     = EditorGUILayout.IntField("Random seed", bm.randomSeed);
            bm.greebleMat     = EditorGUILayout.ObjectField("Rooftop Material", bm.greebleMat, typeof(Material), true) as Material;

            GUILayout.BeginVertical();
            for (int i = 0; i < bm.rooftopElements.Length; i++)
            {
                bm.rooftopElements[i] = EditorGUILayout.ObjectField("" + i, bm.rooftopElements[i], typeof(GameObject), true) as GameObject;
            }
            GUILayout.BeginHorizontal("Box");
            if (GUILayout.Button("-", "Label", GUILayout.Width(20), GUILayout.Height(15)))
            {
                System.Array.Resize(ref bm.rooftopElements, bm.rooftopElements.Length - 1);
            }
            if (GUILayout.Button("+", "Label", GUILayout.Width(20), GUILayout.Height(15)))
            {
                System.Array.Resize(ref bm.rooftopElements, bm.rooftopElements.Length + 1);
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();



            if (GUI.changed)
            {
                bm.AwakeMe();
                bm.UpdateElements();
                EditorUtility.SetDirty(bm);
            }
        }
        public void UpdateAdvertisingCulling()
        {
            CSRandomizerComponent = gameObject.GetComponent <CityRandomizer>();
            csDetailsObject       = CSRandomizerComponent.buildings;
            foreach (Transform go in csDetailsObject.transform.Cast <Transform>().Reverse())
            {
                CSAdvertising rooftops = go.GetComponent(typeof(CSAdvertising)) as CSAdvertising;
                if (rooftops != null)
                {
                    rooftops.instancesX     = advertsDensity;
                    rooftops.lodDistance    = advertsCullingSize;
                    rooftops.useAdvertising = useRooftops;
                    rooftops.animateLodFade = true;
                    rooftops.DeleteSolution();
                    rooftops.UpdateElements();
                }
            }

            foreach (Transform go in csDetailsObject.transform.Cast <Transform>().Reverse())
            {
                BuildingModifier bm = go.GetComponent(typeof(BuildingModifier)) as BuildingModifier;
                if (bm != null)
                {
                    bm.useAdvertising = useRooftops;
                    //   bm.AwakeCity();
                    bm.UpdateCity();
                }
            }
        }
Пример #3
0
        void OnEnable()
        {
            CSAdvertising bm = (CSAdvertising)target;

            banner = Resources.Load("CSHeader") as Texture;
            bm.AwakeMe();
            bm.UpdateElements();
        }
Пример #4
0
        public void ModifyBuilding()
        {
            if (gameObject.activeInHierarchy)
            {
                if (gameObject.GetComponent <CSRooftops>() != null)
                {
                    hasRooftops = true;
                }
                else
                {
                    hasRooftops = false;
                }

                if (gameObject.GetComponent <CSAdvertising>() != null)
                {
                    hasAdvertising = true;
                }
                else
                {
                    hasAdvertising = false;
                }

                balcony = gameObject.GetComponent <CSArray>();
                if (balcony != null)
                {
                    hasBalcony             = true;
                    balcony.useAdvertising = useAdvertising;
                }
                else
                {
                    hasBalcony = false;
                }

                floorDetails = gameObject.GetComponent <CSFloorDetails>();
                if (floorDetails != null)
                {
                    hasFloorDetails = true;
                }
                else
                {
                    hasFloorDetails = false;
                }

                id1.x = CompressIDs(materialId1);
                id2.x = CompressIDs(materialId2);
                id3.x = CompressIDs(materialId3);
                id4.x = CompressIDs(materialId4);


                //originalVertices = meshOriginal.vertices;
                //originalColors = meshOriginal.colors;
                //originalUVs = meshOriginal.uv;
                transform.localScale = new Vector3(1, 1, 1);
                //mesh = GetComponent<MeshFilter>().mesh;
                Vector4[] vColorsFloat = new Vector4[mesh.uv.Length];
                Vector3[] vertices     = mesh.vertices;
                Vector2[] uV           = mesh.uv;
                vertexColor = mesh.colors32;

                Vector3[] transformVertices = mesh.vertices;
                Vector2[] transformUV       = mesh.uv;

                Vector3[] normals = mesh.normals;

                lightVec  = Mathf.FloorToInt(colorVariation.x) + Mathf.FloorToInt(colorVariation.y) * 0.1f + Mathf.FloorToInt(colorVariation.z) * 0.01f + Mathf.FloorToInt(colorVariation.w) * 0.001f + Mathf.FloorToInt(lightsOnOff) * 0.0001f + 0.00002f;
                lightVec2 = Mathf.FloorToInt(colorVariation2.x) + Mathf.FloorToInt(colorVariation2.y) * 0.1f + Mathf.FloorToInt(colorVariation2.z) * 0.01f + Mathf.FloorToInt(colorVariation2.w) * 0.001f + Mathf.FloorToInt(lightsOnOff2) * 0.0001f + 0.00002f;
                lightVec3 = Mathf.FloorToInt(colorVariation3.x) * 0.01f + Mathf.FloorToInt(colorVariation3.y) * 0.001f + lightnessFront * 0.0001f + 0.00002f;
                lightVec6 = Mathf.FloorToInt(colorVariation3.x) * 0.01f + Mathf.FloorToInt(colorVariation3.y) * 0.001f + lightnessFront * 0.0001f + 0.00002f;

                lightVec4 = Mathf.FloorToInt(windowOpen) + Mathf.FloorToInt(colorVariation4.x) * 0.1f + (materialId5) * 0.001f + borderCol * 0.0001f + 0.00002f;
                lightVec5 = Mathf.FloorToInt(windowOpen) + Mathf.FloorToInt(colorVariation4.x) * 0.1f + (0) * 0.001f + borderCol * 0.0001f + 0.00002f;

                lightVec7 = Mathf.FloorToInt(colorVariation5.x) * 0.01f + Mathf.FloorToInt(colorVariation5.y) * 0.001f + lightnessSide * 0.0001f + 0.00002f;
                lightVec8 = Mathf.FloorToInt(colorVariation5.x) * 0.01f + Mathf.FloorToInt(colorVariation5.y) * 0.001f + lightnessSide * 0.0001f + 0.00002f;


                //   Debug.Log(lightVec);
                int i = 0;
                while (i < vertices.Length)
                {
                    transformVertices[i] = new Vector3(0, 0, 0);
                    transformUV[i]       = new Vector2(0, 0);
                    vColors[i]           = new Vector4(id1.x + lightVec3, id1.y, lightVec2, lightVec) * 0.1f;
                    Vector3 invNormal = normals[i] * -1;

                    if (originalVertices[i].y > lowFloorBound.y)
                    {
                        if (floorNumber < prefabFloors)
                        {
                            floorNumber = prefabFloors;
                        }
                        transformVertices[i].y = (floorNumber - prefabFloors) * floorHeight;
                        transformUV[i].y       = floorNumber - prefabFloors;
                    }
                    ////
                    if (thresholdResizeY != 0 && (lowFloorBound.y - (thresholdResizeY / 2f)) < originalVertices[i].y && (lowFloorBound.y + (thresholdResizeY / 2f)) > originalVertices[i].y)
                    {
                        if (floorNumber < prefabFloors)
                        {
                            floorNumber = prefabFloors;
                        }
                        transformVertices[i].y = (floorNumber / 2 - prefabFloors / 2) * floorHeight;
                        transformUV[i].y       = floorNumber / 2 - prefabFloors / 2;
                    }

                    if (originalVertices[i].x > lowFloorBound.x)
                    {
                        if (buildingWidth < prefabWidth)
                        {
                            buildingWidth = prefabWidth;
                        }

                        transformVertices[i].x = (buildingWidth - prefabWidth) * floorHeight;


                        if (invNormal.z < 1 + normalThreshold && invNormal.z > 1 - normalThreshold)
                        {
                            transformUV[i].x = buildingWidth - prefabWidth;
                        }
                        if (normals[i].z < 1 + normalThreshold && normals[i].z > 1 - normalThreshold)
                        {
                            transformUV[i].x = -(buildingWidth - prefabWidth);
                        }
                    }
                    //New resize function
                    if (thresholdResizeX != 0 && (lowFloorBound.x + (thresholdResizeX / 2f)) > originalVertices[i].x && originalVertices[i].x > (lowFloorBound.x - (thresholdResizeX / 2f)))
                    {
                        if (buildingWidth < prefabWidth)
                        {
                            buildingWidth = prefabWidth;
                        }

                        transformVertices[i].x = (buildingWidth / 2 - prefabWidth / 2) * floorHeight;


                        if (invNormal.z < 1 + normalThreshold && invNormal.z > 1 - normalThreshold)
                        {
                            transformUV[i].x = buildingWidth / 2 - prefabWidth / 2;
                        }
                        if (normals[i].z < 1 + normalThreshold && normals[i].z > 1 - normalThreshold)
                        {
                            transformUV[i].x = -(buildingWidth / 2 - prefabWidth / 2);
                        }
                    }


                    if (originalVertices[i].z > lowFloorBound.z)
                    {
                        if (buildingDepth < prefabDepth)
                        {
                            buildingDepth = prefabDepth;
                        }
                        transformVertices[i].z = (buildingDepth - prefabDepth) * floorHeight;

                        if (normals[i].x < 1 + normalThreshold && normals[i].x > 1 - normalThreshold)
                        {
                            transformUV[i].x = (buildingDepth - prefabDepth);
                        }
                        if (invNormal.x < 1 + normalThreshold && invNormal.x > 1 - normalThreshold)
                        {
                            transformUV[i].x = -(buildingDepth - prefabDepth);
                        }
                    }

                    if (thresholdResizeZ != 0 && (lowFloorBound.z + (thresholdResizeZ / 2f)) > originalVertices[i].z && originalVertices[i].z > (lowFloorBound.z - (thresholdResizeZ / 2f)))
                    {
                        if (buildingDepth < prefabDepth)
                        {
                            buildingDepth = prefabDepth;
                        }
                        transformVertices[i].z = (buildingDepth / 2 - prefabDepth / 2) * floorHeight;

                        if (normals[i].x < 1 + normalThreshold && normals[i].x > 1 - normalThreshold)
                        {
                            transformUV[i].x = (buildingDepth / 2 - prefabDepth / 2);
                        }
                        if (invNormal.x < 1 + normalThreshold && invNormal.x > 1 - normalThreshold)
                        {
                            transformUV[i].x = -(buildingDepth / 2 - prefabDepth / 2);
                        }
                    }
                    ////Extend foundations for supporting tererain

                    if (extendFoundations != 0f)
                    {
                        if (originalVertices[i].y <= extFoundationsTreshhold)
                        {
                            transformVertices[i].y = transformVertices[i].y - extendFoundations;
                            transformUV[i].y       = transformUV[i].y - extendFoundations / 3;
                        }
                    }


                    if (useSlantedRoofsResize)
                    {
                        if (originalVertices[i].y >= slantedRoofsVal.y)
                        {
                            if (slantedRoofsVal.w != 0)
                            {
                                transformVertices[i].y = transformVertices[i].y + (buildingDepth - 1) * slantedRoofsVal.w;
                            }
                            if (slantedRoofsVal.z != 0)
                            {
                                transformVertices[i].y = transformVertices[i].y + (buildingWidth - 1) * slantedRoofsVal.z;
                            }
                            //                          transformUV[i].y = transformUV[i].y - extendFoundations / 3;
                        }
                    }

                    ///////// manipulate Vertex colors



                    if (prefabHasVertexInfo)
                    {
                        if (originalColors[i].r < 0.2f)
                        {
                            if (invNormal.z < 1 + normalThreshold && invNormal.z > 1 - normalThreshold)
                            {
                                vColors[i] = new Vector4(id2.x + lightVec3, lightVec4, lightVec2, lightVec) * 0.1f;
                            }
                            if (normals[i].z < 1 + normalThreshold && normals[i].z > 1 - normalThreshold)
                            {
                                vColors[i] = new Vector4(id2.x + lightVec6, lightVec4, lightVec2, lightVec) * 0.1f;
                            }
                            if (normals[i].x < 1 + normalThreshold && normals[i].x > 1 - normalThreshold)
                            {
                                vColors[i] = new Vector4(id3.x + lightVec7, lightVec4, lightVec2, lightVec) * 0.1f;
                            }
                            if (invNormal.x < 1 + normalThreshold && invNormal.x > 1 - normalThreshold)
                            {
                                vColors[i] = new Vector4(id3.x + lightVec8, lightVec4, lightVec2, lightVec) * 0.1f;
                            }
                        }
                        else
                        {
                            vColors[i] = new Vector4(id1.x + lightVec3, lightVec5, lightVec2, lightVec) * 0.1f;
                        }
                    }
                    else
                    {
                        if (invNormal.z < 1 + normalThreshold && invNormal.z > 1 - normalThreshold)
                        {
                            vColors[i] = new Vector4(id2.x + lightVec3, lightVec4, lightVec2, lightVec) * 0.1f;
                        }
                        if (normals[i].z < 1 + normalThreshold && normals[i].z > 1 - normalThreshold)
                        {
                            vColors[i] = new Vector4(id2.x + lightVec6, lightVec4, lightVec2, lightVec) * 0.1f;
                        }
                        if (normals[i].x < 1 + normalThreshold && normals[i].x > 1 - normalThreshold)
                        {
                            vColors[i] = new Vector4(id3.x + lightVec7, lightVec4, lightVec2, lightVec) * 0.1f;
                        }

                        if (invNormal.x < 1 + normalThreshold && invNormal.x > 1 - normalThreshold)
                        {
                            vColors[i] = new Vector4(id3.x + lightVec8, lightVec4, lightVec2, lightVec) * 0.1f;
                        }
                    }
                    //     Debug.Log((id2.x + lightVec3) * 0.1f);

                    vertices[i] = Vector3.Scale(originalVertices[i] + transformVertices[i], new Vector3(1, scale, 1));



                    uV[i] = new Vector2(originalUVs[i].x, originalUVs[i].y) + transformUV[i] + new Vector2(uniqueMapping, 0);



                    if (normals[i].y > 0.9 || normals[i].y < -0.9)
                    {
                        uV[i].x    = vertices[i].x * 0.5f;
                        uV[i].y    = vertices[i].z * 0.5f + 10;
                        vColors[i] = new Vector4(id4.x + lightVec3, lightVec4, lightVec2, lightVec) * 0.1f;
                    }


                    if (autoMap)
                    {
                        if (invNormal.z < 1 + normalThreshold && invNormal.z > 1 - normalThreshold)
                        {
                            uV[i] = new Vector2(vertices[i].x / floorHeight + uniqueMapping, (vertices[i].y / (floorHeight * scale * Mathf.Abs(1 - Mathf.Sin(normals[i].y)))));
                        }

                        if (normals[i].z < 1 + normalThreshold && normals[i].z > 1 - normalThreshold)
                        {
                            uV[i] = new Vector2(vertices[i].x / -floorHeight + uniqueMapping, (vertices[i].y / (floorHeight * scale * Mathf.Abs(1 - Mathf.Sin(normals[i].y)))));
                        }

                        if (normals[i].x < 1 + normalThreshold && normals[i].x > 1 - normalThreshold)
                        {
                            uV[i] = new Vector2(vertices[i].z / floorHeight + uniqueMapping, (vertices[i].y / (floorHeight * scale * Mathf.Abs(1 - Mathf.Sin(normals[i].y)))));
                        }

                        if (invNormal.x < 1 + normalThreshold && invNormal.x > 1 - normalThreshold)
                        {
                            uV[i] = new Vector2(vertices[i].z / -floorHeight + uniqueMapping, (vertices[i].y / (floorHeight * scale * Mathf.Abs(1 - Mathf.Sin(normals[i].y)))));
                        }
                    }

                    if (supportSkewing)
                    {
                        vertices[i] = new Vector3(vertices[i].x + (1 / Mathf.Tan(Mathf.Deg2Rad * ((skew - 90))) * vertices[i].z), vertices[i].y, vertices[i].z);
                    }
                    vColorsFloat[i] = vColors[i];



                    if (prefabHasVertexInfo)
                    {
                        float boolValue = 0;
                        if (customBool2)
                        {
                            boolValue = 0.1f;
                        }

                        if (useGraffiti && vertices[i].y < floorNumber * 3 - 1)
                        {
                            //graffiti written into channel A
                            //Rooftop Value into channel B
                            vertexColor[i] = new Color(vertexColor[i].r, vertexColor[i].g, rooftopID * 0.01f + boolValue, 255);
                        }
                        else
                        {
                            vertexColor[i] = new Color(vertexColor[i].r, 255, rooftopID * 0.01f + boolValue, 0);
                        }
                    }
                    if (hasNoFloorLevel)
                    {
                        uV[i] = new Vector2(uV[i].x, uV[i].y + 2);
                    }

                    i++;
                }



                var list = new List <Vector4>(vColors);

                //if (supportSkewing)
                //{
                //    i = 0;
                //    while (i < vertices.Length)
                //    {
                //        vertices[i] = new Vector3(vertices[i].x + (skew * vertices[i].z), vertices[i].y, vertices[i].z);
                //        i++;
                //    }
                //}

                mesh.vertices = vertices;
                mesh.uv       = uV;
                mesh.SetUVs(3, list);
                mesh.colors32     = vertexColor;
                vertices          = null;
                uV                = null;
                list              = null;
                vertexColor       = null;
                transformVertices = null;
                transformUV       = null;
                //originalVertices = null;
                //originalColors = null;
                //originalUVs = null;


                mesh.RecalculateNormals();
                mesh.RecalculateTangents();

                mesh.RecalculateBounds();
                MeshCollider mColl = gameObject.GetComponent <MeshCollider>();
                if (!gameObject.GetComponent <MeshCollider>())
                {
                    mColl = gameObject.AddComponent <MeshCollider>();
                }
                mColl.convex     = false;
                mColl.sharedMesh = mesh;



                if (hasRooftops)
                {
                    rooftops.UpdateElements();
                }
                if (hasAdvertising)
                {
                    //advertising.Awake();
                    advertising.UpdateElements();
                }

                if (hasBalcony)
                {
                    balcony.UpdateElements();
                }
                if (hasFloorDetails)
                {
                    floorDetails.UpdateElements();
                }
            }
        }