// Use this for initialization
    void Start()
    {
        instance = this;

        basementHeight = 1.5f - floorHeight / 2;
        float elementHeight;


        gridElements   = new gridElement[width * width * height];
        cornerElements = new cornerElement[(width + 1) * (width + 1) * (height + 1)];

        for (int y = 0; y < height + 1; y++)
        {
            for (int x = 0; x < width + 1; x++)
            {
                for (int z = 0; z < width + 1; z++)
                {
                    cornerElement cornerElementInstance = Instantiate(cornerElement, Vector3.zero, Quaternion.identity, this.transform);
                    cornerElementInstance.Initialize(x, y, z);
                    cornerElements[x + (width + 1) * (z + (width + 1) * y)] = cornerElementInstance;
                }
            }
        }


        for (int y = 0; y < height; y++)
        {
            float yPos = y;
            if (y == 0)
            {
                elementHeight = floorHeight;
            }
            else if (y == 1)
            {
                elementHeight = basementHeight;
                yPos          = floorHeight / 2 + basementHeight / 2;
            }
            else
            {
                elementHeight = 1;
            }
            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < width; z++)
                {
                    gridElement gridElementInstance = Instantiate(gridElement, new Vector3(x, yPos, z), Quaternion.identity, this.transform);
                    gridElementInstance.Initialize(x, y, z, elementHeight);
                    gridElements[x + width * (z + width * y)] = gridElementInstance;
                }
            }
        }

        foreach (cornerElement corner in cornerElements)
        {
            corner.SetNearGridElements();
        }

        SetRandomize();
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit) && hit.collider.tag == "gridElement")
        {
            this.transform.position = hit.collider.transform.position;
            lastHit = hit.collider.gameObject.GetComponent <gridElement>();
            this.rectTransform.sizeDelta = new Vector2(1.0f, lastHit.GetElementHeight());
            if (Input.GetMouseButtonDown(1))
            {
                SetCurserButton(0);
            }
        }



        // reset when press 5
        //read a file, instantiate a constructor by width height. then read an array to enable and disable gridElement.
        if (Input.GetKeyDown("5"))
        {
            constructor.instance.freeMemory();
            constructor.instance.initialize(10, 2);
        }
        //save file
        if (Input.GetKeyDown("1"))
        {
            XMLOp.Serialize(constructor.instance.info, "constructorInfo.xml");
        }
        if (Input.GetKeyDown("2"))
        {
            constructorInfo outInfo = new constructorInfo();
            outInfo = XMLOp.Deserialize <constructorInfo>("constructorInfo.xml");
            constructor.instance.info.width  = outInfo.width;
            constructor.instance.info.height = outInfo.height;

            constructor.instance.freeMemory();
            constructor.instance.initialize(outInfo.width, outInfo.height);
            for (int i = 0; i < outInfo.width * outInfo.width * outInfo.height; i++)
            {
                if (outInfo.gridElementStatus[i] == 0)
                {
                    Debug.Log(i);
                    constructor.instance.info.gridElementStatus[i] = 0;
                    constructor.instance.gridElements[i].SetDisable();
                }
                else
                {
                    constructor.instance.info.gridElementStatus[i] = 1;
                    constructor.instance.gridElements[i].SetEnable();
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit) && hit.collider.tag == "gridElement")
        {
            this.transform.position = hit.collider.transform.position;
            lastHit = hit.collider.gameObject.GetComponent <gridElement>();
            this.transform.localScale    = new Vector3(1, 1, 1);
            this.rectTransform.sizeDelta = new Vector2(1.0f, lastHit.GetElementHeight());

            if (Input.GetMouseButtonDown(1))
            {
                SetCurserButton(0);
            }
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0))
        {
            hitSomething = Physics.Raycast(ray, out hit);
        }

        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (GameObject.Find("CanvasPause").GetComponent <PauseMenu>().GameIsPaused == false && Physics.Raycast(ray, out hit) && hit.collider.tag == "gridElement")
        {
            this.transform.position = hit.collider.transform.position;
            lastHit = hit.collider.gameObject.GetComponent <gridElement>();
            this.rectTransform.sizeDelta = new Vector2(1.0f, lastHit.GetElementHeight());

            if (Input.GetMouseButtonDown(1))
            {
                SetCurserButton(0);
            }
        }
    }
