Exemple #1
0
            public static void CopyFolder(string sourcePath, string destinationPath)
            {
                if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(destinationPath))
                {
                    return;
                }
                DirectoryInfo source = new DirectoryInfo(sourcePath);
                DirectoryInfo target = new DirectoryInfo(destinationPath);

                if (!source.Exists)
                {
                    Debug.LogError("Directory not found : " + sourcePath);
                    return;
                }
                if (target.FullName.StartsWith(source.FullName, StringComparison.CurrentCultureIgnoreCase))
                {
                    Debug.LogError(string.Format("父目录 {0} 不能拷贝到子目录 {1}", sourcePath, destinationPath));
                    return;
                }

                CheckDir(destinationPath);
                foreach (FileSystemInfo fsi in source.GetFileSystemInfos())
                {
                    string destName = Path.Combine(destinationPath, fsi.Name);
                    if (fsi is System.IO.FileInfo)
                    {
                        File.Copy(fsi.FullName, destName, true);
                    }
                    else
                    {
                        Directory.CreateDirectory(destName);
                        CopyFolder(fsi.FullName, destName);
                    }
                }
            }
Exemple #2
0
 public static bool CheckSupportedTarget(BuildTargetGroup targetGroup, BuildTarget target)
 {
     //SupportedTargets
     if (!BuildPipeline.IsBuildTargetSupported(targetGroup, target))
     {
         Debug.LogError(string.Format("BuildTarget -> {0} is not supported, Please install first. ", target.ToString()));
         return(false);
     }
     return(true);
 }
        public void SetCompileFlagsForFile(string file, string headersPath, string compileFlags)
        {
            if (string.IsNullOrEmpty(file) || string.IsNullOrEmpty(compileFlags))
            {
                return;
            }
            string fileGuid = mProj.FindFileGuidByProjectPath(file);

            if (fileGuid == null)
            {
                Debug.LogError(string.Format("{0}: Cannot find {1}", TAG, file));
                return;
            }
            List <string> flags = compileFlags.Split(',')
                                  .Select(x =>
            {
                string returnString = x;
                while (true)
                {
                    if (returnString.IndexOf(" ") != 0)
                    {
                        break;
                    }
                    returnString = returnString.Substring(1);
                    if (string.IsNullOrEmpty(returnString))
                    {
                        return(x);
                    }
                }
                while (true)
                {
                    int spaceIndex = returnString.LastIndexOf(" ");
                    if ((returnString.Length - 1) != spaceIndex)
                    {
                        break;
                    }
                    returnString = returnString.Substring(0, (returnString.Length - 1));
                    if (string.IsNullOrEmpty(returnString))
                    {
                        return(x);
                    }
                }
                return(returnString);
            }).ToList();

            mProj.SetCompileFlagsForFile(mTargetGuid, fileGuid, flags);
            if (string.IsNullOrEmpty(headersPath))
            {
                return;
            }
            SetHeaderSearchPaths(new List <string>()
            {
                headersPath
            });
        }
Exemple #4
0
            public static void SetSplashLogos()
            {
                if (GlobalToolConfigure.Current == null || GlobalToolConfigure.Current.SDK == null)
                {
                    Debug.LogError("GlobalToolConfigure not found, Cannot set default icon");
                    return;
                }
                if (string.IsNullOrEmpty(GlobalToolConfigure.Current.SDK.DefaultIconFilter) || string.IsNullOrEmpty(GlobalToolConfigure.Current.SDK.DefaultIconFilterSearchPath))
                {
                    Debug.LogError("GlobalToolConfigure -> SplashLogosFilter、SplashLogosFilterSearchPath is error, Cannot set default icon");
                    return;
                }

                RestoreSplashData();
                Debug.Log("Starting set splash logos");
                string filter           = GlobalToolConfigure.Current.SDK.SplashLogosFilter;
                string filterSearchPath = BuildPipelineAsset.GetChannelFilterSearchPath(GlobalToolConfigure.Current.SDK.SplashLogosFilterSearchPath);
                var    folders          = new List <string>()
                {
                    filterSearchPath
                };

                string[] searchInFolders = folders.ToArray();
                string[] assets          = AssetDatabase.FindAssets(filter, searchInFolders);

                if (assets == null || assets.Length == 0)
                {
                    Debug.LogError(string.Format("Dir: {0} 下未找到匹配的资源, SplashLogos设置失败", filterSearchPath));
                    return;
                }
                PlayerSettingsResolver.SetSplashScreen(backgroundColor: Color.white, show: true, showUnityLogo: false, drawMode: PlayerSettings.SplashScreen.DrawMode.AllSequential);
                List <PlayerSettings.SplashScreenLogo> screenLogos = new List <PlayerSettings.SplashScreenLogo>();

                screenLogos.Clear();
                for (int i = 0; assets != null && i < assets.Length; i++)
                {
                    string assetPath = AssetDatabase.GUIDToAssetPath(assets[i]);
                    if (assetPath == null)
                    {
                        continue;
                    }
                    Sprite asset = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
                    if (asset == null)
                    {
                        continue;
                    }

                    screenLogos.Add(PlayerSettings.SplashScreenLogo.Create(2f, asset));
                }
                PlayerSettingsResolver.SetSplashScreen(screenLogos.ToArray());
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                Debug.Log("Set splash logos succeeded");
            }
