void MakeMethod() { MethodInfo[] allMethods = FCValueType.GetMethods(m_nClassType, m_bOnlyThisAPI);// m_nClassType.GetMethods(); // 函数+get/set方法 if (allMethods == null) { return; } m_CurMethods.Clear(); m_CurValidMethods.Clear(); string szDeclareName = string.Empty; foreach (MethodInfo method in allMethods) { if (!IsNeedExportMember(method.Name)) { continue; } // 去掉参数都一样的,因为FC脚本中 []与List是一个数据类型 szDeclareName = FCValueType.GetMethodDeclare(method); if (m_CurValidMethods.ContainsKey(szDeclareName)) { // 必要的话,这里做个替换 FCValueType.ReplaceMethod(m_CurValidMethods, m_CurMethods, szDeclareName, method); continue; } m_CurValidMethods[szDeclareName] = method; m_CurMethods.Add(method); } foreach (MethodInfo method in m_CurMethods) { PushMethodInfo(method); } }
void PushDelegateType(StringBuilder fileBuilder, string szLeft, Type nClassType) { //ConstructorInfo[] c1 = nClassType.GetConstructors(); MethodInfo method = nClassType.GetMethod("Invoke"); ParameterInfo[] allParams = method.GetParameters(); string szParamDesc = string.Empty; if (allParams != null) { for (int i = 0; i < allParams.Length; ++i) { PushRefType(allParams[i].ParameterType); FCValueType value_param = FCValueType.TransType(allParams[i].ParameterType); if (i > 0) { szParamDesc += ","; } szParamDesc += value_param.GetTypeName(false); szParamDesc += " arg" + i; } } FCValueType value_type = FCValueType.TransType(nClassType); FCValueType value_ret = FCValueType.TransType(method.ReturnType); string szClassName = value_type.GetValueName(false); fileBuilder.AppendFormat("{0}public delegate {1} {2}({3});\r\n", szLeft, value_ret.GetValueName(false), szClassName, szParamDesc); }
void MakeReturnDictionary(FCValueType value) { StringBuilder fileData = m_szTempBuilder; string szKeyName = value.GetKeyName(true); string szValeuName = value.GetValueName(true); fileData.AppendFormat(" public static void ReturnDictionary(Dictionary<{0}, {1}> rList, long L)\r\n", szKeyName, szValeuName); fileData.AppendLine(" {"); fileData.AppendLine(" try"); fileData.AppendLine(" {"); fileData.AppendLine(" long ptr = FCLibHelper.fc_get_return_ptr(L);"); fileData.AppendLine(" FCLibHelper.fc_map_clear(ptr); // 先清空map"); fileData.AppendLine(" if (rList == null) return;"); fileData.AppendLine(" long pKey = FCLibHelper.fc_get_map_push_key_ptr(ptr);"); fileData.AppendLine(" long pValue = FCLibHelper.fc_get_map_push_value_ptr(ptr);"); if (FCValueType.IsRefType(value.m_nKeyType)) { fileData.AppendFormat(" {0} k;\r\n", szKeyName); } if (FCValueType.IsRefType(value.m_nValueType)) { fileData.AppendFormat(" {0} v;\r\n", szKeyName); } fileData.AppendLine(" foreach (var v in rList)"); fileData.AppendLine(" {"); MakeOutDictionaryElement(value); fileData.AppendLine(" }"); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" }"); }
void MakeListWrap(FCValueType value) { StringBuilder fileData = m_szTempBuilder; string szCharpName = value.GetValueName(true, true); string szFuncDeclare = string.Format(" public static List<{0}> GetList(ref List<{0}> rList, long L, int nIndex)", szCharpName, szCharpName); if (TrySetExportFlag(szFuncDeclare)) { return; } fileData.AppendLine(szFuncDeclare); fileData.AppendLine(" {"); fileData.AppendLine(" try"); fileData.AppendLine(" {"); fileData.AppendLine(" long VM = FCLibHelper.fc_get_vm_ptr(L);"); fileData.AppendLine(" if (rList == null)"); fileData.AppendFormat(" rList = new List<{0}>();\r\n", szCharpName); fileData.AppendLine(" else"); fileData.AppendLine(" rList.Clear();"); fileData.AppendLine(" long ptr = FCLibHelper.fc_get_param_ptr(L, nIndex);"); fileData.AppendLine(" int nArraySize = FCLibHelper.fc_get_array_size(ptr);"); AddFCFuncCall(value, szCharpName, true); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" return rList;"); fileData.AppendLine(" }"); }
void MakeOutList(FCValueType value) { StringBuilder fileData = m_szTempBuilder; string szTypeName = value.GetTypeName(true); fileData.AppendFormat(" public static void OutList({0} rList, long L, int nIndex)\r\n", szTypeName); fileData.AppendLine(" {"); fileData.AppendLine(" try"); fileData.AppendLine(" {"); fileData.AppendLine(" int nCount = rList != null ? rList.Count : 0;"); fileData.AppendLine(" long ptr = FCLibHelper.fc_get_param_ptr(L, nIndex);"); fileData.AppendLine(" FCLibHelper.fc_set_array_size(ptr, nCount);"); if (FCValueType.IsRefType(value.m_nValueType)) { fileData.AppendFormat(" {0} v;\r\n", value.GetValueName(true)); } fileData.AppendLine(" for(int i = 0; i<nCount; ++i)"); fileData.AppendLine(" {"); fileData.AppendLine(" long pItem = FCLibHelper.fc_get_array_node_temp_ptr(ptr, i);"); MakeOutListElement(value); fileData.AppendLine(" }"); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" }"); }
void PushConstructor(ConstructorInfo cons) { ParameterInfo[] allParams = cons.GetParameters(); string szCallParam = string.Empty; Type nParamType; if (allParams != null) { for (int i = 0; i < allParams.Length; ++i) { ParameterInfo param = allParams[i]; nParamType = param.ParameterType; PushNameSpace(nParamType.Namespace); PushDelayType(nParamType); PushRefType(nParamType); if (i > 0) { szCallParam += ','; } FCValueType value = FCValueType.TransType(nParamType); szCallParam += value.GetTypeName(false); szCallParam = szCallParam + " " + param.Name; } } m_szTempBuilder.AppendFormat(" public {0}({1}){{}}\r\n", FCValueType.GetClassName(m_nClassType), szCallParam); }
void PushRefType(Type nType) { try { if (nType.IsByRef) { Type nRealType = nType.GetElementType(); if (nRealType != null) { nType = nRealType; } } FCValueType value = FCValueType.TransType(nType); if (value.IsArray || value.IsList) { m_AllRefType[value.m_value] = 1; } else if (value.IsMap) { m_AllRefType[value.m_key] = 1; m_AllRefType[value.m_value] = 1; } else { m_AllRefType[nType] = 1; } } catch (Exception e) { Debug.LogException(e); } }
void MakeReturnList(FCValueType value) { StringBuilder fileData = m_szTempBuilder; string szValueName = value.GetValueName(true, true); string szFuncDeclare = string.Format(" public static void ReturnList(List<{0}> rList, long ptr)", szValueName); if (TrySetExportFlag(szFuncDeclare)) { return; } fileData.AppendLine(szFuncDeclare); fileData.AppendLine(" {"); fileData.AppendLine(" try"); fileData.AppendLine(" {"); fileData.AppendLine(" int nCount = rList != null ? rList.Count : 0;"); //fileData.AppendLine(" long ptr = FCLibHelper.fc_get_return_ptr(L);"); fileData.AppendLine(" FCLibHelper.fc_set_array_size(ptr, nCount);"); if (FCValueType.IsRefType(value.m_nValueType)) { fileData.AppendFormat(" {0} v;\r\n", szValueName); } fileData.AppendLine(" for(int i = 0; i<nCount; ++i)"); fileData.AppendLine(" {"); fileData.AppendLine(" long pItem = FCLibHelper.fc_get_array_node_temp_ptr(ptr, i);"); MakeOutListElement(value); fileData.AppendLine(" }"); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" }"); }
void MakeOutDictionaryElement(FCValueType value) { StringBuilder fileData = m_szTempBuilder; string szKeyName = FCValueType.GetFCLibFuncShortName(value.m_nKeyType); string szValueName = FCValueType.GetFCLibFuncShortName(value.m_nValueType); if (string.IsNullOrEmpty(szKeyName) || string.IsNullOrEmpty(szValueName)) { return; } if (FCValueType.IsRefType(value.m_nKeyType)) { fileData.AppendFormat(" k = v.Key;", szKeyName); fileData.AppendFormat(" FCLibHelper.fc_set_value_{0}(pKey, ref k);", szKeyName); } else { fileData.AppendFormat(" FCLibHelper.fc_set_value_{0}(pKey, v.Key);", szKeyName); } if (FCValueType.IsRefType(value.m_nValueType)) { fileData.AppendFormat(" v = v.Value;", szKeyName); fileData.AppendFormat(" FCLibHelper.fc_set_value_{0}(pKey, ref v);", szKeyName); } else { fileData.AppendFormat(" FCLibHelper.fc_set_value_{0}(pValue, v.Value);", szValueName); } fileData.AppendLine(" FCLibHelper.fc_map_push_key_value(ptr);"); }
void MakeOutListElement(FCValueType value) { StringBuilder fileData = m_szTempBuilder; if (fc_value_type.fc_value_system_object == value.m_nValueType || fc_value_type.fc_value_object == value.m_nValueType || fc_value_type.fc_value_unity_object == value.m_nValueType) { fileData.AppendLine(" FCLibHelper.fc_set_value_intptr(pItem, FCGetObj.PushObj(rList[i]));"); return; } string szName = FCValueType.GetFCLibFuncShortName(value.m_nValueType); if (string.IsNullOrEmpty(szName)) { return; } if (FCValueType.IsRefType(value.m_nValueType)) { fileData.AppendLine(" v = rList[i];"); fileData.AppendFormat(" FCLibHelper.fc_set_value_{0}(pItem, ref v);\r\n", szName); } else { fileData.AppendFormat(" FCLibHelper.fc_set_value_{0}(pItem, rList[i]);\r\n", szName); } }
// 功能:添加公有变量 void PushFieldInfo(FieldInfo value) { if (m_bPartWrap) { if (!value.IsDefined(typeof(PartWrapAttribute), false)) { return; } } // 如果该变量有不导出的标记 if (value.IsDefined(typeof(DontWrapAttribute), false)) { return; } if (value.IsDefined(typeof(ObsoleteAttribute), false)) { return; } PushNameSpace(value.FieldType.Namespace); // 生成get_value, set_value方法 FCValueType ret_value = FCTemplateWrap.Instance.PushGetTypeWrap(value.FieldType); if (ret_value.m_nTemplateType == fc_value_tempalte_type.template_none && ret_value.m_nValueType == fc_value_type.fc_value_delegate) { PushPropertyDelegate(ret_value, value.Name, false, true, value.IsStatic); // // 委托只能set, 不可get } else { PushPropertyFunc(value.FieldType, value.Name, true, true, value.IsStatic); } }
void AddReturnCmd(FCValueType ret_value) { // 目前不是所有的类型都支持返回 switch (ret_value.m_nValueType) { case fc_value_type.fc_value_bool: case fc_value_type.fc_value_char: case fc_value_type.fc_value_byte: case fc_value_type.fc_value_short: case fc_value_type.fc_value_ushort: case fc_value_type.fc_value_int: case fc_value_type.fc_value_uint: case fc_value_type.fc_value_float: case fc_value_type.fc_value_double: case fc_value_type.fc_value_int64: case fc_value_type.fc_value_uint64: case fc_value_type.fc_value_string_a: case fc_value_type.fc_value_vector2: case fc_value_type.fc_value_vector3: case fc_value_type.fc_value_vector4: m_szTempBuilder.AppendLine(" FCDll.GetReturnParam(ref ret);"); break; } m_szTempBuilder.AppendLine(" return ret;"); }
public static string GetDelegateName(Type nParamType) { FCValueType v = TransType(nParamType); string szName = v.GetValueName(true); return("UnityAction_" + szName + "_delegate"); }
void MakeArrayWrap(FCValueType value) { StringBuilder fileData = m_szTempBuilder; string szCharpName = value.GetValueName(true, true); string szFuncDeclare = string.Format(" public static {0}[] GetArray(ref {1}[] rList, long L, int nIndex)", szCharpName, szCharpName); if (TrySetExportFlag(szFuncDeclare)) { return; } fileData.AppendLine(szFuncDeclare); fileData.AppendLine(" {"); fileData.AppendLine(" try"); fileData.AppendLine(" {"); fileData.AppendLine(" long ptr = FCLibHelper.fc_get_param_ptr(L, nIndex);"); fileData.AppendLine(" int nArraySize = FCLibHelper.fc_get_array_size(ptr);"); fileData.AppendFormat(" rList = new {0}[nArraySize];\r\n", szCharpName); AddFCFuncCall(value, szCharpName, false); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" return rList;"); fileData.AppendLine(" }"); }
public static string GetMethodDeclare(MethodInfo method) { string szFullName = method.Name; ParameterInfo[] allParams = method.GetParameters(); string szCallParam = string.Empty; if (allParams != null) { Type nParamType; for (int i = 0; i < allParams.Length; ++i) { nParamType = allParams[i].ParameterType; if (i > 0) { szCallParam += ','; } FCValueType value = TransType(nParamType); szCallParam += value.GetTypeName(false); szCallParam += " "; szCallParam += allParams[i].Name; } } return(szFullName + szCallParam); }
//[MenuItem("FCScript/测试", false, 5)] //static void TestExport() //{ // TestUnsafeStruct(); // FCClassWrap pWrap = new FCClassWrap(); // pWrap.BeginExport("", false); // WrapUnityClass(pWrap); // WrapUIClass(pWrap); // WrapCustomAttribClass(pWrap); // 导出打有[ClassAutoWrap]标签的类 // pWrap.EndExport(); // MakeFCProj(); //} static void TestUnsafeStruct() { int nSize = FCValueType.GetStructMemSize(typeof(Vector3)); Debug.Log(string.Format("Vector3 mem size = {0}", nSize)); nSize = FCValueType.GetStructMemSize(typeof(Vector4)); Debug.Log(string.Format("Vector4 mem size = {0}", nSize)); nSize = FCValueType.GetStructMemSize(typeof(Matrix4x4)); Debug.Log(string.Format("Matrix4x4 mem size = {0}", nSize)); Quaternion q1 = new Quaternion(); Vector4 v4 = new Vector4(); v4.x = 1.1f; v4.y = 2.2f; v4.z = 3.3f; v4.w = 4.4f; //IntPtr ptr1 = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(v4); // 在这里可以将C#的结构体,传给C++ unsafe { FCLibHelper.fc_test_struct(&v4, FCValueType.GetStructMemSize(typeof(Vector4))); } Debug.Log(string.Format("v4: x = {0}, y = {1}, z = {2}, w = {3}", v4.x, v4.y, v4.z, v4.w)); //System.Runtime.InteropServices.Marshal.Release(ptr1); }
void MakeProperty() { FieldInfo[] allFields = FCValueType.GetFields(m_nClassType, m_bOnlyThisAPI); PropertyInfo[] allProperties = FCValueType.GetProperties(m_nClassType, m_bOnlyThisAPI); if (allFields != null) { foreach (FieldInfo field in allFields) { if (IsNeedExportMember(field.Name)) { PushFieldInfo(field); } } } if (allProperties != null) { foreach (PropertyInfo property in allProperties) { if (IsNeedExportMember(property.Name)) { PushPropertyInfo(property); } } } }
public static string GetMethodDeclare(MethodInfo method, ref bool bNeedExport) { bNeedExport = true; string szFullName = method.Name; ParameterInfo[] allParams = method.GetParameters(); string szCallParam = string.Empty; string szParamName = string.Empty; if (allParams != null) { Type nParamType; for (int i = 0; i < allParams.Length; ++i) { nParamType = allParams[i].ParameterType; if (i > 0) { szCallParam += ','; } FCValueType value = TransType(nParamType); szParamName = value.GetTypeName(false); if (szParamName.IndexOf('*') != -1) { bNeedExport = false; return(string.Empty); } szCallParam += szParamName; szCallParam += " "; szCallParam += allParams[i].Name; } } return(szFullName + szCallParam); }
void PushPropertyFunc(Type nVaueType, string szName, bool bCanGet, bool bCanSet, bool bStatic) { // bool alphaIsTransparency { get; set; } string szGetBody = string.Empty; string szSetBody = string.Empty; string szStatic = string.Empty; if (bCanGet) { szGetBody = " get; "; } if (bCanSet) { szSetBody = " set; "; } if (bStatic) { szStatic = "static "; } if (!bCanGet && bCanSet) { szSetBody = szSetBody.Replace(";", "{}"); } FCValueType value = FCValueType.TransType(nVaueType); string szValueType = value.GetTypeName(false); if (szValueType.IndexOf('`') != -1) { return; } m_szTempBuilder.AppendFormat(" public {0}{1} {2} {{{3}{4}}}\r\n", szStatic, szValueType, szName, szGetBody, szSetBody); }
public void ExportClass(Type nClassType, string szPathName, bool bPartWrap, bool bOnlyThisApi, Dictionary <string, int> aDontWrapName, Dictionary <string, List <Type> > aTemplateFunc, FCRefClass pRefClass) { m_bPartWrap = bPartWrap; m_bOnlyThisAPI = bOnlyThisApi; m_nClassType = nClassType; m_szPathName = szPathName; m_pRefClass = pRefClass; m_DelayType.Clear(); m_szTempBuilder.Length = 0; m_CurRefNameSpace.Clear(); m_CurRefNameSpacesFlags.Clear(); m_CurDelegate.Clear(); m_CurDontWrapName = aDontWrapName; m_CurSupportTemplateFunc = aTemplateFunc; m_AllExportType[nClassType] = 1; Type nParentType = nClassType.BaseType; m_AllRefType[nParentType] = 1; PushParentType(nParentType); string szParentName = FCValueType.GetClassName(nParentType); if (szParentName == "UnityEvent`1") { szParentName = "UnityEventBase"; } m_szTempBuilder.AppendFormat("\r\nclass {0} : {1}\r\n", FCValueType.GetClassName(nClassType), szParentName); m_szTempBuilder.AppendLine("{"); MakeInnerEnum(); // 分析内部的枚举类 MakeConstructor(); // 分析构造函数 MakeProperty(); // 分析get - set方法 MakeMethod(); // 分析函数 MakeDelegate(); // 成生委托声明 m_szTempBuilder.AppendLine("};\r\n"); // 导出类外的枚举 MakeOuterEnum(); m_szFileBuilder.Length = 0; foreach (string szNameSpace in m_CurRefNameSpace) { if (szNameSpace.IndexOf("UnityEngine") != -1) { if (szNameSpace != "UnityEngine.Events") { continue; } } m_szFileBuilder.AppendFormat("using {0};\r\n", szNameSpace); } m_szFileBuilder.AppendLine(); m_szFileBuilder.Append(m_szTempBuilder.ToString()); File.WriteAllText(m_szPathName, m_szFileBuilder.ToString()); }
public static Type GetDelegeteType(Type nClassType, Type nParamType) { FCValueType v = TransType(nParamType); switch (v.m_nValueType) { case fc_value_type.fc_value_bool: return(typeof(UnityEngine.Events.UnityAction <bool>)); case fc_value_type.fc_value_byte: return(typeof(UnityEngine.Events.UnityAction <byte>)); case fc_value_type.fc_value_char: return(typeof(UnityEngine.Events.UnityAction <char>)); case fc_value_type.fc_value_short: return(typeof(UnityEngine.Events.UnityAction <short>)); case fc_value_type.fc_value_ushort: return(typeof(UnityEngine.Events.UnityAction <ushort>)); case fc_value_type.fc_value_int: return(typeof(UnityEngine.Events.UnityAction <int>)); case fc_value_type.fc_value_uint: return(typeof(UnityEngine.Events.UnityAction <uint>)); case fc_value_type.fc_value_int64: return(typeof(UnityEngine.Events.UnityAction <long>)); case fc_value_type.fc_value_uint64: return(typeof(UnityEngine.Events.UnityAction <ulong>)); case fc_value_type.fc_value_float: return(typeof(UnityEngine.Events.UnityAction <float>)); case fc_value_type.fc_value_double: return(typeof(UnityEngine.Events.UnityAction <double>)); case fc_value_type.fc_value_string_a: return(typeof(UnityEngine.Events.UnityAction <string>)); case fc_value_type.fc_value_vector2: return(typeof(UnityEngine.Events.UnityAction <Vector2>)); case fc_value_type.fc_value_vector3: return(typeof(UnityEngine.Events.UnityAction <Vector3>)); case fc_value_type.fc_value_vector4: return(typeof(UnityEngine.Events.UnityAction <Vector4>)); case fc_value_type.fc_value_int_ptr: return(typeof(UnityEngine.Events.UnityAction <IntPtr>)); default: break; } return(nClassType); }
static string GetDeleteExportName(Type nType, bool bCSharp, bool bFullName) { string szName = bFullName ? nType.FullName : nType.Name; bool bBaseDelegate = false; bool bFuncDelegate = false; if (szName.IndexOf("Action`") != -1) { bBaseDelegate = true; szName = "Action"; } else if (szName.IndexOf("UnityAction`") != -1) { bBaseDelegate = true; szName = "UnityAction"; } else if (szName.IndexOf("Func`") != -1) { bFuncDelegate = true; bBaseDelegate = true; szName = "Func"; } else if (szName.IndexOf("Comparison`1") != -1) { bBaseDelegate = false; szName = "Comparison"; } if (bBaseDelegate) { MethodInfo method = nType.GetMethod("Invoke"); ParameterInfo[] allParams = method.GetParameters(); if (allParams != null) { szName += "<"; for (int i = 0; i < allParams.Length; ++i) { FCValueType value_param = TransType(allParams[i].ParameterType); if (i > 0) { szName += ","; } szName += value_param.GetTypeName(bCSharp, bFullName); } if (bFuncDelegate) { if (allParams.Length > 0) { szName += ","; } FCValueType value_param = TransType(method.ReturnType); szName += value_param.GetTypeName(bCSharp, bFullName); } szName += ">"; } } szName = szName.Replace('+', '.'); return(szName); }
public void ExportDefaultClass(string szPath) { m_szFileBuilder.Length = 0; m_szFileBuilder.AppendLine(); foreach (Type nType in m_AllRefType.Keys) { if (m_AllExportType.ContainsKey(nType)) { continue; } if (nType.IsEnum) { PushInnerType(m_szFileBuilder, string.Empty, nType); continue; } if (nType.IsArray) { continue; } if (!nType.IsClass) { continue; } FCValueType value = FCValueType.TransType(nType); if (value.m_nTemplateType != fc_value_tempalte_type.template_none) { continue; } if (value.m_nValueType == fc_value_type.fc_value_delegate) { continue; } if (FCValueType.IsBaseType(value.m_nValueType)) { continue; } if (nType == typeof(Type)) { m_szFileBuilder.AppendLine("class Type{}"); } else if (nType == typeof(System.Object)) { m_szFileBuilder.AppendFormat("class {0}{{}}\r\n", nType.Name); } else if (nType == typeof(UnityEngine.Object)) { m_szFileBuilder.AppendLine("class UnityObject{}"); } else { m_szFileBuilder.AppendFormat("class {0} : {1}{{}}\r\n", nType.Name, nType.BaseType.Name); } m_szFileBuilder.AppendLine(); } string szPathName = szPath + "all_default_class.cs"; File.WriteAllText(szPathName, m_szFileBuilder.ToString()); }
void MakeOutArray(FCValueType value) { switch (value.m_nValueType) { case fc_value_type.fc_value_bool: case fc_value_type.fc_value_byte: case fc_value_type.fc_value_short: case fc_value_type.fc_value_ushort: case fc_value_type.fc_value_int: case fc_value_type.fc_value_uint: case fc_value_type.fc_value_float: case fc_value_type.fc_value_double: case fc_value_type.fc_value_color32: case fc_value_type.fc_value_color: case fc_value_type.fc_value_vector2: case fc_value_type.fc_value_vector3: case fc_value_type.fc_value_vector4: case fc_value_type.fc_value_rect: MakeOutFastArray(value); return; default: break; } StringBuilder fileData = m_szTempBuilder; string szTypeName = value.GetValueName(true, true); string szFuncDeclare = string.Format(" public static void OutArray({0} []rList, long L, int nIndex)", szTypeName); if (TrySetExportFlag(szFuncDeclare)) { return; } fileData.AppendLine(szFuncDeclare); fileData.AppendLine(" {"); fileData.AppendLine(" try"); fileData.AppendLine(" {"); fileData.AppendLine(" int nCount = rList != null ? rList.Length : 0;"); fileData.AppendLine(" long VM = FCLibHelper.fc_get_vm_ptr(L);"); fileData.AppendLine(" long ptr = FCLibHelper.fc_get_param_ptr(L, nIndex);"); fileData.AppendLine(" FCLibHelper.fc_set_array_size(VM, ptr, nCount);"); if (FCValueType.IsRefType(value.m_nValueType)) { fileData.AppendFormat(" {0} v;\r\n", value.GetValueName(true)); } fileData.AppendLine(" for(int i = 0; i<nCount; ++i)"); fileData.AppendLine(" {"); fileData.AppendLine(" long pItem = FCLibHelper.fc_get_array_node_temp_ptr(VM, ptr, i);"); MakeOutListElement(value); fileData.AppendLine(" }"); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" }"); }
string GetParentInitCall() { Type nBaseType = m_nClassType.BaseType; if (nBaseType == null) { return(string.Empty); } ConstructorInfo[] allConInfos = nBaseType.GetConstructors(); // 得到构造函数信息 if (allConInfos == null) { return(string.Empty); } // 先检测构造参数 int nMinParamCount = 10000; ConstructorInfo pCon = null; foreach (ConstructorInfo cons in allConInfos) { ParameterInfo[] allParams = cons.GetParameters(); int nCurParamCount = allParams != null ? allParams.Length : 0; if (nMinParamCount > nCurParamCount) { nMinParamCount = nCurParamCount; pCon = cons; } } if (nMinParamCount == 0 || pCon == null) { return(string.Empty); } ParameterInfo[] Params = pCon.GetParameters(); string szParamDesc = string.Empty; for (int i = 0; i < Params.Length; ++i) { if (i > 0) { szParamDesc += ','; } FCValueType value = FCValueType.TransType(Params[i].ParameterType); if (value.m_nValueType == fc_value_type.fc_value_string_a) { szParamDesc += "string.Empty"; } else if (value.m_nValueType == fc_value_type.fc_value_system_object) { szParamDesc += "null"; } else { szParamDesc += string.Format("default({0})", value.GetValueName(false)); } } return(string.Format("base({0})", szParamDesc)); }
void MakeMethod() { MethodInfo[] allMethods = FCValueType.GetMethods(m_nClassType, m_bOnlyThisAPI);// m_nClassType.GetMethods(); // 函数+get/set方法 if (allMethods == null) { return; } m_CurMethods.Clear(); m_CurValidMethods.Clear(); string szDeclareName = string.Empty; bool bNeedExport = false; foreach (MethodInfo method in allMethods) { if (!IsNeedExportMember(method.Name)) { continue; } if (m_CurDontWrapName.ContainsKey(method.Name)) { continue; } if (FCExclude.IsDontExportMethod(method)) { continue; } bNeedExport = true; // 去掉参数都一样的,因为FC脚本中 []与List是一个数据类型 szDeclareName = FCValueType.GetMethodDeclare(method, ref bNeedExport); if (!bNeedExport) { continue; } if (m_CurValidMethods.ContainsKey(szDeclareName)) { // 必要的话,这里做个替换 FCValueType.ReplaceMethod(m_CurValidMethods, m_CurMethods, szDeclareName, method); continue; } m_CurValidMethods[szDeclareName] = method; m_CurMethods.Add(method); } foreach (MethodInfo method in m_CurMethods) { PushMethodInfo(method); } // 特殊导出UnityEvent<T>模板类 Type nBaseType = m_nClassType.BaseType; if (nBaseType != null && nBaseType.Name == "UnityEvent`1") { PushUnityEventTemplateFunc(m_nClassType); } }
void PushConstructor(ConstructorInfo cons, string szParentInitCall) { ParameterInfo[] allParams = cons.GetParameters(); // 如果是有参数的,就要考虑要不是导出 if (allParams != null && allParams.Length > 0) { if (m_bPartWrap) { if (!cons.IsDefined(typeof(PartWrapAttribute), false)) { return; } } // 如果该函数有不导出的标记 if (cons.IsDefined(typeof(DontWrapAttribute), false)) { return; } if (cons.IsDefined(typeof(ObsoleteAttribute), false)) { return; } } string szCallParam = string.Empty; Type nParamType; if (allParams != null) { for (int i = 0; i < allParams.Length; ++i) { ParameterInfo param = allParams[i]; nParamType = param.ParameterType; PushNameSpace(nParamType.Namespace); PushDelayType(nParamType); PushDelegateType(nParamType); PushRefType(nParamType); if (i > 0) { szCallParam += ','; } FCValueType value = FCValueType.TransType(nParamType); szCallParam += value.GetTypeName(false); szCallParam = szCallParam + " " + param.Name; } } if (string.IsNullOrEmpty(szParentInitCall)) { m_szTempBuilder.AppendFormat(" public {0}({1}){{}}\r\n", FCValueType.GetClassName(m_nClassType), szCallParam); } else { m_szTempBuilder.AppendFormat(" public {0}({1}):{2}{{}}\r\n", FCValueType.GetClassName(m_nClassType), szCallParam, szParentInitCall); } }
void MakeDeleteCallFunc(Type nClassType) { // 得到委托的参数 MethodInfo method = nClassType.GetMethod("Invoke"); ParameterInfo[] allParams = method.GetParameters(); // 函数参数 FCValueType ret_value = FCValueType.TransType(method.ReturnType); string szCallDesc = string.Empty; int nParamCount = allParams != null ? allParams.Length : 0; for (int i = 0; i < nParamCount; ++i) { FCValueType value_param = FCValueType.TransType(allParams[i].ParameterType); if (i > 0) { szCallDesc += ","; } szCallDesc += string.Format("{0} arg{1}", value_param.GetTypeName(true, true), i); } m_szTempBuilder.AppendFormat(" public {0} CallFunc({1})\r\n", ret_value.GetTypeName(true, true), szCallDesc); m_szTempBuilder.AppendLine(" {"); m_szTempBuilder.AppendLine(" try"); m_szTempBuilder.AppendLine(" {"); string szArg = string.Empty; for (int i = 0; i < nParamCount; ++i) { szArg = string.Format("arg{0}", i); FCValueType value_param = FCValueType.TransType(allParams[i].ParameterType); if (value_param.m_nTemplateType != fc_value_tempalte_type.template_none) { Debug.LogError(nClassType.FullName + "参数不支持模板"); continue; } if (FCValueType.IsRefType(value_param.m_nValueType)) { m_szTempBuilder.AppendFormat(" FCDll.PushCallParam(ref {0});\r\n", szArg); } else { m_szTempBuilder.AppendFormat(" FCDll.PushCallParam({0});\r\n", szArg); } } m_szTempBuilder.AppendLine(" FCLibHelper.fc_call(m_nThisPtr, m_szFuncName);"); m_szTempBuilder.AppendLine(" }"); m_szTempBuilder.AppendLine(" catch(Exception e)"); m_szTempBuilder.AppendLine(" {"); m_szTempBuilder.AppendLine(" Debug.LogException(e);"); m_szTempBuilder.AppendLine(" }"); m_szTempBuilder.AppendLine(" }"); }
void MakeMethod() { MethodInfo[] allMethods = FCValueType.GetMethods(m_nClassType, m_bOnlyThisAPI);// m_nClassType.GetMethods(); // 函数+get/set方法 if (allMethods == null) { return; } foreach (MethodInfo method in allMethods) { PushMethodInfo(method); } }
public static bool IsDontExportMethod(MethodInfo method) { // 先检查函数的返回值 FCValueType ret_value = FCValueType.TransType(method.ReturnType); // 目前先暂不支持IEnumerable, 转换这个有点麻烦 if (ret_value.m_nTemplateType == fc_value_tempalte_type.template_ienumerable) { return(true); } return(false); }