Exemplo n.º 1
0
    private void CreateMapPanel()
    {
        mapGo = GameObject.Instantiate(Resources.Load <GameObject> ("MapGo"));

        mapGo.transform.SetParent(mapContainer, false);

        MeshRenderer mr = mapGo.GetComponent <MeshRenderer> ();

        mr.material = new Material(Shader.Find("Unlit/MapUnit"));

        GameObject[] gos = new GameObject[battle.mapData.dic.Count];

        int index = 0;

        int index2 = 0;

        for (int i = 0; i < battle.mapData.mapHeight; i++)
        {
            for (int m = 0; m < battle.mapData.mapWidth; m++)
            {
                if (i % 2 == 1 && m == battle.mapData.mapWidth - 1)
                {
                    continue;
                }

                if (!battle.mapData.dic.ContainsKey(index))
                {
                    index++;

                    continue;
                }

                GameObject go = GameObject.Instantiate <GameObject>(Resources.Load <GameObject>("MapUnit"));

                go.transform.SetParent(mapContainer, false);

                go.transform.localPosition = new Vector3(m * mapUnitWidth * sqrt3 * 2 + ((i % 2 == 1) ? mapUnitWidth * Mathf.Sqrt(3) : 0), -i * mapUnitWidth * 3, 0);

                go.transform.localScale = new Vector3(mapUnitScale, mapUnitScale, mapUnitScale);

                MapUnit unit = go.GetComponent <MapUnit>();

                mapUnitDic.Add(index, unit);

                unit.Init(index, index2, mr);

                SetMapUnitColor(unit);

                index++;

                gos[index2] = go;

                index2++;
            }
        }

        Mesh mesh = PublicTools.CombineMeshs(gos);

        MeshFilter mf = mapGo.GetComponent <MeshFilter> ();

        mf.mesh = mesh;

        battleContentContainer.localPosition = new Vector3(-0.5f * (battle.mapData.mapWidth * mapUnitWidth * sqrt3 * 2) + mapUnitWidth * sqrt3, mapContainerYFix + 0.5f * (battle.mapData.mapHeight * mapUnitWidth * 3 + mapUnitWidth) - mapUnitWidth * 2, 0);
    }