Exemple #5
0
        private static bool CheckApplicationIdentifier(BuildTargetGroup buildTarget)
        {
            bool valid      = true;
            var  identifier = PlayerSettings.GetApplicationIdentifier(buildTarget);

            if (string.IsNullOrEmpty(identifier) || identifier == DEFAULT_BUNDLE)
            {
                Debug.LogError("Bundle Identifier has not been set up correctly. Please set the Bundle Identifier in the Player Settings. The value must follow the convention 'com.YourCompanyName.YourProductName' and can contain alphanumeric characters and underscore.");
                valid = false;
            }
            return(valid);
        }
Exemple #6
0
        public void Replace(string mark, string text)
        {
            if (string.IsNullOrEmpty(mark))
            {
                Debug.LogError(string.Format("File : {0} mark: {1} is null", mFilePath, mark));
                return;
            }
            int beginIndex = mContent.IndexOf(mark);

            if (beginIndex == -1)
            {
                Debug.LogError(string.Format("File : {0} not found replace mark: {1}", mFilePath, mark));
                return;
            }
            mContent = mContent.Replace(mark, text);
        }
Exemple #7
0
        private static bool CheckAndroidEnvironmentVariables()
        {
            bool   valid = true;
            string path  = AndroidEnvironmentVariables.AndroidSdkRoot;

            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("EditorPrefs -> {AndroidSdkRoot} not fonud");
                valid = false;
            }
            path = AndroidEnvironmentVariables.JdkPath;
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("EditorPrefs -> {JdkPath} not fonud");
                valid = false;
            }
            ScriptingImplementation scriptingImplementation = PlayerSettings.GetScriptingBackend(BuildTargetGroup.Android);

            if (scriptingImplementation == ScriptingImplementation.IL2CPP)
            {
                path = AndroidEnvironmentVariables.AndroidNdkRoot;
                if (string.IsNullOrEmpty(path))
                {
                    Debug.LogError("EditorPrefs -> {AndroidNdkRoot} not fonud");
                    valid = false;
                }
            }

            if (string.IsNullOrEmpty(PlayerSettings.Android.keystoreName) || string.IsNullOrEmpty(PlayerSettings.Android.keystorePass))
            {
                Debug.LogError("keystorepass is empty");
                valid = false;
            }
            if (string.IsNullOrEmpty(PlayerSettings.Android.keyaliasName) || string.IsNullOrEmpty(PlayerSettings.Android.keyaliasPass))
            {
                Debug.LogError("keyaliaspass is empty");
                //Debug.LogError("Unable to sign the application; please provide passwords!");
                valid = false;
            }

            return(valid);
        }
        private static int BuildPlayer(BuildEnvsOptions buildOptions, bool revealInFinder = false)
        {
            BuildPipelineCommonTools.FileUtils.CheckDir(Path.GetDirectoryName(buildOptions.locationPathName));
#if UNITY_2018_1_OR_NEWER
            UnityEditor.Build.Reporting.BuildReport  report  = BuildPipeline.BuildPlayer(buildOptions.GetBuildPlayerOptions());
            UnityEditor.Build.Reporting.BuildSummary summary = report.summary;
            string errorMessage   = string.Join("\n", report.steps.SelectMany(s => s.messages).Where(m => m.type == LogType.Error).Select(m => m.content).ToArray());
            bool   buildSucceeded = (summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded);
#else
            string errorMessage   = BuildPipeline.BuildPlayer(buildOptions.scenes, buildOptions.locationPathName, buildOptions.target, buildOptions.options);
            bool   buildSucceeded = !string.IsNullOrEmpty(errorMessage);
#endif

            UnityEngine.Debug.ClearDeveloperConsole();
            BuildPipelineExecutor.DefaultBuildEnvsOptions.DeletePackagingCacheFolders();
            if (buildSucceeded)
            {
                if (revealInFinder)
                {
                    EditorUtility.RevealInFinder(buildOptions.locationPathName);
                }
#if UNITY_2018_1_OR_NEWER
                Debug.Log("Build completed successfully for {0}: {1} mb and took {2} seconds with {3} error(s). Location: {4}",
                          summary.platform.ToString(),
                          (summary.totalSize / 1024 / 1024).ToString("N2"),
                          summary.totalTime.Seconds,
                          summary.totalErrors,
                          summary.outputPath
                          );
#else
                Debug.Log(string.Format("Build completed successfully for {0} to {1}", buildPlayerOptions.target, buildPlayerOptions.locationPathName));
#endif
                return(0);
            }
            else
            {
                Debug.LogError("Build failed with errors \n" + errorMessage);
                //throw new BuildFailedException("Build failed with errors \n" + errorMessage);
                return(1);
            }
        }
