Exemplo n.º 1
0
    public static IntPtr GetScript(string shortName)
    {
        IntPtrClass ptrClass = null;

        if (compiledScript.TryGetValue(shortName, out ptrClass))
        {
            return(ptrClass.ptr);
        }
        else
        {
//             string fullName = Application.streamingAssetsPath + "/JavaScript/" + shortName + ".javascript";
//
//             StreamReader r = new StreamReader(fullName, Encoding.UTF8);
//             string s = r.ReadToEnd();
//
//             IntPtr intPtr = JSApi.JSh_CompileScript(cx, glob, s, (uint)s.Length, shortName, 1);
//             r.Close();
//             return intPtr;

            UnityEngine.Object obj = Resources.Load(shortName);
            TextAsset          ta  = (TextAsset)obj;
//            string content = ReadFileString(calcFullJSFileName(shortName, false));
//            if (content.Length == 0)
//                return IntPtr.Zero;
            string content = ta.text;
            return(CompileScriptContent(shortName, content, glob));
        }
    }
Exemplo n.º 2
0
    public static IntPtr CompileScriptContent(string shortName, string content, IntPtr obj)
    {
        if (content.Length == 0)
        {
            Debug.Log(shortName + " content length = 0");
            return(IntPtr.Zero);
        }

        IntPtr      ptr      = JSApi.JSh_CompileScript(cx, obj, content, (uint)content.Length, shortName, 1);
        IntPtrClass ptrClass = new IntPtrClass(ptr);
        bool        b        = JSApi.JSh_AddNamedScriptRoot(JSMgr.cx, ref ptrClass.ptr, shortName);

        if (!b)
        {
            Debug.LogWarning("JSh_AddNamedScriptRoot fail!!");
        }
        compiledScript.Add(shortName, ptrClass);
        return(ptr);
    }