public static void Binding() { BindType[] list = WrapFile.getBinds(); for (int i = 0; i < list.Length; i++) { ToLuaExport.Clear(); ToLuaExport.className = list[i].name; ToLuaExport.type = list[i].type; ToLuaExport.isStaticClass = list[i].IsStatic; ToLuaExport.baseClassName = list[i].baseName; ToLuaExport.wrapClassName = list[i].wrapName; ToLuaExport.libClassName = list[i].libName; ToLuaExport.Generate(null); } GenLuaBinder(); // 暂不需要生成委托工厂 //GenLuaDelegates(); Debug.Log("Generate lua binding files over"); AssetDatabase.Refresh(); }
public static void U3dBinding() { List <string> dropList = new List <string> { //特殊修改 "UnityEngine.Object", //一般情况不需要的类, 编辑器相关的 "HideInInspector", "ExecuteInEditMode", "AddComponentMenu", "ContextMenu", "RequireComponent", "DisallowMultipleComponent", "SerializeField", "AssemblyIsEditorAssembly", "Attribute", //一些列文件,都是编辑器相关的 "FFTWindow", "Types", "UnitySurrogateSelector", "TypeInferenceRules", "ThreadPriority", "Debug", //自定义debugger取代 "GenericStack", //异常,lua无法catch "PlayerPrefsException", "UnassignedReferenceException", "UnityException", "MissingComponentException", "MissingReferenceException", //RPC网络 "RPC", "Network", "MasterServer", "BitStream", "HostData", "ConnectionTesterStatus", //unity 自带编辑器GUI "GUI", "EventType", "EventModifiers", //"Event", "FontStyle", "TextAlignment", "TextEditor", "TextEditorDblClickSnapping", "TextGenerator", "TextClipping", "TextGenerationSettings", "TextAnchor", "TextAsset", "TextWrapMode", "Gizmos", "ImagePosition", "FocusType", //地形相关 "Terrain", "Tree", "SplatPrototype", "DetailPrototype", "DetailRenderMode", //其他 "MeshSubsetCombineUtility", "AOT", "Random", "Mathf", "Social", "Enumerator", "SendMouseEvents", "Cursor", "Flash", "ActionScript", //非通用的类 "ADBannerView", "ADInterstitialAd", "Android", "jvalue", "iPhone", "iOS", "CalendarIdentifier", "CalendarUnit", "CalendarUnit", "FullScreenMovieControlMode", "FullScreenMovieScalingMode", "Handheld", "LocalNotification", "Motion", //空类 "NotificationServices", "RemoteNotificationType", "RemoteNotification", "SamsungTV", "TextureCompressionQuality", "TouchScreenKeyboardType", "TouchScreenKeyboard", "MovieTexture", //我不需要的 //2d 类 "AccelerationEventWrap", //加速 "AnimatorUtility", "AudioChorusFilter", "AudioDistortionFilter", "AudioEchoFilter", "AudioHighPassFilter", "AudioLowPassFilter", "AudioReverbFilter", "AudioReverbPreset", "AudioReverbZone", "AudioRolloffMode", "AudioSettings", "AudioSpeakerMode", "AudioType", "AudioVelocityUpdateMode", "Ping", "Profiler", "StaticBatchingUtility", "Font", "Gyroscope", //不需要重力感应 "ISerializationCallbackReceiver", //u3d 继承的序列化接口,lua不需要 "ImageEffectOpaque", //后处理 "ImageEffectTransformsToLDR", "PrimitiveType", // 暂时不需要 GameObject.CreatePrimitive "Skybox", //不会u3d自带的Skybox "SparseTexture", // mega texture 不需要 "Plane", "PlayerPrefs", //不用ugui "SpriteAlignment", "SpriteMeshType", "SpritePackingMode", "SpritePackingRotation", "SpriteRenderer", "Sprite", "UIVertex", "CanvasGroup", "CanvasRenderer", "ICanvasRaycastFilter", "Canvas", "RectTransform", "DrivenRectTransformTracker", "DrivenTransformProperties", "RectTransformAxis", "RectTransformEdge", "RectTransformUtility", "RectTransform", "UICharInfo", "UILineInfo", //不需要轮子碰撞体 "WheelCollider", "WheelFrictionCurve", "WheelHit", //手机不适用雾 "FogMode", "UnityEventBase", "UnityEventCallState", "UnityEvent", "LightProbeGroup", "LightProbes", "NPOTSupport", //只是SystemInfo 的一个枚举值 //没用到substance纹理 "ProceduralCacheSize", "ProceduralLoadingBehavior", "ProceduralMaterial", "ProceduralOutputType", "ProceduralProcessorUsage", "ProceduralPropertyDescription", "ProceduralPropertyType", "ProceduralTexture", //物理关节系统 "JointDriveMode", "JointDrive", "JointLimits", "JointMotor", "JointProjectionMode", "JointSpring", "SoftJointLimit", "SpringJoint", "HingeJoint", "FixedJoint", "ConfigurableJoint", "CharacterJoint", "Joint", "LODGroup", "LOD", "DataUtility", //给sprite使用的 "CrashReport", "CombineInstance", }; List <BindType> list = new List <BindType>(); Assembly assembly = Assembly.Load("UnityEngine"); Type[] types = assembly.GetExportedTypes(); for (int i = 0; i < types.Length; i++) { //不导出: 模版类,event委托, c#协同相关, obsolete 类 if (!types[i].IsGenericType && types[i].BaseType != typeof(System.MulticastDelegate) && !typeof(YieldInstruction).IsAssignableFrom(types[i]) && !ToLuaExport.IsObsolete(types[i])) { list.Add(WrapFile._GT(types[i])); } else { Debug.Log("drop generic type " + types[i].ToString()); } } for (int i = 0; i < dropList.Count; i++) { list.RemoveAll((p) => { return(p.type.ToString().Contains(dropList[i])); }); } //for (int i = 0; i < list.Count; i++) //{ // if (!typeof(UnityEngine.Object).IsAssignableFrom(list[i].type) && !list[i].type.IsEnum && !typeof(UnityEngine.TrackedReference).IsAssignableFrom(list[i].type) // && !list[i].type.IsValueType && !list[i].type.IsSealed) // { // Debug.Log(list[i].type.Name); // } //} for (int i = 0; i < list.Count; i++) { try { ToLuaExport.Clear(); ToLuaExport.className = list[i].name; ToLuaExport.type = list[i].type; ToLuaExport.isStaticClass = list[i].IsStatic; ToLuaExport.baseClassName = list[i].baseName; ToLuaExport.wrapClassName = list[i].wrapName; ToLuaExport.libClassName = list[i].libName; ToLuaExport.Generate(null); } catch (Exception e) { Debug.LogWarning("Generate wrap file error: " + e.ToString()); } } GenLuaBinder(); Debug.Log("Generate lua binding files over, Generate " + list.Count + " files"); AssetDatabase.Refresh(); }
static HashSet <Type> GetCustomDelegateTypes() { BindType[] list = WrapFile.getBinds(); HashSet <Type> set = new HashSet <Type>(); BindingFlags binding = BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.Instance; for (int i = 0; i < list.Length; i++) { Type type = list[i].type; FieldInfo[] fields = type.GetFields(BindingFlags.GetField | BindingFlags.SetField | binding); PropertyInfo[] props = type.GetProperties(BindingFlags.GetProperty | BindingFlags.SetProperty | binding); MethodInfo[] methods = null; if (type.IsInterface) { methods = type.GetMethods(); } else { methods = type.GetMethods(BindingFlags.Instance | binding); } for (int j = 0; j < fields.Length; j++) { Type t = fields[j].FieldType; if (typeof(System.Delegate).IsAssignableFrom(t)) { set.Add(t); } } for (int j = 0; j < props.Length; j++) { Type t = props[j].PropertyType; if (typeof(System.Delegate).IsAssignableFrom(t)) { set.Add(t); } } for (int j = 0; j < methods.Length; j++) { MethodInfo m = methods[j]; if (m.IsGenericMethod) { continue; } ParameterInfo[] pifs = m.GetParameters(); for (int k = 0; k < pifs.Length; k++) { Type t = pifs[k].ParameterType; if (typeof(System.MulticastDelegate).IsAssignableFrom(t)) { set.Add(t); } } } } return(set); }