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

112 行
2.9 KiB

using System;
using HuaweiService.Auth;
using UnityEngine;
using UnityEngine.UI;
namespace HuaweiAuthDemo
{
[Serializable]
public class ActionBar
{
public RectTransform container;
public RectTransform content;
public Transform title;
public Transform separationLine;
public Button closeButton;
public Button backButton;
}
[Serializable]
public class Footer
{
public RectTransform rectTransform;
public Button secondaryActionButton;
public Transform separationLine;
}
/// <summary>
/// Base class for all panels
/// </summary>
public abstract class AbstractPanel : MonoBehaviour
{
private Canvas canvas;
public AbstractPanel ParentPanel;
public ActionBar actionBar;
public Footer secondaryActionFooter;
void Awake()
{
canvas = gameObject.GetComponent<Canvas>();
}
public virtual void OpenPanel()
{
ShowPanel();
}
public void ClosePanel()
{
HidePanel();
}
public void Back()
{
HidePanel();
ParentPanel?.ShowPanel();
}
protected virtual void ShowPanel()
{
canvas.enabled = true;
}
protected virtual void HidePanel()
{
// reset all input fields
foreach (InputField inputField in GetComponentsInChildren<InputField>())
inputField.text = null;
canvas.enabled = false;
}
public void LogOutClick()
{
try
{
var instance = AGConnectAuth.getInstance();
if (instance != null)
{
instance.signOut();
PanelController.popupinstance.ShowInfo("User has been sign out!");
}
else
{
PanelController.popupinstance.ShowInfo("Don't need log out, no user");
}
} catch (System.Exception e)
{
Error error = new Error();
error.message = e.Message;
PanelController.popupinstance.ShowError(error);
}
PanelController.getInstance()
.OpenPanel(PanelController.getInstance().GetComponentInChildren<SignInPanel>());
}
public bool haveCurrentUser(AbstractPanel parentPanel)
{
AGConnectUser user = AGConnectAuth.getInstance().getCurrentUser();
if (user==null)
{
return false;
}
ParentPanel = parentPanel;
PanelController.getInstance()
.OpenPanel(PanelController.getInstance().GetComponentInChildren<UserAccount>());
return true;
}
}
}