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(" }"); }
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); }
public static string GetDelegateName(Type nParamType) { FCValueType v = TransType(nParamType); string szName = v.GetValueName(true); return("UnityAction_" + szName + "_delegate"); }
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 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(" }"); }
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 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 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(" }"); }
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 MakeDictionary(FCValueType value) { StringBuilder fileData = m_szTempBuilder; string szKeyName = value.GetKeyName(true, true); string szValeuName = value.GetValueName(true, true); string szFuncDeclare = string.Format(" public static Dictionary<{0},{1}> GetDictionary(ref Dictionary<{2},{3}> rList, long L, int nIndex)", szKeyName, szValeuName, szKeyName, szValeuName); if (TrySetExportFlag(szFuncDeclare)) { return; } fileData.AppendLine(szFuncDeclare); fileData.AppendLine(" {"); fileData.AppendLine(" try"); fileData.AppendLine(" {"); fileData.AppendLine(" if (rList == null)"); fileData.AppendFormat(" rList = new Dictionary<{0}, {1}>();\r\n", szKeyName, szValeuName); fileData.AppendLine(" else"); fileData.AppendLine(" rList.Clear();"); fileData.AppendLine(" long VM = FCLibHelper.fc_get_vm_ptr(L);"); fileData.AppendLine(" long ptr = FCLibHelper.fc_get_param_ptr(L, nIndex);"); fileData.AppendLine(" int nCount = FCLibHelper.fc_get_map_size(VM, ptr);"); fileData.AppendLine(" for(; nCount > 0; --nCount)"); fileData.AppendLine(" {"); fileData.AppendLine(" FCLibHelper.fc_map_to_next_pair(VM);"); fileData.AppendLine(" long key_ptr = FCLibHelper.fc_map_get_cur_key_ptr(VM);"); fileData.AppendLine(" long value_ptr = FCLibHelper.fc_map_get_cur_value_ptr(VM);"); bool bValidKey = AddKeyValueCall(value.m_nKeyType, "key", "key_ptr", szKeyName); bool bValidValue = AddKeyValueCall(value.m_nValueType, "value", "value_ptr", szValeuName); if (bValidKey && bValidValue) { fileData.AppendLine(" rList[key] = value;"); } fileData.AppendLine(" }"); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" return rList;"); fileData.AppendLine(" }"); }
// 定制UnityEvent<T>模板函数的导出 void PushUnityEventTemplateFunc(Type nClassType) { Type nBaseType = nClassType.BaseType; Type[] argTypes = nBaseType.GetGenericArguments();// GenericTypeArguments; if (argTypes == null || argTypes.Length == 0) { return; } Type nParamType = argTypes[0]; FCValueType nParamValue = FCValueType.TransType(nParamType); string szParamName = nParamValue.GetValueName(false); m_szTempBuilder.AppendFormat(" public void AddListener(UnityAction<{0}> call){{}}\r\n", szParamName); m_szTempBuilder.AppendFormat(" public void Invoke({0} arg0){{}}\r\n", szParamName); m_szTempBuilder.AppendFormat(" public void RemoveListener(UnityAction<{0}> call){{}}\r\n", szParamName); }
static void TestExport() { Type t1 = typeof(IEnumerable <AssetBundle>); FCValueType v1 = FCValueType.TransType(t1); string s1 = v1.GetValueName(true); int iiii = 0; FCClassWrap pWrap = new FCClassWrap(); pWrap.BeginExport(""); pWrap.BeginModleWrap("AutoClass"); pWrap.WrapClass(typeof(UnityEngine.AssetBundle)); pWrap.EndModleWrap(); pWrap.EndExport(); MakeFCProj(); }
void MakeReturnFastArray(FCValueType value) { StringBuilder fileData = m_szTempBuilder; string szTypeName = value.GetValueName(true); fileData.AppendFormat(" public static void ReturnArray({0} []rList, long L)\r\n", szTypeName); fileData.AppendLine(" {"); fileData.AppendLine(" try"); fileData.AppendLine(" {"); fileData.AppendLine(" int nCount = rList != null ? rList.Length : 0;"); fileData.AppendLine(" long ptr = FCLibHelper.fc_get_return_ptr(L);"); fileData.AppendFormat(" FCLibHelper.fc_set_array_{0}(ptr, rList, 0, nCount);\r\n", FCValueType.GetFCLibFuncShortName(value.m_nValueType)); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" }"); }
string GetDelegateWrapName(Type nType) { // 第一个,按 string szName = nType.Name; szName = szName.Replace("`", ""); switch (szName) { case "Action": case "UnityAction": case "Func": case "Comparer": break; default: szName = "Custom"; break; } MethodInfo method = nType.GetMethod("Invoke"); ParameterInfo[] allParams = method.GetParameters(); // 函数参数 int nParamCount = allParams != null ? allParams.Length : 0; for (int i = 0; i < nParamCount; ++i) { FCValueType value_param = FCValueType.TransType(allParams[i].ParameterType); szName += "_"; szName += value_param.GetTypeName(true, true); } FCValueType ret_value = FCValueType.TransType(method.ReturnType); if (ret_value.m_nValueType != fc_value_type.fc_value_void) { string szRetName = ret_value.GetValueName(true, true); szName = szName + "__" + szRetName; } return(szName); }
void MakeOutFastArray(FCValueType value) { 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.Count : 0;"); fileData.AppendLine(" long ptr = FCLibHelper.fc_get_param_ptr(L, nIndex);"); fileData.AppendFormat(" FCLibHelper.fc_set_array_{0}(ptr, rList, 0, nCount);", FCValueType.GetFCLibFuncShortName(value.m_nValueType)); fileData.AppendLine(" }"); fileData.AppendLine(" catch(Exception e)"); fileData.AppendLine(" {"); fileData.AppendLine(" Debug.LogException(e);"); fileData.AppendLine(" }"); fileData.AppendLine(" }"); }
string GetParentInitCall(ConstructorInfo consCall) { Type nBaseType = m_nClassType.BaseType; if (nBaseType == null) { return(string.Empty); } ConstructorInfo[] allConInfos = nBaseType.GetConstructors(); // 得到构造函数信息 if (allConInfos == null) { return(string.Empty); } ParameterInfo[] InParams = consCall.GetParameters(); if (InParams == null || InParams.Length == 0) { return(string.Empty); } // 先检测构造参数 ConstructorInfo pFindCon = null; foreach (ConstructorInfo cons in allConInfos) { ParameterInfo[] allParams = cons.GetParameters(); int nCurParamCount = allParams != null ? allParams.Length : 0; if (nCurParamCount == 0) { return(string.Empty); } if (nCurParamCount == InParams.Length) { // 比较一个参数 if (IsSameParam(InParams, allParams)) { pFindCon = cons; break; } } } if (pFindCon == null) { return(string.Empty); } ParameterInfo[] Params = pFindCon.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.IsArray || value.IsList || value.IsMap || value.m_nValueType == fc_value_type.fc_value_system_object) { szParamDesc += "null"; } else if (value.m_nValueType == fc_value_type.fc_value_string_a) { szParamDesc += "string.Empty"; } else { szParamDesc += string.Format("default({0})", value.GetValueName(false)); } } return(string.Format("base({0})", szParamDesc)); }