少年修仙传客户端基础资源
lwb
2021-01-15 91daa5595c4e07081db6993c51735d167b2eed34
Assets/Editor/Tool/ClientPackage.cs
@@ -34,9 +34,20 @@
        set { LocalSave.SetInt("HalfAssetPrior", value); }
    }
    static string ANDROID_PLUGIN_PATH = Application.dataPath + "/Plugins/Android";
    static string THE_2TH_WORLD_SDK_PATH = Application.dataPath + "/Plugins/Android/bin";
    // static string MANIFEST_PATH = Application.dataPath + "/Plugins/Android/AndroidManifest.xml";
    static string iOS_PLUGIN_PATH = Application.dataPath + "/Plugins/iOS";
    /// <summary>
    /// 打包
    /// </summary>
    /// <param name="_sdkPath">整合sdk路径</param>
    /// <param name="_assetBundlePath">_assetBundle的资源路径,默认在项目目录下的 AssetBundles/android</param>
    /// <param name="_output">打包完成后的输出路径</param>
    /// <param name="_publisherString">渠道id,可打多个包,用|分割</param>
    /// <param name="_buildIndex">打包序序号,用于标识名称</param>
    /// <param name="_development">是否为开发版</param>
    /// <param name="_replace">ios打包导出xcode工程模式,Append和Replace</param>
    public static void BuildPublishers(string _sdkPath, string _assetBundlePath, string _output, string _publisherString, int _buildIndex, bool _development, bool _replace)
    {
        var publisherIds = new List<string>();
@@ -120,41 +131,35 @@
                    || file.FullName.Contains("HelpInfo.txt")
                    || file.FullName.Contains("PriorBundle.txt")
                    || file.FullName.Contains("PriorLanguage.txt")
                    || file.FullName.Contains("ApkUpdateUrl.txt"))
                    || file.FullName.Contains("ApkUpdateUrl.txt")
                    || file.FullName.Contains("InitialFunction.txt"))
                {
                    builtInFiles.Add(file);
                    continue;
                }
                File.Delete(file.FullName);
                // File.Delete(file.FullName);
            }
            var totalCount = builtInFiles.Count;
            var completeCount = 0;
            foreach (var item in builtInFiles)
            {
                var directory = Path.GetDirectoryName(item.FullName);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                var relativePath = FileExtersion.GetFileRelativePath(_assetBundlePath, item.FullName);
                var to = StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, relativePath);
#if UNITY_ANDROID
                var extension = Path.GetExtension(item.FullName);
                if (extension == ".meta")
                {
                    continue;
                }
                to = to + ".7z";
                SevenZipUtility.Compress(item.FullName, to);
                UnityEditor.EditorUtility.DisplayProgressBar("正在压缩资源", item.Name, (float)completeCount / totalCount);
#elif UNITY_IOS
                File.Copy(item.FullName,to,true);
#endif
                var relativePath = FileExtersion.GetFileRelativePath(_assetBundlePath, item.FullName);
                var to = StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, relativePath);
                var directory = Path.GetDirectoryName(to);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                File.Copy(item.FullName, to, true);
                completeCount++;
            }
@@ -276,24 +281,18 @@
            {
                var relativePath = FileExtersion.GetFileRelativePath(_assetBundlePath, item.FullName);
                var to = StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, relativePath);
                if (relativePath.StartsWith("patch"))//不包含meta文件和补丁
                    continue;
                var directory = Path.GetDirectoryName(to);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
#if UNITY_ANDROID
                var extension = Path.GetExtension(item.FullName);
                if (extension == ".meta")
                {
                    continue;
                }
                to = to + ".7z";
                SevenZipUtility.Compress(item.FullName, to);
                UnityEditor.EditorUtility.DisplayProgressBar("正在压缩资源", item.Name, (float)completeCount / totalCount);
#elif UNITY_IOS
                File.Copy(item.FullName,to,true);
#endif
                File.Copy(item.FullName, to, true);
                completeCount++;
            }
@@ -319,24 +318,18 @@
            {
                var relativePath = FileExtersion.GetFileRelativePath(_assetBundlePath, item.FullName);
                var to = StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, relativePath);
                if (relativePath.StartsWith("patch"))//不包含meta文件和补丁
                    continue;
                var directory = Path.GetDirectoryName(to);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
