public void BuildObjectsFromSave(Save save) { if (save == null) { Debug.LogError("Save is null!"); return; } GridObjectSaveData[] ObjectsToBuildDATA = save.GridObjects; if (ObjectsToBuildDATA.Length <= 0) { Debug.Log("No GridObjects to build!"); return; } foreach (GridObjectSaveData objectToBuild in ObjectsToBuildDATA) { GridObjectID ID = (GridObjectID)objectToBuild.ID; NodeGridPosition GridPos = new NodeGridPosition(objectToBuild.x, objectToBuild.y); int Rot = objectToBuild.Rot; if (!BuildObject(ID, GridPos, Rot)) { Debug.LogWarning("SomeThing Went Wrong!"); } } Debug.Log("Done!"); }
public GridObjectData GetData(GridObjectID ID) { //TODO: Maybe make this more secure if ((int)ID < GridObjects.Length) { return(GridObjects[(int)ID]); } return(null); }
public void SetObjectToBuild(GridObjectID ID) { GridObjectData DATA = IDManager.Instance.GetData(ID); if (DATA == null) { return; } GridObjectToBuild = DATA; if (OnGridObjectToBuildChanged != null) { OnGridObjectToBuildChanged(); } }
public ShopItem(GridObjectID _ID) { ID = _ID; }
//WARNING! NO BUILDMODE CHECK private bool BuildObject(GridObjectSaveData GridObjectSavedData) { if (GridObjectSavedData == null) { return(false); } GridObjectID ID = (GridObjectID)GridObjectSavedData.ID; NodeGridPosition GridPos = new NodeGridPosition(GridObjectSavedData.x, GridObjectSavedData.y); int Rot = GridObjectSavedData.Rot; GridObjectData ObjectData = IDManager.Instance.GetData(GridObjectSavedData.ID); if (ObjectData == null) { Debug.LogError("ObjectData is null!"); return(false); } if (CheckIfOccupied(GetOccupiedNodes(GridPos)) || GridPos == NodeGridPosition.Null) { return(false); } Vector3 WorldPos = Grid.GetWorldPointFromNodeGridPosition(GridPos); while (Rot < 0) { Rot += 4; } Rot %= 4; Quaternion Rotation = Quaternion.Euler(0f, Rot * 90f, 0f); GridObject GridObj = Instantiate(ObjectData.Prefab, WorldPos, Rotation); GridObj.GridPos = GridPos; GridObj.Rot = Rot; GridObjects.Add(GridObj); if (ID == GridObjectID.wall) { Wall wall = GridObj.GetComponent <Wall>(); if (wall != null) { wall.transform.SetParent(WallParent); wall.ShowUpWall(AllWallsShowing); AddWall(wall); } } //If the size of the object is more that 1 in any axis if (GridObj.Size.x > 1 && GridObj.Size.y > 1) { //We go through all the occupied nodes to tell them they have been occupied foreach (NodeGridPosition OccupiedGridPosition in GridObj.GetOccupiedNodes()) { ObjectGrid[OccupiedGridPosition.x, OccupiedGridPosition.y] = GridObj; Node occupiedNode = grid.grid[OccupiedGridPosition.x, OccupiedGridPosition.y]; occupiedNode.Occupied = true; occupiedNode.UpdateWalkable(); } } else { ObjectGrid[GridPos.x, GridPos.y] = GridObj; Node node = grid.grid[GridPos.x, GridPos.y]; node.Occupied = true; node.UpdateWalkable(); } return(true); }