Esempio n. 1
0
    public static void Save(string SaveName)
    {
        Save save = new Save();
        List <GridObjectSaveData> GridObjects = new List <GridObjectSaveData>();


        foreach (GridObject GridObj in BuildManager.Instance.GetAllGridObject())
        {
            GridObjectSaveData gridObjSave = new GridObjectSaveData(GridObj);

            GridObjects.Add(gridObjSave);
        }


        save.GridObjects = GridObjects.ToArray();
        save.Name        = SaveName;

        /* This Still Needs To Be Implemented Yet
         * save.TimeOfSave = System.DateTime.Now.ToLongDateString();
         */

        save.FullName = SaveName /*+ "." + save.TimeOfSave*/ + Extension;

        save.FullPath = Application.dataPath + "/" + save.FullName;

        BinaryFormatter bf     = new BinaryFormatter();
        FileStream      stream = new FileStream(save.FullPath, FileMode.Create);

        bf.Serialize(stream, save);

        stream.Close();
    }
Esempio n. 2
0
    //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);
    }