예제 #1
0
    private static void GenerateMono2JsComConfig()
    {
        var mono2JsCom = new Dictionary <string, string>();

        Assembly logicCodeLib = Assembly.Load("Assembly-CSharp");

        if (logicCodeLib != null)
        {
            var types = logicCodeLib.GetExportedTypes();
            foreach (var t in types)
            {
                if (t.IsSubclassOf(typeof(MonoBehaviour)))
                {
                    if (WillTypeBeTranslatedToJavaScript(t))
                    {
                        string jsComponentName = JSComponentGenerator.GetJSComponentClassName(t);
                        mono2JsCom.Add(JSNameMgr.GetTypeFullName(t, false), jsComponentName);
                    }
                }
            }
        }
        else
        {
            Debug.LogError("Load Assembly-CSharp.dll failed");
        }

        string filePath = JSPathSettings.Mono2JsComConfig;

        File.WriteAllText(filePath, JsonMapper.ToJson(mono2JsCom));
        Debug.Log(string.Format("Mono2JsCom:{0}\nOK. File: {1}", mono2JsCom.Count, filePath));
    }
예제 #2
0
    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);
    }