using UnityEngine;
using System;
using System.Reflection;
namespace MRStore.Util
{
///
/// 通用型接口
///
public interface JavaInterface
{
///
/// 无参函数
///
///
void Call(string method);
///
/// 有参函数
///
///
///
void Call(string method, string args);
}
///
/// 和安卓Java进行交互的方式
/// Java端调用C#代码的方案
/// Java声明接口,由Unity实现相关的代码
/// 重点是,如何设计一个通用的类来实现相关的功能?
///
///
public abstract class JavaProxy : AndroidJavaProxy, JavaInterface where T : JavaProxy
{
///
/// com.shadowcreator.mediasouptool.JavaInterface
///
///
public JavaProxy(string packName) : base(packName) { }
public void Call(string method)
{
MethodInfo methodInfo = typeof(T).GetMethod(method);
if (methodInfo == null) throw new Exception(typeof(T) + method + "method is null");
methodInfo.Invoke(this, null);
}
public void Call(string method, string args)
{
MethodInfo methodInfo = typeof(T).GetMethod(method);
if (methodInfo == null) throw new Exception(typeof(T) + method + "method is null");
methodInfo.Invoke(this, new System.Object[] { args });
}
}
}