Exemple #1
0
    void OnGUI()
    {
        GUILayout.Space(10);


        GUILayout.Label("Fantastic City Generator", EditorStyles.boldLabel);



        EditorGUILayout.BeginHorizontal();

        //cityGenerator = EditorGUILayout.ObjectField(cityGenerator, typeof(CityGenerator), true) as CityGenerator ;
        if (!cityGenerator)
        {
            cityGenerator = AssetDatabase.LoadAssetAtPath("Assets/Fantastic City Generator/Generate.prefab", (typeof(CityGenerator))) as CityGenerator;
        }

        LoadAssets();


        EditorGUILayout.EndHorizontal();



        GUILayout.Space(5);

        GUILayout.BeginVertical("box");


        GUILayout.Space(5);
        GUILayout.Label(new GUIContent("Generate Streets", "Make City"));

        GUILayout.Space(5);


        GUILayout.BeginHorizontal("box");

        if (GUILayout.Button("Small"))
        {
            GenerateCity(1);
        }


        if (GUILayout.Button("Medium"))
        {
            GenerateCity(2);
        }

        if (GUILayout.Button("Large"))
        {
            GenerateCity(3);
        }

        if (GUILayout.Button("Very Large"))
        {
            GenerateCity(4);
        }


        GUILayout.Space(5);


        GUILayout.EndHorizontal();



        GUILayout.EndVertical();

        GUILayout.Space(10);



        GUILayout.BeginVertical("box");

        GUILayout.Space(5);

        GUILayout.Label(new GUIContent("Buildings", "Make or Clear Buildings"));

        GUILayout.Space(5);

        GUILayout.BeginHorizontal("box");


        GUILayout.Space(5);

        if (GUILayout.Button("Generate Buildings"))
        {
            if (!GameObject.Find("Marcador"))
            {
                return;
            }
            cityGenerator.GenerateAllBuildings();
        }


        if (GUILayout.Button("Clear Buildings"))
        {
            if (!GameObject.Find("Marcador"))
            {
                return;
            }
            cityGenerator.DestroyBuildings();
        }



        GUILayout.EndHorizontal();



        GUILayout.EndVertical();



        GUILayout.Space(10);



        GUILayout.BeginVertical("box");

        GUILayout.Space(5);

        GUILayout.Label(new GUIContent("Traffic System", "Make or Clear Traffic System"));

        GUILayout.Space(5);


        GUILayout.BeginHorizontal("box");


        GUILayout.Space(5);

        if (GUILayout.Button("Add Traffic System"))
        {
            if (EditorApplication.isPlaying)
            {
                Debug.Log("Not allowed in play mode");
                return;
            }

            AddVehicles(intenseTraffic);
        }



        //intense traffic

        if (GUILayout.Button("Remove Traffic System"))
        {
            DestroyImmediate(GameObject.Find("CarContainer"));
        }



        GUILayout.EndHorizontal();

        intenseTraffic = GUILayout.Toggle(intenseTraffic, "Intense Traffic", GUILayout.Width(240));



        GameObject rm = GameObject.Find("Road-Mark-Rev");

        if (rm)
        {
            GUILayout.Space(10);

            if (GUILayout.Button("Inverse Car Direction"))
            {
                if (EditorApplication.isPlaying)
                {
                    Debug.Log("Not allowed in play mode");
                }
                else
                {
                    bool je = GameObject.Find("CarContainer");

                    if (je)
                    {
                        DestroyImmediate(GameObject.Find("CarContainer"));
                    }

                    InverseCarDirection(GameObject.Find("RoadMarkRev"));
                    if (je)
                    {
                        AddVehicles(intenseTraffic);
                    }
                }
            }
            GUILayout.Space(5);
        }

        GUILayout.EndVertical();



        GUILayout.Space(10);


        GUILayout.BeginVertical("box");


        if (GUILayout.Button("Combine Meshes"))
        {
            if (!GameObject.Find("Marcador"))
            {
                return;
            }

            float        vertexCount = 0;
            float        tt;
            GameObject   module;
            GameObject[] my_Modules;



            my_Modules = GameObject.FindObjectsOfType(typeof(GameObject)).Select(g => g as GameObject).Where(g => g.name == "Marcador").ToArray();

            tt = my_Modules.Length;

            vertexCount = 0;

            for (int i = 0; i < tt; i++)
            {
                //Debug.Log("i: " + i );

                vertexCount = 0;


                module = my_Modules[i];

                GameObject newBlock = new GameObject("_block");
                newBlock.transform.position = module.transform.position;
                newBlock.transform.rotation = module.transform.rotation;
                newBlock.transform.parent   = module.transform.parent;


                foreach (Transform child in module.transform)
                {      // E1, E2, 100
                    Component[] temp = child.GetComponentsInChildren(typeof(MeshFilter));

                    foreach (MeshFilter currentChild in temp)
                    {
                        vertexCount += currentChild.sharedMesh.vertexCount;
                        if (vertexCount > 50000)
                        {
                            vertexCount = 0;
                            newBlock    = new GameObject("_block");
                            newBlock.transform.position = module.transform.position;
                            newBlock.transform.rotation = module.transform.rotation;
                            newBlock.transform.parent   = module.transform.parent;
                        }

                        if (currentChild.gameObject.name.Contains("(Clone)"))
                        {
                            currentChild.gameObject.transform.parent = newBlock.transform;
                        }
                    }
                }

                DestroyImmediate(my_Modules[i].gameObject);
            }



            GameObject[] myModules = GameObject.FindObjectsOfType(typeof(GameObject)).Select(g => g as GameObject).Where(g => g.name == "_block").ToArray();


            tt = myModules.Length;



            for (int i = 0; i < tt; i++)
            {
                float f = i / tt;

                EditorUtility.DisplayProgressBar("Combining meshes", "Please wait", f);

                module = myModules[i];

                GameObject newObjects = new GameObject("Combined meshes");
                newObjects.transform.parent        = module.transform.parent;
                newObjects.transform.localPosition = Vector3.zero;
                newObjects.transform.localRotation = Quaternion.identity;


                CombineMeshes(module.gameObject, newObjects, i);
            }

            EditorUtility.ClearProgressBar();
        }

        generateLightmapUVs = GUILayout.Toggle(generateLightmapUVs, "Generate Lightmap UVs", GUILayout.Width(240));

        GUILayout.EndVertical();
    }