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(); } } } }
public void clearShip() { for (int i = 0; i < gridZ; i++) { for (int j = 0; j < gridX; j++) { Grid_Object currentGridObject = gridArray[i, j].GetComponent <Grid_Object>(); if (currentGridObject.containsObject()) { currentGridObject.getObject().GetComponent <Pickable_Object>().getSource().GetComponent <Pickable_Object>().changeQuantity(1); Destroy(currentGridObject.getObject(true)); } } } }
public void saveShip(string saveName) { //Debug.Log(test.getList()[0].getType()); //Debug.Log(JsonUtility.ToJson(test)); CustomSaveArray saveArray = new CustomSaveArray(); GameObject[,] gridArray = gridHelper.GetComponent <Grid_Script>().getGridArray(); for (int i = 0; i < gridArray.GetLength(0); i++) { for (int j = 0; j < gridArray.GetLength(1); j++) { if (gridArray[i, j].GetComponent <Grid_Object>().containsObject()) { Grid_Object currentGridObject = gridArray[i, j].GetComponent <Grid_Object>(); saveArray.add(new SaveObject(new Vector2(currentGridObject.transform.position.x, currentGridObject.transform.position.z), currentGridObject.getObject().GetComponent <Pickable_Object>().getType(), currentGridObject.getObject().GetComponent <Pickable_Object>().getOrientation())); } else { Debug.Log("Doesn't contain"); } } } string jsonObject = JsonUtility.ToJson(saveArray); Debug.Log(jsonObject); /* for(int i = 0; i < gridX; i++) { * for (int j = 0; j < gridZ; j++) { * gridArray[i,j].GetComponent<BoxCollider>().enabled = false; * gridArray[i, j].GetComponent<Renderer>().enabled = false; * Debug.Log("Disable"); * } * }*/ //Saving the ship file BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/" + saveName + ".jpeg"; FileStream stream = new FileStream(path, FileMode.Create); Debug.Log(Application.persistentDataPath); formatter.Serialize(stream, saveArray); stream.Close(); }
public void loadShip(string saveName) { string path = Application.persistentDataPath + "/" + saveName + ".jpeg"; Debug.Log(path); if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); CustomSaveArray ship = formatter.Deserialize(stream) as CustomSaveArray; stream.Close(); Debug.Log(ship); string jsonObject = JsonUtility.ToJson(ship); Debug.Log(jsonObject); //putting the ship into the game as a real life thingy GameObject[,] gridArray = gridHelper.GetComponent <Grid_Script>().getGridArray(); GameObject tempObject; foreach (SaveObject component in ship.getList()) { tempObject = Instantiate(GameObject.Find(component.getType()), new Vector3(component.getPos().x, .5f, component.getPos().y), GameObject.Find(component.getType()).transform.rotation); tempObject.GetComponent <Pickable_Object>().setOriginalSource(GameObject.Find(component.getType())); GameObject.Find(component.getType()).GetComponent <Pickable_Object>().changeQuantity(-1); //changing the quantity of the source block //rotating the block so it was in the orientation it was saved in (Yes, this is kinda messy but it would be either way) if (component.getOrientation() == "down") { tempObject.GetComponent <Pickable_Object>().rotateObject(true); tempObject.GetComponent <Pickable_Object>().rotateObject(true); } else if (component.getOrientation() == "right") { tempObject.GetComponent <Pickable_Object>().rotateObject(true); } else if (component.getOrientation() == "left") { tempObject.GetComponent <Pickable_Object>().rotateObject(false); } //adding that object to a grid object (I know this is an shit way to do it, but whatever) foreach (GameObject gridGameObject in gridArray) { Grid_Object gridObject = gridGameObject.GetComponent <Grid_Object>(); if (gridObject.getX() == (int)component.getPos().x&& gridObject.getY() == (int)component.getPos().y) { Debug.Log(gridObject.getX().ToString() + component.getPos().x.ToString() + gridObject.getY().ToString() + component.getPos().y.ToString()); gridObject.setObject(tempObject); Debug.Log("Adding to this grid object"); } } } } else { Debug.LogError("File not found: " + Application.persistentDataPath); } }
public void startGame(GameObject[,] gridArray) { functions = this.GetComponent <Functions>(); //Find the reactor Debug.Log("Starting Game"); for (int i = 0; i < gridArray.GetLength(0); i++) { for (int j = 0; j < gridArray.GetLength(1); j++) { if (gridArray[i, j].GetComponent <Grid_Object>().containsObject()) { if (gridArray[i, j].GetComponent <Grid_Object>().getObject(false).name == "Reactor(Clone)") { reactor = gridArray[i, j].GetComponent <Grid_Object>().getObject(false); } } } } //setting all objects to children of the reactor and giving all the objects the tag of "PlayerShip" for (int i = 0; i < gridArray.GetLength(0); i++) { for (int j = 0; j < gridArray.GetLength(1); j++) { if (gridArray[i, j].GetComponent <Grid_Object>().containsObject()) { gridArray[i, j].GetComponent <Grid_Object>().getObject(false).transform.parent = reactor.transform; gridArray[i, j].GetComponent <Grid_Object>().getObject(false).gameObject.tag = "PlayerShip"; } } } reactor.gameObject.tag = "PlayerShip"; //add the rigid body comonent to the reactor reactor.AddComponent <Rigidbody>(); Rigidbody rbody = reactor.GetComponent <Rigidbody>(); rbody.useGravity = false; rbody.drag = 1; rbody.constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY; //Get a list of all the objects independently //adding all the keys to the dict string[] blockTypes = functions.getBlockTypes(); for (int i = 0; i < blockTypes.Length; i++) { shipComponents.Add(blockTypes[i], new ArrayList()); } //adding all the componets to the dict as values for (int i = 0; i < gridArray.GetLength(0); i++) { for (int j = 0; j < gridArray.GetLength(1); j++) { Grid_Object gridObject = gridArray[i, j].GetComponent <Grid_Object>(); if (gridObject.containsObject()) { shipComponents[gridObject.getObject(false).GetComponent <Pickable_Object>().getType()].Add(gridObject.getObject(false)); } } } //This should be at the end of this entire method functions.setGridArray(gridArray); functions.setShipComponents(shipComponents); this.GetComponent <Thrusters>().onstart(); //Debug to check if dict contains the right values /* * foreach(KeyValuePair<string,ArrayList> temp in shipComponents) { * foreach(GameObject gamobj in temp.Value) { * Debug.Log(gamobj.GetComponent<Pickable_Object>().getType()); * } * } */ }