Exemple #9
0
        public void Append(string mark, string text)
        {
            if (string.IsNullOrEmpty(mark))
            {
                Debug.LogError(string.Format("File : {0} mark: {1} is null", mFilePath, mark));
                return;
            }
            if (mContent.Contains(text))
            {
                mContent.Replace(text, string.Empty);
            }

            int beginIndex = mContent.IndexOf(mark);

            if (beginIndex == -1)
            {
                Debug.LogError(string.Format("File : {0} not found append mark: {1}", mFilePath, mark));
                return;
            }
            int endIndex = mContent.LastIndexOf("\n", beginIndex + mark.Length);

            mContent = mContent.Substring(0, endIndex) + "\n" + text + "\n" + mContent.Substring(endIndex);
        }
Exemple #10
0
        //[UnityEditor.MenuItem("Tools/导出自解压安装包exe")]
        //public static void Test()
        //{
        //    string path = EditorUtility.OpenFolderPanel("请选择需要压缩的目录", "../ProjectBuilder/Output/PC", "");
        //    if (string.IsNullOrEmpty(path)) return;

        //    if (!File.Exists(path + "/ylqt-Setup.exe"))
        //    {
        //        EditorUtility.DisplayDialog("", "不合法的目录", "确认");
        //        return;
        //    }

        //    GenerateWinExe(path + "/ylqt-Setup.exe");
        //}

        public static void GenerateWinExe(string pathToBuiltProject)
        {
            Debug.Log("BuildProjectPath: " + pathToBuiltProject);
            string zipRootDir = Path.GetDirectoryName(pathToBuiltProject) + "/";
            string path       = Path.GetDirectoryName(pathToBuiltProject);
            int    index      = path.LastIndexOf("/");
            string setupName  = path.Substring(index, path.Length - index);
            //string setupExeName = Path.GetFileName(pathToBuiltProject);
            string targetExePath = zipRootDir + setupName + ".exe";

            if (File.Exists(targetExePath))
            {
                File.Delete(targetExePath);
            }

            //复制icon
            string icoFilePath   = zipRootDir + "icon.ico";
            string bmpFilePath   = zipRootDir + "icon.bmp";
            string sfxConfigPath = zipRootDir + "sfxConfig.txt";
            string uninstallPath = zipRootDir + "uninstall.exe";

            File.Copy("Assets/Res/Logo/PC/icon.ico", icoFilePath, true);
            File.Copy("Assets/Res/Logo/PC/icon.bmp", bmpFilePath, true);
            File.Copy("Assets/Res/Logo/PC/sfxConfig.txt", sfxConfigPath, true);
            File.Copy("Assets/Res/Logo/PC/uninstall.exe", uninstallPath, true);

            //获取winrar路径
            var    regKeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe";
            string winrarPath = null;

            try
            {//windows
                var regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKeyPath);
                winrarPath = regKey.GetValue("").ToString();
                regKey.Close();
            }
            catch (Exception)
            {//mac os
                winrarPath = "/usr/local/bin/rar";
                File.Copy("Assets/Res/Logo/PC/sfxConfigMac.txt", sfxConfigPath, true);
            }

            Debug.Log("WinRAR.exe Path=" + winrarPath);

            //        StringBuilder sfxConfig = new StringBuilder();
            //        sfxConfig.AppendLine("Title=妖恋奇谭安装程序"); //安装标题
            //        sfxConfig.AppendLine("Text=妖恋奇谭说明"); //安装说明
            //        sfxConfig.AppendLine("Path=C:\\Program Files\\ylqt\\"); //安装路径
            //        sfxConfig.AppendLine("Shortcut=D," + setupExeName + ",,,"+"妖恋奇谭,"+ "icon.ico"); //桌面快捷方式
            //        sfxConfig.AppendLine("Overwrite=1"); //覆盖所有文件
            //        sfxConfig.AppendLine("Update=U"); //更新新的或不存在的文件
            //        sfxConfig.AppendLine(
            //@"License=最终用户许可协议书
            //{
            //所有版权于 妖恋奇谭 均属于作者所专有。
            //此程序是共享软件,任何人在测试期限内均可以使用此软件。
            //在测试期限过后,您“必须”注册。
            //}"
            //        ); //许可
            //File.WriteAllText(sfxConfigPath, sfxConfig.ToString());

            string argument = "";

            argument += "a -r -sfx ";           //压缩,递归,自解压
            argument += "-iimg" + "icon.bmp ";  //解压图标
            argument += "-iicon" + "icon.ico "; //解压图标
            argument += "-zsfxConfig.txt ";     //注释

            argument += targetExePath + " * ";  //指定目录

            Debug.Log("argument=" + argument);
            try
            {//运行进程
                var p = new System.Diagnostics.Process();
                p.StartInfo.FileName               = winrarPath;
                p.StartInfo.WorkingDirectory       = zipRootDir;
                p.StartInfo.Arguments              = argument;
                p.StartInfo.ErrorDialog            = false;
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.CreateNoWindow         = false;
                p.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Normal;//与CreateNoWindow联合使用可以隐藏进程运行的窗体
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardInput  = true;
                p.StartInfo.RedirectStandardError  = true;
                p.EnableRaisingEvents              = true;         // 启用Exited事件
                                                                   //p.Exited += p_Exited;
                p.Start();

                p.WaitForExit();

                if (p.ExitCode == 0)//正常退出
                {
                    //TODO记录日志
                    Debug.Log("执行完毕!");
                }
                else
                {
                    Debug.LogError("error exitcode " + p.ExitCode);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("系统错误:", ex);
            }
        }
