参考文章:
http://blog.youkuaiyun.com/u010665359/article/details/50950989
http://blog.youkuaiyun.com/u010665359/article/details/51013433
tolua导入插件思路:其实框架里面都已经做好了扩展接口ToLuaExport.cs 里面的ProcessExtends函数。
注意:extendName = “ToLua_” + className.Replace(“.”, “”); 这是tolua约束好的格式以Tolua开头,也就是说插件导出来的函数名必须以Tolua开头,而且className也约束了这个函数将写入到哪个wrap。
extendType = Type.GetType(extendName + “, Assembly-CSharp-Editor”);后面就是type.GetMethods获取所有的方法进行读入,写入。
extendType.GetField(“AdditionNameSpace”); 这句大概就是加入的头 ,如果你需要加入头就在导出的插件函数这个字段写入头字段。比如你要导入的头是Dotween—>public static string AdditionNameSpace = “DG.Tweening”;
下面是操作步骤:
在LuaFramework/Editor下创建两个文件夹分别为LuaExtensions和Wrap,创建ToLuaFile.cs和ToLuaFileExport.cs放在LuaExtensions文件夹下。
ToLuaFile.cs
using System;
public static class ToLuaFile {
public static Type[] exports = new Type[]
{
typeof(DG.Tweening.TweenSettingsExtensions),
typeof(DG.Tweening.ShortcutExtensions),
typeof(DG.Tweening.TweenExtensions),
};
}
ToLuaFileExport.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Text;
using System.Collections.Generic;
using System;
using System.Reflection;
using System.IO;
public static class ToLuaFileExport
{
[MenuItem("Lua/Export ToLuaExtendFile", false, 53)]
public static void ExportToLuaExtendFile()
{
if (!Application.isPlaying)
{
EditorApplication.isPlaying = true;
}
Type[] list = ToLuaFile.exports;
Dictionary<Type, List<MethodInfo>> dicTypeMethods = new Dictionary<Type, List<MethodInfo>>();
for (int i = 0; i < list.Length; ++i)
{
Type type = list[i];
List<MethodInfo> ltMethodInfo = new List<MethodInfo>();
ltMethodInfo.AddRange(type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly));
for (int j = 0; j < ltMethodInfo.Count; ++j)
{
MethodInfo method = ltMethodInfo[j];
ParameterInfo[] parameterInfos = method.GetParameters();
if (parameterInfos == null || parameterInfos.Length <= 0)
continue;
Type parameterType = GetType(parameterInfos[0].ParameterType);
if (parameterType.IsGenericParameter)
continue;
if (dicTypeMethods.ContainsKey(parameterType))
{
dicTypeMethods[parameterType].Add(method);
}
else
{
List<MethodInfo> lt = new List<MethodInfo>();
lt.Add(method);
dicTypeMethods[parameterType] = lt;
}
}
}
foreach (KeyValuePair<Type, List<MethodInfo>> pair in