Пример #1
0
    void setNumberOfStreets()
    {
        StreetCreation street_creation = (StreetCreation)target as StreetCreation;

        //read the file so i know how many buildings are


        number_of_streets = street_creation.getNumberOfStreets();
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        StreetCreation street_creation = (StreetCreation)target as StreetCreation;

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        EditorGUILayout.PrefixLabel("Reads Road");
        street_creation.readRoads = EditorGUILayout.Toggle(street_creation.readRoads);

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        EditorGUILayout.PrefixLabel("Generate All Roads");
        street_creation.generateAllRoads = EditorGUILayout.Toggle(street_creation.generateAllRoads);

        EditorGUILayout.EndHorizontal();


        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        Rect startButton = EditorGUILayout.BeginHorizontal();

        startButton.x      = startButton.width / 2 - 100;
        startButton.width  = 200;
        startButton.height = 18;



        if (GUI.Button(startButton, "Create Streets"))
        {
            //street_creation.createBuilding();

            GUIUtility.ExitGUI();
        }



        if (GUI.changed)
        {
            EditorUtility.SetDirty(street_creation);
        }
    }
Пример #3
0
    public void createBuilding()
    {
        /* parser.xmlParser();
         * XMLParser.FileToCreate[] type_of_file = new XMLParser.FileToCreate[2];
         * type_of_file[0] = XMLParser.FileToCreate.Buildings;
         * type_of_file[1] = XMLParser.FileToCreate.Streets;
         * parser.deleteAllFiles();
         * parser.createFile(type_of_file);*/



        lsystem = this.gameObject.AddComponent <LSystem>();

        //    Debug.Log(f);
        //LSystem lsystem = new LSystem();
        //foreach(float f in data[3][3])
        lsystem.init();

        for (int i = 0; i < (generateAllBuildings ? data.Count : buildingsToGenerate); i++)
        {
            if (data[i].Count <= 2)
            {
                continue;
            }
            Vector3[]  vertices = new Vector3[data[i].Count - 1];
            GameObject building = new GameObject();
            building.name = "Building_" + i;
            // building.AddComponent("CollisionDetection");
            //@Michele: add for reference in a simple way all the buildings in case of collision
            //building.tag = "Building";
            building.transform.parent = this.gameObject.transform;
            int   j = 0;
            int   height = 0;
            float minX = Mathf.Infinity, maxX = -Mathf.Infinity, minZ = Mathf.Infinity, maxZ = -Mathf.Infinity;
            foreach (double[] dArray in data[i])
            {
                if (j < data[i].Count - 1)
                { // Ignore last node, since it's equal to the first
                    //vertices[j].x = (float)dArray[0] * scalingFactor;
                    //vertices[j].z = (float)dArray[1] * scalingFactor;
                    vertices[j].x = (float)(dArray[0] * Terrain.activeTerrain.terrainData.size.x); // / (Terrain.activeTerrain.terrainData.size.x)) * (Terrain.activeTerrain.terrainData.heightmapResolution);
                    vertices[j].z = (float)(dArray[1] * Terrain.activeTerrain.terrainData.size.z); // / (Terrain.activeTerrain.terrainData.size.z)) * (Terrain.activeTerrain.terrainData.heightmapResolution);
                    if (vertices[j].x < minX)
                    {
                        minX = vertices[j].x;
                    }
                    if (vertices[j].x > maxX)
                    {
                        maxX = vertices[j].x;
                    }
                    if (vertices[j].z < minZ)
                    {
                        minZ = vertices[j].z;
                    }
                    if (vertices[j].z > maxZ)
                    {
                        maxZ = vertices[j].z;
                    }

                    //Debug.Log("x: " + vertices[j].x + "   z; " + vertices[j].z);
                    if (dArray[2] != 0)
                    {
                        height = (int)dArray[2];
                    }
                    j++;
                }
            }
            Vector3 offset = new Vector3(minX + ((maxX - minX) / 2), 0, minZ + ((maxZ - minZ) / 2));
            for (j = 0; j < vertices.Length; j++)
            {
                vertices[j] -= offset;
            }
            float randHeight = lsystem.randHeight();
            building.AddComponent <BoxCollider>();
            building.GetComponent <BoxCollider>().center = new Vector3(0, randHeight / 2, 0);
            building.GetComponent <BoxCollider>().size   = new Vector3(maxX - minX, randHeight, maxZ - minZ);

            if (height == 0)
            {
                lsystem.visualize(building /*this.gameObject*/, vertices, offset, randHeight);
            }
            //   else
            //      lsystem.visualize(building, vertices, height);

            /*if (i % 100 == 0 && i > 0)
             *  Debug.Log("Buildings created: " + i);*/


            StreetCreation street = this.gameObject.AddComponent <StreetCreation>();
            street.getData();
        }
    }
