/// <see cref="SceneGraphManager.Load"/> public void Load(string filePath) { string json = FileIO.LoadJsonFromFile(filePath); var objectsToRestore = JsonConvert.DeserializeObject <List <WWObjectJSONBlob> >(json); Debug.Log(string.Format("Loaded {0} objects from file", objectsToRestore.Count)); foreach (WWObjectJSONBlob obj in objectsToRestore) { var objectData = new WWObjectData(obj); WWObject go = WWObjectFactory.Instantiate(objectData); Add(go); } // re-link children since all the objects have been instantiated in game world foreach (WWObjectJSONBlob obj in objectsToRestore) { WWObject root = Get(obj.id); var childrenToRestore = new List <WWObject>(); foreach (Guid childID in obj.children) { WWObject childObject = Get(childID); childrenToRestore.Add(childObject); } root.AddChildren(childrenToRestore); } }
public static List <Coordinate> CreateTerrainFromImage(Texture2D heightmap) { var coordinates = new List <Coordinate>(); var maxHeight = 10; for (var x = 0; x < heightmap.width; x++) { for (var y = 0; y < heightmap.height; y++) { var height = (int)(heightmap.GetPixel(x, y).r *maxHeight); var c = new Coordinate(x, height, y); coordinates.Add(c); var wwTransform = new WWTransform(c, 0); WWObjectData parentData = WWObjectFactory.CreateNew(wwTransform, "white"); WWObject parentObj = WWObjectFactory.Instantiate(parentData); ManagerRegistry.Instance.GetAnInstance <SceneGraphManager>().Add(parentObj); while (height > 0) { height--; c = new Coordinate(x, height, y); coordinates.Add(c); wwTransform = new WWTransform(c, 0); WWObjectData childData = WWObjectFactory.CreateNew(wwTransform, "white"); WWObject childObj = WWObjectFactory.Instantiate(childData); ManagerRegistry.Instance.GetAnInstance <SceneGraphManager>().Add(childObj); var children = new List <WWObject>(); children.Add(childObj); parentObj.AddChildren(children); parentObj = childObj; } } } return(coordinates); }