#if UNITY_ANDROID
                var extension = Path.GetExtension(item.FullName);
                if (extension == ".meta")
                {
                    continue;
                }
                to = to + ".7z";
                SevenZipUtility.Compress(item.FullName, to);
                UnityEditor.EditorUtility.DisplayProgressBar("正在压缩资源", item.Name, (float)completeCount / totalCount);
#elif UNITY_IOS
                File.Copy(item.FullName,to,true);
#endif
                File.Copy(item.FullName, to, true);
                completeCount++;
            }
@@ -354,6 +347,7 @@
    public static void BuildApk(string _sdkPath, string _output, string _publisher, int _buildIndex, bool _development)
    {
        return;
        PreBuild(_publisher, _buildIndex);
        var auditTimeFile = StringUtility.Contact(Application.dataPath, Path.DirectorySeparatorChar, "Resources/Config/AuditTime.txt");
        if (File.Exists(auditTimeFile))
@@ -384,38 +378,68 @@
        // 针对某一些打包的特殊性, 这里特指依赖的第三方库含有资源的问题
        // 这里对有这种特型的渠道的sdk在打包的时候差异化gradle文件
        // 更名原有文件
        string _gradleTemplateUrl = EditorApplication.applicationContentsPath + "/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/";
        string _gradleFileUrl = _gradleTemplateUrl + "mainTemplate.gradle";
        string _diffGradleFileUrl = StringUtility.Contact(_sdkPath, "/GradleDiff/", versionConfig.appId, "/mainTemplate.gradle");
        FileInfo _fileInfo = new FileInfo(_diffGradleFileUrl);
        // string _gradleTemplateUrl = EditorApplication.applicationContentsPath + "/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/";
        // string _gradleFileUrl = _gradleTemplateUrl + "mainTemplate.gradle";
        // string _diffGradleFileUrl = StringUtility.Contact(_sdkPath, "/GradleDiff/", versionConfig.appId, "/mainTemplate.gradle");
        // FileInfo _fileInfo = new FileInfo(_diffGradleFileUrl);
        if (!_fileInfo.Exists)
        {
            EditorUtility.DisplayDialog("警告", "Gradle模式需要配置差异文件,但是没有找到该文件: " + _diffGradleFileUrl, "@Hale");
            return;
        }
        // if (!_fileInfo.Exists)
        // {
        //     EditorUtility.DisplayDialog("警告", "Gradle模式需要配置差异文件,但是没有找到该文件: " + _diffGradleFileUrl, "@Hale");
        //     return;
        // }
        _fileInfo.CopyTo(_gradleFileUrl, true);
        // _fileInfo.CopyTo(_gradleFileUrl, true);
        // 移动配置文件至打包工作目录中
        PlayerSettings.Android.keystoreName = Application.dataPath + "/Editor/Keystore/" + versionConfig.keystoreFileName + ".keystore";
        var keystorePath = Application.dataPath + "/Editor/Keystore/" + versionConfig.keystoreFileName + ".keystore";
        if (!File.Exists(keystorePath))
        {
            Debug.LogError("签名文件不存在");
            return;
        }
        PlayerSettings.Android.keystoreName = keystorePath;
        PlayerSettings.Android.keystorePass = versionConfig.keystorePassword;
        PlayerSettings.Android.keyaliasName = versionConfig.keystoreAlias;
        PlayerSettings.Android.keyaliasPass = versionConfig.keystoreAliasPassword;
        PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevel22;
        // PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevel22;
        PlayerSettings.Android.bundleVersionCode = VersionConfig.GetVersionNumber(versionConfig.version);
        PlayerSettings.enableInternalProfiler = _development;
        if (Directory.Exists(ANDROID_PLUGIN_PATH))
        {
            Directory.Delete(ANDROID_PLUGIN_PATH, true);
        }
        //删除原sdk文件
        if (Directory.Exists(THE_2TH_WORLD_SDK_PATH))
            Directory.Delete(THE_2TH_WORLD_SDK_PATH, true);
        //删除原清单文件
        // if (File.Exists(MANIFEST_PATH))
        //     File.Delete(MANIFEST_PATH);
        Debug.LogFormat("执行Android SDK 文件拷贝,from:{0};to:{1}", StringUtility.Contact(_sdkPath, "/Android/release"), ANDROID_PLUGIN_PATH);
        FileExtersion.DirectoryCopy(StringUtility.Contact(_sdkPath, "/Android/release"), ANDROID_PLUGIN_PATH);
        FileExtersion.DirectoryCopy(StringUtility.Contact(_sdkPath, "/ChannelDiff/Android/", versionConfig.appId), ANDROID_PLUGIN_PATH);
        var variant = _development ? "debug" : "release";
        // var manifestpath = StringUtility.Contact(_sdkPath, "/Channel/Android/", versionConfig.appId, "/AndroidManifest.xml");
        var channelSdkPath = StringUtility.Contact(_sdkPath, "/Channel/Android/", versionConfig.appId, "/", variant);
        // if (File.Exists(manifestpath))
        // {
        //     File.Copy(manifestpath, MANIFEST_PATH);
        //     DebugEx.LogFormat("执行Android 清单文件拷贝,from:{0};to:{1}", manifestpath, MANIFEST_PATH);
        // }
        // else
        // {
        //     DebugEx.LogFormat("Android 清单文件不存在,{0}", manifestpath);
        //     // return;
        // }
        if (Directory.Exists(channelSdkPath))
        {
            FileExtersion.DirectoryCopy(channelSdkPath, THE_2TH_WORLD_SDK_PATH);
            DebugEx.LogFormat("执行Android 渠道SDK 文件拷贝,from:{0};to:{1}", channelSdkPath, THE_2TH_WORLD_SDK_PATH);
        }
        else
        {
            DebugEx.LogFormat("Android 渠道SDK文件不存在,{0}", channelSdkPath);
            return;
        }
        var option = AssetDatabase.LoadAssetAtPath<Options>("Assets/Editor/Beebyte/Obfuscator/ObfuscatorOptions.asset");
        if (option != null)
@@ -427,6 +451,8 @@
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        IFix.Editor.IFixEditor.InjectAllAssemblys();//对injectAssemblys里的程序集进行注入,然后备份
        if (_development)
        {
            var apkName = StringUtility.Contact(_output, "/", versionName, "_", versionConfig.clientPackageFlag, "_v", versionConfig.m_Version, "_", _buildIndex, "_development.apk");
@@ -437,17 +463,6 @@
            var apkName = StringUtility.Contact(_output, "/", versionName, "_", versionConfig.clientPackageFlag, "_v", versionConfig.m_Version, "_", _buildIndex, ".apk");
            BuildPipeline.BuildPlayer(baseLevels, apkName, BuildTarget.Android, BuildOptions.None);
        }
        FileUtil.MoveFileOrDirectory(Application.dataPath + "/Scripts/PocoSDK",
                                     Application.dataPath + "/Editor/PocoSDK");
        var _content = File.ReadAllText(Application.dataPath + "/Scripts/Core/GameEngine/Login/Launch.cs");
        int _start = _content.IndexOf("// ## PocoManager Start") + "// ## PocoManager Start".Length;
        int _end = _content.IndexOf("// ## PocoManager End");
        var _front = _content.Substring(0, _start);
        var _back = _content.Substring(_end);
        _content = _front + "\r\n// ## PocoManager\r\n" + _back;
        File.WriteAllText(Application.dataPath + "/Scripts/Core/GameEngine/Login/Launch.cs", _content);
    }
    public static void BuildIpa(string _sdkPath, string _publisher, int _buildIndex, bool _replace)
