void NetworkUpdateWorld(byte[] data)
    {
        World world = (World)FindObjectOfType(typeof(World));
        world.loadDefaultWorld();

        string size = "";
        CompressionType compression;

        using (MemoryStream stream = new MemoryStream(data))
        {
            using (WorldInputStream reader = new WorldInputStream(stream))
         			{
                reader.Read(world);

                size = stream.Length.GetSizeReadable();
                compression = reader.compressionType;
            }
        }

        UnityEngine.Debug.Log("world received (" + size + " | " + compression + ")");

        GameObject player = GameObject.FindWithTag("Player");
        if (player)
            player.SendMessage("Respawn");

        CircularObjectPool.instance.RecallAllObjectsForType("Debris");
    }
Пример #2
0
    public void Load(string path)
    {
        World world = GetComponent<World>();

        if (!world.initialized)
            return;

        Stopwatch stopWatch = Stopwatch.StartNew();

        /// Revert the world to its default state
        world.loadDefaultWorld();

        string size = "";
        CompressionType compression = CompressionType.BZIP2;

        using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
        {
            using (WorldInputStream reader = new WorldInputStream(stream))
            {
                reader.Read(world);

                size = stream.Length.GetSizeReadable();
                compression = reader.compressionType;
            }
        }

        stopWatch.Stop();
        UnityEngine.Debug.Log("world loaded (" + stopWatch.ElapsedMilliseconds + " ms | " + size + " | " + compression + ")");

        /// Cleanup all debris
        CircularObjectPool.instance.RecallAllObjectsForType("Debris");

        Scaffolding[] builders = (Scaffolding[])FindObjectsOfType(typeof(Scaffolding));
        foreach (Scaffolding scaffolding in builders)
            scaffolding.OnComplete();

        GameObject player = GameObject.FindWithTag("Player");
        if (player)
            player.SendMessage("Respawn");
    }