public static bool IsWebClientObject(object obj) { Type t = obj as Type; if (t != null) { return(JsTypeAttribute.IsJsType(t)); } return(obj is IJavascriptType || obj is IWebClientComponent || obj is IWebClientControl || obj is ISupportWebClientMethods); }
public static MethodInfo[] GetWebMethods(bool isStatic, object obj) { bool includeClient = MethodInfoWebClient.IsWebClientObject(obj); bool includeServer = MethodInfoWebClient.IsWebServerObject(obj); List <MethodInfo> lst = new List <MethodInfo>(); BindingFlags flags; if (isStatic) { flags = BindingFlags.Public | BindingFlags.Static; } else { flags = BindingFlags.Public | BindingFlags.Instance; } Type t = obj as Type; if (t == null) { t = obj.GetType(); } bool isPhp = PhpTypeAttribute.IsPhpType(t); bool isJs = JsTypeAttribute.IsJsType(t); MethodInfo[] ret = t.GetMethods(flags); if (ret != null && ret.Length > 0) { for (int i = 0; i < ret.Length; i++) { if (!ret[i].IsSpecialName) { if (VPLUtil.IsNotForProgramming(ret[i])) { continue; } bool include = false; if (isPhp) { if (WebServerMemberAttribute.IsServerMethod(ret[i])) { lst.Add(ret[i]); } continue; } if (isJs) { if (WebClientMemberAttribute.IsClientMethod(ret[i])) { lst.Add(ret[i]); } continue; } if (includeClient) { object[] objs = ret[i].GetCustomAttributes(typeof(WebClientMemberAttribute), true); if (objs != null && objs.Length > 0) { include = true; } } if (!include) { if (includeServer) { object[] objs = ret[i].GetCustomAttributes(typeof(WebServerMemberAttribute), true); if (objs != null && objs.Length > 0) { include = true; } } } if (include) { lst.Add(ret[i]); } } } } ret = lst.ToArray(); return(ret); }
public static void OutputAllTypesWithJsTypeAttribute() { //var sb = new StringBuilder(); var sb2 = new StringBuilder(); // sb.Append(@"/* Generated by JSBinding Menu : JSB | Generate SharpKit JsType file CS.require list //* see JSAnalyzer.cs / OutputAllTypesWithJsTypeAttribute() function //* better not modify manually. //*/ // //"); sb2.Append(@"/* Generated by JSBinding Menu : JSB | Generate MonoBehaviour to JSComponent_XX * see JSAnalyzer.cs / OutputAllTypesWithJsTypeAttribute() function * better not modify manually. */ "); sb2.AppendLine("var MonoBehaviour2JSComponentName =").AppendLine("["); foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) { Type[] types = a.GetTypes(); foreach (Type t in types) { if (JSSerializerEditor.WillTypeBeTranslatedToJavaScript(t)) { System.Object[] attrs = t.GetCustomAttributes(typeof(JsTypeAttribute), false); JsTypeAttribute jsTypeAttr = (JsTypeAttribute)attrs[0]; if (jsTypeAttr.Filename != null) { //Debug.Log(jsTypeAttr.filename); string mustBegin = "StreamingAssets/JavaScript/"; //string mustBegin = JSBindingSettings.sharpKitGenFileDir; int index = 0; if ((index = jsTypeAttr.Filename.IndexOf(mustBegin)) >= 0) { //sb.AppendFormat("CS.require(\"{0}\");\n", jsTypeAttr.Filename.Substring(index + mustBegin.Length)); } else { Debug.LogError(JSNameMgr.GetTypeFullName(t) + " is ignored because JsType.filename doesn't contain \"" + mustBegin + "\""); } } ///// if (t.IsSubclassOf(typeof(MonoBehaviour))) { string jsComponentName = JSComponentGenerator.GetJSComponentClassName(t); sb2.AppendFormat(" \"{0}|{1}\",\n", JSNameMgr.GetTypeFullName(t, false), jsComponentName); } } } } sb2.AppendLine("];"); sb2.Append(@" var GetMonoBehaviourJSComponentName = function (i) { if (i < MonoBehaviour2JSComponentName.length) { return MonoBehaviour2JSComponentName[i]; } return """"; // returning empty string when end } "); //Debug.Log(sb); string path = JSBindingSettings.sharpkitGeneratedFiles; // 现在不需要这个 // File.WriteAllText(path, sb.ToString()); // Debug.Log("OK. File: " + path); // AssetDatabase.Refresh(); path = JSBindingSettings.monoBehaviour2JSComponentName; File.WriteAllText(path, sb2.ToString()); Debug.Log("OK. File: " + path); }