Esempio n. 5
0
    // Start is called before the first frame update
    void Start()
    {
        blockCount   = -width * length;
        housingCount = 0;
        instance     = this;
        blockSize    = 3;
        avratio      = 0.00f;

        basementHeight = 1.5f - floorHeight / 2;
        float elementHeight = 1;

        gridElements   = new gridElement[width * length * height];
        cornerElements = new cornerElement[(width + 1) * (length + 1) * (height + 1)];

        for (int y = 0; y < height + 1; y++)
        {
            for (int x = 0; x < width + 1; x++)
            {
                for (int z = 0; z < length + 1; z++)
                {
                    cornerElement cornerElementInstance = Instantiate(cornerElement, Vector3.zero, Quaternion.identity, this.transform);
                    cornerElementInstance.Initialize(x, y, z);
                    cornerElements[x + (width + 1) * (z + (length + 1) * y)] = cornerElementInstance;
                }
            }
        }

        for (int y = 0; y < height; y++)
        {
            float yPos = y;
            if (y == 0)
            {
                elementHeight = floorHeight;
            }
            else if (y == 1)
            {
                elementHeight = basementHeight;
                yPos          = floorHeight / 2 + basementHeight / 2;
            }
            else
            {
                elementHeight = 1;
            }

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < length; z++)
                {
                    gridElement gridElementInstance = Instantiate(gridElement, new Vector3(x, yPos, z), Quaternion.identity, this.transform);
                    gridElementInstance.Initialize(x, y, z, elementHeight);
                    gridElements[x + width * (z + length * y)] = gridElementInstance;
                }
            }
        }


        foreach (cornerElement corner in cornerElements)
        {
            corner.SetNearGridElements();
        }

        foreach (gridElement gridElement in gridElements)
        {
            gridElement.SetEnable(gridElement.GetCoord());
        }
    }
Esempio n. 6
0
    public void initialize(int width, int height)
    {
        info           = new constructorInfo(width, height);
        this.height    = height;
        this.width     = width;
        basementHeight = 1.5f - floorHeight / 2;
        float elementHeight = 1f;

        gridElementPrefabs   = new GameObject[width * width * height];
        cornerElementPrefabs = new GameObject[(width + 1) * (width + 1) * (height + 1)];
        gridElements         = new gridElement[width * width * height];
        cornerElements       = new cornerElement[(width + 1) * (width + 1) * (height + 1)];


        //Instantiate and register each CE
        for (int y = 0; y < height + 1; y++)
        {
            for (int x = 0; x < width + 1; x++)
            {
                for (int z = 0; z < width + 1; z++)
                {
                    //intantiate (place) prefab there
                    GameObject    cornerElementPrefabInstance = Instantiate(cornerElementPrefab, Vector3.zero, Quaternion.identity, this.transform);
                    cornerElement cornerElementInstance       = cornerElementPrefabInstance.GetComponent <cornerElement>();
                    //set instance
                    cornerElementInstance.Initialize(x, y, z);
                    //record cornerElement.
                    cornerElements[x + (width + 1) * (z + (width + 1) * y)]       = cornerElementInstance;
                    cornerElementPrefabs[x + (width + 1) * (z + (width + 1) * y)] = cornerElementPrefabInstance;
                }
            }
        }
        //Instantiate and register each GE
        for (int y = 0; y < height; y++)
        {
            float yPos = y;
            if (y == 0) //floor
            {
                elementHeight = floorHeight;
            }

            else if (y == 1)//basement
            {
                elementHeight = basementHeight;
                yPos          = floorHeight / 2 + basementHeight / 2;
            }
            else
            {
                elementHeight = 1;
            }

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < width; z++)
                {
                    //intantiate (place) prefab there
                    GameObject  gridElementPrefabInstance = Instantiate(gridElementPrefab, new Vector3(x, yPos, z), Quaternion.identity, this.transform);
                    gridElement gridElementInstance       = gridElementPrefabInstance.GetComponent <gridElement>();
                    //set instance, record surrounding cornerElement and place them.
                    gridElementInstance.Initialize(x, y, z, elementHeight);
                    //record gridElement.
                    gridElements[x + width * (z + width * y)]       = gridElementInstance;
                    gridElementPrefabs[x + width * (z + width * y)] = gridElementPrefabInstance;
                }
            }
        }


        //register surrounding GE nearby foreach CE
        foreach (cornerElement corner in cornerElements)
        {
            corner.SetNearGridElements();
        }

        //set every GE enabled.
        foreach (gridElement gridElement in gridElements)
        {
            gridElement.SetEnable();
        }
    }