Exemplo n.º 1
0
        void PlaceObject()
        {
            if (hasObj)
            {
                UpdateMousePosition();

                Node curNode = gridBase.NodeFromWorldPosition(mousePosition);

                worldPosition = curNode.vis.transform.position;

                if (cloneObj == null)
                {
                    cloneObj      = Instantiate(objToPlace, worldPosition, Quaternion.identity) as GameObject;
                    objProperties = cloneObj.GetComponent <Level_Object>();
                }
                else
                {
                    cloneObj.transform.position = worldPosition;

                    if (Input.GetMouseButton(0) && !ui.mouseOverUIElement)
                    {
                        if (curNode.placeObj != null)
                        {
                            manager.inSceneGameObjects.Remove(curNode.placeObj.gameObject);
                            Destroy(curNode.placeObj.gameObject);
                            curNode.placeObj = null;
                        }

                        GameObject actualObjPlaced = Instantiate(objToPlace, worldPosition, cloneObj.transform.rotation) as GameObject;
                        actualObjPlaced.transform.parent = GameObject.Find("room").transform;
                        Level_Object placedObjProperties = actualObjPlaced.GetComponent <Level_Object>();


                        curNode.placeObj             = placedObjProperties;
                        placedObjProperties.gridPosX = curNode.nodePosX;
                        placedObjProperties.gridPosY = curNode.nodePosY;


                        manager.inSceneGameObjects.Add(actualObjPlaced);
                    }

                    if (Input.GetMouseButton(1))
                    {
                        objProperties.ChangeRotation();
                    }
                }
            }

            else
            {
                if (cloneObj != null)
                {
                    Destroy(cloneObj);
                }
            }
        }
Exemplo n.º 2
0
        void PlaceStackObj()
        {
            if (placeStackObj)
            {
                UpdateMousePosition();

                Node curNode = gridBase.NodeFromWorldPosition(mousePosition);

                worldPosition = curNode.vis.transform.position;

                if (stackCloneObj == null)
                {
                    stackCloneObj      = Instantiate(stackObjToPlace, worldPosition, Quaternion.identity) as GameObject;
                    stackObjProperties = stackCloneObj.GetComponent <Level_Object>();
                }
                else
                {
                    stackCloneObj.transform.position = worldPosition;

                    if (Input.GetMouseButtonUp(0) && !ui.mouseOverUIElement)
                    {
                        GameObject   actualObjPlaced     = Instantiate(stackObjToPlace, worldPosition, stackCloneObj.transform.rotation) as GameObject;
                        Level_Object placedObjProperties = actualObjPlaced.GetComponent <Level_Object>();

                        placedObjProperties.gridPosX = curNode.nodePosX;
                        placedObjProperties.gridPosY = curNode.nodePosY;
                        curNode.stackedObjs.Add(placedObjProperties);
                        manager.inSceneStackObjects.Add(actualObjPlaced);
                    }

                    if (Input.GetMouseButtonUp(1))
                    {
                        stackObjProperties.ChangeRotation();
                    }
                }
            }
            else
            {
                if (stackCloneObj != null)
                {
                    Destroy(stackCloneObj);
                }
            }
        }