Пример #4
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        StreetCreation street_creation = (StreetCreation)target as StreetCreation;


        if (street_creation.emptyDictionary())
        {
            setNumberOfStreets();
            street_creation.getData();
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        EditorGUILayout.PrefixLabel("Reads Road");
        street_creation.readRoads = EditorGUILayout.Toggle(street_creation.readRoads);

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        EditorGUILayout.PrefixLabel("Generate All Roads");
        street_creation.generateAllRoads = EditorGUILayout.Toggle(street_creation.generateAllRoads);

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        street_creation.roadsToGenerate = EditorGUILayout.IntSlider("Generate Amount Of Roads", street_creation.roadsToGenerate, 1, number_of_streets);

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();



        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        EditorGUILayout.PrefixLabel("Car Prefab");
        street_creation.car = (GameObject)EditorGUILayout.ObjectField(street_creation.car, typeof(GameObject));

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        EditorGUILayout.PrefixLabel("Checkpoint Prefab");
        street_creation.checkpoint = (GameObject)EditorGUILayout.ObjectField(street_creation.checkpoint, typeof(GameObject));

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        EditorGUILayout.PrefixLabel("Car Mesh");
        street_creation.carHelper = (GameObject)EditorGUILayout.ObjectField(street_creation.carHelper, typeof(GameObject));

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();


        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        Rect startButton = EditorGUILayout.BeginHorizontal();

        startButton.x      = startButton.width / 2 - 100;
        startButton.width  = 200;
        startButton.height = 18;

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();


        if (GUI.Button(startButton, "Create Streets"))
        {
            //street_creation.createStreets() ;

            //GUIUtility.ExitGUI();
        }



        if (GUI.changed)
        {
            EditorUtility.SetDirty(street_creation);
        }
    }
Пример #5
0
    public void OnSceneGUI()
    {
        StreetCreation street_creation = (StreetCreation)target as StreetCreation;

        Event currentEvent = Event.current;

        if (street_creation.emptyDictionary())
        {
            street_creation.getData();
        }

        if (currentEvent.type == EventType.KeyUp && currentEvent.keyCode == KeyCode.R)
        {
            ray = Camera.current.ScreenPointToRay(new Vector2(currentEvent.mousePosition.x, Screen.height - (currentEvent.mousePosition.y + 25)));
            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log("After Physics Raycast");
                Debug.Log("hit.point:" + hit.point);
                if (!endSelect)
                {
                    street_creation.path_finder.startNode = street_creation.path_finder.nearestNode(hit.point);
                    // startNode.getGameObject().renderer.material.color = Color.green;
                    Debug.Log("START NODE COORDINATES: " + street_creation.path_finder.startNode.getPosition());
                    endSelect = true;
                }
                else
                {
                    street_creation.path_finder.endNode = street_creation.path_finder.nearestNode(hit.point);
                    //   endNode.getGameObject().renderer.material.color = Color.green;
                    Debug.Log("GOAL NODE COORDINATES: " + street_creation.path_finder.endNode.getPosition());
                    waitForAStar = true;
                    ArrayList bestPath = street_creation.path_finder.FindPath();
                    endSelect = false;
                }
            }
        }
        else if (currentEvent.type == EventType.KeyDown && currentEvent.keyCode == KeyCode.D)
        {
            ray = Camera.current.ScreenPointToRay(new Vector2(currentEvent.mousePosition.x, Screen.height - (currentEvent.mousePosition.y + 25)));
            if (Physics.Raycast(ray, out hit))
            {
                if (!checkpointPlacement)
                {
                    checkpointPlacement = true;
                    checkpoint          = (GameObject)Instantiate(street_creation.path_finder.checkpoint, hit.point /* + new Vector3(0,2,0)*/, Quaternion.identity);
                }
                else
                {
                    checkpointPlacement = false;
                    Debug.Log("Checkpoint PLACED on track!");
                }
            }
        }
        else if (currentEvent.type == EventType.KeyDown && currentEvent.keyCode == KeyCode.C)
        {
            ray = Camera.current.ScreenPointToRay(new Vector2(currentEvent.mousePosition.x, Screen.height - (currentEvent.mousePosition.y + 25)));
            if (Physics.Raycast(ray, out hit))
            {
                if (!carPlacement)
                {
                    carPlacement = true;
                    car          = (GameObject)Instantiate(street_creation.path_finder.carHelper, hit.point, Quaternion.identity);
                }
                else
                {
                    carPlacement = false;
                    Instantiate(street_creation.path_finder.car, car.transform.position + new Vector3(0, 5, 0), car.transform.rotation).name = "car";
                    DestroyImmediate(car);
                    GameObject[] planes = GameObject.FindGameObjectsWithTag("plane");
                    if (planes != null && planes.Length > 0)
                    {
                        foreach (GameObject plane in planes)
                        {
                            DestroyImmediate(plane);
                        }
                    }
                    EditorApplication.isPlaying = true;
                    Debug.Log("Car PLACED on track!");
                }
            }
        }
        else if (currentEvent.type == EventType.MouseUp && currentEvent.button == 1)
        {
            if (checkpointPlacement && checkpoint != null)
            {
                Debug.Log("Should destroy checkpoint!");
                DestroyImmediate(checkpoint);
                checkpointPlacement = false;
            }
            else if (carPlacement && car != null)
            {
                Debug.Log("Should destroy car!");
                DestroyImmediate(car);
                carPlacement = false;
            }
        }
        else if (currentEvent.type == EventType.MouseMove)
        {
            if (checkpointPlacement)
            {
                if (!currentEvent.shift)
                {
                    ray = Camera.current.ScreenPointToRay(new Vector2(currentEvent.mousePosition.x, Screen.height - (currentEvent.mousePosition.y + 25)));
                    if (Physics.Raycast(ray, out hit))
                    {
                        checkpoint.transform.position = hit.point;
                    }
                }
                else
                {
                    checkpoint.transform.RotateAround(Vector3.up, currentEvent.delta.x / 20f);
                }
            }
            else if (carPlacement)
            {
                if (!currentEvent.shift)
                {
                    ray = Camera.current.ScreenPointToRay(new Vector2(currentEvent.mousePosition.x, Screen.height - (currentEvent.mousePosition.y + 25)));
                    if (Physics.Raycast(ray, out hit))
                    {
                        car.transform.position = hit.point;
                    }
                }
                else
                {
                    car.transform.RotateAround(Vector3.up, currentEvent.delta.x / 20f);
                }
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(street_creation);
        }
    }