private void btnAdd_Click(object sender, EventArgs e) { txtOutput.Clear(); MAP m; if (!dataContext.MAP.Any()) { m = new MAP() { NAME = "New map", DESCRIPTION = "Map of doom" }; dataContext.AddToMAP(m); } else { m = dataContext.MAP.First(); } HEX lastHex = (from h in dataContext.HEX select h).OrderByDescending(h => h.Y).FirstOrDefault(); HEX newHex = new HEX() { TERRAIN_ID = 1, HEIGHT = 0 }; if (lastHex == null) { newHex.X = 0; newHex.Y = 0; } else { newHex.X = 0; newHex.Y = lastHex.Y + 1; } m.HEXES.Add(newHex); dataContext.SaveChanges(); txtOutput.AppendText("Hex " + newHex.ID + " added"); }
void GenMeshWithBound(HEX _hex) { if (tri_ver == null) { tri_ver = new Vector3[] { new Vector3(_bound.min.x, _bound.min.y, 0), new Vector3(_bound.max.x, _bound.min.y, 0), new Vector3(_bound.min.x, _bound.max.y, 0), new Vector3(_bound.max.x, _bound.max.y, 0) }; } mPlan = new Mesh(); mPlan.vertices = tri_ver; mPlan.triangles = tri_idx; mPlan.colors = null; mPlan.tangents = null; mPlan.uv = null; mPlan.bounds = _bound; //计算法线 mPlan.RecalculateNormals(); MeshFilter mf = gameObject.GetComponent <MeshFilter>(); if (mf == null) { mf = gameObject.AddComponent <MeshFilter>(); } mf.sharedMesh = mPlan; MeshRenderer mr = gameObject.GetComponent <MeshRenderer>(); if (mr == null) { mr = gameObject.AddComponent <MeshRenderer>(); } mr.sharedMaterial = _hex.GetTerrainBlendMat(); //UpdateBlock(); //mr.SetPropertyBlock(_block); //_weak_mat = new WeakReference(mr.material); //_weak_mesh = new WeakReference(mf.mesh); //BoxCollider pb = gameObject.AddComponent<BoxCollider>(); //pb.center = _bound.center; //pb.size = _bound.size; }
static BigInteger ToBigInteger(string value, int @base) { const string HEX = "0123456789ABCDEF"; if (@base < 1 || @base > HEX.Length) { throw new ArgumentException("Base is out of range."); } BigInteger bi = BigInteger.Zero; foreach (char c in value) { char c2 = Char.ToUpper(c); int idx = HEX.IndexOf(c2); if (idx == -1 || idx >= @base) { throw new ArgumentOutOfRangeException("Illegal character encountered."); } bi = bi * @base + idx; } return(bi); }
public static HSL HexToHsl(HEX hex) { var rgb = HexToRgb(hex); return(RgbToHsl(rgb)); }
public static CMYK HexToCmyk(HEX hex) { var rgb = HexToRgb(hex); return(RgbToCmyk(rgb)); }
public static bool Equals(HSV source, HEX target) { return(source.Equals(ColorConverter.HexToHsv(target))); }
public static bool Equals(RGB source, HEX target) { return(source.Equals(ColorConverter.HexToRgb(target))); }
void GenHexMesh(HEX _hex) { MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); Vector3[] hexgon = { #if HEXGON0 new Vector3(0, 0, 0), // 0 #endif new Vector3(0, +1, 0), // 1 new Vector3(+Tx, +Ty, 0), // 2 new Vector3(+Tx, -Ty, 0), // 3 new Vector3(0, -1, 0), // 4 new Vector3(-Tx, -Ty, 0), // 5 new Vector3(-Tx, +Ty, 0), // 6 }; Vector2[] water = { new Vector2(0, 0), new Vector2(1, 0), }; Color[] sc = { new Color(0, 0, 0, 0), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0), new Color(0, 0, 0, 1), }; Vector4[] vc = { new Vector4(0, 0, 0, 0), new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1), }; int siz = (_hex.yTile + 1) * (_hex.yTile + 1) * 8; if (lst == null) { lst = new int[siz]; } for (int i = 0; i < siz; i++) { lst[i] = -1; } element e = new element(); _reindex_Blend reindex_Blend = (ref element _elm, int _ver, int _col, int _row, Color BlendColor, Vector4 BlendTangent) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); int loc = ((_row + 1) * (_hex.xTile + 1) + (_col + 1)) * 8 + _ver; int idx = lst[loc]; //if (idx >= 0) // return idx; idx = _elm.vHex.Count; lst[loc] = idx; Vector3 _v = Vector3.zero; Vector3 _n = Vector3.zero; Vector4 _t = Vector4.zero; Vector2 _u = Vector2.zero; Color _c; float _R = Tx * 2.0f + _hex.fvHex.x; int m = tileVo.mat; int n = isGenHeight ? tileVo.height : MapConst.MAP_HEIGHT_HORIZON; if (m == 8) { _c = sc[0]; _t = vc[0]; } else { _c = sc[m <= 3 ? m + 1 : 0]; _t = vc[m >= 4 ? m - 3 : 0]; } _v.x = _R * _col; _v.y = _R * Tx * _row; _v.z = n; _n.z = m; if (_row % 2 == 0) { _v.x += 0.0f; } else { _v.x += Tx + Ty * _hex.fvHex.x; } _elm.vHex.Add(hexgon[_ver] + _v); _elm.vNor.Add(_n); _elm.vClr.Add(BlendColor); _elm.vTan.Add(BlendTangent); _elm.vTex.Add(_u); return(idx); }; _recheck recheck = (int _ver, int _col, int _row) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); //if (tileVo.mat < 1) if (tileVo.IsWater()) { return(false); } return(true); }; int nHexIndices, nIndexOffset; #if HEXGON0 int[] tdx = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 1, }; nHexIndices = 18; nIndexOffset = 0; #else int[] tdx = { 0, 1, 5, 5, 1, 4, 2, 4, 1, 3, 4, 2 }; nHexIndices = 12; nIndexOffset = 1; #endif int[][] edx = { new int[] { 6, 5, 2, 3, 2, 5 }, new int[] { 5, 4, 1, 2, 1, 4 }, new int[] { 1, 6, 3, 4, 3, 6 }, new int[] { 6, 2, 4, 5, 1, 3 }, }; List <int> vIdx = new List <int>(); List <int> vSub = new List <int>(); List <int> vBld = new List <int>(); bool pass = true; Color C1000 = new Color(1, 0, 0, 0); Color C0000 = new Color(0, 0, 0, 0); Color C0001 = new Color(0, 0, 0, 1); Color C0010 = new Color(0, 0, 1, 0); Color C0100 = new Color(0, 1, 0, 0); Color C1010 = new Color(1, 0, 1, 0); Color C0110 = new Color(0, 1, 1, 0); Color C1111 = new Color(1, 1, 1, 1); for (int y = 0; y < _yTile; y++) { for (int x = 0; x < _xTile; x++) { /*if (!(_x == 1 && _y == 0 && x == 0 && (y >= 11 && y < 15))) * { * continue; * }*/ /*if (!(_x == 1 && _y == 1 && x == 0 && (y >= 1 && y < 5))) * { * continue; * }*/ int thisCoordX = x + _xTile * _x; int thisCoordY = y + _yTile * _y; int thisMatNameInd = GetMatNameInd(thisCoordX, thisCoordY, -1); // west -> x-1 // south west -> odd : x, y-1 even: x-1, y-1 // south -> odd: x+1, y-1 even: x, y-1 int t = y % 2; int ww = x - 1; // y int sw = t > 0 ? x : x - 1; // y-1 int nw = t > 0 ? x : x - 1; // y+1 if (IsValid(ww, y)) { // block 4 int neighbor4MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 4); Vector4 tangent = new Vector4(thisMatNameInd * 0.1f, neighbor4MatNameInd * 0.1f, -1, -1); pass = true; pass &= recheck(edx[0][0] - nIndexOffset, x, y); pass &= recheck(edx[0][1] - nIndexOffset, x, y); pass &= recheck(edx[0][2] - nIndexOffset, ww, y); bool bBld = false; if (x == 0) { bBld = true; } if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[0][0] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[0][1] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[0][2] - nIndexOffset, ww, y, C0100, tangent)); } pass = true; pass &= recheck(edx[0][3] - nIndexOffset, ww, y); pass &= recheck(edx[0][4] - nIndexOffset, ww, y); pass &= recheck(edx[0][5] - nIndexOffset, x, y); if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[0][3] - nIndexOffset, ww, y, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[0][4] - nIndexOffset, ww, y, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[0][5] - nIndexOffset, x, y, C1000, tangent)); } // tri 4 int neighbor5MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 5); tangent = new Vector4(thisMatNameInd * 0.1f, neighbor4MatNameInd * 0.1f, neighbor5MatNameInd * 0.1f, -1); if (IsValid(nw, y + 1)) { pass = true; pass &= recheck(edx[3][0] - nIndexOffset, x, y); pass &= recheck(edx[3][1] - nIndexOffset, ww, y); pass &= recheck(edx[3][2] - nIndexOffset, nw, y + 1); if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[3][0] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[3][1] - nIndexOffset, ww, y, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[3][2] - nIndexOffset, nw, y + 1, C0010, tangent)); } } // tri 3 int neighbor3MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 3); tangent = new Vector4(thisMatNameInd * 0.1f, neighbor3MatNameInd * 0.1f, neighbor4MatNameInd * 0.1f, -1); if (IsValid(sw, y - 1)) { pass = true; pass &= recheck(edx[3][3] - nIndexOffset, x, y); pass &= recheck(edx[3][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[3][5] - nIndexOffset, ww, y); if (pass == true && bBld) { if (x == 0 && y == 0) { // diag tri 3 } else { vBld.Add(reindex_Blend(ref e, edx[3][3] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[3][4] - nIndexOffset, sw, y - 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[3][5] - nIndexOffset, ww, y, C0010, tangent)); } } } } if (IsValid(sw, y - 1)) { // block 3 int neighbor3MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 3); Vector4 tangent = new Vector4(thisMatNameInd * 0.1f, neighbor3MatNameInd * 0.1f, -1, -1); bool bBld = false; if (x == 0 && y % 2 == 0) { bBld = true; } pass = true; pass &= recheck(edx[1][0] - nIndexOffset, x, y); pass &= recheck(edx[1][1] - nIndexOffset, x, y); pass &= recheck(edx[1][2] - nIndexOffset, sw, y - 1); if (pass == true && bBld) { if (x == 0 && y == 0) { // diag block 3 } else { vBld.Add(reindex_Blend(ref e, edx[1][0] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[1][1] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[1][2] - nIndexOffset, sw, y - 1, C0100, tangent)); } } pass = true; pass &= recheck(edx[1][3] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][5] - nIndexOffset, x, y); if (pass == true && bBld) { if (x == 0 && y == 0) { // diag block 3 } else { vBld.Add(reindex_Blend(ref e, edx[1][3] - nIndexOffset, sw, y - 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[1][4] - nIndexOffset, sw, y - 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[1][5] - nIndexOffset, x, y, C1000, tangent)); } } } if (IsValid(nw, y + 1)) { // block 5 int neighbor5MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 5); Vector4 tangent = new Vector4(thisMatNameInd * 0.1f, neighbor5MatNameInd * 0.1f, -1, -1); bool bBld = false; if (x == 0 && y % 2 == 0) { bBld = true; } pass = true; pass &= recheck(edx[2][0] - nIndexOffset, x, y); pass &= recheck(edx[2][1] - nIndexOffset, x, y); pass &= recheck(edx[2][2] - nIndexOffset, nw, y + 1); if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[2][0] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[2][1] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[2][2] - nIndexOffset, nw, y + 1, C0100, tangent)); } pass = true; pass &= recheck(edx[2][3] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][4] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][5] - nIndexOffset, x, y); if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[2][3] - nIndexOffset, nw, y + 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[2][4] - nIndexOffset, nw, y + 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[2][5] - nIndexOffset, x, y, C1000, tangent)); } } } } Mesh me = new Mesh(); me.subMeshCount = 1; me.vertices = e.vHex.ToArray(); //me.SetTriangles(vIdx.ToArray(), 0); //me.SetTriangles(vSub.ToArray(), 1); me.SetTriangles(vBld.ToArray(), 0); me.normals = e.vNor.ToArray(); me.colors = e.vClr.ToArray(); me.tangents = e.vTan.ToArray(); me.uv = e.vTex.ToArray(); me.bounds = _bound; var mf = gameObject.GetComponent <MeshFilter>(); if (mf == null) { mf = gameObject.AddComponent <MeshFilter>(); } mf.sharedMesh = me; var mr = gameObject.GetComponent <MeshRenderer>(); if (mr == null) { mr = gameObject.AddComponent <MeshRenderer>(); } mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; mr.sharedMaterial = _hex.GetTerrainBlendMat(); //mr.SetPropertyBlock(UpdateBlock()); }
public static bool Equals(HEX source, CMYK target) { return(source.Equals(ColorConverter.CmykToHex(target))); }
public static bool Equals(HEX source, HEX target) { return(source.Equals(target)); }
public static bool Equals(HEX source, RGB target) { return(source.Equals(ColorConverter.RgbToHex(target))); }
public static bool Equals(XYZ source, HEX target) { return(source.Equals(ColorConverter.HexToXyz(target))); }
void GenHexMesh(HEX _hex) { MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); Vector3[] hexgon = { #if HEXGON0 new Vector3(0, 0, 0), // 0 #endif new Vector3(0, +1, 0), // 1 new Vector3(+Tx, +Ty, 0), // 2 new Vector3(+Tx, -Ty, 0), // 3 new Vector3(0, -1, 0), // 4 new Vector3(-Tx, -Ty, 0), // 5 new Vector3(-Tx, +Ty, 0), // 6 }; Vector2[] water = { new Vector2(0, 0), new Vector2(1, 0), }; Color[] sc = { new Color(0, 0, 0, 0), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0), new Color(0, 0, 0, 1), }; Vector4[] vc = { new Vector4(0, 0, 0, 0), new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1), }; int siz = (_hex.yTile + 1) * (_hex.yTile + 1) * 8; if (lst == null) { lst = new int[siz]; } for (int i = 0; i < siz; i++) { lst[i] = -1; } element e = new element(); _reindex reindex = (ref element _elm, int _ver, int _col, int _row, float tmpindex, Vector2 uv2) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); int loc = ((_row + 1) * (_hex.xTile + 1) + (_col + 1)) * 8 + _ver; int idx = lst[loc]; //if (idx >= 0) // return idx; idx = _elm.vHex.Count; lst[loc] = idx; Vector3 _v = Vector3.zero; Vector3 _n = Vector3.zero; Vector4 _t = Vector4.zero; Vector2 _u = Vector2.zero; Color _c; float _R = Tx * 2.0f + _hex.fvHex.x; int m = tileVo.mat; /* * // sz test * if(_x==0 && _y==0) * { * m=0; * } * else if(_x==1 && _y==0) * { * m=0; * } * else if(_x==0 && _y==1) * { * m=0; * } * else if(_x==1 && _y==1) * { * m=0; * } * // sz test */ int n = isGenHeight ? tileVo.height : MapConst.MAP_HEIGHT_HORIZON; if (m == 8) { _c = sc[0]; _t = vc[0]; } else { _c = sc[m <= 3 ? m + 1 : 0]; _t = vc[m >= 4 ? m - 3 : 0]; } _v.x = _R * _col; _v.y = _R * Tx * _row; _v.z = n; _n.z = m; if (_row % 2 == 0) { _v.x += 0.0f; } else { _v.x += Tx + Ty * _hex.fvHex.x; } _elm.vHex.Add(hexgon[_ver] + _v); _elm.vNor.Add(_n); _elm.vClr.Add(_c); if (tmpindex < 100) { _t.z = tmpindex; } else { _t.w = (int)tmpindex / 100; _t.z = tmpindex - _t.w * 100; } _elm.vTan.Add(_t); _elm.vTex.Add(_u); _elm.vNorTex.Add(uv2); return(idx); }; _recheck recheck = (int _ver, int _col, int _row) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); //if (tileVo.mat < 1) if (tileVo.IsWater()) { return(false); } return(true); }; int nHexIndices, nIndexOffset; #if HEXGON0 int[] tdx = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 1, }; nHexIndices = 18; nIndexOffset = 0; #else int[] tdx = { 0, 1, 5, 5, 1, 4, 2, 4, 1, 3, 4, 2 }; nHexIndices = 12; nIndexOffset = 1; #endif int[][] edx = { new int[] { 6, 5, 2, 3, 2, 5 }, new int[] { 5, 4, 1, 2, 1, 4 }, new int[] { 1, 6, 3, 4, 3, 6 }, new int[] { 6, 2, 4, 5, 1, 3 }, }; List <int> vIdx = new List <int>(); List <int> vSub = new List <int>(); List <int> vBld = new List <int>(); bool pass = true; Color R = new Color(1, 0, 0, 1); Color G = new Color(0, 1, 0, 1); Color B = new Color(0, 0, 1, 1); Color C1 = new Color(1, 1, 1, 1); Color C0 = new Color(0, 0, 0, 0); Vector4 V1 = new Vector4(1, 1, 1, 1); Vector4 V0 = new Vector4(0, 0, 0, 0); Vector2 uv2_zero = new Vector2(0, 0); /*Vector2 uv2_normal_block0_6 = new Vector2(0.251f, 0.643f); * Vector2 uv2_normal_block0_5 = new Vector2(0.743f, 0.643f); * Vector2 uv2_normal_block0_2 = new Vector2(0.259f, 0.357f); * Vector2 uv2_normal_block0_3 = new Vector2(0.755f, 0.357f); * Vector2 uv2_normal_hex_0 = new Vector2(0.5f, 1.0f); * Vector2 uv2_normal_hex_5 = new Vector2(0.746f, 0.643f); * Vector2 uv2_normal_hex_6 = new Vector2(0.251f, 0.643f); * Vector2 uv2_normal_hex_00 = new Vector2(0.5f, 0.0f); * Vector2 uv2_normal_hex_2 = new Vector2(0.259f, 0.357f); * Vector2 uv2_normal_hex_3 = new Vector2(0.755f, 0.357f); * Vector2 uv2_normal_tri_6 = new Vector2(0.251f, 0.643f); * Vector2 uv2_normal_tri_2 = new Vector2(0.259f, 0.357f); * Vector2 uv2_normal_tri_4 = new Vector2(0.003f, 0.523f); * Vector2 uv2_normal_tri_5 = new Vector2(0.746f, 0.643f); * Vector2 uv2_normal_tri_1 = new Vector2(0.998f, 0.509f); * Vector2 uv2_normal_tri_3 = new Vector2(0.755f, 0.357f);*/ Vector2 uv2_normal_block0_6 = new Vector2(0.324f, 0.670f); Vector2 uv2_normal_block0_5 = new Vector2(0.662f, 0.670f); Vector2 uv2_normal_block0_2 = new Vector2(0.329f, 0.249f); Vector2 uv2_normal_block0_3 = new Vector2(0.668f, 0.250f); Vector2 uv2_normal_hex_0 = new Vector2(0.5f, 1.0f); Vector2 uv2_normal_hex_5 = new Vector2(0.662f, 0.670f); Vector2 uv2_normal_hex_6 = new Vector2(0.324f, 0.670f); Vector2 uv2_normal_hex_00 = new Vector2(0.5f, 0.0f); Vector2 uv2_normal_hex_2 = new Vector2(0.329f, 0.249f); Vector2 uv2_normal_hex_3 = new Vector2(0.668f, 0.250f); Vector2 uv2_normal_tri_6 = new Vector2(0.324f, 0.670f); Vector2 uv2_normal_tri_2 = new Vector2(0.329f, 0.249f); Vector2 uv2_normal_tri_4 = new Vector2(0.154f, 0.494f); Vector2 uv2_normal_tri_5 = new Vector2(0.662f, 0.670f); Vector2 uv2_normal_tri_1 = new Vector2(0.843f, 0.485f); Vector2 uv2_normal_tri_3 = new Vector2(0.668f, 0.250f); /*Vector2 uv2_normal_block0_6 = new Vector2(0.326f, 0.668f); * Vector2 uv2_normal_block0_5 = new Vector2(0.660f, 0.668f); * Vector2 uv2_normal_block0_2 = new Vector2(0.331f, 0.251f); * Vector2 uv2_normal_block0_3 = new Vector2(0.666f, 0.252f); * Vector2 uv2_normal_hex_0 = new Vector2(0.5f, 1.0f); * Vector2 uv2_normal_hex_5 = new Vector2(0.662f, 0.670f); * Vector2 uv2_normal_hex_6 = new Vector2(0.324f, 0.670f); * Vector2 uv2_normal_hex_00 = new Vector2(0.5f, 0.0f); * Vector2 uv2_normal_hex_2 = new Vector2(0.329f, 0.249f); * Vector2 uv2_normal_hex_3 = new Vector2(0.668f, 0.250f); * Vector2 uv2_normal_tri_6 = new Vector2(0.326f, 0.672f); * Vector2 uv2_normal_tri_2 = new Vector2(0.331f, 0.247f); * Vector2 uv2_normal_tri_4 = new Vector2(0.152f, 0.494f); * Vector2 uv2_normal_tri_5 = new Vector2(0.660f, 0.668f); * Vector2 uv2_normal_tri_1 = new Vector2(0.845f, 0.485f); * Vector2 uv2_normal_tri_3 = new Vector2(0.666f, 0.252f);*/ for (int y = 0; y < _yTile; y++) { for (int x = 0; x < _xTile; x++) { /*if(!(x==1 && y==1 || x== && y==1)) * { * continue; * }*/ /*if (_x == 1 && _y == 1 && (x < 11 || y < 6)) * { * continue; * }*/ // get height info int thisCoordX = x + _xTile * _x; int thisCoordY = y + _yTile * _y; Coord c = new Coord(thisCoordX, thisCoordY); int thisHeight = mapProxy.GetTile(c).height; int height_neighbor0 = GetNeighborHeight(thisCoordX, thisCoordY, 0); int height_neighbor1 = GetNeighborHeight(thisCoordX, thisCoordY, 1); int height_neighbor2 = GetNeighborHeight(thisCoordX, thisCoordY, 2); int height_neighbor3 = GetNeighborHeight(thisCoordX, thisCoordY, 3); int height_neighbor4 = GetNeighborHeight(thisCoordX, thisCoordY, 4); int height_neighbor5 = GetNeighborHeight(thisCoordX, thisCoordY, 5); // block5 left Vector2 uv2_hex0_0 = new Vector2(0.0f, 0.5f); Vector2 uv2_hex0_1 = new Vector2(0.375f, 0.211f); Vector2 uv2_hex0_2 = new Vector2(0.375f, 0.785f); // block0 right Vector2 uv2_hex3_0 = new Vector2(1.0f, 0.5f); Vector2 uv2_hex3_4 = new Vector2(0.621f, 0.785f); Vector2 uv2_hex3_5 = new Vector2(0.621f, 0.211f); float[] hex_index1 = { 1.5f, 1.5f, 1.5f, 0.5f, 0.5f, 0.5f, 2.5f, 2.5f, 2.5f, 1.5f, 1.5f, 1.5f, 0.5f, 0.5f, 0.5f, 2.5f, 2.5f, 2.5f, }; Vector2[] hex_index2 = { uv2_hex0_0, uv2_hex0_1, uv2_hex0_1, uv2_hex0_0, uv2_hex0_1, uv2_hex0_1, uv2_hex0_0, uv2_hex0_1, uv2_hex0_1, uv2_hex3_0, uv2_hex3_4, uv2_hex3_5, uv2_hex3_0, uv2_hex3_4, uv2_hex3_5, uv2_hex3_0, uv2_hex3_4, uv2_hex3_5, }; float heightCompare0 = CompareHeight(thisHeight, height_neighbor0); float heightCompare1 = CompareHeight(thisHeight, height_neighbor1); float heightCompare2 = CompareHeight(thisHeight, height_neighbor2); float heightCompare3 = CompareHeight(thisHeight, height_neighbor3); float heightCompare4 = CompareHeight(thisHeight, height_neighbor4); float heightCompare5 = CompareHeight(thisHeight, height_neighbor5); float[] hex_index3 = { thisHeight *100 + heightCompare0, thisHeight *100 + heightCompare0, thisHeight *100 + heightCompare0, thisHeight *100 + heightCompare1, thisHeight *100 + heightCompare1, thisHeight *100 + heightCompare1, thisHeight *100 + heightCompare2, thisHeight *100 + heightCompare2, thisHeight *100 + heightCompare2, thisHeight *100 + heightCompare3, thisHeight *100 + heightCompare3, thisHeight *100 + heightCompare3, thisHeight *100 + heightCompare4, thisHeight *100 + heightCompare4, thisHeight *100 + heightCompare4, thisHeight *100 + heightCompare5, thisHeight *100 + heightCompare5, thisHeight *100 + heightCompare5, }; Vector2[] hex_index4 = { uv2_normal_hex_00, uv2_normal_hex_2, uv2_normal_hex_3, uv2_normal_hex_00, uv2_normal_hex_2, uv2_normal_hex_3, uv2_normal_hex_00, uv2_normal_hex_2, uv2_normal_hex_3, uv2_normal_hex_0, uv2_normal_hex_5, uv2_normal_hex_6, uv2_normal_hex_0, uv2_normal_hex_5, uv2_normal_hex_6, uv2_normal_hex_0, uv2_normal_hex_5, uv2_normal_hex_6, }; // hexgon for (int i = 0; i < nHexIndices; i++) { if (recheck(tdx[i], x, y) == true) { //vIdx.Add(reindex(ref e, tdx[i], x, y, hex_index3[i], hex_index4[i])); vIdx.Add(reindex(ref e, tdx[i], x, y, 4.5f, hex_index4[i])); } } // west -> x-1 // south west -> odd : x, y-1 even: x-1, y-1 // south -> odd: x+1, y-1 even: x, y-1 int t = y % 2; int ww = x - 1; // y int sw = t > 0 ? x : x - 1; // y-1 int nw = t > 0 ? x : x - 1; // y+1 if (IsValid(ww, y)) { Vector2 uv2_block0_6 = new Vector2(0.621f, 0.211f); Vector2 uv2_block0_5 = new Vector2(0.621f, 0.785f); Vector2 uv2_block0_3 = new Vector2(0.375f, 0.785f); Vector2 uv2_block0_2 = new Vector2(0.375f, 0.211f); Vector2 uv2_tri0_6 = new Vector2(0.621f, 0.211f); Vector2 uv2_tri0_2 = new Vector2(0.375f, 0.211f); Vector2 uv2_tri0_4 = new Vector2(0.5f, 0.0f); Vector2 uv2_tri5_5 = new Vector2(0.621f, 0.785f); Vector2 uv2_tri5_1 = new Vector2(0.5f, 1.0f); Vector2 uv2_tri5_3 = new Vector2(0.375f, 0.785f); // block 4 pass = true; pass &= recheck(edx[0][0] - nIndexOffset, x, y); pass &= recheck(edx[0][1] - nIndexOffset, x, y); pass &= recheck(edx[0][2] - nIndexOffset, ww, y); bool bBld = false; if (x == 0 && isBlend) { bBld = true; } if (pass == true && !bBld) { /*vSub.Add( reindex(ref e, edx[0][0] - nIndexOffset, x, y, 0.5f, uv2_block0_6) ); * vSub.Add( reindex(ref e, edx[0][1] - nIndexOffset, x, y, 0.5f, uv2_block0_5) ); * vSub.Add( reindex(ref e, edx[0][2] - nIndexOffset, ww, y, 0.5f, uv2_block0_2) );*/ vSub.Add(reindex(ref e, edx[0][0] - nIndexOffset, x, y, heightCompare4, uv2_normal_block0_6)); vSub.Add(reindex(ref e, edx[0][1] - nIndexOffset, x, y, heightCompare4, uv2_normal_block0_5)); vSub.Add(reindex(ref e, edx[0][2] - nIndexOffset, ww, y, heightCompare4, uv2_normal_block0_2)); } pass = true; pass &= recheck(edx[0][3] - nIndexOffset, ww, y); pass &= recheck(edx[0][4] - nIndexOffset, ww, y); pass &= recheck(edx[0][5] - nIndexOffset, x, y); if (pass == true && !bBld) { /*vSub.Add(reindex(ref e, edx[0][3] - nIndexOffset, ww, y, 0.5f, uv2_block0_3)); * vSub.Add(reindex(ref e, edx[0][4] - nIndexOffset, ww, y, 0.5f, uv2_block0_2)); * vSub.Add(reindex(ref e, edx[0][5] - nIndexOffset, x, y, 0.5f, uv2_block0_5));*/ vSub.Add(reindex(ref e, edx[0][3] - nIndexOffset, ww, y, heightCompare4, uv2_normal_block0_3)); vSub.Add(reindex(ref e, edx[0][4] - nIndexOffset, ww, y, heightCompare4, uv2_normal_block0_2)); vSub.Add(reindex(ref e, edx[0][5] - nIndexOffset, x, y, heightCompare4, uv2_normal_block0_5)); } // tri 4 if (IsValid(nw, y + 1)) { pass = true; pass &= recheck(edx[3][0] - nIndexOffset, x, y); pass &= recheck(edx[3][1] - nIndexOffset, ww, y); pass &= recheck(edx[3][2] - nIndexOffset, nw, y + 1); Vector2 v0_uv = new Vector2(); Vector2 v1_uv = new Vector2(); Vector2 v2_uv = new Vector2(); int heightCompare_type = CompareHeight_Tri0(height_neighbor5, height_neighbor4, thisHeight); float heightCompare_tri0 = 0; switch (heightCompare_type) { case 0: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_3; v1_uv = uv2_normal_tri_5; v2_uv = uv2_normal_tri_1; break; case 1: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_5; v1_uv = uv2_normal_tri_1; v2_uv = uv2_normal_tri_3; break; case 2: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_2; v1_uv = uv2_normal_tri_4; v2_uv = uv2_normal_tri_6; break; case 3: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_6; v1_uv = uv2_normal_tri_2; v2_uv = uv2_normal_tri_4; break; case 4: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_2; v1_uv = uv2_normal_tri_4; v2_uv = uv2_normal_tri_6; break; case 5: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_5; v1_uv = uv2_normal_tri_1; v2_uv = uv2_normal_tri_3; break; default: heightCompare_tri0 = 4.5f; break; } if (pass == true && !bBld) { //if (heightCompare_type == 3) { /*vSub.Add(reindex(ref e, edx[3][0] - nIndexOffset, x, y, 0.5f, uv2_tri0_6)); * vSub.Add(reindex(ref e, edx[3][1] - nIndexOffset, ww, y, 0.5f, uv2_tri0_2)); * vSub.Add(reindex(ref e, edx[3][2] - nIndexOffset, nw, y+1, 0.5f, uv2_tri0_4));*/ vSub.Add(reindex(ref e, edx[3][0] - nIndexOffset, x, y, heightCompare_tri0, v0_uv)); vSub.Add(reindex(ref e, edx[3][1] - nIndexOffset, ww, y, heightCompare_tri0, v2_uv)); vSub.Add(reindex(ref e, edx[3][2] - nIndexOffset, nw, y + 1, heightCompare_tri0, v1_uv)); } } } // tri 3 if (IsValid(sw, y - 1)) { pass = true; pass &= recheck(edx[3][3] - nIndexOffset, x, y); pass &= recheck(edx[3][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[3][5] - nIndexOffset, ww, y); Vector2 v0_uv = new Vector2(); Vector2 v1_uv = new Vector2(); Vector2 v2_uv = new Vector2(); int heightCompare_type = CompareHeight_Tri0(height_neighbor3, thisHeight, height_neighbor4); float heightCompare_tri0 = 0; switch (heightCompare_type) { case 0: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_1; v1_uv = uv2_normal_tri_3; v2_uv = uv2_normal_tri_5; break; case 1: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_5; v1_uv = uv2_normal_tri_1; v2_uv = uv2_normal_tri_3; break; case 2: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_2; v1_uv = uv2_normal_tri_4; v2_uv = uv2_normal_tri_6; break; case 3: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_6; v1_uv = uv2_normal_tri_2; v2_uv = uv2_normal_tri_4; break; case 4: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_2; v1_uv = uv2_normal_tri_4; v2_uv = uv2_normal_tri_6; break; case 5: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_5; v1_uv = uv2_normal_tri_1; v2_uv = uv2_normal_tri_3; break; default: heightCompare_tri0 = 4.5f; break; } if (y == 0 && isBlend) { bBld = true; } float heightCompare_tri5 = 4.5f; if (heightCompare3 != 4.5f) { heightCompare_tri5 = heightCompare3; } if (heightCompare4 != 4.5f) { heightCompare_tri5 = heightCompare4; } if (pass == true && !bBld) { /*vSub.Add(reindex(ref e, edx[3][3] - nIndexOffset, x, y, 0.5f, uv2_tri5_5)); * vSub.Add(reindex(ref e, edx[3][4] - nIndexOffset, sw, y-1, 0.5f, uv2_tri5_1)); * vSub.Add(reindex(ref e, edx[3][5] - nIndexOffset, ww, y, 0.5f, uv2_tri5_3));*/ vSub.Add(reindex(ref e, edx[3][3] - nIndexOffset, x, y, heightCompare_tri5, v0_uv)); vSub.Add(reindex(ref e, edx[3][4] - nIndexOffset, sw, y - 1, heightCompare_tri5, v1_uv)); vSub.Add(reindex(ref e, edx[3][5] - nIndexOffset, ww, y, heightCompare_tri5, v2_uv)); } } } if (IsValid(sw, y - 1)) { Vector2 uv2_block5_5 = new Vector2(0.621f, 0.211f); Vector2 uv2_block5_4 = new Vector2(0.621f, 0.785f); Vector2 uv2_block5_2 = new Vector2(0.375f, 0.785f); Vector2 uv2_block5_1 = new Vector2(0.375f, 0.211f); // block 3 pass = true; pass &= recheck(edx[1][0] - nIndexOffset, x, y); pass &= recheck(edx[1][1] - nIndexOffset, x, y); pass &= recheck(edx[1][2] - nIndexOffset, sw, y - 1); bool bBld = false; if ((x == 0 && y % 2 == 0 || y == 0) && isBlend) { bBld = true; } if (pass == true && !bBld) { vSub.Add(reindex(ref e, edx[1][0] - nIndexOffset, x, y, heightCompare3, uv2_normal_block0_6)); vSub.Add(reindex(ref e, edx[1][1] - nIndexOffset, x, y, heightCompare3, uv2_normal_block0_5)); vSub.Add(reindex(ref e, edx[1][2] - nIndexOffset, sw, y - 1, heightCompare3, uv2_normal_block0_2)); } pass = true; pass &= recheck(edx[1][3] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][5] - nIndexOffset, x, y); if (pass == true && !bBld) { vSub.Add(reindex(ref e, edx[1][3] - nIndexOffset, sw, y - 1, heightCompare3, uv2_normal_block0_3)); vSub.Add(reindex(ref e, edx[1][4] - nIndexOffset, sw, y - 1, heightCompare3, uv2_normal_block0_2)); vSub.Add(reindex(ref e, edx[1][5] - nIndexOffset, x, y, heightCompare3, uv2_normal_block0_5)); } } if (IsValid(nw, y + 1)) { Vector2 uv2_block1_1 = new Vector2(0.621f, 0.211f); Vector2 uv2_block1_6 = new Vector2(0.621f, 0.785f); Vector2 uv2_block1_4 = new Vector2(0.375f, 0.785f); Vector2 uv2_block1_3 = new Vector2(0.375f, 0.211f); // block 5 pass = true; pass &= recheck(edx[2][0] - nIndexOffset, x, y); pass &= recheck(edx[2][1] - nIndexOffset, x, y); pass &= recheck(edx[2][2] - nIndexOffset, nw, y + 1); bool bBld = false; if (x == 0 && y % 2 == 0 && isBlend) { bBld = true; } if (pass == true && !bBld) { vSub.Add(reindex(ref e, edx[2][0] - nIndexOffset, x, y, heightCompare5, uv2_normal_block0_6)); vSub.Add(reindex(ref e, edx[2][1] - nIndexOffset, x, y, heightCompare5, uv2_normal_block0_5)); vSub.Add(reindex(ref e, edx[2][2] - nIndexOffset, nw, y + 1, heightCompare5, uv2_normal_block0_2)); } pass = true; pass &= recheck(edx[2][3] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][4] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][5] - nIndexOffset, x, y); if (pass == true && !bBld) { vSub.Add(reindex(ref e, edx[2][3] - nIndexOffset, nw, y + 1, heightCompare5, uv2_normal_block0_3)); vSub.Add(reindex(ref e, edx[2][4] - nIndexOffset, nw, y + 1, heightCompare5, uv2_normal_block0_2)); vSub.Add(reindex(ref e, edx[2][5] - nIndexOffset, x, y, heightCompare5, uv2_normal_block0_5)); } } } } Mesh me = new Mesh(); me.subMeshCount = 3; me.vertices = e.vHex.ToArray(); me.SetTriangles(vIdx.ToArray(), 0); me.SetTriangles(vSub.ToArray(), 1); me.SetTriangles(vBld.ToArray(), 2); me.normals = e.vNor.ToArray(); me.colors = e.vClr.ToArray(); me.tangents = e.vTan.ToArray(); me.uv = e.vTex.ToArray(); me.uv2 = e.vNorTex.ToArray(); me.bounds = _bound; var mf = gameObject.GetComponent <MeshFilter>(); if (mf == null) { mf = gameObject.AddComponent <MeshFilter>(); } mf.sharedMesh = me; var mr = gameObject.GetComponent <MeshRenderer>(); if (mr == null) { mr = gameObject.AddComponent <MeshRenderer>(); } mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; mr.sharedMaterials = _hex.GetTerrainMats(); //mr.SetPropertyBlock(UpdateBlock()); }
public static RGB HEX2RGB(HEX hex) { string r = (hex.Value[0].ToString() + hex.Value[1].ToString()); string g = (hex.Value[2].ToString() + hex.Value[3].ToString()); string b = (hex.Value[4].ToString() + hex.Value[5].ToString()); int R = int.Parse(r, System.Globalization.NumberStyles.HexNumber); int G = int.Parse(g, System.Globalization.NumberStyles.HexNumber); int B = int.Parse(b, System.Globalization.NumberStyles.HexNumber); return new RGB(R, G, B); }
private void ImpBtn_Click(object sender, EventArgs e) { String FName = ""; String FValue = ""; long RecNo = 1; try { this.StatusLabel.Text = Program.language.getMessage(MsgList.PleaseWait); this.FileNameCombo.Enabled = false; this.Enabled = false; this.ImportDialog.InitialDirectory = Application.StartupPath; this.ImportDialog.FileName = this.selectedComboName.Substring(0, this.selectedComboName.LastIndexOf(".")); this.ImportDialog.Filter = "Tab-SeparatedValues files (*.tsv)|*.tsv"; this.ImportDialog.FilterIndex = 1; this.ImportDialog.RestoreDirectory = true; if (this.ImportDialog.ShowDialog() == DialogResult.OK) { this.DatInfo_init(); string line = ""; System.Text.Encoding enc = System.Text.Encoding.GetEncoding(Program.config.TextEncoding); System.IO.StreamReader sr = new System.IO.StreamReader(this.ImportDialog.FileName, enc); this.StatusProgress.Minimum = 0; this.StatusProgress.Maximum = (int)sr.BaseStream.Length; this.StatusProgress.Value = 0; this.StatusProgress.Visible = true; while ((line = sr.ReadLine()) != null) { if (line.StartsWith("#")) { continue; } String[] TmpStr = line.Split(new char[] { '\t' }); for (int i = 0; i < TmpStr.Length; i++) { TmpStr[i] = TmpStr[i].Trim(new char[] { '"' }); } L2DatDefinition item = this.DatInfo.getDefinition(); for (int i = 0, j = 0; i < this.DatInfo.getFieldNames().Count; i++, j++) { FName = this.DatInfo.getFieldNames()[i]; FValue = TmpStr[j]; FieldInfo FType = this.DatInfo.getDefinition().GetType().GetField(FName); if (FType == null) { continue; } if (FType.FieldType.FullName.EndsWith("UInt32")) { FType.SetValue(item, Convert.ToUInt32(TmpStr[j])); } else if (FType.FieldType.FullName.EndsWith("Int32")) { FType.SetValue(item, Convert.ToInt32(TmpStr[j])); } else if (FType.FieldType.FullName.EndsWith("Single")) { FType.SetValue(item, Convert.ToSingle(TmpStr[j])); } else if (FType.FieldType.FullName.EndsWith("Color")) { FType.SetValue(item, LmUtils.ConvertUtilities.HtmlColorToColor(TmpStr[j])); } else if (FType.FieldType.FullName.EndsWith("CNTINT_PAIR")) { CNTINT_PAIR tmpMtx = new CNTINT_PAIR(); string[] TmpStr2 = new string[tmpMtx.getFieldCount()]; for (int k = 0; k < tmpMtx.getFieldCount(); k++) { TmpStr2[k] = TmpStr[j]; if (k < tmpMtx.getFieldCount() - 1) { j++; } } tmpMtx.setText(TmpStr2); FType.SetValue(item, tmpMtx); } else if (FType.FieldType.FullName.EndsWith("CNTRINT_PAIR")) { CNTRINT_PAIR tmpMtx = new CNTRINT_PAIR(); string[] TmpStr2 = new string[tmpMtx.getFieldCount()]; for (int k = 0; k < tmpMtx.getFieldCount(); k++) { TmpStr2[k] = TmpStr[j]; if (k < tmpMtx.getFieldCount() - 1) { j++; } } tmpMtx.setText(TmpStr2); FType.SetValue(item, tmpMtx); } else if (FType.FieldType.FullName.EndsWith("CNTTXT_PAIR")) { CNTTXT_PAIR tmpMtx = new CNTTXT_PAIR(); string[] TmpStr2 = new string[tmpMtx.getFieldCount()]; for (int k = 0; k < tmpMtx.getFieldCount(); k++) { TmpStr2[k] = TmpStr[j]; if (k < tmpMtx.getFieldCount() - 1) { j++; } } tmpMtx.setText(TmpStr2); FType.SetValue(item, tmpMtx); } else if (FType.FieldType.FullName.EndsWith("CNTTXT_PAIR2")) { CNTTXT_PAIR2 tmpMtx = new CNTTXT_PAIR2(); string[] TmpStr2 = new string[tmpMtx.getFieldCount()]; for (int k = 0; k < tmpMtx.getFieldCount(); k++) { TmpStr2[k] = TmpStr[j]; if (k < tmpMtx.getFieldCount() - 1) { j++; } } tmpMtx.setText(TmpStr2); FType.SetValue(item, tmpMtx); } else if (FType.FieldType.FullName.EndsWith("CNTASCF_PAIR")) { CNTASCF_PAIR tmpMtx = new CNTASCF_PAIR(); string[] TmpStr2 = new string[tmpMtx.getFieldCount()]; for (int k = 0; k < tmpMtx.getFieldCount(); k++) { TmpStr2[k] = TmpStr[j]; if (k < tmpMtx.getFieldCount() - 1) { j++; } } tmpMtx.setText(TmpStr2); FType.SetValue(item, tmpMtx); } else if (FType.FieldType.FullName.EndsWith("MTX")) { MTX tmpMtx = new MTX(); string[] TmpStr2 = new string[tmpMtx.getFieldCount()]; for (int k = 0; k < tmpMtx.getFieldCount(); k++) { TmpStr2[k] = TmpStr[j]; if (k < tmpMtx.getFieldCount() - 1) { j++; } } tmpMtx.setText(TmpStr2); FType.SetValue(item, tmpMtx); } else if (FType.FieldType.FullName.EndsWith("MTX2")) { MTX2 tmpMtx = new MTX2(); string[] TmpStr2 = new string[tmpMtx.getFieldCount()]; for (int k = 0; k < tmpMtx.getFieldCount(); k++) { TmpStr2[k] = TmpStr[j]; if (k < tmpMtx.getFieldCount() - 1) { j++; } } tmpMtx.setText(TmpStr2); FType.SetValue(item, tmpMtx); } else if (FType.FieldType.FullName.EndsWith("MTX3")) { MTX3 tmpMtx = new MTX3(); string[] TmpStr2 = new string[tmpMtx.getFieldCount()]; for (int k = 0; k < tmpMtx.getFieldCount(); k++) { TmpStr2[k] = TmpStr[j]; if (k < tmpMtx.getFieldCount() - 1) { j++; } } tmpMtx.setText(TmpStr2); FType.SetValue(item, tmpMtx); } else if (FType.FieldType.FullName.EndsWith("ASCF")) { ASCF tmpStr2 = new ASCF(); tmpStr2.Text = TmpStr[j]; FType.SetValue(item, tmpStr2); } else if (FType.FieldType.FullName.EndsWith("HEX")) { HEX tmpStr2 = new HEX(); tmpStr2.Text = TmpStr[j]; FType.SetValue(item, tmpStr2); } else if (FType.FieldType.FullName.EndsWith("UNICODE")) { UNICODE tmpStr2 = new UNICODE(); tmpStr2.Text = TmpStr[j]; FType.SetValue(item, tmpStr2); } else if (FType.FieldType.FullName.EndsWith("FILLER_360")) { FILLER_360 tmpStr2 = new FILLER_360(); tmpStr2.Text = TmpStr[j]; FType.SetValue(item, tmpStr2); } else if (FType.FieldType.FullName.EndsWith("FILLER_90")) { FILLER_90 tmpStr2 = new FILLER_90(); tmpStr2.Text = TmpStr[j]; FType.SetValue(item, tmpStr2); } else { FType.SetValue(item, TmpStr[j]); } } this.DatDatas.Add(item); this.StatusProgress.Value = (int)sr.BaseStream.Position; RecNo++; } sr.Close(); this.SaveBtn.Enabled = true; this.ExpBtn.Enabled = true; } else { return; } } catch (Exception ex) { ex = new ApplicationException(String.Format("Error importing string file (RecNo: {0} FieldName: {1} FieldValue: {2})", RecNo, FName, FValue), ex); Program.log.Add(ex, true); } finally { this.Enabled = true; this.FileNameCombo.Enabled = true; this.StatusProgress.Visible = false; this.Forms_Update(); } this.StatusLabel.Text = Program.language.getMessage(MsgList.COMPLETE) + String.Format(Program.language.getMessage(MsgList.CompleteImp), this.DatDatas.Count); }
public static bool Equals(HEX source, HSL target) { return(source.Equals(ColorConverter.HslToHex(target))); }
public static bool Equals(HEX source, XYZ target) { return(source.Equals(ColorConverter.XyzToHex(target))); }
public static bool Equals(CMYK source, HEX target) { return(source.Equals(ColorConverter.HexToCmyk(target))); }
void GenHexMesh(HEX _hex) { MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); Vector3[] hexgon = { #if HEXGON0 new Vector3(0, 0, 0), // 0 #endif new Vector3(0, +1, 0), // 1 new Vector3(+Tx, +Ty, 0), // 2 new Vector3(+Tx, -Ty, 0), // 3 new Vector3(0, -1, 0), // 4 new Vector3(-Tx, -Ty, 0), // 5 new Vector3(-Tx, +Ty, 0), // 6 }; Vector2[] water = { new Vector2(0, 0), new Vector2(1, 0), }; Color[] sc = { new Color(0, 0, 0, 0), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0), new Color(0, 0, 0, 1), }; Vector4[] vc = { new Vector4(0, 0, 0, 0), new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1), }; int siz = (_hex.yTile + 1) * (_hex.yTile + 1) * 8; if (lst == null) { lst = new int[siz]; } for (int i = 0; i < siz; i++) { lst[i] = -1; } welement e = new welement(); _reindex reindex = (ref welement _elm, int _ver, int _col, int _row) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); int loc = ((_row + 1) * (_hex.xTile + 1) + (_col + 1)) * 8 + _ver; int idx = lst[loc]; if (idx >= 0) { return(idx); } idx = _elm.vHex.Count; lst[loc] = idx; Vector3 _v = Vector3.zero; Vector3 _n = Vector3.zero; Vector4 _t = Vector4.zero; Vector2 _u = Vector2.zero; Color _c; Vector2 _waterColor; float _R = Tx * 2.0f + _hex.fvHex.x; int m = tileVo.mat; int n = isGenHeight ? tileVo.height : MapConst.MAP_HEIGHT_HORIZON; if (m == 8) { _waterColor = water[1]; _c = sc [0]; _t = vc [0]; } else { _waterColor = water[0]; _c = sc [m < 4 ? m + 1 : 0]; _t = vc [m > 3 ? m - 3 : 0]; } _v.x = _R * _col; _v.y = _R * Tx * _row; _v.z = n; _n.z = m; if (_row % 2 == 0) { _v.x += 0.0f; } else { _v.x += Tx + Ty * _hex.fvHex.x; } _elm.vHex.Add(hexgon [_ver] + _v); _elm.vNor.Add(_n); _elm.vClr.Add(_c); _elm.vTan.Add(_t); _elm.vTex.Add(_u); _elm.vWater.Add(_waterColor); _elm.hasFoam.Add(new Vector2(tileVo.blockType == MapBlockType.WaterWave ? 1 : 0, 0)); return(idx); }; _recheck recheck = (int _ver, int _col, int _row) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); //if (tileVo.mat < 1) if (tileVo.IsWater()) { return(false); } return(true); }; int nHexIndices, nIndexOffset; #if HEXGON0 int[] tdx = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 1, }; nHexIndices = 18; nIndexOffset = 0; #else int[] tdx = { 0, 1, 5, 5, 1, 4, 2, 4, 1, 3, 4, 2 }; nHexIndices = 12; nIndexOffset = 1; #endif int[][] edx = { new int[] { 6, 5, 2, 3, 2, 5 }, new int[] { 5, 4, 1, 2, 1, 4 }, new int[] { 1, 6, 3, 4, 3, 6 }, new int[] { 6, 2, 4, 5, 1, 3 }, }; List <int> vIdx = new List <int>(); List <int> vSub = new List <int>(); bool pass = true; for (int y = 0; y < _yTile; y++) { for (int x = 0; x < _xTile; x++) { for (int i = 0; i < nHexIndices; i++) { if (recheck(tdx[i], x, y) == false) { vIdx.Add(reindex(ref e, tdx[i], x, y)); } } // west -> x-1 // south west -> odd : x, y-1 even: x-1, y-1 // south -> odd: x+1, y-1 even: x, y-1 int t = y % 2; int ww = x - 1; // y int sw = t > 0 ? x : x - 1; // y-1 int nw = t > 0 ? x : x - 1; // y+1 if (IsValid(ww, y)) { pass = true; pass &= recheck(edx[0][0] - nIndexOffset, x, y); pass &= recheck(edx[0][1] - nIndexOffset, x, y); pass &= recheck(edx[0][2] - nIndexOffset, ww, y); if (pass == false) { vSub.Add(reindex(ref e, edx[0][0] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[0][1] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[0][2] - nIndexOffset, ww, y)); } pass = true; pass &= recheck(edx[0][3] - nIndexOffset, ww, y); pass &= recheck(edx[0][4] - nIndexOffset, ww, y); pass &= recheck(edx[0][5] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[0][3] - nIndexOffset, ww, y)); vSub.Add(reindex(ref e, edx[0][4] - nIndexOffset, ww, y)); vSub.Add(reindex(ref e, edx[0][5] - nIndexOffset, x, y)); } if (IsValid(nw, y + 1)) { pass = true; pass &= recheck(edx[3][0] - nIndexOffset, x, y); pass &= recheck(edx[3][1] - nIndexOffset, ww, y); pass &= recheck(edx[3][2] - nIndexOffset, nw, y + 1); if (pass == false) { vSub.Add(reindex(ref e, edx[3][0] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[3][1] - nIndexOffset, ww, y)); vSub.Add(reindex(ref e, edx[3][2] - nIndexOffset, nw, y + 1)); } } if (IsValid(sw, y - 1)) { pass = true; pass &= recheck(edx[3][3] - nIndexOffset, x, y); pass &= recheck(edx[3][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[3][5] - nIndexOffset, ww, y); if (pass == false) { vSub.Add(reindex(ref e, edx[3][3] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[3][4] - nIndexOffset, sw, y - 1)); vSub.Add(reindex(ref e, edx[3][5] - nIndexOffset, ww, y)); } } } if (IsValid(sw, y - 1)) { pass = true; pass &= recheck(edx[1][0] - nIndexOffset, x, y); pass &= recheck(edx[1][1] - nIndexOffset, x, y); pass &= recheck(edx[1][2] - nIndexOffset, sw, y - 1); if (pass == false) { vSub.Add(reindex(ref e, edx[1][0] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[1][1] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[1][2] - nIndexOffset, sw, y - 1)); } pass = true; pass &= recheck(edx[1][3] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][5] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[1][3] - nIndexOffset, sw, y - 1)); vSub.Add(reindex(ref e, edx[1][4] - nIndexOffset, sw, y - 1)); vSub.Add(reindex(ref e, edx[1][5] - nIndexOffset, x, y)); } } if (IsValid(nw, y + 1)) { pass = true; pass &= recheck(edx[2][0] - nIndexOffset, x, y); pass &= recheck(edx[2][1] - nIndexOffset, x, y); pass &= recheck(edx[2][2] - nIndexOffset, nw, y + 1); if (pass == false) { vSub.Add(reindex(ref e, edx[2][0] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[2][1] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[2][2] - nIndexOffset, nw, y + 1)); } pass = true; pass &= recheck(edx[2][3] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][4] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][5] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[2][3] - nIndexOffset, nw, y + 1)); vSub.Add(reindex(ref e, edx[2][4] - nIndexOffset, nw, y + 1)); vSub.Add(reindex(ref e, edx[2][5] - nIndexOffset, x, y)); } } if (y == 0) { // we only patch west, north west, south west, which leaves crack in zero line if (IsValid(x, y - 1)) { pass = true; pass &= recheck(edx[2][3] - nIndexOffset, x, y); pass &= recheck(edx[2][4] - nIndexOffset, x, y); pass &= recheck(edx[2][5] - nIndexOffset, x, y - 1); if (pass == false) { vSub.Add(reindex(ref e, edx[2][3] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[2][4] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[2][5] - nIndexOffset, x, y - 1)); } pass = true; pass &= recheck(edx[2][0] - nIndexOffset, x, y - 1); pass &= recheck(edx[2][1] - nIndexOffset, x, y - 1); pass &= recheck(edx[2][2] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[2][0] - nIndexOffset, x, y - 1)); vSub.Add(reindex(ref e, edx[2][1] - nIndexOffset, x, y - 1)); vSub.Add(reindex(ref e, edx[2][2] - nIndexOffset, x, y)); } if (IsValid(x - 1, y - 1)) { pass = true; pass &= recheck(edx[3][0] - nIndexOffset, x, y - 1); pass &= recheck(edx[3][1] - nIndexOffset, x - 1, y - 1); pass &= recheck(edx[3][2] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[3][0] - nIndexOffset, x, y - 1)); vSub.Add(reindex(ref e, edx[3][1] - nIndexOffset, x - 1, y - 1)); vSub.Add(reindex(ref e, edx[3][2] - nIndexOffset, x, y)); } } } } } } Mesh me = new Mesh(); me.subMeshCount = 2; me.vertices = e.vHex.ToArray(); me.SetTriangles(vIdx.ToArray(), 0); me.SetTriangles(vSub.ToArray(), 1); me.normals = e.vNor.ToArray(); me.colors = e.vClr.ToArray(); me.tangents = e.vTan.ToArray(); me.uv = e.vTex.ToArray(); me.uv2 = e.vWater.ToArray(); me.uv3 = e.hasFoam.ToArray(); me.bounds = _bound; var mf = gameObject.GetComponent <MeshFilter>(); if (mf == null) { mf = gameObject.AddComponent <MeshFilter>(); } mf.sharedMesh = me; var mr = gameObject.GetComponent <MeshRenderer>(); if (mr == null) { mr = gameObject.AddComponent <MeshRenderer>(); } mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; mr.sharedMaterials = _hex.GetWaterMats(); //mr.SetPropertyBlock(UpdateBlock()); }
void Start() { hex = GetComponent <HEX>(); }