Main/Assets/Launcher/UpdateFormDll/Center/GameCenterScriptProxy.cs

81 lines
2.4 KiB
C#
Raw Permalink Normal View History

2025-01-25 04:38:09 +08:00
using System;
using System.Reflection;
using UnityEngine;
namespace Thousandto.UpdateForm.Center
{
//游戏中心的脚本代理
public class GameCenterScriptProxy
{
//游戏中心脚本类型
private static Type _gameCenterScriptType;
//游戏脚本的对象
private static object _gameCenterScriptObj;
//设置游戏启动参数
private static MethodInfo _miGameStart;
//设置游戏启动参数
private static MethodInfo _miChangeToLogin;
//设置原始对象
public static void SetOriginalObject(object obj)
{
if (obj != null)
{
_gameCenterScriptObj = obj;
_gameCenterScriptType = obj.GetType();
}
else
{
UnityEngine.Debug.LogError("获取GameCenterScript脚本失败!");
}
}
//设置游戏启动参数
public static void GameStart(string lan)
{
if (_miGameStart == null)
{
if (_gameCenterScriptType != null)
{
_miGameStart = _gameCenterScriptType.GetMethod("GameStart", BindingFlags.InvokeMethod | BindingFlags.Instance| BindingFlags.Public);
}
}
if (_miGameStart != null)
{
Debug.Log("调用GameCenter.GameStart");
_miGameStart.Invoke(_gameCenterScriptObj, new object[] { lan });
}
else
{
UnityEngine.Debug.LogError("获取GameCenterScript.GameStart方法失败!");
}
}
//切换到登录状态
public static void ChangeToLogin()
{
if (_miChangeToLogin == null)
{
if (_gameCenterScriptType != null)
{
_miChangeToLogin = _gameCenterScriptType.GetMethod("ChangeToLogin", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance);
}
}
if (_miChangeToLogin != null)
{
Debug.Log("调用GameCenter.ChangeToLogin");
_miChangeToLogin.Invoke(_gameCenterScriptObj, new object[] { });
}
else
{
UnityEngine.Debug.LogError("获取GameCenterScript.ChangeToLogin方法失败!");
}
}
}
}