Exemple #1
0
        public static void ExportExcelProtobuf(ConfigType configType)
        {
            string        exportPath    = PathUtil.GetPath(PathType.DataPath, GetProtobufPath(configType));
            string        classPath     = PathUtil.GetPath(PathType.DataPath, GetClassPath(configType));
            string        jsonPath      = PathUtil.GetPath(PathType.DataPath, GetJsonPath(configType));
            List <string> protoNameList = new List <string>();

            foreach (string item in Directory.GetFiles(classPath, "*.cs"))
            {
                protoNameList.Add(Path.GetFileNameWithoutExtension(item));
            }
            foreach (string item in protoNameList)
            {
                string json = FileUtil.GetAsset($"{jsonPath}/{item}.txt").GetString();
                object obj;
                if (configType == ConfigType.Model)
                {
                    obj = JsonUtil.ToObject(typeof(Manager).Assembly.GetType($"{typeof(Manager).Namespace}.{item}Category"), json);
                }
                else
                {
                    obj = JsonUtil.ToObject(typeof(LccHotfix.Manager).Assembly.GetType($"{typeof(LccHotfix.Manager).Namespace}.{item}Category"), json);
                }
                FileUtil.SaveAsset($"{exportPath}/{item}Category.bytes", ProtobufUtil.Serialize(obj));
            }
        }
Exemple #2
0
        public static void BuildHotfix()
        {
            if (File.Exists("Assets/Hotfix/Unity.Hotfix.asmdef~"))
            {
                File.Move("Assets/Hotfix/Unity.Hotfix.asmdef~", "Assets/Hotfix/Unity.Hotfix.asmdef");
                LogUtil.Log("安装Hotfix");
                AssetDatabase.Refresh();
            }
            else
            {
                if (File.Exists("Assets/Hotfix/Unity.Hotfix.asmdef"))
                {
                    LogUtil.Log("安装Hotfix");
                }
                else
                {
                    LogUtil.Log("Hotfix丢失");
                }
            }
            if (File.Exists("Assets/Resources/DLL/Unity.Hotfix.dll.bytes"))
            {
                File.Delete("Assets/Resources/DLL/Unity.Hotfix.dll.bytes");
            }
            if (File.Exists("Assets/Resources/DLL/Unity.Hotfix.pdb.bytes"))
            {
                File.Delete("Assets/Resources/DLL/Unity.Hotfix.pdb.bytes");
            }
            if (File.Exists("Assets/Bundles/DLL/Unity.Hotfix.dll.bytes"))
            {
                File.Delete("Assets/Bundles/DLL/Unity.Hotfix.dll.bytes");
            }
            if (File.Exists("Assets/Bundles/DLL/Unity.Hotfix.pdb.bytes"))
            {
                File.Delete("Assets/Bundles/DLL/Unity.Hotfix.pdb.bytes");
            }
#if Release
            if (File.Exists("Unity.Hotfix.csproj"))
            {
                RoslynUtil.BuildDll("Unity.Hotfix.csproj", "Assets/Resources/DLL/Unity.Hotfix.dll.bytes", BuildType.Release, false);
                FileUtil.SaveAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes", RijndaelUtil.RijndaelEncrypt("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", FileUtil.GetAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes")));
                File.Copy("Assets/Resources/DLL/Unity.Hotfix.dll.bytes", "Assets/Bundles/DLL/Unity.Hotfix.dll.bytes", true);
            }
#else
            if (File.Exists("Library/ScriptAssemblies/Unity.Hotfix.dll") && File.Exists("Library/ScriptAssemblies/Unity.Hotfix.pdb"))
            {
                File.Copy("Library/ScriptAssemblies/Unity.Hotfix.dll", "Assets/Resources/DLL/Unity.Hotfix.dll.bytes", true);
                File.Copy("Library/ScriptAssemblies/Unity.Hotfix.pdb", "Assets/Resources/DLL/Unity.Hotfix.pdb.bytes", true);
                FileUtil.SaveAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes", RijndaelUtil.RijndaelEncrypt("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", FileUtil.GetAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes")));
                File.Copy("Assets/Resources/DLL/Unity.Hotfix.dll.bytes", "Assets/Bundles/DLL/Unity.Hotfix.dll.bytes", true);
                File.Copy("Assets/Resources/DLL/Unity.Hotfix.pdb.bytes", "Assets/Bundles/DLL/Unity.Hotfix.pdb.bytes", true);
            }
#endif
            LinkUtil.BuildLink();
            AssetDatabase.Refresh();
        }
