Пример #1
0
    void Render(floorplan script, GameObject tile, Material mat)
    {
        GameObject gO = new GameObject("Walls");

        gO.transform.parent = GameObject.Find("New Floorplan Geometry").transform;
        Vector3 topLeft    = new Vector3(Mathf.Max(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Max(mouseStart.z, mouseEnd.z));
        Vector3 bottomLeft = new Vector3(Mathf.Min(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Min(mouseStart.z, mouseEnd.z));

        for (int x = 0; x < Mathf.Abs(width); x += (int)script.tileSize)
        {
            GameObject wall = script.createInstance(tile, (topLeft - new Vector3(x + script.tileSize, 0, 0)), Quaternion.LookRotation(Vector3.right, Vector3.up));
            wall.GetComponent <Renderer>().material = mat;
            wall.transform.parent.parent            = gO.transform;

            wall = script.createInstance(tile, (bottomLeft - new Vector3(-x, 0, 0)), Quaternion.LookRotation(Vector3.right, Vector3.up));
            wall.GetComponent <Renderer>().material = mat;
            wall.transform.parent.parent            = gO.transform;
        }
        for (int z = 0; z < Mathf.Abs(height); z += (int)script.tileSize)
        {
            GameObject wall = script.createInstance(tile, (topLeft - new Vector3(0, 0, z + script.tileSize)), Quaternion.identity);
            wall.GetComponent <Renderer>().material = mat;
            wall.transform.parent.parent            = gO.transform;

            wall = script.createInstance(tile, (bottomLeft - new Vector3(0, 0, -z)), Quaternion.identity);
            wall.GetComponent <Renderer>().material = mat;
            wall.transform.parent.parent            = gO.transform;
        }
        Undo.RegisterCreatedObjectUndo(gO, "Undo wall creation");
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        floorplan script = (floorplan)target;

        if (GUILayout.Button("Spawn Pillar"))
        {
            script.createInstance(script.tileset.pillarTile, script.gameObject.transform.position, Quaternion.identity);
        }
        if (GUILayout.Button("Spawn Floor Tile"))
        {
            script.createInstance(script.tileset.floorTile, script.gameObject.transform.position, Quaternion.LookRotation(Vector3.right, Vector3.up));
        }
    }
Пример #3
0
    public void Render(GameObject tile, floorplan script, Material[] mats)
    {
        GameObject gO = new GameObject("Floor");

        gO.transform.parent = script.geometry.transform;
        Vector3 topLeft = new Vector3(Mathf.Max(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Max(mouseStart.z, mouseEnd.z));

        for (int y = 0; y < Mathf.Abs(height); y += (int)script.tileSize)
        {
            for (int x = 0; x < Mathf.Abs(width); x += (int)script.tileSize)
            {
                GameObject floor = script.createInstance(tile, (topLeft - new Vector3(x, 0, y + script.tileSize)), Quaternion.identity);
                floor.GetComponent <Renderer>().materials = mats;
                floor.transform.parent.parent             = gO.transform;
            }
        }
        Undo.RegisterCreatedObjectUndo(gO, "Undo floor creation");
    }
Пример #4
0
    void Render(floorplan script, GameObject tile, Material[] mats)
    {
        GameObject pillar = script.getTilesFromType(TileTypes.Pillar)[0];
        GameObject gO     = new GameObject("Walls");

        gO.transform.parent = script.geometry.transform;
        Vector3 topLeft    = new Vector3(Mathf.Max(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Max(mouseStart.z, mouseEnd.z));
        Vector3 bottomLeft = new Vector3(Mathf.Min(mouseStart.x, mouseEnd.x), mouseStart.y, Mathf.Min(mouseStart.z, mouseEnd.z));

        for (int x = 0; x < Mathf.Abs(width); x += (int)script.tileSize)
        {
            Vector3 offset  = topLeft - new Vector3(x + script.tileSize / 2, -.5f, 0);
            Vector3 offset2 = bottomLeft - new Vector3(-x - script.tileSize / 2, -.5f, 0);

            GameObject wall = null;
            if (!Physics.CheckSphere(offset, .1f))
            {
                wall = script.createInstance(tile, (topLeft - new Vector3(x + script.tileSize, 0, 0)), Quaternion.LookRotation(Vector3.right, Vector3.up));
                wall.GetComponent <Renderer>().materials = mats;
                wall.transform.parent.parent             = gO.transform;
            }
            if (!Physics.CheckSphere(offset2, .1f))
            {
                wall = script.createInstance(tile, (bottomLeft - new Vector3(-x - script.tileSize, 0, 0)), Quaternion.LookRotation(-Vector3.right, Vector3.up));
                wall.GetComponent <Renderer>().materials = mats;
                wall.transform.parent.parent             = gO.transform;
            }
        }
        for (int z = 0; z < Mathf.Abs(height); z += (int)script.tileSize)
        {
            Vector3    offset  = topLeft - new Vector3(0, -.5f, z + script.tileSize / 2);
            Vector3    offset2 = bottomLeft - new Vector3(0, -.5f, -z - script.tileSize / 2);
            GameObject wall    = null;
            if (!Physics.CheckSphere(offset, .1f))
            {
                wall = script.createInstance(tile, (topLeft - new Vector3(0, 0, z)), Quaternion.LookRotation(-Vector3.forward, Vector3.up));
                wall.GetComponent <Renderer>().materials = mats;
                wall.transform.parent.parent             = gO.transform;
            }

            if (!Physics.CheckSphere(offset2, .1f))
            {
                wall = script.createInstance(tile, (bottomLeft - new Vector3(0, 0, -z)), Quaternion.identity);
                wall.GetComponent <Renderer>().materials = mats;
                wall.transform.parent.parent             = gO.transform;
            }
        }
        //Create pillars. God all of the code in this place is awful. I'm sorry.
        GameObject pillarTopLeft     = script.createInstance(pillar, bottomLeft, Quaternion.identity);
        GameObject pillarBottomLeft  = script.createInstance(pillar, topLeft, Quaternion.identity);
        GameObject pillarTopRight    = script.createInstance(pillar, topLeft + new Vector3(width, 0, 0), Quaternion.identity);
        GameObject pillarBottomRight = script.createInstance(pillar, bottomLeft + new Vector3(-width, 0, 0), Quaternion.identity);

        pillarTopLeft.GetComponent <Renderer>().materials     = mats;
        pillarBottomLeft.GetComponent <Renderer>().materials  = mats;
        pillarTopRight.GetComponent <Renderer>().materials    = mats;
        pillarBottomRight.GetComponent <Renderer>().materials = mats;


        pillarTopLeft.transform.parent.parent     = gO.transform;
        pillarBottomLeft.transform.parent.parent  = gO.transform;
        pillarTopRight.transform.parent.parent    = gO.transform;
        pillarBottomRight.transform.parent.parent = gO.transform;

        Undo.RegisterCreatedObjectUndo(gO, "Undo wall creation");
    }