コード例 #1
0
    public void Deserialize(SerializedGrid grid)
    {
        layers = grid.layers;
        foreach (BlockController block in blocks.Values)
        {
            Destroy(block.gameObject);
        }
        blocks.Clear();

        foreach (SerializedBlock block in grid.blocks)
        {
            BlockPosition   position    = new BlockPosition(block.position);
            GameObject      blockObject = Instantiate(BlockPrefabFromType((BlockType)block.type), BlockToWorldPosition(position), Quaternion.identity, transform);
            BlockController controller  = blockObject.GetComponent <BlockController>();

            controller.Init(position);
            controller.UpdateLayer(player.selectedLayer);
            controller.SetCharge(block.charge);
            controller.shouldTick           = block.shouldTick;
            controller.destinationOfAnyPath = block.destinationOfAnyPath;
            blocks.Add(position, controller);
        }

        foreach (SerializedBlock block in grid.blocks)
        {
            BlockPosition   position   = new BlockPosition(block.position);
            BlockController controller = blocks[position];

            foreach (SerializedUpdatePath path in block.paths)
            {
                controller.paths.Add(new UpdatePath(blocks[new BlockPosition(path.source)], blocks[new BlockPosition(path.destination)]));
            }
        }
    }
コード例 #2
0
    SerializedGrid LoadFromFile(string name)
    {
        StreamReader   reader = new StreamReader(Path.Combine(SavePath, name + SaveExtension));
        string         json   = reader.ReadToEnd();
        SerializedGrid save   = JsonUtility.FromJson <SerializedGrid>(json);

        reader.Close();

        return(save);
    }
コード例 #3
0
ファイル: PlotIO.cs プロジェクト: tg1230/Space-Zoologist
    public SerializedPlot SavePlot()
    {
        SerializedGrid       serializedGrid       = new SerializedGrid(GridSystem);
        SerializedMapObjects serializedMapObjects = new SerializedMapObjects();

        foreach (GridObjectManager gridObjectManager in this.gridObjectManagers)
        {
            gridObjectManager.Serialize(serializedMapObjects);
        }
        return(new SerializedPlot(serializedMapObjects, serializedGrid));
    }
コード例 #4
0
 // Start is called before the first frame update
 public SerializedPlot(SerializedMapObjects serializedMapObjects, SerializedGrid serializedGrid)
 {
     this.serializedMapObjects = serializedMapObjects;
     this.serializedGrid       = serializedGrid;
 }
コード例 #5
0
    void Update()
    {
        if (!pauseMenu.open)
        {
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                selectedBlockType = BlockType.Cable;
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                selectedBlockType = BlockType.Source;
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                selectedBlockType = BlockType.Inverter;
            }
            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                selectedBlockType = BlockType.Delay;
            }
            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                selectedBlockType = BlockType.Via;
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                selectedRotation = (selectedRotation + 1) % 4;
            }
            if (Input.GetKeyDown(KeyCode.LeftBracket))
            {
                selectedLayer = max(selectedLayer - 1, 0);
            }
            if (Input.GetKeyDown(KeyCode.RightBracket))
            {
                selectedLayer = min(selectedLayer + 1, grid.layers - 1);
            }

            if (Input.GetMouseButton(0))
            {
                Vector2       position      = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                BlockPosition blockPosition = grid.WorldToBlockPosition(position);
                grid.PlaceBlock(selectedBlockType, new BlockPosition(blockPosition.x, blockPosition.y, selectedLayer, selectedRotation));
            }

            if (Input.GetMouseButton(1))
            {
                Vector2 position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                grid.RemoveBlock(grid.WorldToBlockPosition(position));
            }

            if (Input.GetKeyDown(KeyCode.LeftBracket) || Input.GetKeyDown(KeyCode.RightBracket))
            {
                foreach (BlockController block in grid.blocks.Values)
                {
                    block.UpdateLayer(selectedLayer);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Minus))
        {
            string json = JsonUtility.ToJson(new SerializedGrid(grid));

            StreamWriter writer = new StreamWriter(Path.Combine(Application.persistentDataPath + Path.DirectorySeparatorChar + "save.json"));
            writer.Write(json);
            writer.Close();
        }

        if (Input.GetKeyDown(KeyCode.Equals))
        {
            StreamReader   reader = new StreamReader(Path.Combine(Application.persistentDataPath + Path.DirectorySeparatorChar + "save.json"));
            string         json   = reader.ReadToEnd();
            SerializedGrid save   = JsonUtility.FromJson <SerializedGrid>(json);
            reader.Close();

            grid.Deserialize(save);
        }
    }