private static void ContextMenuManager() { if (currentEvent != null) { if (currentEvent.button == 2) { if (currentEvent.type == EventType.MouseDown) { if (Selection.activeGameObject != null) { gridObjectCube = Selection.activeGameObject.GetComponentInParent <Grid_Object>(); gridNode = Selection.activeGameObject.GetComponent <Grid_Node>(); if (gridObjectCube != null) { switch (gridObjectCube.cubeData.cubeType) { case Grid_Object.CubeType.Delivery: DeliveryDropdown(); break; case Grid_Object.CubeType.Timer: TimerDropdown(); break; case Grid_Object.CubeType.Sticky: StickyDropdown(); break; case Grid_Object.CubeType.Switch: SwitchDropdown(); break; case Grid_Object.CubeType.Elevator: ElevatorDropdown(); break; default: BasicCubeDropdown(); break; } } } else { BaseDropdownMenu(); } //currentEvent.Use(); } } } }
//Creates a grid of Nodes (empty positions) public void CreateGrid(Vector3Int size) { //ClearCurrentGrid(); //define the number of entries in the of the array based on the x, y and z size of the grid grid = new Node[size.x, size.y, size.z]; sizeX = size.x; sizeY = size.y; sizeZ = size.z; for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { for (int z = 0; z < size.z; z++) { //declare the final X, Y and Z positions with the offset float offsetPosX = x * offset; float offsetPosY = y * offset; float offsetPosZ = z * offset; //Place the grid's cell at the current node position Vector3 offsetPos = new Vector3(offsetPosX, offsetPosY, offsetPosZ); //Spawn a new cube at the corresponding "world" position of the node (WITH OFFSET) GameObject go = Instantiate(nodePrefab, offsetPos, Quaternion.identity); go.transform.parent = transform.GetChild(0).GetChild(0).transform; Grid_Node nodeObject = go.GetComponent <Grid_Node>(); nodeObject.posX = x; nodeObject.posY = y; nodeObject.posZ = z; Node currNode = new Node(); //generate a new node to store the current cell's information currNode.nodeViz = go; //assign nodePrefab as the node viz currNode.nodePosX = x; //assign current Node's info with x, y, z (NO OFFSET, CORRESPONDS TO GRID POSITION) currNode.nodePosY = y; currNode.nodePosZ = z; grid[x, y, z] = currNode; //store the node's information in the gridInfo array nodes.Add(currNode); //add the node to a List that can be tracked in the inspector onPlayNodePosList.Add(go); } } } gridCleared = false; }
public void ExtractLevel(LevelEditorData receivedLevelData) { //foreach object in saveObjectData //create a new ObjectData bin to assign values to; //get the cubeType data //get the world position data //get the nodePOs data //create a new Cube from prefab //Get the cube's EditorObject Component //set the component's values to match the recovered data //Get the new nodes in the world //get the worldPosition of each of their ndoes //set cube worldPosition to its corresponding Node_Object worldPosition GameObject newCube; GameObject newDecor; if (isInEditor) { _LevelEditor.instance.inSceneGameObjects.Clear(); } foreach (DecorData recoveredDecorFromSave in receivedLevelData.savedEnvironmentData) { newDecor = Instantiate(decorPrefab, Vector3.zero, Quaternion.identity); newDecor.transform.parent = _Grid.instance.gameObject.transform.GetChild(0).GetChild(2); newDecor.transform.localPosition = recoveredDecorFromSave.localPosition; newDecor.transform.localRotation = recoveredDecorFromSave.localRotation; //get the new cube's Object Data and create a reference to it DecorData newDecorData = newDecor.GetComponent <_DecorObject>().decorData; //assign the new Cube's data to match the recovered cube's newDecorData = recoveredDecorFromSave; } foreach (ObjectData recoveredDataFromSave in receivedLevelData.savedObjectsData) { //create a new empty cube newCube = Instantiate(cubePrefab, Vector3.zero, Quaternion.identity); //get the new cube's Object Data and create a reference to it ObjectData newCubeData = newCube.GetComponent <Grid_Object>().cubeData; //assign the new Cube's data to match the recovered cube's newCubeData = recoveredDataFromSave; //assign the cube's parent in the hiearchy newCube.transform.parent = _Grid.instance.gameObject.transform.GetChild(0).transform.GetChild(1).transform; //add the newly created cube to a list of existing cubes if (isInEditor) { _LevelEditor.instance.inSceneGameObjects.Add(newCube); } for (int i = 0; i < _Grid.instance.onPlayNodePosList.Count; i++) { Grid_Node newNodeObjects = _Grid.instance.onPlayNodePosList[i].GetComponent <Grid_Node>(); if (newCubeData.gridPositionX >= _Grid.instance.gridSize.x || newCubeData.gridPositionY >= _Grid.instance.gridSize.y || newCubeData.gridPositionZ >= _Grid.instance.gridSize.z) { Destroy(newCube); } else if (newNodeObjects.posX == newCubeData.gridPositionX && newNodeObjects.posY == newCubeData.gridPositionY && newNodeObjects.posZ == newCubeData.gridPositionZ) { newCube.SendMessage("ReceiveData", recoveredDataFromSave); if (isInEditor) { Node nodeToPlace = _Grid.instance.grid[(int)newCubeData.gridPositionX, (int)newCubeData.gridPositionY, (int)newCubeData.gridPositionZ]; nodeToPlace.cubeOnNodePos = newCube.GetComponent <Grid_Object>(); } newCube.transform.position = _Grid.instance.onPlayNodePosList[i].transform.position; newCubeData.worldPosition = newCube.transform.position; newCube.transform.GetChild(0).rotation = newCubeData.worldRotation; } } } receivedLevelData.savedObjectsData.Clear(); receivedLevelData.savedEnvironmentData.Clear(); levelIsLoaded = true; }