public static void GenBindings() { //var d = typeof(UnityEngine.MonoBehaviour).GetConstructors(); //Debug.Log("d.length=" + d.Length); //return; if (EditorApplication.isCompiling) { EditorUtility.DisplayDialog("提示", "等待Unity编译完再点", "确定" ); return; } Type[] arrEnums, arrClasses; HashSet <string> bridgeTypes; if (!JSBindingSettings.CheckClasses(out arrEnums, out arrClasses, out bridgeTypes)) { return; } JSDataExchangeEditor.reset(); UnityEngineManual.initManual(); CSGenerator.GenBindings(arrEnums, arrClasses); JSGenerator.GenBindings(arrEnums, arrClasses); CSWrapGenerator.GenWraps(arrEnums, arrClasses, bridgeTypes); AssetDatabase.Refresh(); }
public static void GenBindings() { if (EditorApplication.isCompiling) { EditorUtility.DisplayDialog("Tip:", "please wait EditorApplication compiling", "OK"); return; } Type[] classes = JSBindingSettings.CheckClassBindings(); if (classes == null) { return; } // if (!EditorUtility.DisplayDialog("Tip", // "Files in these directories will all be deleted and re-created: \n" + // JSBindingSettings.csGenDir + "\n", // "OK", "Cancel") // ) // { // return; // } CSGenerator.Log = JSGenerator.Log = Debug.Log; CSGenerator.LogError = JSGenerator.LogError = Debug.LogError; JSGenerator.Application_dataPath = Application.dataPath; JSDataExchangeEditor.reset(); UnityEngineManual.InitManual(); CSGenerator.GenBindings(classes); JSGenerator.GenBindings(classes, JSBindingSettings.enums); UnityEngineManual.AfterUse(); AssetDatabase.Refresh(); }
public static int AddTypeInfo(Type type, out ATypeInfo tiOut) { ATypeInfo ti = new ATypeInfo(); ti.fields = type.GetFields(JSMgr.BindingFlagsField); ti.properties = type.GetProperties(JSMgr.BindingFlagsProperty); ti.methods = type.GetMethods(JSMgr.BindingFlagsMethod); ti.constructors = type.GetConstructors(); if (JSBindingSettings.NeedGenDefaultConstructor(type)) { // null means it's default constructor var l = new List <ConstructorInfo>(); l.Add(null); l.AddRange(ti.constructors); ti.constructors = l.ToArray(); } ti.howmanyConstructors = ti.constructors.Length; FilterTypeInfo(type, ti); int slot = allTypeInfo.Count; allTypeInfo.Add(ti); tiOut = ti; return(slot); }
protected override void BuildIntern(StubOptions options) { var black = JSBindingSettings.LoadBridgeDefinedTypes(false); foreach (var t in options.blackList) { black.Add(t.FullName); } // var a = typeof(UnityEngine.Object).Assembly; // var b = typeof(UnityEditor.EditorWindow).Assembly; // var set = new HashSet<string> { // "UnityEngine", // "UnityEditor", // "UnityEngine.AI", // "UnityEngine.Profiling", // // "UnityEngine.Serialization", // "UnityEngine.EventSystems", // "UnityEngine.SceneManagement", // "UnityEngine.Networking", // "UnityEngine.Events", // "UnityEngine.UI" // }; // var bl = new HashSet<string> { // "UnityEngine.Experimental" // }; // var all = a.GetTypes().Concat(b.GetTypes()).Where( // t => t.IsClass && // t.IsPublic).ToArray(); // foreach(var z in all) { // Debug.Log(z.Namespace); // } // JSBindingSettings.classes = all; JSBindingSettings.classes = options.whiteList.ToArray(); JSBindingSettings.CswFilePath = options.outputPath; var dir = Path.GetDirectoryName(options.outputPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // Debug.Log(JSBindingSettings.CswFilePath); CSWrapGenerator.stubName = options.stubName; CSWrapGenerator.namespaceInterceptor = options.namespaceInterceptor; CSWrapGenerator.GenWraps(JSBindingSettings.classes, black, options.filter); // clear it CSWrapGenerator.stubName = ""; CSWrapGenerator.namespaceInterceptor = null; }
public static StringBuilder BuildConstructors(Type type, ConstructorInfo[] constructors, ClassCallbackNames ccbn) { /* * methods * 0 function name * 1 list<CSParam> generation * 2 function call */ string fmt = @" static bool {0}(JSVCall vc, int start, int count) [[ {1} return true; ]] "; StringBuilder sb = new StringBuilder(); if (constructors.Length == 0 && JSBindingSettings.IsGeneratedDefaultConstructor(type) && (type.IsValueType || (type.IsClass && !type.IsAbstract && !type.IsInterface))) { int olIndex = 1; bool returnVoid = false; string functionName = type.Name + "_" + type.Name + (olIndex > 0 ? olIndex.ToString() : "") + "";// (cons.IsStatic ? "_S" : ""); sb.AppendFormat(fmt, functionName, BuildNormalFunctionCall(new ParameterInfo[0], type.Name, type.Name, false, returnVoid, null, true)); ccbn.constructors.Add(functionName); ccbn.constructorsCSParam.Add(GenListCSParam2(new ParameterInfo[0]).ToString()); } for (int i = 0; i < constructors.Length; i++) { ConstructorInfo cons = constructors[i]; ParameterInfo[] paramS = cons.GetParameters(); int olIndex = i + 1; // for constuctors, they are always overloaded bool returnVoid = false; string functionName = type.Name + "_" + type.Name + (olIndex > 0 ? olIndex.ToString() : "") + (cons.IsStatic ? "_S" : ""); sb.AppendFormat(fmt, functionName, BuildNormalFunctionCall(paramS, type.Name, cons.Name, cons.IsStatic, returnVoid, null, true)); ccbn.constructors.Add(functionName); ccbn.constructorsCSParam.Add(GenListCSParam2(paramS).ToString()); } return(sb); }
public static void FilterTypeInfo(Type type, ATypeInfo ti) { List <ConstructorInfo> lstCons = new List <ConstructorInfo>(); List <FieldInfo> lstField = new List <FieldInfo>(); List <PropertyInfo> lstPro = new List <PropertyInfo>(); Dictionary <string, int> proAccessors = new Dictionary <string, int>(); List <MethodInfo> lstMethod = new List <MethodInfo>(); for (int i = 0; i < ti.constructors.Length; i++) { if (!IsMemberObsolete(ti.constructors[i])) { lstCons.Add(ti.constructors[i]); } } for (int i = 0; i < ti.fields.Length; i++) { if (typeof(System.Delegate).IsAssignableFrom(ti.fields[i].FieldType.BaseType)) { //Debug.Log("[field]" + type.ToString() + "." + ti.fields[i].Name + "is delegate!"); } if (!IsMemberObsolete(ti.fields[i]) && !JSBindingSettings.IsDiscard(type, ti.fields[i])) { lstField.Add(ti.fields[i]); } } for (int i = 0; i < ti.properties.Length; i++) { PropertyInfo pro = ti.properties[i]; if (typeof(System.Delegate).IsAssignableFrom(pro.PropertyType.BaseType)) { // Debug.Log("[property]" + type.ToString() + "." + pro.Name + "is delegate!"); } MethodInfo[] accessors = pro.GetAccessors(); foreach (var v in accessors) { if (!proAccessors.ContainsKey(v.Name)) { proAccessors.Add(v.Name, 0); } } if (pro.Name == "Item") //[] not support { continue; } // Skip Obsolete if (IsMemberObsolete(pro)) { continue; } if (JSBindingSettings.IsDiscard(type, pro)) { continue; } lstPro.Add(pro); } for (int i = 0; i < ti.methods.Length; i++) { MethodInfo method = ti.methods[i]; // skip property accessor if (method.IsSpecialName && proAccessors.ContainsKey(method.Name)) { continue; } if (method.IsSpecialName) { if (method.Name == "op_Addition" || method.Name == "op_Subtraction" || method.Name == "op_UnaryNegation" || method.Name == "op_Multiply" || method.Name == "op_Division" || method.Name == "op_Equality" || method.Name == "op_Inequality") { if (!method.IsStatic) { // Debug.LogWarning("IGNORE not-static special-name function: " + type.Name + "." + method.Name); continue; } } else { // Debug.LogWarning("IGNORE special-name function:" + type.Name + "." + method.Name); continue; } } // Skip Obsolete if (IsMemberObsolete(method)) { continue; } if (method.IsGenericMethod || method.IsGenericMethodDefinition) { //Debug.Log(type.Name + "." + method.Name); continue; } if (JSBindingSettings.IsDiscard(type, method)) { continue; } lstMethod.Add(method); } if (lstMethod.Count == 0) { ti.methodsOLInfo = null; } else { // sort methods lstMethod.Sort(MethodInfoComparison); ti.methodsOLInfo = new int[lstMethod.Count]; } int overloadedIndex = 1; bool bOL = false; for (int i = 0; i < lstMethod.Count; i++) { ti.methodsOLInfo[i] = 0; if (bOL) { ti.methodsOLInfo[i] = overloadedIndex; } if (i < lstMethod.Count - 1 && lstMethod[i].Name == lstMethod[i + 1].Name && ((lstMethod[i].IsStatic && lstMethod[i + 1].IsStatic) || (!lstMethod[i].IsStatic && !lstMethod[i + 1].IsStatic))) { if (!bOL) { overloadedIndex = 1; bOL = true; ti.methodsOLInfo[i] = overloadedIndex; } overloadedIndex++; } else { bOL = false; overloadedIndex = 1; } } ti.constructors = lstCons.ToArray(); ti.fields = lstField.ToArray(); ti.properties = lstPro.ToArray(); ti.methods = lstMethod.ToArray(); }
public static void FilterTypeInfo(Type type, ATypeInfo ti) { bool bIsStaticClass = (type.IsClass && type.IsAbstract && type.IsSealed); bool bIsAbstractClass = (type.IsClass && type.IsAbstract); List <ConstructorInfoAndIndex> lstCons = new List <ConstructorInfoAndIndex>(); List <FieldInfoAndIndex> lstField = new List <FieldInfoAndIndex>(); List <PropertyInfoAndIndex> lstPro = new List <PropertyInfoAndIndex>(); Dictionary <string, int> proAccessors = new Dictionary <string, int>(); List <MethodInfoAndIndex> lstMethod = new List <MethodInfoAndIndex>(); for (int i = 0; i < ti.constructors.Length; i++) { if (bIsAbstractClass) { continue; } if (ti.constructors[i] == null) { lstCons.Add(new ConstructorInfoAndIndex(null, i)); continue; } // don't generate MonoBehaviour constructor if (type == typeof(UnityEngine.MonoBehaviour)) { continue; } if (!IsMemberObsolete(ti.constructors[i]) && !JSBindingSettings.IsDiscard(type, ti.constructors[i])) { lstCons.Add(new ConstructorInfoAndIndex(ti.constructors[i], i)); } } for (int i = 0; i < ti.fields.Length; i++) { if (typeof(System.Delegate).IsAssignableFrom(ti.fields[i].FieldType.BaseType)) { //Debug.Log("[field]" + type.ToString() + "." + ti.fields[i].Name + "is delegate!"); } if (ti.fields[i].FieldType.ContainsGenericParameters) { continue; } if (!IsMemberObsolete(ti.fields[i]) && !JSBindingSettings.IsDiscard(type, ti.fields[i])) { lstField.Add(new FieldInfoAndIndex(ti.fields[i], i)); } } for (int i = 0; i < ti.properties.Length; i++) { PropertyInfo pro = ti.properties[i]; if (typeof(System.Delegate).IsAssignableFrom(pro.PropertyType.BaseType)) { // Debug.Log("[property]" + type.ToString() + "." + pro.Name + "is delegate!"); } MethodInfo[] accessors = pro.GetAccessors(); foreach (var v in accessors) { if (!proAccessors.ContainsKey(v.Name)) { proAccessors.Add(v.Name, 0); } } // if (pro.GetIndexParameters().Length > 0) // continue; // if (pro.Name == "Item") //[] not support // continue; // Skip Obsolete if (IsMemberObsolete(pro)) { continue; } if (JSBindingSettings.IsDiscard(type, pro)) { continue; } lstPro.Add(new PropertyInfoAndIndex(pro, i)); } for (int i = 0; i < ti.methods.Length; i++) { MethodInfo method = ti.methods[i]; // skip non-static method in static class if (bIsStaticClass && !method.IsStatic) { // NGUITools //Debug.Log("........."+type.Name+"."+method.Name); continue; } // skip property accessor if (method.IsSpecialName && proAccessors.ContainsKey(method.Name)) { continue; } if (method.IsSpecialName) { if (method.Name == "op_Addition" || method.Name == "op_Subtraction" || method.Name == "op_UnaryNegation" || method.Name == "op_Multiply" || method.Name == "op_Division" || method.Name == "op_Equality" || method.Name == "op_Inequality" || method.Name == "op_LessThan" || method.Name == "op_LessThanOrEqual" || method.Name == "op_GreaterThan" || method.Name == "op_GreaterThanOrEqual" || method.Name == "op_Implicit") { if (!method.IsStatic) { Debug.Log("IGNORE not-static special-name function: " + type.Name + "." + method.Name); continue; } } else { Debug.Log("IGNORE special-name function:" + type.Name + "." + method.Name); continue; } } // Skip Obsolete if (IsMemberObsolete(method)) { continue; } ParameterInfo[] ps; bool bDiscard = false; // // ignore static method who contains T coming from class type // because there is no way to call it // SharpKit doesn't give c# the type of T // if (method.IsGenericMethodDefinition && /* || method.IsGenericMethod*/ method.IsStatic) { ps = method.GetParameters(); for (int k = 0; k < ps.Length; k++) { if (ps[k].ParameterType.ContainsGenericParameters) { var Ts = JSDataExchangeMgr.RecursivelyGetGenericParameters(ps[k].ParameterType); foreach (var t in Ts) { if (t.DeclaringMethod == null) { bDiscard = true; break; } } if (bDiscard) { break; } } } if (bDiscard) { Debug.LogWarning("Ignore static method " + type.Name + "." + method.Name); continue; } } // does it have unsafe parameter? bDiscard = false; ps = method.GetParameters(); for (var k = 0; k < ps.Length; k++) { Type pt = ps[k].ParameterType; while (true) { if (pt.IsPointer) { bDiscard = true; break; } else if (pt.HasElementType) { pt = pt.GetElementType(); } else { break; } } if (bDiscard) { break; } } if (bDiscard) { Debug.Log(type.Name + "." + method.Name + " was discard because it has unsafe parameter."); continue; } if (JSBindingSettings.IsDiscard(type, method)) { continue; } lstMethod.Add(new MethodInfoAndIndex(method, i)); } if (lstMethod.Count == 0) { ti.methodsOLInfo = null; } else { // sort methods lstMethod.Sort(MethodInfoComparison); ti.methodsOLInfo = new int[lstMethod.Count]; } int overloadedIndex = 1; bool bOL = false; for (int i = 0; i < lstMethod.Count; i++) { ti.methodsOLInfo[i] = 0; if (bOL) { ti.methodsOLInfo[i] = overloadedIndex; } if (i < lstMethod.Count - 1 && lstMethod[i].method.Name == lstMethod[i + 1].method.Name && ((lstMethod[i].method.IsStatic && lstMethod[i + 1].method.IsStatic) || (!lstMethod[i].method.IsStatic && !lstMethod[i + 1].method.IsStatic))) { if (!bOL) { overloadedIndex = 1; bOL = true; ti.methodsOLInfo[i] = overloadedIndex; } overloadedIndex++; } else { bOL = false; overloadedIndex = 1; } } ti.constructors = new ConstructorInfo[lstCons.Count]; ti.constructorsIndex = new int[lstCons.Count]; for (var k = 0; k < lstCons.Count; k++) { ti.constructors[k] = lstCons[k].method; ti.constructorsIndex[k] = lstCons[k].index; } // ti.fields = lstField.ToArray(); ti.fields = new FieldInfo[lstField.Count]; ti.fieldsIndex = new int[lstField.Count]; for (var k = 0; k < lstField.Count; k++) { ti.fields[k] = lstField[k].method; ti.fieldsIndex[k] = lstField[k].index; } // ti.properties = lstPro.ToArray(); ti.properties = new PropertyInfo[lstPro.Count]; ti.propertiesIndex = new int[lstPro.Count]; for (var k = 0; k < lstPro.Count; k++) { ti.properties[k] = lstPro[k].method; ti.propertiesIndex[k] = lstPro[k].index; } ti.methods = new MethodInfo[lstMethod.Count]; ti.methodsIndex = new int[lstMethod.Count]; for (var k = 0; k < lstMethod.Count; k++) { ti.methods[k] = lstMethod[k].method; ti.methodsIndex[k] = lstMethod[k].index; } }
public static PropertyInfo[] GetTypeSerializedProperties(Type type) { return(JSBindingSettings.GetTypeSerializedProperties(type)); }