Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HUP-874] fix: Splash ad icon error, kit settings error fixed and added manual script complatiton button in Huawei/Utils menu. #512

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Assets/Huawei/Demos/Ads/AdsDemoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private void Init()
HMSAdsKitManager.Instance = new Builder()
.SetHasPurchasedNoAds(false)
.SetRewardedAdLoadMethod(RewardedAdLoadMethod, rewardVerifyConfig)
.SetBannerAdLoadMethod(InterstitialAdLoadMethod)
.SetInterstitialAdLoadMethod(BannerAdLoadMethod)
.SetBannerAdLoadMethod(BannerAdLoadMethod)
.SetInterstitialAdLoadMethod(InterstitialAdLoadMethod)
.SetSplashAdLoadMethod(SplashAdLoadMethod)
.Build();

Expand Down
5 changes: 5 additions & 0 deletions Assets/Huawei/Editor/View/MainWindow/HMSMainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static void KeyTool()
{
GetWindow(typeof(HMSKeyToolWindow), false, "HMS Key Tool", true);
}
[MenuItem("Huawei/Utils/Script Compilation")]
public static void ScriptCompilation()
{
GetWindow(typeof(CompilationWindow), false, "Script Compilation", true);
}

public override IDrawer CreateDrawer()
{
Expand Down
46 changes: 46 additions & 0 deletions Assets/Huawei/Editor/View/Utils/CompilationWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using UnityEditor;
#if UNITY_2019_3_OR_NEWER
using UnityEditor.Compilation;
#elif UNITY_2017_1_OR_NEWER
using System.Reflection;
#endif
using UnityEngine;

public class CompilationWindow : EditorWindow
{
[MenuItem("Window/Compilation")]
private static void ShowWindow()
{
var window = GetWindow<CompilationWindow>();
window.titleContent = new GUIContent("Compilation");
window.Show();
}

private void OnGUI()
{
// Add space at the top
GUILayout.Space(10);

// Button to request script compilation
if (GUILayout.Button("Request Script Compilation"))
{
#if UNITY_2019_3_OR_NEWER
// Request script compilation for Unity 2019.3 or newer
CompilationPipeline.RequestScriptCompilation();
#elif UNITY_2017_1_OR_NEWER
// Request script compilation for Unity 2017.1 or newer
try
{
var editorAssembly = Assembly.GetAssembly(typeof(Editor));
var editorCompilationInterfaceType = editorAssembly.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface");
var dirtyAllScriptsMethod = editorCompilationInterfaceType.GetMethod("DirtyAllScripts", BindingFlags.Static | BindingFlags.Public);
dirtyAllScriptsMethod.Invoke(editorCompilationInterfaceType, null);
}
catch (Exception ex)
{
Debug.LogError($"Error requesting script compilation: {ex.Message}");
}
#endif
}
}
}
11 changes: 11 additions & 0 deletions Assets/Huawei/Editor/View/Utils/CompilationWindow.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 21 additions & 10 deletions Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class HMSAdsKitManager : HMSManagerSingleton<HMSAdsKitManager>
private const string TestRewardedAdId = "testx9dtjwj8hp";
private const string TestSplashImageAdId = "testq6zq98hecj";
private const string TestSplashVideoAdId = "testd7c5cewoj6";
private const string DefaultIcon = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; // 1x1 transparent pixel(base64 encoded)

#endregion

#region PRIVATE_MEMBERS
Expand Down Expand Up @@ -731,20 +733,29 @@ public void LoadSplashAd(string adId, SplashAdOrientation orientation)
{
AdId = adId,
Orientation = orientation,
Title = string.IsNullOrEmpty(adsKitSettings.Get(HMSAdsKitSettings.SplashTitle)) ? "Splash Title" : adsKitSettings.Get(HMSAdsKitSettings.SplashTitle),
SubText = string.IsNullOrEmpty(adsKitSettings.Get(HMSAdsKitSettings.SplashSubText)) ? "Splash SubText" : adsKitSettings.Get(HMSAdsKitSettings.SplashSubText)
Title = string.IsNullOrEmpty(adsKitSettings.Get(HMSAdsKitSettings.SplashTitle))
? "Splash Title"
: adsKitSettings.Get(HMSAdsKitSettings.SplashTitle),
SubText = string.IsNullOrEmpty(adsKitSettings.Get(HMSAdsKitSettings.SplashSubText))
? "Splash SubText"
: adsKitSettings.Get(HMSAdsKitSettings.SplashSubText)
};

if (!string.IsNullOrEmpty(adsKitSettings.Get(HMSAdsKitSettings.SplashImageBytes)))
{
Texture2D texture = new Texture2D(28, 28);
texture.LoadImage(Convert.FromBase64String(adsKitSettings.Get(HMSAdsKitSettings.SplashImageBytes)));
splashView.Icon = texture;
}
Texture2D texture = new Texture2D(28, 28);
texture.LoadImage(Convert.FromBase64String(adsKitSettings.Get(HMSAdsKitSettings.SplashImageBytes) ?? DefaultIcon));
splashView.Icon = texture;

splashView.SetSplashAdDisplayListener(new SplashAdDisplayListener(
SplashAdStatusListener_OnAdShowed,
SplashAdStatusListener_OnAdClicked));

splashView.SetSplashAdLoadListener(new SplashAdLoadListener(
SplashAdStatusListener_OnAdDismissed,
SplashAdStatusListener_OnAdFailedToLoad,
SplashAdStatusListener_OnAdLoaded));

splashView.SetSplashAdDisplayListener(new SplashAdDisplayListener(SplashAdStatusListener_OnAdShowed, SplashAdStatusListener_OnAdClicked));
splashView.SetSplashAdLoadListener(new SplashAdLoadListener(SplashAdStatusListener_OnAdDismissed, SplashAdStatusListener_OnAdFailedToLoad, SplashAdStatusListener_OnAdLoaded));
splashView.LoadAd(new AdParam.Builder().Build());

}