Exemple #3
0
 public static void ExportClassAndJson()
 {
     content = FileUtil.GetAsset(templatePath).GetString();
     foreach (string item in Directory.GetFiles(excelPath, "*.xlsx"))
     {
         ExportExcelClass(new XSSFWorkbook(item), Path.GetFileNameWithoutExtension(item), ConfigType.Model);
         ExportExcelClass(new XSSFWorkbook(item), Path.GetFileNameWithoutExtension(item), ConfigType.Hotfix);
         ExportExcelJson(new XSSFWorkbook(item), Path.GetFileNameWithoutExtension(item), ConfigType.Model);
         ExportExcelJson(new XSSFWorkbook(item), Path.GetFileNameWithoutExtension(item), ConfigType.Hotfix);
     }
     AssetDatabase.Refresh();
 }
Exemple #4
0
        public static List <AssetBundleData> BuildAssetBundleData(AssetBundleRule[] assetBundleRules)
        {
            List <AssetBundleData> assetBundleDataList = new List <AssetBundleData>();
            List <string>          assetNameList       = new List <string>();

            foreach (AssetBundleRule item in assetBundleRules)
            {
                if (item.assetBundleRuleType == AssetBundleRuleType.File)
                {
                    FileInfo[] fileInfos = FileUtil.GetFiles(new DirectoryInfo(item.path), new List <FileInfo>());
                    if (fileInfos.Length == 0)
                    {
                        continue;
                    }
                    List <FileInfo> fileInfoList = (from fileInfo in fileInfos where !string.IsNullOrEmpty(Path.GetExtension(fileInfo.Name)) && Path.GetExtension(fileInfo.Name) != ".meta" select fileInfo).ToList();
                    foreach (FileInfo fileInfo in fileInfoList)
                    {
                        string assetName = fileInfo.FullName.Substring(fileInfo.FullName.IndexOf("Assets")).Replace("\\", "/");
                        string md5       = MD5Util.ComputeMD5(assetName);
                        assetBundleDataList.Add(new AssetBundleData($"{md5}.unity3d", string.Empty, uint.MinValue, long.MinValue, new string[] { assetName }));
                    }
                }
                if (item.assetBundleRuleType == AssetBundleRuleType.Directory)
                {
                    DirectoryInfo[] directoryInfos = DirectoryUtil.GetDirectorys(new DirectoryInfo(item.path), new List <DirectoryInfo>());
                    if (directoryInfos.Length == 0)
                    {
                        continue;
                    }
                    foreach (DirectoryInfo directoryInfo in directoryInfos)
                    {
                        FileInfo[] fileInfos = directoryInfo.GetFiles();
                        if (fileInfos.Length == 0)
                        {
                            continue;
                        }
                        List <FileInfo> fileInfoList = (from fileInfo in fileInfos where !string.IsNullOrEmpty(Path.GetExtension(fileInfo.Name)) && Path.GetExtension(fileInfo.Name) != ".meta" select fileInfo).ToList();
                        foreach (FileInfo fileInfo in fileInfoList)
                        {
                            assetNameList.Add(fileInfo.FullName.Substring(fileInfo.FullName.IndexOf("Assets")).Replace("\\", "/"));
                        }
                        if (assetNameList.Count > 0)
                        {
                            string assetName = directoryInfo.FullName.Substring(directoryInfo.FullName.IndexOf("Assets")).Replace("\\", "/");
                            string md5       = MD5Util.ComputeMD5(assetName);
                            assetBundleDataList.Add(new AssetBundleData($"{md5}.unity3d", string.Empty, uint.MinValue, long.MinValue, assetNameList.ToArray()));
                            assetNameList.Clear();
                        }
                    }
                }
            }
            return(assetBundleDataList);
        }
Exemple #5
0
        public static void ExportExcelJson(XSSFWorkbook xssfWorkbook, string name, ConfigType configType)
        {
            string        exportPath    = $"{PathUtil.GetPath(PathType.DataPath, GetJsonPath(configType))}/{Path.GetFileNameWithoutExtension(name)}.txt";
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("{\n\t\"list\" : [");
            for (int i = 0; i < xssfWorkbook.NumberOfSheets; i++)
            {
                ExportSheetJson(xssfWorkbook.GetSheetAt(i), stringBuilder);
            }
            stringBuilder.Append("]\n}");
            FileUtil.SaveAsset(exportPath, stringBuilder.ToString());
        }