Exemple #11
0
            public static void SetSplashScreen()
            {
                if (GlobalToolConfigure.Current == null || GlobalToolConfigure.Current.SDK == null)
                {
                    Debug.LogError("GlobalToolConfigure not found, Cannot set default icon");
                    return;
                }
                if (string.IsNullOrEmpty(GlobalToolConfigure.Current.SDK.DefaultIconFilter) || string.IsNullOrEmpty(GlobalToolConfigure.Current.SDK.DefaultIconFilterSearchPath))
                {
                    Debug.LogError("GlobalToolConfigure -> SplashScreenFilter、SplashScreenFilterSearchPath is error, Cannot set default icon");
                    return;
                }

                RestoreSplashData();
                Debug.Log("Starting set splash screen");
                string filter           = GlobalToolConfigure.Current.SDK.SplashScreenFilter;
                string filterSearchPath = BuildPipelineAsset.GetChannelFilterSearchPath(GlobalToolConfigure.Current.SDK.SplashScreenFilterSearchPath);
                var    folders          = new List <string>()
                {
                    filterSearchPath
                };

                string[] searchInFolders = folders.ToArray();
                string[] assets          = AssetDatabase.FindAssets(filter, searchInFolders);

                if (assets == null || assets.Length == 0)
                {
                    Debug.LogError(string.Format("Dir: {0} 下未找到匹配的资源, SplashScreen设置失败", filterSearchPath));
                    return;
                }
                PlayerSettingsResolver.SetSplashScreen(backgroundColor: Color.white, show: true, showUnityLogo: false, drawMode: PlayerSettings.SplashScreen.DrawMode.AllSequential);

                List <Texture2D> mSplashs = new List <Texture2D>();

                mSplashs.Clear();
                for (int i = 0; assets != null && i < assets.Length; i++)
                {
                    string assetPath = AssetDatabase.GUIDToAssetPath(assets[i]);
                    if (assetPath == null)
                    {
                        continue;
                    }
                    Texture2D asset = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath);
                    if (asset == null)
                    {
                        continue;
                    }
                    mSplashs.Add(asset);
                }

                BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget;

                switch (buildTarget)
                {
                case BuildTarget.iOS:
                    PlayerSettingsResolver.iOS.SetiPhoneLaunchScreenType(iOSLaunchScreenType.ImageAndBackgroundRelative);
                    QuickEditorUtils.SetSplashScreen("iOSLaunchScreenPortrait", mSplashs[0]);
                    QuickEditorUtils.SetSplashScreen("iOSLaunchScreenLandscape", mSplashs[0]);
                    break;

                case BuildTarget.Android:
                    QuickEditorUtils.SetSplashScreen("androidSplashScreen", mSplashs[0]);
                    break;

                default:
                    break;
                }
                //PlayerSettings.SplashScreen.background = mSplashs[0];
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                Debug.Log("Set splash screen succeeded");
            }
