Ejemplo n.º 1
0
 private static void OnPostProcessItem(ResItem item)
 {
     if (item.name != item.name.ToLower())
     {
         Debug.LogError("严重错误:缩略图名称存在大写>>>>" + item.path);
     }
 }
Ejemplo n.º 2
0
        private static bool AddTextureResItem(string name, string path, List <ResItem> items, List <ResItem> textureInfoItems)
        {
            path = path.Replace("\\", "/");
            var localPath = path.Substring(7).ToLower();

            var abInfoItem = textureInfoItems.FirstOrDefault(s => s.path == localPath + ".png");


            if (abInfoItem != null)
            {
//				var rootdir = mCurCreateAndroid ? PublisherGlobal.ROOTDIR_ANDROID : PublisherGlobal.ROOTDIR_IOS;
                var resItem = new ResItem {
                    name = abInfoItem.name
                };
                resItem.hash = abInfoItem.hash;
                resItem.size = abInfoItem.size;
//				resItem.path = Path.GetDirectoryName(rootdir + "/" + localPath) + "/" + resItem.name;
                resItem.path = abInfoItem.path;
                if (items.All(s => s.path != resItem.path))
                {
                    items.Add(resItem);
                }
                return(true);
            }

            Debug.LogError("abinfo 里面 找不到>>>>>" + path);
//			EditorUtility.DisplayDialog("错误","abinfo 里面 找不到>>>>>" + path,"确定");
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 生成指定资源目录内 所有资源的  resconfig.json 配置文件
        /// </summary>
        /// <param name="resDirs">需要生成的资源所在目录</param>
        /// <param name="configFilePath">生成的配置文件路径</param>
        /// <param name="resRefPath">配置文件中 资源下载 相对路径</param>
        /// <param name="filters">需要生成配置项的资源类型</param>
        public static void GenerateResConfig(string[] resDirs, string configFilePath, string resRefPath, Action <ResItem> OnPostProcess,
                                             params string[] filters)
        {
            resRefPath = Path.GetFullPath(resRefPath);
            if (!resRefPath.EndsWith("/"))
            {
                resRefPath += "/";
            }

            string resVersion = "100";

            if (File.Exists(configFilePath))
            {
                ResConfig oldResConfig = JsonUtility.FromJson <ResConfig>(File.ReadAllText(configFilePath));
                resVersion = (int.Parse(oldResConfig.resversion) + 1).ToString();
            }

            ResConfig resConfig = new ResConfig {
                items = new List <ResItem>(), resversion = resVersion
            };

            foreach (string dir in resDirs)
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(dir);

                FileInfo[] fileInfos = directoryInfo.GetFiles("*", SearchOption.AllDirectories)
                                       .Where(s => !s.Name.EndsWith(".DS_Store") &&
                                              (filters == null || filters.Contains(Path.GetExtension(s.FullName)))).ToArray();
                int total   = fileInfos.Length;
                int counter = 0;
                foreach (var fileInfo in fileInfos)
                {
                    string  fullName = fileInfo.FullName;
                    string  refPath  = fullName.Replace(resRefPath, "");
                    ResItem item     = CreateConfigItem(fullName, Path.GetFileNameWithoutExtension(fullName), refPath);
                    if (OnPostProcess != null)
                    {
                        OnPostProcess(item);
                    }
                    resConfig.items.Add(item);

                    counter++;
                    EditorUtility.DisplayProgressBar("generating resconfig", "generating" + counter + "/" + total, counter * 1.0f / total);
                }
            }

            string configDir = Path.GetDirectoryName(configFilePath);

            if (!Directory.Exists(configDir))
            {
                Directory.CreateDirectory(configDir);
            }
            string contents = JsonUtility.ToJson(resConfig, true);

            File.WriteAllText(configFilePath, contents);
            AssetDatabase.Refresh();

            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 4
0
        private static ResItem CreateConfigItem(string realPath, string fileName, string refPath)
        {
            ResItem resItem = new ResItem {
                name = fileName, path = refPath
            };

            byte[] fileBytes = GetFileBytes(realPath);
            resItem.hash = GetMD5(fileBytes);
            resItem.size = fileBytes.Length;
            return(resItem);
        }
Ejemplo n.º 5
0
        private static bool AddResItem(string name, string path, List <ResItem> items, List <ResItem> modelAbInfoItems)
        {
//			Debug.LogError(name+"--ggggg>>>"+path);
            path = path.Replace("\\", "/");

            var localPath   = path.Substring(7).ToLower();
            var abInfoItems = modelAbInfoItems.Where(s => Path.GetDirectoryName(s.path) == localPath).ToArray();


            if (abInfoItems != null && abInfoItems.Length == 2)
            {
                foreach (var abInfoItem in abInfoItems)
                {
//					var rootdir = mCurCreateAndroid ? PublisherGlobal.ROOTDIR_ANDROID : PublisherGlobal.ROOTDIR_IOS;
                    var resItem = new ResItem {
                        name = abInfoItem.name
                    };
                    resItem.hash = abInfoItem.hash;
                    resItem.size = abInfoItem.size;
                    resItem.path = abInfoItem.path;
                    if (items.All(s => s.path != resItem.path))
                    {
                        items.Add(resItem);
                    }
                }

                return(true);
            }


//			if (abInfoItem!=null)
//			{
//				var rootdir = mCurCreateAndroid ? PublisherGlobal.ROOTDIR_ANDROID : PublisherGlobal.ROOTDIR_IOS;
//				resItem.hash = abInfoItem.hash;
//				resItem.size = abInfoItem.size;
//				resItem.path = Path.GetDirectoryName(rootdir + "/" + localPath) + "/" + resItem.name;
//				if (items.All(s => s.path != resItem.path))
//				{
//					items.Add(resItem);
//				}
//				return true;
//			}

            Debug.LogError("abinfo 里面 找不到>>>>>" + path);
//			EditorUtility.DisplayDialog("错误","abinfo 里面 找不到>>>>>" + path,"确定");
            return(false);
        }
Ejemplo n.º 6
0
        private static void AssignSingleMaterials(List <string> materials, string materialDir, List <ResItem> items, List <ResItem> modelAbInfoItems, List <ResItem> textureInfoItems, List <PEMaterialUtl.MaterialInfo> materialInfos)
        {
            foreach (var materialStr in materials)
            {
                var abFile = Path.Combine(materialDir, materialStr);

                if (!File.Exists(abFile + ".mat"))
                {
                    abFile = Path.Combine(BlockPath.MaterialCommon(), materialStr);
                }

//				Debug.LogError(materialDir+">>>>>>>>materialDir>>>>>"+abFile+"   -->>>> "+materialStr);


                var materialInfo = materialInfos.FirstOrDefault(s => s.name == materialStr);
//				Debug.LogError(materialStr+"-->>>>>materialStr");
                if (materialInfo != null)
                {
                    if (materialInfo.propsTex.Any())
                    {
                        foreach (var item in materialInfo.propsTex)
                        {
//							Debug.LogError(item.data+" >>>item.data");
                            var t = textureInfoItems.FirstOrDefault(b => b.path == item.data);
                            if (t != null)
                            {
                                var resItem = new ResItem {
                                    name = item.name
                                };
                                resItem.hash = t.hash;
                                resItem.size = t.size;
                                resItem.path = t.path;
                                if (items.All(s => s.path != resItem.path))
                                {
                                    items.Add(resItem);
                                }
                            }
                        }
                    }
                }

//				AddResItem(materialStr,abFile,items,modelAbInfoItems);
            }
        }