@@ -463,31 +478,33 @@
            Directory.Delete(iOS_PLUGIN_PATH, true);
        }
        if (!versionConfig.appId.Equals("test"))
        {
            FileExtersion.DirectoryCopy(StringUtility.Contact(_sdkPath, "/ChannelDiff/iOS/", versionConfig.appId), iOS_PLUGIN_PATH);
        }
        // if (!versionConfig.appId.Equals("test"))
        // {
        FileExtersion.DirectoryCopy(StringUtility.Contact(_sdkPath, "/ChannelDiff/iOS/", versionConfig.appId), iOS_PLUGIN_PATH);
        // }
        DateTime outTime;
        var correct = DateTime.TryParse(auditOutTime, out outTime);
        var directory = Application.dataPath + Path.DirectorySeparatorChar + "Resources/Config";
        if (Directory.Exists(directory))
        if (!Directory.Exists(directory))
        {
            Directory.CreateDirectory(directory);
        }
        File.WriteAllText(Application.dataPath + Path.DirectorySeparatorChar + "Resources/Config/AuditTime.txt", correct ? auditOutTime : "");
        var option = AssetDatabase.LoadAssetAtPath<Options>("Assets/Editor/Beebyte/Obfuscator/ObfuscatorOptions.asset");
        if (option!=null)
        if (option != null)
        {
            option.enabled = obfuscatorEnabled;
            EditorUtility.SetDirty(option);
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        PlayerSettings.iOS.buildNumber = VersionConfig.Get().buildIndex.ToString();
        PlayerSettings.iOS.appleDeveloperTeamID = VersionConfig.Get().appleDeveloperTeamID;
        IFix.Editor.IFixEditor.InjectAllAssemblys();//对injectAssemblys里的程序集进行注入,然后备份
        if (_replace)
        {
@@ -517,10 +534,18 @@
            newVersionConfig.buildTime = DateTime.Now.ToString("yy/MM/dd--HH:mm");
            newVersionConfig.buildIndex = _buildIndex;
            if (File.Exists(Application.dataPath + "/Resources/Game.txt"))
            {
                File.Delete(Application.dataPath + "/Resources/Game.txt");
            }
            File.WriteAllText(Application.dataPath + "/Resources/Game.txt", GetGameId(_publisher));
            AssetDatabase.CreateAsset(newVersionConfig, newVersionConfigPath);
            EditorUtility.SetDirty(newVersionConfig);
            SetIconAndSplashImage(versionName);
            //SetCreateRoleAnimation();
            PlayerSettings.companyName = "TheSecondWorld";
            PlayerSettings.productName = newVersionConfig.productName;
@@ -532,34 +557,11 @@
            PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;
            PlayerSettings.bundleVersion = VersionConfig.GetVersionNumber(newVersionConfig.version).ToString();
            if (VersionConfig.Get().appId.Equals("test"))
            if (GetBuildTarget() == BuildTargetGroup.Android)
            {
                FileUtil.MoveFileOrDirectory(Application.dataPath + "/Editor/PocoSDK",
                                             Application.dataPath + "/Scripts/PocoSDK");
                var _launchScript = File.ReadAllText(Application.dataPath + "/Scripts/Core/GameEngine/Login/Launch.cs");
                if (_launchScript != null)
                {
                    if (_launchScript.IndexOf("// ## PocoManager") == -1)
                    {
                        Debug.LogError("找不到替代字符串");
                    }
                    else
                    {
                        _launchScript.Replace("// ## PocoManager",
                        "if (VersionConfig.Get().appId.Equals(\"test\"))" +
                        "{" +
                            "SnxxzGame.Instance.gameObject.AddComponent<PocoManager>();" +
                        "}");
                        File.WriteAllText(Application.dataPath + "/Scripts/Core/GameEngine/Login/Launch.cs",
                                          _launchScript);
                    }
                }
                CSObjectWrapEditor.Generator.ClearAll();
                CSObjectWrapEditor.Generator.GenAll();
            }
            CSObjectWrapEditor.Generator.ClearAll();
            CSObjectWrapEditor.Generator.GenAll();
        }
        catch (Exception ex)
        {
@@ -594,6 +596,22 @@
        return null;
    }
    static string GetGameId(string _publisher)
    {
        var lines = File.ReadAllLines(versionsFilePath);
        for (int i = 2; i < lines.Length; i++)
        {
            var line = lines[i];
            var lineStrings = line.Split('\t');
            if (lineStrings[0] == _publisher)
            {
                return lineStrings[7];
            }
        }
        return "xbqy";
    }
    static void SetIconAndSplashImage(string _versionName)
    {
        var buildTarget = GetBuildTarget();
@@ -626,6 +644,22 @@
        }
    }
    public static void SetCreateRoleAnimation()
    {
        var from = "Assets/Editor/Video/CreateRoleMovie.mp4";
        var to = "Assets/StreamingAssets/CreateRoleMovie.mp4";
        if (!Directory.Exists(Application.dataPath + "StreamingAssets"))
        {
            Directory.CreateDirectory(Application.dataPath + "StreamingAssets");
        }
        if (AssetDatabase.LoadAssetAtPath<UnityEngine.Video.VideoClip>(to) == null)
        {
            AssetDatabase.CopyAsset(from, to);
        }
    }
    static BuildTargetGroup GetBuildTarget()
    {
#if UNITY_ANDROID