Exemple #12
0
            public static void SetDefaultIcon()
            {
                if (GlobalToolConfigure.Current == null || GlobalToolConfigure.Current.SDK == null)
                {
                    Debug.LogError("GlobalToolConfigure not found, Cannot set default icon");
                    return;
                }
                if (string.IsNullOrEmpty(GlobalToolConfigure.Current.SDK.DefaultIconFilter) || string.IsNullOrEmpty(GlobalToolConfigure.Current.SDK.DefaultIconFilterSearchPath))
                {
                    Debug.LogError("GlobalToolConfigure -> DefaultIconFilter、DefaultIconFilterSearchPath is error, Cannot set default icon");
                    return;
                }

                Debug.Log("Starting set default icon");
                string filter           = GlobalToolConfigure.Current.SDK.DefaultIconFilter;
                string filterSearchPath = BuildPipelineAsset.GetChannelFilterSearchPath(GlobalToolConfigure.Current.SDK.DefaultIconFilterSearchPath);
                var    folders          = new List <string>()
                {
                    filterSearchPath
                };

                string[] searchInFolders = folders.ToArray();
                string[] assets          = AssetDatabase.FindAssets(filter, searchInFolders);

                if (assets == null || assets.Length == 0)
                {
                    Debug.LogError(string.Format("Dir: {0} 下未找到匹配的资源, Icon设置失败", filterSearchPath));
                    return;
                }

                List <Texture2D> mTextures = new List <Texture2D>();

                mTextures.Clear();
                for (int i = 0; assets != null && i < assets.Length; i++)
                {
                    string assetPath = AssetDatabase.GUIDToAssetPath(assets[i]);
                    if (assetPath == null)
                    {
                        continue;
                    }
                    Texture2D asset = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath);
                    if (asset == null)
                    {
                        continue;
                    }
                    mTextures.Add(asset);
                }

                BuildTarget      buildTarget      = EditorUserBuildSettings.activeBuildTarget;
                BuildTargetGroup buildTargetGroup = BuildPipelineCommonTools.BuildUtils.GetBuildTargetGroup(buildTarget);

                int[]       iconSize     = PlayerSettings.GetIconSizesForTargetGroup(buildTargetGroup);
                Texture2D[] textureArray = new Texture2D[iconSize.Length];
                for (int i = 0; i < textureArray.Length; i++)
                {
                    textureArray[i] = mTextures[0];
                }
                PlayerSettings.SetIconsForTargetGroup(buildTargetGroup, textureArray);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();

                Debug.Log("Set default icon succeeded");
                //MethodInfo getIconFormPlatform = typeof(PlayerSettings).GetMethod("GetIconsForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
                //MethodInfo getIconSizesForPlatform = typeof(PlayerSettings).GetMethod("GetIconSizesForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
                //MethodInfo setIconsForPlatform = typeof(PlayerSettings).GetMethod("SetIconsForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
                //Texture2D[] textureArray = (Texture2D[])getIconFormPlatform.Invoke(null, new object[] { string.Empty });
                //var iconSizesForPlatform = (int[])getIconSizesForPlatform.Invoke(null, new object[] { string.Empty });
                //if (textureArray.Length != iconSizesForPlatform.Length)
                //{
                //    textureArray = new Texture2D[iconSizesForPlatform.Length];
                //    setIconsForPlatform.Invoke(null, new object[] { string.Empty, textureArray });
                //}
                //textureArray[0] = mTextures[0];
                //setIconsForPlatform.Invoke(null, new object[] { string.Empty, textureArray });
                //AssetDatabase.SaveAssets();
            }