internal static void Request(bool ignoreSession = false) { if (!ignoreSession) { if (SessionState.GetBool(sessionState, false)) { return; } SessionState.SetBool(sessionState, true); HMSEditorUtils.HandleAssemblyDefinitions(HMSPluginSettings.Instance.Settings.GetBool(PluginToggleEditor.PluginEnabled, true)); } Task.Delay(2000).ContinueWith(t => { GameObject obj = new GameObject(); obj.hideFlags = HideFlags.HideAndDontSave; request = obj.AddComponent <HMSPluginUpdateRequest>(); request.StartRequest(ignoreSession); }, TaskScheduler.FromCurrentSynchronizationContext()); }
public void OnPostGenerateGradleAndroidProject(string path) { if (!HMSPluginSettings.Instance.Settings.GetBool(PluginToggleEditor.PluginEnabled, true)) { HMSEditorUtils.HandleAssemblyDefinitions(false); return; } string fileName = "agconnect-services.json"; string filePath = Path.Combine(Application.streamingAssetsPath, fileName); string destPath = ""; #if UNITY_2019_3_OR_NEWER || UNITY_2020 destPath = Path.Combine(Directory.GetParent(path).FullName + "//launcher", fileName); string hmsMainTemplatePath = Application.dataPath + "/Plugins/Android/hmsMainTemplate.gradle"; FileUtil.CopyFileOrDirectory(hmsMainTemplatePath, Path.GetFullPath(path) + @"/hmsMainTemplate.gradle"); using (var writer = File.AppendText(Path.GetFullPath(path) + "/build.gradle")) writer.WriteLine("\napply from: 'hmsMainTemplate.gradle'"); string launcherTemplatePath = Application.dataPath + "/Plugins/Android/hmsLauncherTemplate.gradle"; FileUtil.CopyFileOrDirectory(launcherTemplatePath, Directory.GetParent(path).FullName + @"/launcher/hmsLauncherTemplate.gradle"); using (var writer = File.AppendText(Directory.GetParent(path).FullName + "/launcher/build.gradle")) writer.WriteLine("\napply from: 'hmsLauncherTemplate.gradle'"); string baseProjectTemplatePath = Application.dataPath + "/Plugins/Android/hmsBaseProjectTemplate.gradle"; FileUtil.CopyFileOrDirectory(baseProjectTemplatePath, Directory.GetParent(path).FullName + @"/hmsBaseProjectTemplate.gradle"); using (var writer = File.AppendText(Directory.GetParent(path).FullName + "/build.gradle")) writer.WriteLine("\napply from: 'hmsBaseProjectTemplate.gradle'"); if (HMSMainEditorSettings.Instance.Settings.GetBool(PushToggleEditor.PushKitEnabled)) { string unityPlayerActivityJavaPath = path + @"/src/main/java/com/unity3d/player/UnityPlayerActivity.java"; var sb = new StringBuilder(); FileStream fs = new FileStream(unityPlayerActivityJavaPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None); using (StreamReader sr = new StreamReader(fs)) { string line; do { line = sr.ReadLine(); sb.AppendLine(line); }while (line.Trim().TrimStart().TrimEnd() != "import android.os.Process;"); sb.AppendLine("import org.m0skit0.android.hms.unity.push.PushBridge;"); do { line = sr.ReadLine(); sb.AppendLine(line); }while (line.Trim().TrimStart().TrimEnd() != "mUnityPlayer.newIntent(intent);"); sb.AppendLine("PushBridge.OnNotificationMessage(intent);"); sb.Append(sr.ReadToEnd()); } using (var sw = new StreamWriter(unityPlayerActivityJavaPath)) { sw.Write(sb.ToString()); } } #elif UNITY_2018_1_OR_NEWER string hmsMainTemplatePath = Application.dataPath + @"/Plugins/Android/hmsMainTemplate.gradle"; var lines = File.ReadAllLines(hmsMainTemplatePath); File.AppendAllLines(path + "/build.gradle", lines); destPath = Path.Combine(path, fileName); #endif if (File.Exists(destPath)) { FileUtil.DeleteFileOrDirectory(destPath); } FileUtil.CopyFileOrDirectory(filePath, destPath); }