public void SaveObjects() { // Clear Object List GameSystem.Instance.objectList.Clear(); // Save Object List for (int i = 0; i < objectGrid.GetLength(0); i++) { for (int j = 0; j < objectGrid.GetLength(1); j++) { if (objectGrid[i, j] != null) { Object_Values objectValues = objectGrid[i, j].GetComponent <Object_Values>(); float rotation = objectGrid[i, j].transform.eulerAngles.y; rotation = rotation == -90 ? 270 : rotation; ObjectProperties objectProperties = new ObjectProperties(objectValues.ID, objectValues.placedPosition, rotation); GameSystem.Instance.AddObject(objectProperties); } } } // Save Game GameSystem.SaveGameSystem(); // Update Seat List GamePlaySystem.Instance.UpdateSeatList(); }
private void GetObjectComponents() { hitObjectParent = hitObject.transform.parent.gameObject; hitObjectParentValues = hitObjectParent.GetComponent <Object_Values>(); hitObjectParentMovement = hitObjectParent.GetComponent <Object_Movement>(); hitObjectColliderPosition = hitObject.GetComponent <Collider_Position>(); }
public bool PlaceObjectOnGrid(GameObject obj, Vector2Int pos, Vector2Int offset) { Vector2Int posWithOffset = pos - offset; Object_Values objValues = obj.GetComponent <Object_Values>(); Object_Movement objMovement = obj.GetComponent <Object_Movement>(); if (objectGridOperations.AddObject(obj, posWithOffset)) { GameObject tile = floorGridInstantiate.floorGrid[posWithOffset.x, posWithOffset.y]; objMovement.MoveToGridTileWithOffset(tile, new Vector2Int(0, 0)); objValues.placedPosition = posWithOffset; return(true); } return(false); }
// Remove gameobject at position public void RemoveObject(Vector2Int pos) { if (IsPositionEmpty(pos)) { return; } GameObject obj = GetObject(pos); Object_Values objectValues = GetObjectValues(obj); // Remove from index grid foreach (Vector2Int deltaPos in objectValues.previousOccupiedSpace) { Vector2Int relativePos = deltaPos + pos; integerObjectGrid[relativePos.x, relativePos.y] = emptyIntObjectElement; } // Remove object from gameobject grid objectGrid[pos.x, pos.y] = null; }
// Add gameobject at position public bool AddObject(GameObject obj, Vector2Int pos) { Object_Values objectValues = GetObjectValues(obj); if (!IsObjectPlaceableAtPosition(obj, pos)) { return(false); } // Add object to interger grid foreach (Vector2Int deltaPos in objectValues.occupiedSpace) { Vector2Int relativePos = deltaPos + pos; integerObjectGrid[relativePos.x, relativePos.y] = pos; } //Add object to gameobject grid objectGrid[pos.x, pos.y] = obj; return(true); }
// Add gameobject at position public bool IsObjectPlaceableAtPosition(GameObject obj, Vector2Int pos) { Object_Values objectValues = GetObjectValues(obj); foreach (Vector2Int deltaPos in objectValues.occupiedSpace) { Vector2Int relativePos = deltaPos + pos; // Out of bounds x position if (relativePos.x < 0 || relativePos.x >= width) { return(false); } // Out of boundy y position if (relativePos.y < 0 || relativePos.y >= length) { return(false); } // Position empty Vector2Int objectGridPosition = integerObjectGrid[relativePos.x, relativePos.y]; if (!IsPositionEmpty(objectGridPosition)) { if (obj != objectGrid[objectGridPosition.x, objectGridPosition.y]) { return(false); } } if (IsPositionBlocked(relativePos)) { return(false); } } return(true); }