コード例 #1
0
        //   float range = 30;


        void OnEnable()
        {
            BuildingModifier bm = (BuildingModifier)target;

            bm.AwakeCity();
            bm.UpdateCity();
            banner = Resources.Load("CSHeader") as Texture;
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            BuildingModifier bm = (BuildingModifier)target;


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

            GUILayout.BeginVertical("box");
            GUILayout.Label("Facade Shape");
            bm.colorVariation4.x = EditorGUILayout.IntSlider("Floor Level Shape", Mathf.FloorToInt(bm.colorVariation4.x), 0, 9);
            //  bm.materialId1 = EditorGUILayout.IntSlider("Material ID 1", bm.materialId1, 20, 29);
            bm.materialId2 = EditorGUILayout.IntSlider("Front Faccade Shape", bm.materialId2, 0, 19);
            bm.materialId3 = EditorGUILayout.IntSlider("Lateral Faccade Shape", bm.materialId3, 0, 19);
            //  bm.materialId4 = EditorGUILayout.IntSlider("Material ID 4", bm.materialId4, 30, 39);
            bm.materialId5 = EditorGUILayout.IntSlider("Subdivision Shape", bm.materialId5, 0, 22);

            bm.colorVariation2.y = EditorGUILayout.Slider("Height Subdivision", (bm.colorVariation2.y), 0f, 9f);
            bm.colorVariation2.z = EditorGUILayout.Slider("Width Subdivision", (bm.colorVariation2.z), 0f, 9f);
            GUILayout.EndHorizontal();
            //configure Prefab



            GUILayout.BeginVertical("box");
            GUILayout.Label("Material Styling");

            // bm.pattern = EditorGUILayout.Slider("Floor Pattern", bm.pattern, 0f, 0.9f);
            bm.colorVariation3.x = EditorGUILayout.Slider("Faccade Mat 1 front/back", bm.colorVariation3.x, 0f, 9f);
            bm.colorVariation3.y = EditorGUILayout.Slider("Faccade Mat 2 front/back", bm.colorVariation3.y, 0f, 9f);
            bm.colorVariation5.x = EditorGUILayout.Slider("Faccade Mat 1 Lateral", bm.colorVariation5.x, 0f, 9f);
            bm.colorVariation5.y = EditorGUILayout.Slider("Faccade Mat 2 Lateral", bm.colorVariation5.y, 0f, 9f);
            bm.rooftopID         = EditorGUILayout.IntSlider("Rooftop Mat", bm.rooftopID, 0, 9);
            bm.colorVariation.z  = EditorGUILayout.Slider("Building floor Colors", (bm.colorVariation.z), 0f, 9f);
            //  bm.customData1 = EditorGUILayout.IntSlider("NotImplemented", bm.customData1, 0, 9);
            bm.customBool2    = EditorGUILayout.Toggle("Blinds in front of Window", bm.customBool2);
            bm.lightnessFront = EditorGUILayout.IntSlider("Lightness front/back", (bm.lightnessFront), 0, 9);
            bm.lightnessSide  = EditorGUILayout.IntSlider("Lightness Sides", (bm.lightnessSide), 0, 9);
            bm.borderCol      = EditorGUILayout.IntSlider("Window Border Col", (bm.borderCol), 0, 9);


            bm.colorVariation2.x = EditorGUILayout.Slider("Window Gloss", bm.colorVariation2.x, 0f, 9f);
            bm.windowOpen        = EditorGUILayout.Slider("Window Lights", bm.windowOpen, 0f, 9f);

            bm.colorVariation2.w = EditorGUILayout.Slider("Blinds open", (bm.colorVariation2.w), 0f, 9f);

            bm.lightsOnOff2 = EditorGUILayout.Slider("Shop Signs Density", (bm.lightsOnOff2), 0f, 9f);
            bm.useGraffiti  = EditorGUILayout.Toggle("Use Graffiti", bm.useGraffiti);



            bm.colorVariation.x = EditorGUILayout.Slider("Faccade Lights Height", bm.colorVariation.x, 0f, 9f);
            bm.lightsOnOff      = EditorGUILayout.Slider("Faccade Lights Tiling", (bm.lightsOnOff), 0f, 9f);
            bm.colorVariation.y = EditorGUILayout.Slider("Lights R", (bm.colorVariation.y), 0f, 9f);

            bm.colorVariation.w = EditorGUILayout.Slider("Lights B", (bm.colorVariation.w), 0f, 9f);


            bm.uniqueMapping = EditorGUILayout.IntField("Unique Mapping", bm.uniqueMapping);
            bm.floorNumber   = EditorGUILayout.IntField("Floor Number", bm.floorNumber);
            bm.buildingDepth = EditorGUILayout.IntField("Building depth", bm.buildingDepth);
            bm.buildingWidth = EditorGUILayout.IntField("Building Width", bm.buildingWidth);
            //   bm.distortXZ = EditorGUILayout.FloatField("Building Width", bm.distortXZ);
            bm.useAdvertising = EditorGUILayout.Toggle("Use Advertising Panels", bm.useAdvertising);
            bm.supportSkewing = EditorGUILayout.Toggle("Support Skewing", bm.supportSkewing);
            if (bm.supportSkewing)
            {
                bm.skew = EditorGUILayout.FloatField("Skew Amount", bm.skew);
            }
            bm.scale                   = EditorGUILayout.FloatField("Scale Floors", bm.scale);
            bm.extendFoundations       = EditorGUILayout.FloatField("Extend Foundations", bm.extendFoundations);
            bm.extFoundationsTreshhold = EditorGUILayout.FloatField("Extend Foundations Threshold", bm.extFoundationsTreshhold);
            bm.useSlantedRoofsResize   = EditorGUILayout.Toggle("Use slanted Roofs", bm.useSlantedRoofsResize);
            bm.slantedRoofsVal         = EditorGUILayout.Vector4Field("Slanted roof val", bm.slantedRoofsVal);
            bm.hasNoFloorLevel         = EditorGUILayout.Toggle("building has no floor level", bm.hasNoFloorLevel);

            //if (GUILayout.Button("Generate Lightmapping UV"))
            //{
            //    bm.GenerateLightmaps();
            //}
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            //if (GUILayout.Button("Split Building X"))
            //{
            //    SplitX();

            //}
            //if (GUILayout.Button("Split Building Z"))
            //{
            //    SplitZ();

            //}

            if (GUILayout.Button("Randomize Materials"))
            {
                bm.colorVariation.x = Random.Range(0, 9);

                bm.colorVariation2.x = Random.Range(0, 9);
                bm.colorVariation2.y = Random.Range(0, 9);
                bm.colorVariation2.z = Random.Range(0, 9);
                bm.colorVariation2.w = Random.Range(2, 9);

                bm.colorVariation3.x = Random.Range(0, 9);
                bm.colorVariation3.y = Random.Range(0, 9);
                bm.colorVariation3.z = Random.Range(0, 9);
                bm.colorVariation3.w = Random.Range(0, 9);

                bm.colorVariation4.x = Random.Range(0, 9);
                bm.colorVariation4.y = Random.Range(0, 9);
                bm.colorVariation4.z = Random.Range(0, 9);
                bm.colorVariation4.w = Random.Range(0, 9);
                bm.lightnessFront    = Random.Range(0, 9);
                bm.lightnessSide     = Random.Range(0, 9);
                bm.colorVariation5.x = Random.Range(0, 9);
                bm.colorVariation5.y = Random.Range(0, 9);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical("box");
            configurePrefab = EditorGUILayout.Foldout(configurePrefab, "Template Configuration");
            if (configurePrefab)
            {
                bm.meshOriginal = EditorGUILayout.ObjectField("Mesh Template", bm.meshOriginal, typeof(Mesh), true) as Mesh;
                if (GUILayout.Button("Update Mesh Template"))
                {
                    bm.AwakeCity();
                    bm.UpdateCity();
                }
                if (GUILayout.Button("Guess building size"))
                {
                    bm.GuessPrefabSize();
                    bm.AwakeCity();
                    bm.UpdateCity();
                }
                bm.scaleFrom1to3         = EditorGUILayout.Toggle("Model unit is one CScape Unit", bm.scaleFrom1to3);
                bm.lowFloorBound         = EditorGUILayout.Vector3Field("Resizer Center", bm.lowFloorBound);
                bm.thresholdResizeX      = EditorGUILayout.FloatField("Threshold X", bm.thresholdResizeX);
                bm.thresholdResizeY      = EditorGUILayout.FloatField("Threshold Y", bm.thresholdResizeY);
                bm.thresholdResizeZ      = EditorGUILayout.FloatField("Threshold Z", bm.thresholdResizeZ);
                bm.prefabFloors          = EditorGUILayout.IntField("Prefab floor number", bm.prefabFloors);
                bm.prefabWidth           = EditorGUILayout.IntField("Prefab width", bm.prefabWidth);
                bm.prefabDepth           = EditorGUILayout.IntField("Prefab depth", bm.prefabDepth);
                bm.normalThreshold       = EditorGUILayout.Slider("Normal threshold", bm.normalThreshold, 0f, 0.9f);
                bm.floorHeight           = EditorGUILayout.FloatField("Floor Height", bm.floorHeight);
                bm.advertisingPanelCoord = EditorGUILayout.Vector3Field("Advert Panel Zone", bm.advertisingPanelCoord);

                bm.prefabHasVertexInfo = EditorGUILayout.Toggle("Prefab has vertex Info", bm.prefabHasVertexInfo);
                bm.autoMap             = EditorGUILayout.Toggle("Use Auto Map UV", bm.autoMap);
                bm.useFloorLimiting    = EditorGUILayout.Toggle("Use Floor Limiting", bm.useFloorLimiting);
                if (bm.useFloorLimiting)
                {
                    bm.minFloorNumber = EditorGUILayout.IntField("Min floor number", bm.minFloorNumber);
                    bm.maxFloorNumber = EditorGUILayout.IntField("Min floor number", bm.maxFloorNumber);
                }



                ///Rooftops Array
                GUILayout.BeginVertical("Box");
                for (int i = 0; i < bm.roofOffsetY.Length; i++)
                {
                    bm.roofOffsetX[i] = EditorGUILayout.Vector2Field("Roof Elements X", bm.roofOffsetX[i]);
                    bm.roofOffsetZ[i] = EditorGUILayout.Vector2Field("Roof Elements Z", bm.roofOffsetZ[i]);
                    bm.roofOffsetY[i] = EditorGUILayout.FloatField("Roof Height", bm.roofOffsetY[i]);
                }



                GUILayout.BeginHorizontal("Box");
                if (GUILayout.Button("-", "Label", GUILayout.Width(20), GUILayout.Height(15)))
                {
                    System.Array.Resize(ref bm.roofOffsetX, bm.roofOffsetX.Length - 1);
                    System.Array.Resize(ref bm.roofOffsetY, bm.roofOffsetY.Length - 1);
                    System.Array.Resize(ref bm.roofOffsetZ, bm.roofOffsetZ.Length - 1);
                }
                if (GUILayout.Button("+", "Label", GUILayout.Width(20), GUILayout.Height(15)))
                {
                    System.Array.Resize(ref bm.roofOffsetX, bm.roofOffsetX.Length + 1);
                    System.Array.Resize(ref bm.roofOffsetY, bm.roofOffsetY.Length + 1);
                    System.Array.Resize(ref bm.roofOffsetZ, bm.roofOffsetZ.Length + 1);
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
                /////Advertising Panels layout
                GUILayout.BeginVertical("Box");
                for (int i = 0; i < bm.advertOffsetY.Length; i++)
                {
                    bm.advertOffsetX[i] = EditorGUILayout.Vector2Field("Roof Elements X", bm.advertOffsetX[i]);
                    bm.advertOffsetZ[i] = EditorGUILayout.Vector2Field("Roof Elements Z", bm.advertOffsetZ[i]);
                    bm.advertOffsetY[i] = EditorGUILayout.FloatField("Roof Height", bm.advertOffsetY[i]);
                }



                GUILayout.BeginHorizontal("Box");
                if (GUILayout.Button("-", "Label", GUILayout.Width(20), GUILayout.Height(15)))
                {
                    System.Array.Resize(ref bm.advertOffsetX, bm.advertOffsetX.Length - 1);
                    System.Array.Resize(ref bm.advertOffsetY, bm.advertOffsetY.Length - 1);
                    System.Array.Resize(ref bm.advertOffsetZ, bm.advertOffsetZ.Length - 1);
                }
                if (GUILayout.Button("+", "Label", GUILayout.Width(20), GUILayout.Height(15)))
                {
                    System.Array.Resize(ref bm.advertOffsetX, bm.advertOffsetX.Length + 1);
                    System.Array.Resize(ref bm.advertOffsetY, bm.advertOffsetY.Length + 1);
                    System.Array.Resize(ref bm.advertOffsetZ, bm.advertOffsetZ.Length + 1);
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
            }
            GUILayout.EndVertical();


            if (GUI.changed)
            {
                bm.UpdateCity();
                EditorUtility.SetDirty(bm);
#if UNITY_5_4_OR_NEWER
                EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
#endif
            }
        }
コード例 #3
0
        void Update()
        {
            CityRandomizer cityRandomizer = gameObject.GetComponent <CityRandomizer>();

            if (execute)
            {
                foreach (Transform go in rootHolder.transform.Cast <Transform>().Reverse())
                {
                    GuessWorldRotation(go.gameObject);
                    // we have to reset reference object rotation to be able to calculate real bounding box, here we are storing a real rotation
                    Quaternion oldTransform = go.rotation;

                    //reseting rotation
                    go.eulerAngles = new Vector3(go.eulerAngles.x, 0, go.eulerAngles.z);

                    //calculate bounding box and apporximate building size in CScape building units
                    Vector3 center            = go.gameObject.GetComponent <Renderer>().bounds.center;
                    Vector3 bounds            = go.gameObject.GetComponent <Renderer>().bounds.extents;
                    Vector3 CScapeCoordinates = new Vector3(center.x - bounds.x, center.y - bounds.y, center.z - bounds.z);
                    int     depth             = Mathf.FloorToInt((bounds.z * 2f) / 3f);
                    int     width             = Mathf.FloorToInt((bounds.x * 2f) / 3f);
                    int     height            = Mathf.FloorToInt((bounds.y * 2f) / 3f);



                    //take random building objects from a CityRandomizer array of buildings ad choose only those that can fit reference buildings
                    GameObject prefabToInstantiate = null;
                    int        iterations          = districtStyle.prefabs.Length;
                    bool       validate            = false;
                    int        prefabChoice        = Random.Range(0, districtStyle.prefabs.Length);

                    while (validate == false)
                    {
                        prefabToInstantiate = districtStyle.prefabs[prefabChoice];
                        //                      BuildingModifier buildingToInstantiate = prefabToInstantiate.GetComponent<BuildingModifier>();
                        if (prefabToInstantiate.GetComponent <BuildingModifier>().prefabDepth <= depth && prefabToInstantiate.GetComponent <BuildingModifier>().prefabDepth <= depth)
                        {
                            validate = true;
                        }
                        else
                        {
                            prefabChoice++;
                        }

                        if (iterations > districtStyle.prefabs.Length)
                        {
                            prefabToInstantiate = districtStyle.prefabs[0];
                            validate            = true;
                        }

                        iterations++;
                    }

                    //Generate building
                    GameObject cloneH = Instantiate(prefabToInstantiate, CScapeCoordinates, transform.rotation) as GameObject;
                    //parent to reference building
                    cloneH.transform.parent = go.transform;
                    //restore original object rotation
                    go.rotation = oldTransform;
                    //unparent from reference building, and parent to Cscape city
                    cloneH.transform.parent = cityRandomizer.buildings.transform;
                    BuildingModifier buildingModifier = cloneH.GetComponent(typeof(BuildingModifier)) as BuildingModifier;
                    buildingModifier.buildingDepth = depth;
                    buildingModifier.buildingWidth = width;
                    buildingModifier.floorNumber   = height;

                    buildingModifier.AwakeCity();
                    buildingModifier.UpdateCity();
                }


                execute = false;
            }
        }