示例#1
0
    static MapAreaType GetAreaType(MapAreaSettings setting, Texture mainTex)
    {
        //var texPath = AssetDatabase.GetAssetOrScenePath (mainTex);
        var texPath = mainTex.name;

        foreach (var name in setting.rockTexturePrefix)
        {
            if (texPath.Contains(name))
            {
                return(MapAreaType.ROCK);
            }
        }

        foreach (var name in setting.grassTexturePrefix)
        {
            if (texPath.Contains(name))
            {
                return(MapAreaType.GRASS);
            }
        }

        foreach (var name in setting.woodTexturePrefix)
        {
            if (texPath.Contains(name))
            {
                return(MapAreaType.WOOD);
            }
        }

        foreach (var name in setting.waterTexturePrefix)
        {
            if (texPath.Contains(name))
            {
                return(MapAreaType.WATER);
            }
        }

        foreach (var name in setting.earthTexturePrefix)
        {
            if (texPath.Contains(name))
            {
                return(MapAreaType.EARTH);
            }
        }

        return(MapAreaType.EARTH);
    }
示例#2
0
    static MapAreaType GetAreaType(MapAreaSettings setting, MeshRenderer meshRender)
    {
        MapAreaType areaType = MapAreaType.EARTH;
        var         t4m      = meshRender.gameObject.GetComponent("T4MObjSC");

        if (t4m != null)
        {
            var controlTex = meshRender.sharedMaterial.GetTexture("_Control");
            areaType = MapAreaType.GRASS;
        }
        else if (meshRender.sharedMaterial.name.Contains("Water"))
        {
            areaType = MapAreaType.WATER;
        }
        else
        {
            Dictionary <MapAreaType, int> areaTypes = new Dictionary <MapAreaType, int> ();
            foreach (var mat in meshRender.sharedMaterials)
            {
                var mainTex = mat.GetTexture("_MainTex");
                if (mainTex != null)
                {
                    areaType = GetAreaType(setting, mainTex);
                    if (areaTypes.ContainsKey(areaType))
                    {
                        areaTypes [areaType] = areaTypes [areaType] + 1;
                    }
                    else
                    {
                        areaTypes.Add(areaType, 1);
                    }
                }
            }
            int maxCount = 0;
            foreach (var t in areaTypes)
            {
                if (t.Value > maxCount)
                {
                    areaType = t.Key;
                }
            }
        }
        return(areaType);
    }
示例#3
0
    private static void GenerateSceneConfguration(MapAreaSettings settings, string path, ref Vector3 min, ref Vector3 max)
    {
        var meshObjects = GameObject.Find(path).GetComponentsInChildren <MeshRenderer> ();

        foreach (var meshRenderer in meshObjects)
        {
            if (meshRenderer.gameObject.layer != LayerMask.NameToLayer("Surface"))
            {
                continue;
            }
            var sceneExt = meshRenderer.GetComponent <SceneExt> ();
            if (sceneExt == null)
            {
                sceneExt = meshRenderer.gameObject.AddComponent <SceneExt> ();
            }
            sceneExt.areaType = GetAreaType(settings, meshRenderer);
            if (meshRenderer.bounds.min.x < min.x)
            {
                min.x = meshRenderer.bounds.min.x;
            }
            if (meshRenderer.bounds.min.y < min.y)
            {
                min.y = meshRenderer.bounds.min.y;
            }
            if (meshRenderer.bounds.min.z < min.z)
            {
                min.z = meshRenderer.bounds.min.z;
            }

            if (meshRenderer.bounds.max.x > max.x)
            {
                max.x = meshRenderer.bounds.max.x;
            }
            if (meshRenderer.bounds.max.y > max.y)
            {
                max.y = meshRenderer.bounds.max.y;
            }
            if (meshRenderer.bounds.max.z > max.z)
            {
                max.z = meshRenderer.bounds.max.z;
            }
        }
    }
示例#4
0
    static MapAreaType GetT4MAreaColor(MapAreaSettings setting, SceneExt sceneExt, Vector2 uv)
    {
        MapAreaType areaType   = sceneExt.areaType;
        var         material   = sceneExt.GetComponent <MeshRenderer> ().sharedMaterial;
        var         controlTex = material.GetTexture("_Control") as Texture2D;

        var px    = controlTex.width * uv.x;
        var py    = controlTex.height * uv.y;
        var color = controlTex.GetPixel(Mathf.RoundToInt(px), Mathf.RoundToInt(py));

        var maxChannel = Mathf.Max(color.r, Mathf.Max(color.g, Mathf.Max(color.b, color.a)));

        /*if (color.r >= maxChannel) {
         *      areaType = MapAreaType.ROCK;
         * } else if (color.g >= maxChannel) {
         *      areaType = MapAreaType.EARTH;
         * } else if (color.b >= maxChannel) {
         *      areaType = MapAreaType.GRASS;
         * } else {
         *      areaType = MapAreaType.GRASS;
         * }*/

        if (color.r >= maxChannel)
        {
            areaType = MapAreaType.ROCK;
        }
        else if (color.b >= maxChannel)
        {
            areaType = MapAreaType.GRASS;
        }
        else if (color.g >= maxChannel)
        {
            areaType = MapAreaType.EARTH;
        }
        else
        {
            areaType = MapAreaType.GRASS;
        }

        return(areaType);
    }
示例#5
0
    static void ExportMapArea(string path, Example.MapTile[,] tiles, MapAreaSettings settings, int width, int height)
    {
        var tileList = new List <int> ();

        Example.MapTile tile = null;

        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                tile = tiles [y, x];
                if (tile != null)
                {
                    tileList.Add((int)tile.Type);
                }
                else
                {
                    tileList.Add(-1);
                }
            }
        }

        /*for (int y = 0; y < height; ++y) {
         *      for (int x = 0; x < width; ++x) {
         *              Debug.LogFormat ("x={0},y={1}",x,y);
         *              tileList [y * height + x] = tiles [y, x];
         *      }
         * }*/

        Example.MapTiles tileAll = new Example.MapTiles();
        tileAll.CellSize = settings.resolution;
        tileAll.Row      = height;
        tileAll.Column   = width;
        tileAll.Pos      = MapUtil.ToVector3f(mapBounds.min);
        tileAll.Tiles    = tileList;

        File.WriteAllBytes(path, Example.MapTiles.SerializeToBytes(tileAll));
    }