set => SetValue(MapProperty, value);
Example #2
0
 protected void TraverseMap(MapProperty map, TestElementTraverser traverser)
 {
     PropertyIterator iter = map.valueIterator();
     while (iter.hasNext())
     {
         TraverseProperty(traverser, iter.next());
     }
 }
    /// <summary>
    /// 获取指定路径下的所有贴图(地图瓦片)
    /// </summary>
    /// <param name="mapPath"></param>
    public static void GetAllTextures(string mapPath)
    {
        if (string.IsNullOrEmpty(mapPath))
        {
            Debug.LogError("请输入路径!");
            return;
        }
        AllMapTextures = new List <List <MapProperty> >();

        DirectoryInfo directoryInfo = null;

        //获取路径下的所有文件夹
        try
        {
            directoryInfo = new DirectoryInfo(mapPath);
        }
        catch (Exception)
        {
            directoryInfo = null;
        }

        if (directoryInfo == null)
        {
            Debug.LogError("目录不存在!");
            return;
        }

        DirectoryInfo[] dirs = null;

        try
        {
            dirs = directoryInfo.GetDirectories();
        }
        catch (Exception)
        {
            Debug.LogError("目录不存在!");
            return;
        }

        if (dirs == null || dirs.Length == 0)
        {
            Debug.LogError("该目录下不存在存放瓦片的子文件夹!");
            return;
        }


        //遍历所有目录
        foreach (var dir in dirs)
        {
            //获取所有后缀为jpg的文件(仅遍历当前目录,子目录不遍历)
            FileInfo[] fileInfos = dir.GetFiles("*.jpg", SearchOption.TopDirectoryOnly);


            List <MapProperty> textures = new List <MapProperty>();

            //获取当前路径下的所有Texture并指定AllTextures的属性
            foreach (var file in fileInfos)
            {
                //Texture texture = AssetDatabase.LoadAssetAtPath<Texture>(file.FullName);

                //删除当前文件路径的前部(Assets之前的路径),从而获取相对路径
                string path = file.FullName.Remove(0, file.FullName.IndexOf("Assets"));
                //获取当前路径下指定的Texture
                Texture texture = (Texture)AssetDatabase.LoadAssetAtPath(path, typeof(Texture));
                //获取针对Texture生成的Material的名称
                string textureSaveName = dir.Name + "_" + file.Name.Replace(".jpg", "");

                //初始化TextureProperty属性
                MapProperty textureProperty = new MapProperty();
                textureProperty.Map     = texture;
                textureProperty.MapName = textureSaveName;

                textures.Add(textureProperty);
            }
            if (textures != null && textures.Count != 0)
            {
                AllMapTextures.Add(textures);
            }
        }
    }