Exemple #6
0
        public Object CreateAssetFormTemplate(string pathName, string resourceFile)
        {
            //获取要创建资源的绝对路径
            string fullName = Path.GetFullPath(pathName);
            //获取资源的文件名
            string fileName = Path.GetFileNameWithoutExtension(pathName);
            //读取本地模版文件 替换默认的文件名
            string content = FileUtil.GetAsset(resourceFile).GetString().Replace(resourceFile.Substring(resourceFile.IndexOf('N'), resourceFile.IndexOf('.') - resourceFile.IndexOf('N')), fileName);

            //写入新文件
            FileUtil.SaveAsset(fullName, content);
            //刷新本地资源
            AssetDatabase.Refresh();
            return(AssetDatabase.LoadAssetAtPath(pathName, typeof(Object)));
        }
Exemple #7
0
        public Object CreateAssetFormTemplate(string pathName, string resourceFile)
        {
            //获取要创建资源的绝对路径
            string fullName = Path.GetFullPath(pathName);
            //获取资源的文件名
            string fileName = Path.GetFileNameWithoutExtension(pathName);
            //读取本地模版文件 替换默认的文件名
            string content = FileUtil.GetAsset(resourceFile).GetString().Replace("(Class)", fileName).Replace("(ViewModel)", fileName.Replace("Panel", string.Empty));

            //写入新文件
            FileUtil.SaveAsset(fullName, content);
            //刷新本地资源
            AssetDatabase.Refresh();
            return(AssetDatabase.LoadAssetAtPath(pathName, typeof(Object)));
        }
Exemple #8
0
        public void BuildCrossBinding()
        {
            if (string.IsNullOrEmpty(assets))
            {
                editorWindow.ShowNotification(new GUIContent("请输入程序集"));
                return;
            }
            if (string.IsNullOrEmpty(className))
            {
                editorWindow.ShowNotification(new GUIContent("请输入脚本名"));
                return;
            }
            string path = $"Library/ScriptAssemblies/{assets}.dll";

            if (!File.Exists(path))
            {
                editorWindow.ShowNotification(new GUIContent("程序集路径错误"));
                return;
            }
            Type type;

            if (string.IsNullOrEmpty(namespaceName))
            {
                type = Assembly.LoadFile(path).GetType(className);
            }
            else
            {
                type = Assembly.LoadFile(path).GetType($"{namespaceName}.{className}");
            }
            if (type == null)
            {
                editorWindow.ShowNotification(new GUIContent("没有此脚本"));
                return;
            }
            if (File.Exists($"Assets/Scripts/Runtime/Core/Manager/ILRuntime/Adapter/{className}Adapter.cs"))
            {
                File.Delete($"Assets/Scripts/Runtime/Core/Manager/ILRuntime/Adapter/{className}Adapter.cs");
            }
            FileUtil.SaveAsset($"Assets/Scripts/Runtime/Core/Manager/ILRuntime/Adapter/{className}Adapter.cs", CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(type, "LccModel"));
            AssetDatabase.Refresh();
        }
Exemple #9
0
        public static void ExportClass(string name, List <Cell> cellList, ConfigType configType)
        {
            string        exportPath    = $"{PathUtil.GetPath(PathType.DataPath, GetClassPath(configType))}/{name}.cs";
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < cellList.Count; i++)
            {
                Cell cell = cellList[i];
                if (cell.attribute.StartsWith("#"))
                {
                    continue;
                }
                stringBuilder.Append($"\t\t[ProtoMember({i + 1}, IsRequired = true)]\n");
                stringBuilder.Append($"\t\tpublic {cell.type} {cell.name} {{ get; set; }}");
                if (i != cellList.Count - 1)
                {
                    stringBuilder.Append("\n");
                }
            }
            string content = ExcelExportUtil.content.Replace("(LccModel)", $"Lcc{configType}").Replace("(CustomConfig)", name).Replace("(Propertys)", stringBuilder.ToString());

            FileUtil.SaveAsset(exportPath, content);
        }
