private static Dictionary <string, object> GetPushNotificationOptions(UnitySocialSettings settings) { if (settings == null) { return(null); } Dictionary <string, object> pnOptions = new Dictionary <string, object>(); string backend = settings.androidPushNotificationBackend; if (backend != null && backend.Length > 0) { pnOptions.Add("backend", backend); } else { return(null); } string senderId = settings.androidPushNotificationSenderId; if (senderId != null && senderId.Length > 0) { pnOptions.Add("senderId", senderId); } else { Debug.LogWarning("Push notifications backend is set but no sender ID is set. Disabling push notifications."); return(null); } return(pnOptions); }
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) { try { UnitySocialSettings settings = UnitySocialSettingsEditor.LoadSettings(); if (settings != null && string.IsNullOrEmpty(settings.bakedLeaderboards)) { Debug.LogError("Leaderboards info was not pulled from server. Use Edit/Unity Social/Bake Game Services Data menu item."); } if (settings != null && settings.isValid) { if (settings.iosSupportEnabled && target == BuildTarget.iOS) { pathToBuiltProject = FixErroneousPathComponent(pathToBuiltProject); UpdateXcodeProject(pathToBuiltProject); UpdatePlist(pathToBuiltProject, settings.clientId); Debug.Log("Unity Social postprocess done."); } } } catch (Exception e) { Debug.Log("Unity Social postprocess failed: " + e.ToString()); } }
// Handle delayed loading of the dependency resolvers. private static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath) { foreach (string asset in importedAssets) { if (asset.Contains("IOSResolver") || asset.Contains("JarResolver")) { RegisterDependencies(); break; } } UnitySocialSettings settings = UnitySocialSettingsEditor.LoadSettings(); if (settings == null) { return; } PluginImporter[] pluginImporters = PluginImporter.GetAllImporters(); foreach (PluginImporter pluginImporter in pluginImporters) { if (pluginImporter.assetPath.Contains("Plugins/UnitySocial/Native/Android")) { pluginImporter.SetCompatibleWithPlatform(BuildTarget.Android, settings.androidSupportEnabled); } } SetAndroidManifestConfig(settings); }
private void OnDisable() { if (m_CurrentSettings != null) { EditorUtility.SetDirty(m_CurrentSettings); m_CurrentSettings = null; } }
void OnDisable() { if (currentSettings != null) { EditorUtility.SetDirty(currentSettings); currentSettings = null; } }
public static void ValidateState(UnitySocialSettings settings) { bool isValid = false; if (settings != null && settings.isValid) { isValid = true; } UnitySocialPostprocessor.SetScriptingDefineSymbolForTarget(BuildTargetGroup.iOS, "UNITY_SOCIAL", isValid ? settings.iosSupportEnabled : false); UnitySocialPostprocessor.SetScriptingDefineSymbolForTarget(BuildTargetGroup.Android, "UNITY_SOCIAL", isValid ? settings.androidSupportEnabled : false); }
public static void ShowSettings() { UnitySocialSettings settingsInstance = LoadSettings(); if (settingsInstance == null) { settingsInstance = CreateSettings(); } if (settingsInstance != null) { Selection.activeObject = settingsInstance; } }
public static void BakeGameServicesData() { string upid = Application.cloudProjectId; UnitySocialSettings settings = (UnitySocialSettings)Resources.Load("UnitySocialSettings"); if (settings != null) { upid = settings.clientId; } FetchData(kLeaderboardsURL + upid, "Leaderboards", ref settings.bakedLeaderboards); EditorUtility.SetDirty(settings); AssetDatabase.SaveAssets(); }
public static void SetAndroidManifestConfig(UnitySocialSettings settings) { string configDir = Path.Combine(Application.dataPath, k_ConfigManifestDir); if (Directory.Exists(configDir)) { Directory.Delete(configDir, true); } if (settings.androidSupportEnabled) { Directory.CreateDirectory(configDir); CreateConfigManifestXML(settings); CreateConfigProjectProperties(); } }
public static void RegisterDependencies() { Google.VersionHandler.InvokeInstanceMethod(GetSvcSupport(), "ClearDependencies", new object[] {}); UnitySocialSettings settings = (UnitySocialSettings)Resources.Load("UnitySocialSettings"); if (settings != null && settings.androidSupportEnabled) { Debug.Log("Registering UnitySocial dependencies."); Google.VersionHandler.InvokeInstanceMethod( GetSvcSupport(), "DependOn", new object[] { "com.google.firebase", "firebase-messaging", "9.8.0" }, namedArgs: new Dictionary <string, object>() { { "packageIds", new string[] { "extra-google-m2repository" } } }); Google.VersionHandler.InvokeInstanceMethod( GetSvcSupport(), "DependOn", new object[] { "com.android.support", "support-v4", "23.0.1" }, namedArgs: new Dictionary <string, object>() { { "packageIds", new string[] { "extra-android-m2repository" } } }); Google.VersionHandler.InvokeInstanceMethod( GetSvcSupport(), "DependOn", new object[] { "com.android.support", "appcompat-v7", "23.0.1" }, namedArgs: new Dictionary <string, object>() { { "packageIds", new string[] { "extra-android-m2repository" } } }); Google.VersionHandler.InvokeInstanceMethod( GetSvcSupport(), "DependOn", new object[] { "com.android.support", "recyclerview-v7", "23.0.1" }, namedArgs: new Dictionary <string, object>() { { "packageIds", new string[] { "extra-android-m2repository" } } }); } }
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) { try { UnitySocialSettings settings = UnitySocialSettingsEditor.LoadSettings(); if (settings != null && settings.IsValid) { if (settings.iosSupportEnabled && target == kBuildTarget_iOS) { if (pathToBuiltProject.StartsWith("./")) // Fix two erroneous path cases on Unity 5.4f03 { pathToBuiltProject = Path.Combine(Application.dataPath.Replace("Assets", ""), pathToBuiltProject.Replace("./", "")); } else if (pathToBuiltProject.Contains("./")) { pathToBuiltProject = pathToBuiltProject.Replace("./", ""); } UpdateXcodeProject(pathToBuiltProject); UpdatePlist(pathToBuiltProject, settings.clientId); Debug.Log("Unity Social postprocess done."); } } else if (settings.androidSupportEnabled && target == BuildTarget.Android) { PluginImporter[] pluginImporters = PluginImporter.GetAllImporters(); foreach (PluginImporter pluginImporter in pluginImporters) { if (pluginImporter.assetPath.Contains("Plugins/UnitySocial/Native/Android")) { pluginImporter.SetCompatibleWithPlatform(BuildTarget.Android, settings.androidSupportEnabled); } } } } catch (Exception e) { Debug.Log("Unity Social postprocess failed: " + e.ToString()); } }
private static UnitySocialSettings CreateSettings() { UnitySocialSettings everyplaySettings = (UnitySocialSettings)ScriptableObject.CreateInstance(typeof(UnitySocialSettings)); if (everyplaySettings != null) { if (!Directory.Exists(System.IO.Path.Combine(Application.dataPath, "Plugins/UnitySocial/Resources"))) { AssetDatabase.CreateFolder("Assets/Plugins/UnitySocial", "Resources"); } AssetDatabase.CreateAsset(everyplaySettings, "Assets/Plugins/UnitySocial/Resources/" + kSettingsFile + kSettingsFileExtension); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return(everyplaySettings); } return(null); }
public static void ValidateState(UnitySocialSettings settings) { bool isValid = false; if (settings != null && settings.IsValid) { isValid = true; } foreach (BuildTargetGroup target in System.Enum.GetValues(typeof(BuildTargetGroup))) { if (target == kBuildTargetGroup_iOS) { UnitySocialPostprocessor.SetScriptingDefineSymbolForTarget(kBuildTargetGroup_iOS, "UNITY_SOCIAL", isValid ? settings.iosSupportEnabled : false); } else if (target == BuildTargetGroup.Android) { UnitySocialPostprocessor.SetScriptingDefineSymbolForTarget(BuildTargetGroup.Android, "UNITY_SOCIAL", isValid ? settings.androidSupportEnabled : false); } } }
public static UnitySocialBridge GetBridge() { if (s_BridgeInstance == null && !Application.isEditor) { UnitySocialSettings settings = (UnitySocialSettings)Resources.Load("UnitySocialSettings"); if (settings != null) { if (settings.enabled) { GameObject gameObject = new GameObject("UnitySocial"); if (gameObject != null) { gameObject.name = gameObject.name + gameObject.GetInstanceID(); s_BridgeInstance = gameObject.AddComponent <UnitySocialBridge>(); if (s_BridgeInstance != null) { #if UNITY_ANDROID && !UNITY_EDITOR && UNITY_SOCIAL var options = GetPushNotificationOptions(settings); s_AndroidPushNotificationOptions = (options != null) ? Tools.Json.Serialize(options) : null; #endif UnitySocialInitialize(settings.clientId, s_BridgeInstance.name, "{\"data\":[]}", settings.bakedLeaderboards); Factory.Initialize(new QuickMatchImpl(s_BridgeInstance)); } DontDestroyOnLoad(gameObject); } } } } return(s_BridgeInstance); }
private static void CreateConfigManifestXML(UnitySocialSettings settings) { string configDir = Path.Combine(Application.dataPath, k_ConfigManifestDir); string androidManifestXmlPath = Path.Combine(configDir, "AndroidManifest.xml"); XmlDocument doc = new XmlDocument(); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("android", "android"); XmlNode manifest = doc.CreateElement("manifest"); XmlAttribute manifestXmlnsAttribute = doc.CreateAttribute("xmlns:android"); manifestXmlnsAttribute.Value = "http://schemas.android.com/apk/res/android"; manifest.Attributes.Append(manifestXmlnsAttribute); XmlAttribute manifestPackageAttribute = doc.CreateAttribute("package"); manifestPackageAttribute.Value = "com.unity.unitysocial.internal"; manifest.Attributes.Append(manifestPackageAttribute); doc.AppendChild(manifest); XmlNode application = doc.CreateElement("application"); manifest.AppendChild(application); XmlElement activity = doc.CreateElement("activity"); XmlAttribute activityNameAttribute = doc.CreateAttribute(ns.LookupNamespace("android"), "name", "http://schemas.android.com/apk/res/android"); activityNameAttribute.Value = "com.unity.unitysocial.UriHandlerActivity"; activity.Attributes.Append(activityNameAttribute); XmlAttribute activityNoHistoryAttribute = doc.CreateAttribute(ns.LookupPrefix("android"), "noHistory", "http://schemas.android.com/apk/res/android"); activityNoHistoryAttribute.Value = "true"; activity.Attributes.Append(activityNoHistoryAttribute); application.AppendChild(activity); XmlNode intentFilter = doc.CreateElement("intent-filter"); activity.AppendChild(intentFilter); XmlNode action = doc.CreateElement("action"); XmlAttribute actionNameAttribute = doc.CreateAttribute(ns.LookupNamespace("android"), "name", "http://schemas.android.com/apk/res/android"); actionNameAttribute.Value = "android.intent.action.VIEW"; action.Attributes.Append(actionNameAttribute); intentFilter.AppendChild(action); XmlNode category0 = doc.CreateElement("category"); XmlAttribute category0NameAttribute = doc.CreateAttribute(ns.LookupNamespace("android"), "name", "http://schemas.android.com/apk/res/android"); category0NameAttribute.Value = "android.intent.category.DEFAULT"; category0.Attributes.Append(category0NameAttribute); intentFilter.AppendChild(category0); XmlNode category1 = doc.CreateElement("category"); XmlAttribute category1NameAttribute = doc.CreateAttribute(ns.LookupNamespace("android"), "name", "http://schemas.android.com/apk/res/android"); category1NameAttribute.Value = "android.intent.category.BROWSABLE"; category1.Attributes.Append(category1NameAttribute); intentFilter.AppendChild(category1); XmlNode data = doc.CreateElement("data"); XmlAttribute dataSchemeAttribute = doc.CreateAttribute(ns.LookupNamespace("android"), "scheme", "http://schemas.android.com/apk/res/android"); dataSchemeAttribute.Value = "us" + settings.clientId; data.Attributes.Append(dataSchemeAttribute); intentFilter.AppendChild(data); doc.Save(androidManifestXmlPath); }
public override void OnInspectorGUI() { try { // Might be null when this gui is open and this file is being reimported if (target == null) { Selection.activeObject = null; return; } m_CurrentSettings = (UnitySocialSettings)target; if (m_CurrentSettings != null) { bool settingsValid = m_CurrentSettings.isValid; EditorGUILayout.HelpBox("1) Enter your game credentials", MessageType.None); if (!m_CurrentSettings.isValid) { EditorGUILayout.HelpBox("Invalid or missing game credentials, Unity Social disabled.", MessageType.Error); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(s_LabelClientId, GUILayout.Width(108), GUILayout.Height(18)); string newClientId = TrimmedText(EditorGUILayout.TextField(m_CurrentSettings.clientId)); if (m_CurrentSettings.clientId != newClientId) { m_CurrentSettings.clientId = newClientId; GameServicesEditor.BakeGameServicesData(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.HelpBox("2) Enable Unity Social on these platforms", MessageType.None); EditorGUILayout.BeginVertical(); bool validityChanged = m_CurrentSettings.isValid != settingsValid; bool selectedPlatformsChanged = false; m_IOSSupportEnabled = EditorGUILayout.Toggle(s_LabelSupport_iOS, m_CurrentSettings.iosSupportEnabled); m_AndroidSupportEnabled = EditorGUILayout.Toggle(s_LabelSupport_Android, m_CurrentSettings.androidSupportEnabled); if (GUILayout.Button("Refresh Baked Game Services Data")) { GameServicesEditor.BakeGameServicesData(); } if (m_IOSSupportEnabled != m_CurrentSettings.iosSupportEnabled) { selectedPlatformsChanged = true; m_CurrentSettings.iosSupportEnabled = m_IOSSupportEnabled; if (m_IOSSupportEnabled) { FixiOSVersion(); } GameServicesEditor.BakeGameServicesData(); EditorUtility.SetDirty(m_CurrentSettings); } else if (m_AndroidSupportEnabled != m_CurrentSettings.androidSupportEnabled) { EnableAndroidSupport(m_AndroidSupportEnabled); UnitySocialAndroidDependencies.SetAndroidManifestConfig(m_CurrentSettings); selectedPlatformsChanged = true; m_CurrentSettings.androidSupportEnabled = m_AndroidSupportEnabled; GameServicesEditor.BakeGameServicesData(); if (m_AndroidSupportEnabled) { AndroidSdkVersions sdkVer = PlayerSettings.Android.minSdkVersion; if (sdkVer < AndroidSdkVersions.AndroidApiLevel16) { PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel16; Debug.Log("Unity Social requires minimum Android API level 16. API minSdkVersion updated to 16."); } } EditorUtility.SetDirty(m_CurrentSettings); } if (m_AndroidSupportEnabled) { AndroidPushNotificationSettings(); if (GUILayout.Button("Force Import Android dependencies")) { UnitySocialAndroidDependencies.PlayServicesImport(); } } if (validityChanged || selectedPlatformsChanged) { UnitySocialPostprocessor.ValidateState(m_CurrentSettings); } EditorGUILayout.EndVertical(); } } catch (Exception) { } }
public override void OnInspectorGUI() { try { // Might be null when this gui is open and this file is being reimported if (target == null) { Selection.activeObject = null; return; } currentSettings = (UnitySocialSettings)target; if (currentSettings != null) { bool settingsValid = currentSettings.IsValid; EditorGUILayout.HelpBox("1) Enter your game credentials", MessageType.None); if (!currentSettings.IsValid) { EditorGUILayout.HelpBox("Invalid or missing game credentials, Unity Social disabled.", MessageType.Error); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(labelClientId, GUILayout.Width(108), GUILayout.Height(18)); currentSettings.clientId = TrimmedText(EditorGUILayout.TextField(currentSettings.clientId)); EditorGUILayout.EndHorizontal(); EditorGUILayout.HelpBox("2) Enable Unity Social on these platforms", MessageType.None); EditorGUILayout.BeginVertical(); bool validityChanged = currentSettings.IsValid != settingsValid; bool selectedPlatformsChanged = false; iosSupportEnabled = EditorGUILayout.Toggle(labelSupport_iOS, currentSettings.iosSupportEnabled); androidSupportEnabled = EditorGUILayout.Toggle(labelSupport_Android, currentSettings.androidSupportEnabled); if (iosSupportEnabled != currentSettings.iosSupportEnabled) { selectedPlatformsChanged = true; currentSettings.iosSupportEnabled = iosSupportEnabled; if (iosSupportEnabled) { iOSTargetOSVersion v = PlayerSettings.iOS.targetOSVersion; if (v == iOSTargetOSVersion.iOS_4_0 || v == iOSTargetOSVersion.iOS_4_1 || v == iOSTargetOSVersion.iOS_4_2 || v == iOSTargetOSVersion.iOS_4_3 || v == iOSTargetOSVersion.iOS_5_0 || v == iOSTargetOSVersion.iOS_5_1 || v == iOSTargetOSVersion.iOS_6_0 || v == iOSTargetOSVersion.Unknown) { PlayerSettings.iOS.targetOSVersion = iOSTargetOSVersion.iOS_7_0; Debug.Log("Unity Social requires minimum iOS 7.0. Target OS version updated to 7.0"); } } EditorUtility.SetDirty(currentSettings); } else if (androidSupportEnabled != currentSettings.androidSupportEnabled) { EnableAndroidSupport(androidSupportEnabled); selectedPlatformsChanged = true; currentSettings.androidSupportEnabled = androidSupportEnabled; if (androidSupportEnabled) { AndroidSdkVersions sdkVer = PlayerSettings.Android.minSdkVersion; if (sdkVer < AndroidSdkVersions.AndroidApiLevel16) { PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel16; Debug.Log("Unity Social requires minimum Android API level 16. API minSdkVersion updated to 16."); } } EditorUtility.SetDirty(currentSettings); } if (validityChanged || selectedPlatformsChanged) { UnitySocialPostprocessor.ValidateState(currentSettings); } EditorGUILayout.EndVertical(); } } catch (Exception e) { if (e != null) { } } }