本演示项目在Unity for Android Build中启用部分华为HMS和AGC服务,对应的类和函数的名称和用法相同。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

99 行
3.1 KiB

using System.Security.Cryptography;
using HuaweiHms;
using UnityEngine;
namespace HuaweiHmsDemo
{
public class AppMessageTest : Test<AppMessageTest>
{
private AGConnectAppMessaging appMessaging
{
get
{
if (_appMessaging == null)
{
_appMessaging = AGConnectAppMessaging.getInstance();
}
return _appMessaging;
}
}
private AGConnectAppMessaging _appMessaging;
public bool showApp = false;
public override void RegisterEvent(TestEvent registerEvent)
{
// appMessaging.setDisplayEnable(false);
registerEvent("Show/Hide App Message", ShowAppMessage);
registerEvent("Force Fetch", ForceFetch);
registerEvent("Add OnClick Listener", AddOnClickListener);
registerEvent("Add Dismiss Listener", AddDismissListener);
registerEvent("Add Display Listener", AddDisplayListener);
registerEvent("Register Custom view", RegisterCustomView);
registerEvent("Remove Custom view", RemoveCustomView);
registerEvent("Set Display Location", SetDisplayLocation);
registerEvent("trigger", Trigger);
}
public void ShowAppMessage()
{
showApp = !showApp;
appMessaging.setDisplayEnable(showApp);
TestTip.Inst.ShowText($"set display to {showApp}");
}
public void ForceFetch()
{
appMessaging.setForceFetch();
TestTip.Inst.ShowText("force fetch");
}
public void AddOnClickListener()
{
ClickListener listener = new ClickListener();
appMessaging.addOnClickListener(listener);
TestTip.Inst.ShowText("Add on click listener success");
}
public void AddDismissListener()
{
DismissListener listener = new DismissListener();
appMessaging.addOnDismissListener(listener);
TestTip.Inst.ShowText("Add on dismiss listener success");
}
public void AddDisplayListener()
{
DisplayListener listener = new DisplayListener();
appMessaging.addOnDisplayListener(listener);
TestTip.Inst.ShowText("Add on display listener success");
}
public void RegisterCustomView()
{
CustomDisplayView view = new CustomDisplayView();
appMessaging.addCustomView(view);
TestTip.Inst.ShowText("Add custom view success");
}
public void RemoveCustomView()
{
appMessaging.removeCustomView();
TestTip.Inst.ShowText("remove custom view success");
}
public void SetDisplayLocation()
{
appMessaging.setDisplayLocation(MessageLocation.BOTTOM);
TestTip.Inst.ShowText("set location");
}
public void Trigger()
{
appMessaging.trigger("justtest");
TestTip.Inst.ShowText("trigger");
}
}
}