private void SelectingCubes() { if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(0)) { selectingCube = true; } if (selectingCube) { selectedCube = currentSelectedNode.cubeOnNodePos; selectedCube.gameObject.transform.rotation = appliedCubeRotation; } }
void PlaceCube() { if (placingCubes) { //if the player clicks the mouse button to place an object if (Input.GetMouseButtonDown(0) && !mouseOverUIElement) { //make sure that their isn't an object already present at the node's position if (currentSelectedNode.cubeOnNodePos != null) { //if there is, destroy the present object and "reset" the position Destroy(inSceneGameObjects[inSceneGameObjects.IndexOf(currentSelectedNode.cubeOnNodePos.gameObject)]); //remove the object from the list of active objects in scene inSceneGameObjects.Remove(currentSelectedNode.cubeOnNodePos.gameObject); currentSelectedNode.cubeOnNodePos = null; } //place the "actual" where you were pointing the preview object GameObject placedObject = Instantiate(objectToPlace, worldPositionOfNode, Quaternion.identity) as GameObject; //Get the object properties so that they can be modified Grid_Object placedObjectProperties = placedObject.GetComponent <Grid_Object>(); //set the position of the object in node coordinates placedObjectProperties.cubeData.gridPositionX = currentSelectedNode.nodePosX; placedObjectProperties.cubeData.gridPositionY = currentSelectedNode.nodePosY; placedObjectProperties.cubeData.gridPositionZ = currentSelectedNode.nodePosZ; placedObjectProperties.cubeData.worldPosition = placedObject.transform.position; placedObjectProperties.cubeData.worldRotation = appliedCubeRotation; placedObject.transform.parent = _Grid.instance.gameObject.transform.GetChild(0).transform.GetChild(1).transform; placedObjectProperties.cubeTexture = AssetIntegrator.instance.selectedTexture; if (Input.GetMouseButtonDown(0)) { placedObject.SendMessage("CubeTypeMessage", cubeType); } //place object at currently selected node position currentSelectedNode.cubeOnNodePos = placedObjectProperties; inSceneGameObjects.Add(placedObject); } } else { return; } }
public void PlaceCubeInEditor(EditorCubeType cubeTypeToPlace, Node receivedNode) { localWorldPositionOfNode = receivedNode.nodeViz.transform.position; Debug.Log("Placed a Cube " + cubeTypeToPlace.ToString() + " : " + receivedNode.nodePosX + " " + receivedNode.nodePosY + " " + receivedNode.nodePosZ); //make sure that their isn't an object already present at the node's position if (receivedNode.cubeOnNodePos != null) { //if there is, destroy the present object and "reset" the position DestroyImmediate(inSceneGameObjects[inSceneGameObjects.IndexOf(receivedNode.cubeOnNodePos.gameObject)]); //remove the object from the list of active objects in scene inSceneGameObjects.Remove(receivedNode.cubeOnNodePos.gameObject); receivedNode.cubeOnNodePos = null; } //place the "actual" where you were pointing the preview object GameObject placedObject = Instantiate(objectToPlace, localWorldPositionOfNode, Quaternion.identity) as GameObject; //Get the object properties so that they can be modified Grid_Object placedObjectProperties = placedObject.GetComponent <Grid_Object>(); //set the position of the object in node coordinates placedObjectProperties.cubeData.gridPositionX = receivedNode.nodePosX; placedObjectProperties.cubeData.gridPositionY = receivedNode.nodePosY; placedObjectProperties.cubeData.gridPositionZ = receivedNode.nodePosZ; placedObjectProperties.cubeData.worldPosition = placedObject.transform.position; placedObjectProperties.cubeData.worldRotation = appliedCubeRotation; placedObject.transform.parent = _Grid.instance.gameObject.transform.GetChild(0).transform.GetChild(1).transform; placedObjectProperties.cubeTexture = AssetIntegrator.instance.selectedTexture; placedObject.SendMessage("CubeTypeMessage", cubeTypeToPlace); //place object at currently selected node position receivedNode.cubeOnNodePos = placedObjectProperties; inSceneGameObjects.Add(placedObject); }
void DisableCubes() { if (disablingColliders) { GetMousePositionInGrid(); //find node that the mouse is over Node currentSelectedNode = _Grid.instance.NodeFromWorldPosition(mousePositionNode); if (Input.GetMouseButtonDown(0) && !mouseOverUIElement) { if (currentSelectedNode.cubeOnNodePos != null) { Grid_Object selectedNodeObject = currentSelectedNode.cubeOnNodePos.GetComponent <Grid_Object>(); foreach (GameObject selectedItem in _Grid.instance.onPlayNodePosList) { Grid_Node selectedItemInGrid = selectedItem.GetComponent <Grid_Node>(); if (selectedItemInGrid.posZ == selectedNodeObject.cubeData.gridPositionZ) { hiddenNodes.Add(selectedItemInGrid.gameObject); selectedItemInGrid.gameObject.SetActive(false); } foreach (GameObject selectedItem2 in inSceneGameObjects) { Grid_Object selectedItemInGrid2 = selectedItem2.GetComponent <Grid_Object>(); if (selectedItemInGrid2.cubeData.gridPositionZ == selectedNodeObject.cubeData.gridPositionZ) { hiddenNodes.Add(selectedItemInGrid2.gameObject); selectedItemInGrid2.gameObject.SetActive(false); } } } } else if (currentSelectedNode.cubeOnNodePos == null) { foreach (GameObject selectedItem in _Grid.instance.onPlayNodePosList) { Grid_Node selectedItemInGrid = selectedItem.GetComponent <Grid_Node>(); if (selectedItemInGrid.posZ == currentSelectedNode.nodePosZ) { hiddenNodes.Add(selectedItemInGrid.gameObject); selectedItemInGrid.gameObject.SetActive(false); } foreach (GameObject selectedItem2 in inSceneGameObjects) { Grid_Object selectedItemInGrid2 = selectedItem2.GetComponent <Grid_Object>(); if (selectedItemInGrid2.cubeData.gridPositionZ == currentSelectedNode.nodePosZ) { hiddenNodes.Add(selectedItemInGrid2.gameObject); selectedItemInGrid2.gameObject.SetActive(false); } } } } } } }