Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created November 2, 2018 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/2ead2936ed93d7e55b5c2b3be2df5110 to your computer and use it in GitHub Desktop.
Save tsubaki/2ead2936ed93d7e55b5c2b3be2df5110 to your computer and use it in GitHub Desktop.
Entityの読込
using Unity.Entities;
using Unity.Entities.Serialization;
using UnityEngine;
public class LoadWorld : MonoBehaviour
{
[SerializeField] string fileName = "save.sav";
[SerializeField] GameObject sharedData = null;
private World localWorld;
private const string worldName = "local world";
private void OnEnable()
{
localWorld = new World(worldName);
localWorld.GetOrCreateManager<EntityManager>();
}
private void OnDisable()
{
if (localWorld.IsCreated)
localWorld.Dispose();
}
public void Load()
{
var entityManager = localWorld.GetExistingManager<EntityManager>();
using (var reader = new StreamBinaryReader(fileName))
{
SerializeUtilityHybrid.Deserialize(entityManager, reader, sharedData);
}
World.Active.GetExistingManager<EntityManager>().MoveEntitiesFrom(entityManager);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment