public static void GenCSToLua() { CSToLuaRegisterManager.GetInstance().Init(Application.dataPath.Replace("\\", "/") + "/ClientCode/client-tools/CSRegisterToLua"); CSToLuaRegisterManager.GetInstance().ConvertCSToLua(Application.dataPath.Replace("\\", "/") + "/ClientCode/client-cstolua"); CSToLuaRegisterManager.GetInstance().Dispose(); AssetDatabase.Refresh(); }
private void RegisterMethod(BindingFlags flags) { MethodInfo[] methods = registerType.GetMethods(flags); Dictionary <string, int> methodIndexDic = new Dictionary <string, int>(); foreach (MethodInfo m in methods) { if (m.IsGenericMethod) { continue; } if (m.IsDefined(typeof(ObsoleteAttribute), true)) { continue; } if (!CSToLuaRegisterManager.GetInstance().IsMethodExport(registerType.FullName, m.Name)) { continue; } if (m.Name.StartsWith("set_") || m.Name.StartsWith("get_") || m.Name.StartsWith("add_") || m.Name.StartsWith("remove_") || m.Name.StartsWith("op_")) { continue; } string aliasName = m.Name; if (methodIndexDic.ContainsKey(aliasName)) { methodIndexDic[aliasName] += 1; aliasName += methodIndexDic[aliasName]; } else { methodIndexDic.Add(aliasName, 0); } ParameterInfo[] pInfos = m.GetParameters(); bool isExport = true; foreach (ParameterInfo pInfo in pInfos) { Type t = pInfo.ParameterType; if (t.IsGenericType) { isExport = false; break; } } if (isExport) { registerList.Add(new CSToLuaMethodRegister(this, m, aliasName)); } } }
private void RegisterConstructor() { if (!CSToLuaRegisterManager.GetInstance().IsConstructorExport(CSToLuaRegisterHelper.GetTypeFullName(registerType))) { return; } ConstructorInfo[] cInfos = registerType.GetConstructors(BindingFlags.Public | BindingFlags.Instance); if (cInfos != null && cInfos.Length > 0) { registerList.Add(new CSToLuaConstructorRegister(this, cInfos)); } }
public string RegisterFunctionToLua(int indent) { CSToLuaRegisterManager.GetInstance().DebugLog(" " + methodInfo.Name); ParameterInfo[] pInfos = methodInfo.GetParameters(); StringBuilder sb = new StringBuilder(); sb.Append(CSToLuaRegisterHelper.GetRegisterFunStart(indent, "Method_" + altasName)); if (!methodInfo.IsStatic) { indent++; sb.Append(CSToLuaRegisterHelper.GetToUserDataAction(indent, classRegister.RegisterType, 1, "obj")); indent--; } indent++; if (pInfos == null || pInfos.Length == 0) { RegisterNMethod(indent, sb); RegisterReturnMethod(indent, sb); } else { RegisterCheckParamCount(indent, sb); if (!isParams && parDefaultStartIndex == -1) { RegisterNPamasNDefaultMethod(indent, sb, methodInfo.IsStatic ? 1 : 2); RegisterReturnMethod(indent, sb); } else if (!isParams && parDefaultStartIndex >= 0) { RegisterNParamsDefaultMethod(indent, sb, methodInfo.IsStatic ? 1 : 2); RegisterReturnMethod(indent, sb); } else if (isParams && parDefaultStartIndex == -1) { RegisterParamsNDefaultMethod(indent, sb, methodInfo.IsStatic ? 1 : 2); RegisterReturnMethod(indent, sb); } else { RegisterParamsDefaultMethod(indent, sb, methodInfo.IsStatic ? 1 : 2); } } indent--; sb.Append(CSToLuaRegisterHelper.GetRegisterFunEnd(indent)); return(sb.ToString()); }
private void RegisterField(BindingFlags flags) { FieldInfo[] fields = registerType.GetFields(flags); foreach (FieldInfo f in fields) { if (f.IsDefined(typeof(ObsoleteAttribute), true)) { continue; } if (!CSToLuaRegisterManager.GetInstance().IsPropertyOrFieldExport(registerType.FullName, f.Name)) { continue; } registerList.Add(new CSToLuaFieldRegister(this, f)); } }
private void RegisterProperty(BindingFlags flags) { PropertyInfo[] propertys = registerType.GetProperties(flags); foreach (PropertyInfo p in propertys) { if (p.IsDefined(typeof(ObsoleteAttribute), true)) { continue; } if (!CSToLuaRegisterManager.GetInstance().IsPropertyOrFieldExport(registerType.FullName, p.Name)) { continue; } if (p.GetIndexParameters().Length > 0) { continue; } registerList.Add(new CSToLuaPropertyRegister(this, p)); } }