public static void GenerateClassBindings() { if (!typeClassName.ContainsKey(typeof(UnityEngine.Object))) { typeClassName.Add(typeof(UnityEngine.Object), "UnityObject"); } JSGenerator.OnBegin(); // enums for (int i = 0; i < JSBindingSettings.enums.Length; i++) { JSGenerator.Clear(); JSGenerator.type = JSBindingSettings.enums[i]; JSGenerator.GenerateEnum(); } // classes for (int i = 0; i < JSBindingSettings.classes.Length; i++) { JSGenerator.Clear(); JSGenerator.type = JSBindingSettings.classes[i]; if (!typeClassName.TryGetValue(type, out className)) { className = type.Name; } JSGenerator.GenerateClass(); } JSGenerator.OnEnd(); Debug.Log("Generate JS Bindings finish. enum " + JSBindingSettings.enums.Length.ToString() + ", class " + JSBindingSettings.classes.Length.ToString()); }
public static void GenBindings(Type[] types, Type[] enums) { JSGenerator.Classes = types; JSGenerator.Enums = enums; JSGenerator.OnBegin(); // enums for (int i = 0; i < Enums.Length; i++) { JSGenerator.Clear(); JSGenerator.type = Enums[i]; JSGenerator.GenerateEnum(); } // typeName -> member list Dictionary <string, List <string> > allDefs = new Dictionary <string, List <string> >(); // classes for (int i = 0; i < Classes.Length; i++) { JSGenerator.Clear(); JSGenerator.type = Classes[i]; if (!typeClassName.TryGetValue(type, out className)) { className = type.Name; } List <string> memberNames = JSGenerator.GenerateClass(); allDefs.Add(SharpKitClassName(type), memberNames); } JSGenerator.OnEnd(); StringBuilder sb = new StringBuilder(); foreach (var KV in allDefs) { sb.AppendFormat("[{0}]\r\n", KV.Key); var lst = KV.Value; foreach (var l in lst) { sb.AppendFormat(" {0}\r\n", l); } sb.Append("\r\n"); } string dir = Application_dataPath + "/Temp"; Directory.CreateDirectory(dir); File.WriteAllText(dir + "/AllExportedMembers.txt", sb.ToString()); Log("Generate JS Bindings OK. enum " + Enums.Length.ToString() + ", class " + Classes.Length.ToString()); }
//[MenuItem("JSBinding/Generate JS Bindings")] public static void GenerateClassBindings() { // if (!typeClassName.ContainsKey(typeof(UnityEngine.Object))) // typeClassName.Add(typeof(UnityEngine.Object), "UnityObject"); JSGenerator.OnBegin(); // enums for (int i = 0; i < JSBindingSettings.enums.Length; i++) { JSGenerator.Clear(); JSGenerator.type = JSBindingSettings.enums[i]; JSGenerator.GenerateEnum(); } // typeName -> member list Dictionary <string, List <string> > allDefs = new Dictionary <string, List <string> >(); // classes for (int i = 0; i < JSBindingSettings.classes.Length; i++) { JSGenerator.Clear(); JSGenerator.type = JSBindingSettings.classes[i]; if (!typeClassName.TryGetValue(type, out className)) { className = type.Name; } List <string> memberNames = JSGenerator.GenerateClass(); allDefs.Add(SharpKitClassName(type), memberNames); } JSGenerator.OnEnd(); StringBuilder sb = new StringBuilder(); foreach (var KV in allDefs) { sb.AppendFormat("[{0}]\r\n", KV.Key); var lst = KV.Value; foreach (var l in lst) { sb.AppendFormat(" {0}\r\n", l); } sb.Append("\r\n"); } File.WriteAllText(JSAnalyzer.GetAllExportedMembersFile(), sb.ToString()); Debug.Log("Generate JS Bindings OK. enum " + JSBindingSettings.enums.Length.ToString() + ", class " + JSBindingSettings.classes.Length.ToString()); }