private void search() { searDefine(); Dictionary <Color, int> result = new Dictionary <Color, int>(); if (kProvinceMap == null) { return; } var width = kProvinceMap.width; var height = kProvinceMap.height; LC_Helper.Loop(width, (i) => { LC_Helper.Loop(height, (j) => { var col = kProvinceMap.GetPixel(i, j); var count = 0; if (result.TryGetValue(col, out count)) { result[col] = count + 1; } else { result.Add(col, 1); } }); }); kProvinceCount = result.Count; kProvinceData = new ProvinceData[ConfigParam.MAXProvinceCount]; int flag = 0; foreach (var colcount in result) { var col = colcount.Key; kProvinceColorToIDMap.TryGetValue(col, out flag); kProvinceData[flag] = new ProvinceData(flag, col); } kProvincePolitimap = new Texture2D(ConfigParam.BLOCKMAXWIDTH, ConfigParam.BLOCKMAXHEIGHT); Graphics.ConvertTexture(kProvinceMap, kProvincePolitimap); //DebugProvinceCol(); ChangeProvinceColor(); }
public IEnumerator GenRiverIE() { if (kRiverMap != null) { var xsize = (int)kRiverMap.width; var zsize = (int)kRiverMap.height; bool[][] Gened = new bool[xsize][]; ObjectPool <RiverData> pool = new ObjectPool <RiverData>(); LC_Helper.Loop(xsize, (i) => { Gened[i] = new bool[zsize]; LC_Helper.Loop(zsize, (j) => { Gened[i][j] = false; RiverData.SearMap(kRiverMap.GetPixel(i, j)); }); }); for (int i = 0, iMax = xsize; i < iMax; ++i) { Exi = i; for (int j = 0, jMax = zsize; j < jMax; ++j) { bool hasmarked = Gened[i][j]; if (hasmarked) { continue; } var tex = kRiverMap.GetPixel(i, j); if (RiverData.isRiverTex(tex)) { Vector3 pos = new Vector3(i, 0, j); var newRiver = pool.New(); newRiver.PointGenRiver(pos, kRiverMap, Gened, rivers.Count); rivers.Add(newRiver); } RiverCount = rivers.Count; yield return(null); } } } yield break; }
private void searDefine() { var path = Application.dataPath; var searpath = Path.Combine(path, "Map/definition.csv"); kProvinceColorToIDMap.Clear(); if (File.Exists(searpath)) { var data = OpenCSV(searpath); var provincetoken = data.FindToken("province"); var redtoken = data.FindToken("red"); var greentoken = data.FindToken("green"); var bluetoken = data.FindToken("blue"); int tempint = 0; LC_Helper.Loop(data.data.Count, (i) => { var pid = data.FindDataAtIndexWithToken(i, provincetoken); var red = data.FindDataAtIndexWithToken(i, redtoken); var green = data.FindDataAtIndexWithToken(i, greentoken); var blue = data.FindDataAtIndexWithToken(i, bluetoken); int.TryParse(red, out tempint); var tempr = (float)tempint / 255f; int.TryParse(green, out tempint); var tempg = (float)tempint / 255f; int.TryParse(blue, out tempint); var tempb = (float)tempint / 255f; int.TryParse(pid, out tempint); Color nColor = new Color(tempr, tempg, tempb, 1); var id = -1; if (kProvinceColorToIDMap.TryGetValue(nColor, out id)) { //Debug.Log("has id " + id); } else { kProvinceColorToIDMap.Add(nColor, tempint); } }); } }
private void Awake() { var objtar = kcell.gameObject; var transformcache = this.transform; cells = new TerrainCell[ConfigParam.BLOCKWIDTHCOUNT * ConfigParam.BLOCKHEIGHTCOUNT]; LC_Helper.DoubleLoop(ConfigParam.BLOCKWIDTHCOUNT, ConfigParam.BLOCKHEIGHTCOUNT, (i, j) => { var ins = GameObject.Instantiate(objtar, transformcache); var cell = ins.GetComponent <TerrainCell>(); ins.name = objtar.name + string.Format("({0},{1})", i, j); cells[i * ConfigParam.BLOCKHEIGHTCOUNT + j] = cell; cell.Gen(i, j); cell.Apply(); }); }
public void DebugProvinceCol() { LC_Helper.Loop(kProvinceData.Length, (i) => { var data = kProvinceData[i]; if (data.ID % 2 == 0) { data.kShowColor = Color.white; data.kShowColor.a = 1; } else { data.kShowColor = Color.black; data.kShowColor.a = 0; } }); }
public static void LoadAssembly(byte[] dll_data, byte[] pdb_data = null) { if (dll_data == null || dll_data.Length == 0) { Debug.LogError("== LoadAssembly parameter is null =="); return; } //首先实例化ILRuntime的AppDomain,AppDomain是一个应用程序域,每个AppDomain都是一个独立的沙盒 if (null == _appdomain) { _appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); //TODO For Debug //_appdomain.DebugService.StartDebugService(56000); LC_AdaptorHelper.Init(_appdomain); LC_Helper.Init(_appdomain); SetupCLRRedirection(); SetupCLRRedirection2(); CLRBindings.Initialize(_appdomain); #if UNITY_EDITOR // _appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; //Debug.Log("m_pcAppDomain.UnityMainThreadID:" + _appdomain.UnityMainThreadID); #endif } using (var fs = new MemoryStream(dll_data)) { MemoryStream p = null; if (pdb_data != null) { p = new MemoryStream(pdb_data); } _appdomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider()); } }
public void ChangeProvinceColor() { var width = kProvinceMap.width; var height = kProvinceMap.height; LC_Helper.Loop(width, (i) => { LC_Helper.Loop(height, (j) => { var col = kProvinceMap.GetPixel(i, j); var pdata = GetProvinceData(col); if (pdata != null) { kProvincePolitimap.SetPixel(i, j, pdata.kShowColor); } }); }); kProvincePolitimap.Apply(); Graphics.Blit(kProvincePolitimap, kProvinceColorMap); }
public void Gen() { vertices = new List <Vector3>(); colors = new List <Color>(); uvs = new List <Vector2>(); triangles = new List <int>(); int halfwidth = ConfigParam.BLOCKMAXWIDTH / 2; int halfheight = ConfigParam.BLOCKMAXHEIGHT / 2; this.transform.localPosition = new Vector3(halfwidth, ConfigParam.Water_Height, halfheight); Vector3 leftdown = new Vector3(-halfwidth, 0, -halfheight); Vector3 leftup = new Vector3(-halfwidth, 0, halfheight); LC_Helper.Loop(4, (index) => { bool left = index < 2; bool down = index == 0 || index == 3; int leftm = left ? -1 : 1; int downm = down ? -1 : 1; Vector3 a = new Vector3(leftm * halfwidth, 0, downm * halfheight); vertices.Add(a); }); triangles.Add(0); triangles.Add(1); triangles.Add(2); triangles.Add(2); triangles.Add(3); triangles.Add(0); Apply(); }
private void GenFromCenter(List <Vector3> kCenterPoints) { List <Vector3> Modifyer = new List <Vector3>(); LC_Helper.Loop(kCenterPoints.Count, (i) => { var tar = kCenterPoints[i]; Modifyer.Add(new Vector3(tar.x, tar.y, tar.z)); }); for (int i = 1, iMax = kCenterPoints.Count; i < iMax; ++i) { var target = kCenterPoints[i]; var preindex = i - 1; var pre = kCenterPoints[i - 1]; var deltax = target.x - pre.x; var deltaz = target.z - pre.z; for (int j = preindex; j >= 0; --j) { deltax *= kxModify; deltaz *= kzModify; var temptarget = Modifyer[j]; temptarget.x += deltax; temptarget.z += deltaz; Modifyer[j] = new Vector3(temptarget.x, temptarget.y, temptarget.z); } } for (int i = 0, iMax = Modifyer.Count - 1; i < iMax; ++i) { var target = Modifyer[i]; var next = Modifyer[i + 1]; var curupdir = NorDir(i, Modifyer); var nextdir = NorDir(i + 1, Modifyer); if (curupdir.magnitude < 0.99 || nextdir.magnitude < 0.99) { Debug.Log("Error Dir"); } if (Vector3.Dot(curupdir, nextdir) < 0) { var zero = target + curupdir * 0.5f; var one = target - curupdir * 0.5f; var second = next - nextdir * 0.5f; var third = next + nextdir * 0.5f; var dirone = second - one; var dirtwo = third - zero; zero = ModifyVector(zero); one = ModifyVector(one); second = ModifyVector(second); third = ModifyVector(third); if (Vector3.Dot(Vector3.Cross(dirone, dirtwo), Vector3.up) < 0) { vertices.Add(one); vertices.Add(zero); vertices.Add(third); vertices.Add(second); } else { vertices.Add(zero); vertices.Add(one); vertices.Add(second); vertices.Add(third); } } else { var zero = target + curupdir * 0.5f; var one = target - curupdir * 0.5f; var second = next + nextdir * 0.5f; var third = next - nextdir * 0.5f; zero = ModifyVector(zero); one = ModifyVector(one); second = ModifyVector(second); third = ModifyVector(third); var dirone = second - one; var dirtwo = third - zero; if (Vector3.Dot(Vector3.Cross(dirone, dirtwo), Vector3.up) < 0) { vertices.Add(one); vertices.Add(zero); vertices.Add(third); vertices.Add(second); } else { vertices.Add(zero); vertices.Add(one); vertices.Add(second); vertices.Add(third); } } triangles.Add(verticesOffset + 0); triangles.Add(verticesOffset + 2); triangles.Add(verticesOffset + 3); triangles.Add(verticesOffset + 3); triangles.Add(verticesOffset + 1); triangles.Add(verticesOffset + 0); verticesOffset += 4; } ; }
public void Gen(int BlockCountx, int BlockCountz) { vertices = new List <Vector3>(); colors = new List <Color>(); uvs = new List <Vector2>(); triangles = new List <int>(); var xBase = ConfigParam.PERBLOCKNUMBERSIZE * BlockCountx; var zBase = ConfigParam.PERBLOCKNUMBERSIZE * BlockCountz; var heightx = ConfigParam.PERBLOCKCOUNT * BlockCountx; var heightz = ConfigParam.PERBLOCKCOUNT * BlockCountz; this.transform.localPosition = new Vector3(xBase, 0, zBase); //vertice; //ConfigParam.PERBLOCKCOUNT cell //ConfigParam.PERBLOCKCOUNT + 1 vertices; LC_Helper.DoubleLoop(ConfigParam.PERBLOCKCOUNTEX + 1, ConfigParam.PERBLOCKCOUNTEX + 1, (i, j) => { float x = i * ConfigParam.PERBLOCKWORLDSIZE; // + xBase; float z = j * ConfigParam.PERBLOCKWORLDSIZE; //+ zBase; float xx = heightx + ConfigParam.PERBLOCKUVSIZE * i; float zz = heightz + ConfigParam.PERBLOCKUVSIZE * j; // int xx = (int)(heightx + ConfigParam.PERBLOCKUVSIZE * i); // int zz = (int)(heightz + ConfigParam.PERBLOCKUVSIZE * j); //float y = GetHeight(xx, zz) * ConfigParam.BLOCKHEIGHT; float y = GetHeight(xx, zz) * ConfigParam.BLOCKHEIGHT; var temp = new Vector3(x, y, z); //kHeightMap.GetPixel(indexi, indexi); vertices.Add(temp); colors.Add(Color.white); uvs.Add(GetUV(xx, zz)); }); //triangles; LC_Helper.DoubleLoop(ConfigParam.PERBLOCKCOUNTEX, ConfigParam.PERBLOCKCOUNTEX, (i, j) => { //PerCount = ConfigParam.PERBLOCKCOUNT + 1; //LeftTop = i * PerCount + j //RightTop = i * PerCount + j + i //LeftDown = ( i + 1 ) * PerCount + j; //RightDown = ( i + 1 ) * PerCount + j + 1; int PerCount = ConfigParam.PERBLOCKCOUNTEX + 1; var LeftTop = i * PerCount + j; var RightTop = LeftTop + 1; var LeftDown = (i + 1) * PerCount + j; var RightDown = LeftDown + 1; triangles.Add(LeftTop); triangles.Add(RightDown); triangles.Add(LeftDown); triangles.Add(LeftTop); triangles.Add(RightTop); triangles.Add(RightDown); }); }