Exemple #10
0
        public static void BuildAssetBundle(AssetBundleSetting assetBundleSetting)
        {
            Dictionary <string, AssetBundleData>     assetBundleDataDict     = new Dictionary <string, AssetBundleData>();
            Dictionary <string, AssetBundleRuleType> assetBundleRuleTypeDict = new Dictionary <string, AssetBundleRuleType>();
            string path = DirectoryUtil.GetDirectoryPath($"{assetBundleSetting.outputPath}/{GetPlatformForAssetBundle(EditorUserBuildSettings.activeBuildTarget)}");

            foreach (DirectoryInfo item in DirectoryUtil.GetDirectorys(new DirectoryInfo(path), new List <DirectoryInfo>()))
            {
                item.Delete();
            }
            foreach (FileInfo item in FileUtil.GetFiles(new DirectoryInfo(path), new List <FileInfo>()))
            {
                item.Delete();
            }
            List <AssetBundleBuild> assetBundleBuildList = new List <AssetBundleBuild>();

            foreach (AssetBundleRule item in assetBundleSetting.assetBundleRuleList)
            {
                if (item.assetBundleRuleType == AssetBundleRuleType.File)
                {
                    FileInfo[] fileInfos = FileUtil.GetFiles(new DirectoryInfo(item.path), new List <FileInfo>());
                    if (fileInfos.Length == 0)
                    {
                        continue;
                    }
                    List <FileInfo> fileInfoList = (from fileInfo in fileInfos where !string.IsNullOrEmpty(Path.GetExtension(fileInfo.Name)) && Path.GetExtension(fileInfo.Name) != ".meta" select fileInfo).ToList();
                    foreach (FileInfo fileInfo in fileInfoList)
                    {
                        assetBundleRuleTypeDict.Add(fileInfo.FullName.Substring(fileInfo.FullName.IndexOf("Assets")).Replace("\\", "/"), AssetBundleRuleType.File);
                    }
                }
                if (item.assetBundleRuleType == AssetBundleRuleType.Directory)
                {
                    DirectoryInfo[] directoryInfos = DirectoryUtil.GetDirectorys(new DirectoryInfo(item.path), new List <DirectoryInfo>()
                    {
                        new DirectoryInfo(item.path)
                    });
                    if (directoryInfos.Length == 0)
                    {
                        continue;
                    }
                    foreach (DirectoryInfo directoryInfo in directoryInfos)
                    {
                        foreach (FileInfo fileInfo in directoryInfo.GetFiles())
                        {
                            assetBundleRuleTypeDict.Add(fileInfo.FullName.Substring(fileInfo.FullName.IndexOf("Assets")).Replace("\\", "/"), AssetBundleRuleType.Directory);
                        }
                    }
                }
            }
            foreach (AssetBundleData item in assetBundleSetting.assetBundleDataList)
            {
                assetBundleBuildList.Add(new AssetBundleBuild()
                {
                    assetBundleName = item.assetBundleName,
                    assetNames      = item.assetNames,
                });
            }
            AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(path, assetBundleBuildList.ToArray(), BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);

            foreach (AssetBundleData item in assetBundleSetting.assetBundleDataList)
            {
                item.assetBundleHash = assetBundleManifest.GetAssetBundleHash(item.assetBundleName).ToString();
                BuildPipeline.GetCRCForAssetBundle($"{path}/{item.assetBundleName}", out item.assetBundleCRC);
                item.fileSize = FileUtil.GetFileSize($"{path}/{item.assetBundleName}");
                assetBundleDataDict.Add(Path.GetFileNameWithoutExtension(item.assetBundleName), item);
            }
            AssetBundleConfig assetBundleConfig = new AssetBundleConfig(assetBundleSetting.buildId, assetBundleDataDict, assetBundleRuleTypeDict);

            FileUtil.SaveAsset(path, "AssetBundleConfig.json", JsonUtil.ToJson(assetBundleConfig));
            if (assetBundleSetting.isCopyStreamingAssets)
            {
                string copyPath = DirectoryUtil.GetDirectoryPath(PathUtil.GetPath(PathType.StreamingAssetsPath, "Res", GetPlatformForAssetBundle(EditorUserBuildSettings.activeBuildTarget)));
                foreach (DirectoryInfo item in DirectoryUtil.GetDirectorys(new DirectoryInfo(copyPath), new List <DirectoryInfo>()))
                {
                    item.Delete();
                }
                foreach (FileInfo item in FileUtil.GetFiles(new DirectoryInfo(copyPath), new List <FileInfo>()))
                {
                    item.Delete();
                }
                foreach (FileInfo item in FileUtil.GetFiles(new DirectoryInfo(path), new List <FileInfo>()))
                {
                    if (Path.GetExtension(item.Name) == ".meta")
                    {
                        continue;
                    }
                    File.Copy(item.FullName, $"{PathUtil.GetPath(PathType.StreamingAssetsPath, "Res", GetPlatformForAssetBundle(EditorUserBuildSettings.activeBuildTarget))}/{item.Name}");
                }
            }
            AssetDatabase.Refresh();
        }
Exemple #11
0
        public void BuildCLRBinding()
        {
            AppDomain appDomain = new AppDomain();

            using (MemoryStream dll = new MemoryStream(RijndaelUtil.RijndaelDecrypt("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", FileUtil.GetAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes"))))
            {
                appDomain.LoadAssembly(dll);
                ILRuntimeUtil.LccFrameworkRegisterCrossBindingAdaptor(appDomain);
                BindingCodeGenerator.GenerateBindingCode(appDomain, "Assets/Scripts/Runtime/Core/Manager/ILRuntime/Generated");
            }
            AssetDatabase.Refresh();
        }