Ejemplo n.º 1
0
    int GetMatNameInd(int thisCoordX, int thisCoordY, int neighborInd)
    {
        MapProxy mapProxy = GameFacade.GetProxy <MapProxy>();

        if (neighborInd > 5 || neighborInd < 0)
        {
            Coord thisCoord = new Coord(thisCoordX, thisCoordY);
            byte  thisMat   = mapProxy.GetTile(thisCoord).mat;
            if (thisMat == 8)
            {
                thisMat = 0;
            }
            int thisMatNameNum = thisSprites[thisMat];
            spriteIds[0] = thisMatNameNum;
            return(0);
        }

        Coord     c_neighbor = GetNeighborCoord(thisCoordX, thisCoordY, neighborInd);
        MapTileVO t_neighbor = mapProxy.GetTile(c_neighbor);

        if (t_neighbor == null)
        {
            return(-1);
        }

        byte m_neighbor = t_neighbor.mat;

        if (m_neighbor == 8)
        {
            m_neighbor = 0;
        }
        int neighborMatNameNum = -1;
        int neighborMatNameInd = -1;

        switch (neighborInd)
        {
        default:
        case 4:
            neighborMatNameNum = leftSprites[m_neighbor];
            spriteIds[1]       = neighborMatNameNum;
            neighborMatNameInd = 1;
            break;

        case 2:
            neighborMatNameNum = prevSprites[m_neighbor];
            spriteIds[2]       = neighborMatNameNum;
            neighborMatNameInd = 2;
            break;

        case 3:
            neighborMatNameNum = diagSprites[m_neighbor];
            spriteIds[3]       = neighborMatNameNum;
            neighborMatNameInd = 3;
            break;
        }

        return(neighborMatNameInd);
    }
Ejemplo n.º 2
0
    int GetMatNameInd(int thisCoordX, int thisCoordY, int neighborInd)
    {
        MapProxy mapProxy = GameFacade.GetProxy <MapProxy>();

        if (neighborInd > 5 || neighborInd < 0)
        {
            Coord thisCoord = new Coord(thisCoordX, thisCoordY);
            byte  thisMat   = mapProxy.GetTile(thisCoord).mat;
            if (thisMat == 8)
            {
                thisMat = 0;
            }
            int thisMatNameNum = thisSprites[thisMat];
            int thisMatNameInd = FindInSpriteIds(spriteIds, thisMatNameNum);
            return(thisMatNameInd);
        }

        Coord     c_neighbor = GetNeighborCoord(thisCoordX, thisCoordY, neighborInd);
        MapTileVO t_neighbor = mapProxy.GetTile(c_neighbor);

        if (t_neighbor == null)
        {
            return(-1);
        }

        byte m_neighbor = t_neighbor.mat;

        if (m_neighbor == 8)
        {
            m_neighbor = 0;
        }
        int neighborMatNameNum = -1;

        if (neighborInd == 4)
        {
            neighborMatNameNum = leftSprites[m_neighbor];
        }
        else
        {
            if (thisCoordY % 2 == 0)
            {
                neighborMatNameNum = leftSprites[m_neighbor];
            }
            else
            {
                neighborMatNameNum = thisSprites[m_neighbor];
            }
        }

        int neighborMatNameInd = FindInSpriteIds(spriteIds, neighborMatNameNum);

        return(neighborMatNameInd);
    }
 public void ShowMarks(MapEditorEntry.EDIT_OP op, Color[] color)
 {
     if (mMarks == null)
     {
         mMarks = new SpriteRenderer[hex.xTile][];
     }
     for (int x = 0; x < hex.xTile; ++x)
     {
         if (mMarks[x] == null)
         {
             mMarks[x] = new SpriteRenderer[hex.yTile];
         }
         for (int y = 0; y < hex.yTile; ++y)
         {
             Coord c = new Coord(x + hex.xTile * xIdx, y + hex.yTile * yIdx);
             if (mapProxy == null)
             {
                 mapProxy = GameFacade.GetProxy <MapProxy>();
             }
             MapTileVO tileVo = mapProxy.GetTile(c);
             if (tileVo != null)
             {
                 int index;
                 if (op == MapEditorEntry.EDIT_OP.EDIT_AREA)
                 {
                     index = tileVo.camp;
                 }
                 else if (op == MapEditorEntry.EDIT_OP.EDIT_LV)
                 {
                     index = tileVo.level;
                 }
                 else
                 {
                     Debug.LogError("Error Op.");
                     return;
                 }
                 if (index >= color.Length)
                 {
                     Debug.LogError("No defined color of this index.");
                     return;
                 }
                 SpriteRenderer mark;
                 if (mMarks[x][y] != null)
                 {
                     mMarks[x][y].color = color[index];
                     continue;
                 }
                 mark       = GetAMark();
                 mark.color = color[index];
                 mark.transform.localPosition    = layout.HexCenter(tileVo.coord) - transform.localPosition;
                 mark.transform.localScale       = new Vector3(1.5f, 1.55f, 1f);
                 mark.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
                 mMarks[x][y] = mark;
             }
         }
     }
     markRoot.gameObject.SetActive(true);
 }