public void AssignDefaultSplashAdLoad(AdLoadMethod type = AdLoadMethod.Default)
Expand Down
45 changes: 23 additions & 22 deletions Assets/Huawei/Scripts/Utils/ScriptableHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

namespace HmsPlugin
{

public static class ScriptableHelper
{
public static void Save(UnityEngine.Object scriptableObject)
{

#if UNITY_EDITOR
EditorUtility.SetDirty(scriptableObject);

// Note: we do not call AssetDatabase.SaveAssets() because it takes too long on bigger projects
// And SetDirty should be enough to live between play mode changes & reopening Unity
if (scriptableObject != null)
{
EditorUtility.SetDirty(scriptableObject);
}
else
{
Debug.LogWarning("ScriptableObject is null. Cannot set dirty.");
}
// Note: we do not call AssetDatabase.SaveAssets() because it takes too long on bigger projects
// And SetDirty should be enough to live between play mode changes & reopening Unity
#endif
}

Expand All @@ -23,13 +27,7 @@ public static void Save(UnityEngine.Object scriptableObject)
public static T Load<T>(string filename, string path) where T : ScriptableObject
{
var asset = Resources.Load<T>(filename);

if (asset == null)
{
asset = Create<T>(filename, path);
}

return asset;
return asset != null ? asset : Create<T>(filename, path);
}

// path should start with "Assets"
Expand All @@ -38,19 +36,22 @@ public static T Create<T>(string filename, string path) where T : ScriptableObje
{
var asset = ScriptableObject.CreateInstance<T>();
#if UNITY_EDITOR
if (!string.IsNullOrEmpty(path))
{
Directory.CreateDirectory(path);
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(path, filename + ".asset"));
AssetDatabase.CreateAsset(asset, assetPathAndName);
AssetDatabase.SaveAssetIfDirty(asset);
}
else
{
Debug.LogError("Invalid path. Cannot create asset.");

Directory.CreateDirectory(path);
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(path, filename + ".asset"));

AssetDatabase.CreateAsset(asset, assetPathAndName);

// AssetDatabase.SaveAssets ();
// AssetDatabase.Refresh();

}
return asset;
#else
Debug.LogError("Creating ScriptableObjects during runtime is not allowed!");
return (T)null;
return null;
#endif
}
}
Expand Down