public void Init() { UnityCppBindings.Init(32); MapGeneratorData data = new MapGeneratorData() { seed = Random.Range(0, 100), H = 10, I = 5, singleMapSize = 65, /*64+1,1 for same edge line*/ worldMapSize = 1, //only support 1 splatWidth = 65, splatCount = 2, height0 = 500, height1 = 300, height2 = 800, height3 = 240, flags = 0 }; _data = data; WorldMapBindings_InitilizeWorldMap(data, Application.dataPath + "/../Map"); WorldMapBindings_SetGenerateCallBack(OnMapGenerateSuccess); /* if ((data.flags & 0x3) == 1) * { * ThreadStart start = new ThreadStart(Runner); * workThread = new Thread(start); * workThread.Start(); * } * else if ((data.flags & 0x3) == 2) * WorldMapBindings_WorkThreadRunner();*/ // Debug.LogFormat("WorldMapBindings_WorkThreadRunner exit"); //Runner(); }
public void Destroy() { Debug.LogFormat("WorldMapBindings_StopGeneration"); WorldMapBindings_StopGeneration(); Debug.LogFormat("WorldMapBindings_Destroy"); WorldMapBindings_Destroy(); UnityCppBindings.Clear(); Debug.LogFormat("over"); }
public unsafe TerrainPiece(uint ins, int heightMapWidth) { terrainInstance = ins; UnityCppBindings.RegistBinding(terrainInstance, this); _heightMap = UnityCppBindings.GetHeightMapCache(); _splatMap = new float[splatMapSize, splatMapSize, splatCount]; //StartGenerateOrLoad(meshInstanceId); if (null == texture2s[0]) { texture2s[0] = Resources.Load <Texture2D>("Realistic Terrain Collection/Other/Textures/ForestFloor2/forest_floor_2"); texture2s[1] = Resources.Load <Texture2D>("Realistic Terrain Collection/Other/Textures/ForestFloor2/forest_floor_2_normal"); texture2s[2] = Resources.Load <Texture2D>("Realistic Terrain Collection/Other/Textures/SolidRock2/solid_rock_2"); texture2s[3] = Resources.Load <Texture2D>("Realistic Terrain Collection/Other/Textures/SolidRock2/solid_rock_2_normal"); } }
private static bool OnMapGenerateSuccess(uint terrain, uint width, Vector4 location) { Debug.LogFormat("OnMapGenerateSuccess {0} {1},exist {2}", terrain, location, UnityCppBindings.GetTerrain(terrain) != null); var terr = UnityCppBindings.GetTerrain(terrain); if (null != terr) { return(false); } else { terr = new TerrainPiece(terrain, (int)width); return(terr.TerrainInitilizer(width, location)); } }
private void SetNeighbors(TerrainNeighbor ignoreNeighbor = TerrainNeighbor.neighborTotal) { for (TerrainNeighbor n = TerrainNeighbor.neighborPositionLeft; n <= TerrainNeighbor.neighborPositionTop; n++) { uint terr = WorldMapBindings_GetNeighbor(instaneId, (int)n); var t = UnityCppBindings.GetTerrain(terr); SetNeighbor(t, n); //prevent dead loop if (null != t && n != ignoreNeighbor) { t.SetNeighbors((TerrainNeighbor)((int)(n + 2) % (int)TerrainNeighbor.neighborTotal)); } } terrain.SetNeighbors(GetNeighbor(TerrainNeighbor.neighborPositionLeft), GetNeighbor(TerrainNeighbor.neighborPositionTop), GetNeighbor(TerrainNeighbor.neighborPositionRight), GetNeighbor(TerrainNeighbor.neighborPositionBottom)); terrain.Flush(); }
internal void Release() { //UnityCppBindings.RecycleCache(_heightMap); UnityCppBindings.UnResistBinding(terrainInstance); terrainInstance = 0; }