Ejemplo n.º 4
0
    int GetNeighborHeight(int thisCoordX, int thisCoordY, int neighborInd)
    {
        int       height_neighbor = -1;
        Coord     c_neighbor      = GetNeighborCoord(thisCoordX, thisCoordY, neighborInd);
        MapProxy  mapProxy        = GameFacade.GetProxy <MapProxy>();
        MapTileVO t_neighbor      = mapProxy.GetTile(c_neighbor);

        if (t_neighbor != null)
        {
            height_neighbor = t_neighbor.height;
        }
        return(height_neighbor);
    }
    private void SelectBlock(Coord c)
    {
        if (m_WorldModel.m_SelectedOtherItem.m_SelectedState == WorldProxy.SelectedOtherItem.SelectedState.OtherMarch)
        {
            m_WorldModel.m_SelectedOtherItem.SelectOtherMarch.MarchController.UnSelect();
        }
        else if (m_WorldModel.m_SelectedOtherItem.m_SelectedState == WorldProxy.SelectedOtherItem.SelectedState.Block)
        {
            m_WorldView.UnSelectTagObject();
        }

        m_WorldModel.m_SelectedOtherItem.SelectedBlock = m_MapModel.GetTile(c);
        m_WorldView.SelectTagObject(MapHelper.CoordToVector3(c));
        LogModule.DebugLog("SelectBlock:{0}", c);
    }
Ejemplo n.º 6
0
    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());
    }
Ejemplo n.º 7
0
    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());
    }
Ejemplo n.º 8
0
    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());
    }
Ejemplo n.º 9
0
    //Seed All
    void OnMRBAction_Common()
    {
        MapTileVO tile = mapProxy.GetTile(mDst);

        ModifyVOByOp(tile);
        GameFacade.GetProxy <MapProxy>().SeedTile(tile);
    }
    public void UpdateInterSprList()
    {
        MapProxy mapProxy = GameFacade.GetProxy <MapProxy>();

        MapTileVO theTile = mapProxy.GetTile(mHexBg._xTile * mHexBg._x, mHexBg._yTile * mHexBg._y);
        int       theMat  = theTile.mat;

        if (theMat > 3)
        {
            theMat = 0;
        }

        byte leftMat = 255;
        byte prevMat = 255;
        byte diagMat = 255;

        if (left != null)
        {
            MapTileVO leftTile = mapProxy.GetTile(left.mHexBg._xTile * left.mHexBg._x, left.mHexBg._yTile * left.mHexBg._y);
            leftMat = leftTile.mat;
            if (leftMat > 3)
            {
                leftMat = 0;
            }
        }

        if (prev != null)
        {
            MapTileVO prevTile = mapProxy.GetTile(prev.mHexBg._xTile * prev.mHexBg._x, prev.mHexBg._yTile * prev.mHexBg._y);
            prevMat = prevTile.mat;
            if (prevMat > 3)
            {
                prevMat = 0;
            }
        }

        if (diag != null)
        {
            MapTileVO diagTile = mapProxy.GetTile(diag.mHexBg._xTile * diag.mHexBg._x, diag.mHexBg._yTile * diag.mHexBg._y);
            diagMat = diagTile.mat;
            if (diagMat > 3)
            {
                diagMat = 0;
            }
        }

        bool hasLeft = false;

        if (left != null && left.mHexBg.spriteIds.Count > 0)
        {
            hasLeft = true;
        }

        bool hasPrev = false;

        if (prev != null && prev.mHexBg.spriteIds.Count > 0)
        {
            hasPrev = true;
        }

        if (mHexBlendL)
        {
            mHexBlendL.left        = hasLeft;
            mHexBlendL.thisSprites = mHexBg.spriteIds;

            if (hasLeft)
            {
                //int[] same = GetSameSpriteIds(mHexBg.spriteIds, left.mHexBg.spriteIds);
                mHexBlendL.leftSprites = left.mHexBg.spriteIds;
                mHexBlendL.spriteIds.Clear();
                mHexBlendL.spriteIds.AddRange(mHexBg.spriteIds);
                mHexBlendL.spriteIds.AddRange(left.mHexBg.spriteIds);
            }
        }

        if (mHexBlendP)
        {
            mHexBlendP.prev        = hasPrev;
            mHexBlendP.thisSprites = mHexBg.spriteIds;

            if (hasPrev)
            {
                //int[] same = GetSameSpriteIds(mHexBg.spriteIds, prev.mHexBg.spriteIds);
                mHexBlendP.prevSprites = prev.mHexBg.spriteIds;
                mHexBlendP.spriteIds.Clear();
                mHexBlendP.spriteIds.AddRange(mHexBg.spriteIds);
                mHexBlendP.spriteIds.AddRange(prev.mHexBg.spriteIds);
            }
        }

        if (mHexBlendD)
        {
            mHexBlendD.left        = hasLeft;
            mHexBlendD.prev        = hasPrev;
            mHexBlendD.thisSprites = mHexBg.spriteIds;

            if (hasLeft && hasPrev)
            {
                //int[] same = GetSameSpriteIds(mHexBg.spriteIds, prev.mHexBg.spriteIds);
                mHexBlendD.leftSprites = left.mHexBg.spriteIds;
                mHexBlendD.prevSprites = prev.mHexBg.spriteIds;
                mHexBlendD.diagSprites = diag.mHexBg.spriteIds;
                mHexBlendD.spriteIds.Clear();
                mHexBlendD.spriteIds.Add(0);
                mHexBlendD.spriteIds.Add(1);
                mHexBlendD.spriteIds.Add(2);
                mHexBlendD.spriteIds.Add(3);
            }
        }
    }