Пример #1
0
    public override void PlacePreview(int numOfElements)
    {
        if (GameObject.Find("Composition Preview") != null)
        {
            GameObject.DestroyImmediate(GameObject.Find("Composition Preview"));
        }

        previewEncapsulateGO = new GameObject("Composition Preview");

        Camera cam = Camera.main;

        float camSize = cam.orthographicSize;

        string[] res = UnityStats.screenRes.Split('x');

        float aspect = (float.Parse(res [0]) / float.Parse(res [1]));

        if (aspect >= 1)
        {
            camSize *= (float.Parse(res [0]) / float.Parse(res [1]));
        }

        itemSizeX = ((2f * (camSize - camOffset)) - ((float)dimSizeX - 1) * itemOffset) / (float)dimSizeX;
        itemSizeY = itemSizeX;

        xPosStart = cam.gameObject.transform.position.x - camSize + (float)camOffset + itemSizeX / 2f;
        yPosStart = cam.gameObject.transform.position.y - camSize + (float)camOffset + itemSizeY / 2f;

        previewInstanceGO = new GameObject("Instance");
        PrimitivesGenerator.Box(previewInstanceGO, itemSizeX, itemSizeY, 0);
        previewInstanceGO.transform.parent = previewEncapsulateGO.transform;

        for (int i = 0; i < dimSizeX; i++)
        {
            for (int j = 0; j < dimSizeY; j++)
            {
                for (int k = 0; k < dimSize; k++)
                {
                    GameObject elementGO = GameObject.Instantiate(previewInstanceGO) as GameObject;
                    elementGO.name             = "Instance";
                    elementGO.transform.parent = previewEncapsulateGO.transform;

                    elementGO.transform.position = new Vector3(xPosStart + i * (itemSizeX + itemOffset), yPosStart + j * (itemSizeY + itemOffset), k * 10f);
                }
            }
        }

        elementSize = new Vector3(itemSizeX, itemSizeY, 15);

        GameObject.DestroyImmediate(previewInstanceGO);
    }
Пример #2
0
    public override void PlacePreview(int numOfElements)
    {
        if (GameObject.Find("Composition Preview") != null)
        {
            GameObject.DestroyImmediate(GameObject.Find("Composition Preview"));
        }

        previewEncapsulateGO = new GameObject("Composition Preview");

        Camera cam       = Camera.main;
        int    camOffset = 20;
        int    dimSize   = 5;

        float itemSizeX = 2f * (cam.orthographicSize - camOffset);
        float itemSizeY = itemSizeX;

        xPosStart = cam.gameObject.transform.position.x;
        yPosStart = cam.gameObject.transform.position.y;

        itemSizeZ = 15;

        previewInstanceGO = new GameObject("Instance");
        PrimitivesGenerator.Box(previewInstanceGO, itemSizeX, itemSizeY, 0);
        previewInstanceGO.transform.parent = previewEncapsulateGO.transform;

        for (int i = 0; i < dimSize; i++)
        {
            GameObject elementGO = GameObject.Instantiate(previewInstanceGO) as GameObject;
            elementGO.name             = "Instance";
            elementGO.transform.parent = previewEncapsulateGO.transform;

            elementGO.transform.position = new Vector3(xPosStart, yPosStart, i * 10f);
        }

        elementSize = new Vector3(itemSizeX, itemSizeY, 15);

        GameObject.DestroyImmediate(previewInstanceGO);
    }