public void Load(WorldSerialization blob) { var terrainSize = new Vector3(blob.world.size, 1000, blob.world.size); var terrainPosition = 0.5f * terrainSize; Terrain land = GameObject.FindGameObjectWithTag("Land").GetComponent <Terrain>(); Terrain water = GameObject.FindGameObjectWithTag("Water").GetComponent <Terrain>(); WorldConverter.MapInfo terrains = WorldConverter.worldToTerrain(blob); land.terrainData.heightmapResolution = terrains.resolution; land.terrainData.size = terrains.size; water.terrainData.heightmapResolution = terrains.resolution; water.terrainData.size = terrains.size; land.terrainData.SetHeights(0, 0, terrains.land.heights); water.terrainData.SetHeights(0, 0, terrains.water.heights); land.terrainData.alphamapResolution = terrains.resolution; land.terrainData.size = terrains.size; land.terrainData.splatPrototypes = getTextures(); land.terrainData.SetAlphamaps(0, 0, terrains.splatMap); GameObject defaultObj = Resources.Load <GameObject>("Prefabs/DefaultPrefab"); for (int i = 0; i < terrains.prefabData.Length; i++) { Vector3 pos = new Vector3(terrains.prefabData[i].position.x, terrains.prefabData[i].position.y, terrains.prefabData[i].position.z); Vector3 scale = new Vector3(terrains.prefabData[i].scale.x, terrains.prefabData[i].scale.y, terrains.prefabData[i].scale.z); Quaternion rotation = Quaternion.Euler(new Vector3(terrains.prefabData[i].rotation.x, terrains.prefabData[i].rotation.y, terrains.prefabData[i].rotation.z)); GameObject g = FileSystem.Load <GameObject>(StringPool.Get((blob.world.prefabs[i].id))); GameObject newObject = Instantiate(g, pos + terrainPosition, rotation); newObject.transform.localScale = scale; PrefabDataHolder pdh = newObject.GetComponent <PrefabDataHolder>(); if (pdh == null) { newObject.AddComponent <PrefabDataHolder>(); } pdh.prefabData = terrains.prefabData[i]; } GameObject pathObj = Resources.Load <GameObject>("Paths/Path"); for (int i = 0; i < terrains.pathData.Length; i++) { Vector3 averageLocation = Vector3.zero; for (int j = 0; j < terrains.pathData[i].nodes.Length; j++) { averageLocation += terrains.pathData[i].nodes[j]; } averageLocation /= terrains.pathData[i].nodes.Length; GameObject newObject = Instantiate(pathObj, averageLocation + terrainPosition, Quaternion.identity); newObject.GetComponent <PathDataHolder>().pathData = terrains.pathData[i]; newObject.GetComponent <PathDataHolder>().offset = terrainPosition; } }
/// <summary>Creates an instance for the default language.</summary> /// <returns>A repository.</returns> public override IWorldRepository ForDefaultCulture() { var worldConverter = new WorldConverter(); var identifiersResponseConverter = new CollectionResponseConverter <int, int>(new ConverterAdapter <int>()); var responseConverter = new ResponseConverter <WorldDTO, World>(worldConverter); var bulkResponseConverter = new DictionaryRangeResponseConverter <WorldDTO, int, World>(worldConverter, value => value.WorldId); var pageResponseConverter = new CollectionPageResponseConverter <WorldDTO, World>(worldConverter); return(new WorldRepository(this.serviceClient, identifiersResponseConverter, responseConverter, bulkResponseConverter, pageResponseConverter)); }
protected void OnGUI() { const float padding = 10; GUILayout.BeginArea(new Rect(padding, padding, Screen.width - padding - padding, Screen.height - padding - padding)); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Map File"); filename = GUILayout.TextField(filename, GUILayout.MinWidth(100)); #if UNITY_EDITOR if (GUILayout.Button("Browse")) { filename = UnityEditor.EditorUtility.OpenFilePanel("Select Map File", filename, "map"); } #endif if (GUILayout.Button("Load")) { var blob = new WorldSerialization(); Debug.Log("Loading"); // // //StringPool blob.Load(filename); Load(blob); } if (GUILayout.Button("Save")) { Terrain terrain = GameObject.FindGameObjectWithTag("Land").GetComponent <Terrain>(); Terrain water = GameObject.FindGameObjectWithTag("Water").GetComponent <Terrain>(); WorldSerialization world = WorldConverter.terrainToWorld(terrain, water); Debug.Log("Out: " + world.world.maps.Count); Debug.Log("Out: " + world.world.prefabs.Count); Debug.Log("Out: " + world.world.paths.Count); world.Save(@"C:\Users\Jason\rust test\test.map"); Debug.Log(world.Checksum); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //GUILayout.TextArea(result); GUILayout.EndVertical(); GUILayout.EndArea(); }
// Update is called once per frame void Update() { Vector3 screenPos = camera2D.WorldToScreenPoint(transform.position); bool withinBounds = screenPos.x >= 0.0f && screenPos.x <= camera2D.pixelWidth && screenPos.y >= 0.0f && screenPos.y <= camera2D.pixelHeight; if (withinBounds) { instance3D.transform.position = WorldConverter.Convert2DMapToSpherePosition(sphereTransform, transform.position, camera2D, object3DHeight); instance3D.transform.rotation = WorldConverter.Convert2DMapToSphereRotation(sphereTransform, transform.position, camera2D); } else { instance3D.transform.position = new Vector3(8000, 8000, 8000); } }
public static void LoadMapPanel() { string loadFile = ""; loadFile = EditorUtility.OpenFilePanel("Import Map File", loadFile, "map"); if (string.IsNullOrEmpty(loadFile)) { return; } var world = new WorldSerialization(); world.Load(loadFile); MapManager.Load(WorldConverter.WorldToTerrain(world), loadFile); ReloadTreeViews(); }
public void Save(string path) { if (selectedLandLayer != null) { selectedLandLayer.save(); } saveTopologyLayer(); Terrain terrain = GameObject.FindGameObjectWithTag("Land").GetComponent <Terrain>(); Terrain water = GameObject.FindGameObjectWithTag("Water").GetComponent <Terrain>(); if (water == null) { Debug.LogError("Water object is not enabled"); } if (terrain == null) { Debug.LogError("Land object is not enabled"); } WorldSerialization world = WorldConverter.terrainToWorld(terrain, water); world.Save(path); //Debug.Log("Map hash: " + world.Checksum); }
public void Load(WorldSerialization blob) { if (topology == null) { topology = GameObject.FindGameObjectWithTag("Topology").GetComponent <TopologyMesh>(); } Debug.Log("Map hash: " + blob.Checksum); cleanUpMap(); var terrainSize = new Vector3(blob.world.size, 1000, blob.world.size); var terrainPosition = 0.5f * terrainSize; LandData groundLandData = GameObject.FindGameObjectWithTag("Land").transform.Find("Ground").GetComponent <LandData>(); LandData biomeLandData = GameObject.FindGameObjectWithTag("Land").transform.Find("Biome").GetComponent <LandData>(); LandData alphaLandData = GameObject.FindGameObjectWithTag("Land").transform.Find("Alpha").GetComponent <LandData>(); LandData topologyLandData = GameObject.FindGameObjectWithTag("Land").transform.Find("Topology").GetComponent <LandData>(); Terrain land = GameObject.FindGameObjectWithTag("Land").GetComponent <Terrain>(); Terrain water = GameObject.FindGameObjectWithTag("Water").GetComponent <Terrain>(); TopologyMesh topography = GameObject.FindGameObjectWithTag("Topology").GetComponent <TopologyMesh>(); WorldConverter.MapInfo terrains = WorldConverter.worldToTerrain(blob); topography.InitMesh(terrains.topology); land.terrainData.heightmapResolution = terrains.resolution; land.terrainData.size = terrains.size; water.terrainData.heightmapResolution = terrains.resolution; water.terrainData.size = terrains.size; land.terrainData.SetHeights(0, 0, terrains.land.heights); water.terrainData.SetHeights(0, 0, terrains.water.heights); land.terrainData.alphamapResolution = terrains.resolution; //land.terrainData.baseMapResolution = terrains.resolution; //land.terrainData.SetDetailResolution(terrains.resolution,8); land.terrainData.size = terrains.size; groundLandData.setData(terrains.splatMap, "ground"); biomeLandData.setData(terrains.biomeMap, "biome"); alphaLandData.setData(terrains.alphaMap, "alpha"); topologyLandData.setData(topology.getSplatMap((int)topologyLayer), "topology"); changeLandLayer(); Transform prefabsParent = GameObject.FindGameObjectWithTag("Prefabs").transform; GameObject defaultObj = Resources.Load <GameObject>("Prefabs/DefaultPrefab"); for (int i = 0; i < terrains.prefabData.Length; i++) { GameObject newObj = spawnPrefab(defaultObj, terrains.prefabData[i], prefabsParent); newObj.GetComponent <PrefabDataHolder>().prefabData = terrains.prefabData[i]; } Transform pathsParent = GameObject.FindGameObjectWithTag("Paths").transform; GameObject pathObj = Resources.Load <GameObject>("Paths/Path"); for (int i = 0; i < terrains.pathData.Length; i++) { Vector3 averageLocation = Vector3.zero; for (int j = 0; j < terrains.pathData[i].nodes.Length; j++) { averageLocation += terrains.pathData[i].nodes[j]; } averageLocation /= terrains.pathData[i].nodes.Length; GameObject newObject = Instantiate(pathObj, averageLocation + terrainPosition, Quaternion.identity, pathsParent); newObject.GetComponent <PathDataHolder>().pathData = terrains.pathData[i]; newObject.GetComponent <PathDataHolder>().offset = terrainPosition; } }
// Update is called once per frame void Update() { transform.position = WorldConverter.Convert2DMapToSpherePosition(worldSphereTransform, mCurrPosition, camera2D); mCurrPosition += mDirection * Time.deltaTime * cMovementSpeed - playerObject.GetComponent <CharacterController2D>().mMovementThisFrame; }
// Update is called once per frame void Update() { transform.position = WorldConverter.Convert2DMapToSpherePosition(worldSphereTransform, mCurrPosition, camera2D); transform.rotation = WorldConverter.Convert2DMapToSphereRotation(worldSphereTransform, mCurrPosition, camera2D); }