Exemplo n.º 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));
            }
        }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
        public void InitAssets(DownloadData downloadData)
        {
            byte[] bytes = FileUtil.GetAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res")}/AssetBundleConfig.json");
            localAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString());
            List <DownloadData> downloadDataList = new List <DownloadData>();

            foreach (string item in localAssetBundleConfig.assetBundleDataDict.Keys)
            {
                DownloadData data = new DownloadData(item, "", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res")}/{item}.unity3d");
                downloadDataList.Add(data);
            }
            //开始初始化资源
            DownloadManager.Instance.DownloadAsync(downloadDataList.ToArray());
        }
Exemplo n.º 4
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)));
        }
Exemplo n.º 5
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)));
        }
Exemplo n.º 6
0
        public void CheckLocalAsset()
        {
            byte[] bytes = FileUtil.GetAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res")}/AssetBundleConfig.json");
            if (bytes != null)
            {
                //开始更新
                localAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString());
                CheckUpdateAsset(null, string.Empty);
                return;
            }
            DownloadData downloadData = new DownloadData("AssetBundleConfig", "", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res")}/AssetBundleConfig.json");

            downloadData.complete = InitAssets;
            downloadData.error    = CheckUpdateAsset;
            DownloadManager.Instance.DownloadAsync(downloadData);
        }
Exemplo n.º 7
0
 public void InitAssets(Action <string> message = null, Action <int, int> copyProgress = null, Action <int, int> downloadProgress = null, Action <int, int> checkProgress = null, Action complete = null, Action <DownloadData, string> error = null)
 {
     Message          = message;
     CopyProgress     = copyProgress;
     DownloadProgress = downloadProgress;
     CheckProgress    = checkProgress;
     Complete         = complete;
     Error            = error;
     if (File.Exists($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/AssetBundleConfig.json"))
     {
         byte[] bytes = FileUtil.GetAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/AssetBundleConfig.json");
         localAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString());
         //更新资源
         UpdateAssets(string.Empty);
         return;
     }
     else
     {
         StartCoroutine(WebUtil.Download($"{"file:///"}{PathUtil.GetPath(PathType.StreamingAssetsPath, "Res", PathUtil.GetPlatformForAssetBundle())}/AssetBundleConfig.json", InitAssets, UpdateAssets));
     }
 }
Exemplo n.º 8
0
        public void UpdateAssets(DownloadData downloadData)
        {
            Message?.Invoke("检测资源中");
            byte[] bytes = FileUtil.GetAsset($"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/ServerAssetBundleConfig.json");
            serverAssetBundleConfig = JsonUtil.ToObject <AssetBundleConfig>(bytes.GetString());
            List <DownloadData> downloadDataList = new List <DownloadData>();

            if (localAssetBundleConfig == null)
            {
                foreach (string item in serverAssetBundleConfig.assetBundleDataDict.Keys)
                {
                    DownloadData data = new DownloadData(item, $"{url}/{PathUtil.GetPlatformForAssetBundle()}/{item}.unity3d", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{item}.unity3d");
                    data.Complete += DownloadComplete;
                    data.Error    += Error;
                    downloadDataList.Add(data);
                }
            }
            else if (localAssetBundleConfig.version < serverAssetBundleConfig.version)
            {
                foreach (string item in ComputeUpdateAssets())
                {
                    DownloadData data = new DownloadData(item, $"{url}/{PathUtil.GetPlatformForAssetBundle()}/{item}.unity3d", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{item}.unity3d");
                    data.Complete += DownloadComplete;
                    data.Error    += Error;
                    downloadDataList.Add(data);
                }
            }
            DownloadData data1 = new DownloadData(PathUtil.GetPlatformForAssetBundle(), $"{url}/{PathUtil.GetPlatformForAssetBundle()}/{PathUtil.GetPlatformForAssetBundle()}", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{PathUtil.GetPlatformForAssetBundle()}");

            data1.Complete += DownloadComplete;
            data1.Error    += Error;
            DownloadData data2 = new DownloadData($"{PathUtil.GetPlatformForAssetBundle()}.manifest", $"{url}/{PathUtil.GetPlatformForAssetBundle()}/{PathUtil.GetPlatformForAssetBundle()}.manifest", $"{PathUtil.GetPath(PathType.PersistentDataPath, "Res", PathUtil.GetPlatformForAssetBundle())}/{PathUtil.GetPlatformForAssetBundle()}.manifest");

            data2.Complete += DownloadComplete;
            data2.Error    += Error;
            downloadDataList.Add(data1);
            downloadDataList.Add(data2);
            updateCount = downloadDataList.Count;
            DownloadManager.Instance.DownloadAsync(downloadDataList.ToArray());
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
 /// <summary>
 /// 计算文件MD5
 /// </summary>
 /// <param name="path"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static string ComputeFileMD5(string path, string name)
 {
     byte[] bytes = FileUtil.GetAsset($"{path}/{name}");
     return(ComputeMD5(bytes));
 }
Exemplo n.º 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();
        }