Example #1
0
    void Awake()
    {
//         string path = "file://"+Application.streamingAssetsPath + "/JavaScript/RotateObject.javascript";
//         WWW w = new WWW(path);
//         while (true)
//         {
//             if (w.isDone)
//                 break;
//         }
//         Debug.Log(w.text);
//         return;
// #if UNITY_EDITOR_WIN
//         Debug.Log("windows editor");
//         return;
// #endif


        DontDestroyOnLoad(gameObject);

        JSMgr.useReflection = false;// this.useReflection;
        if (JSMgr.InitJSEngine())
        {
            inited = true;
            inst   = this;
            Debug.Log("----------InitJSEngine OK ---");
        }
        else
        {
            Debug.Log("----------InitJSEngine FAIL ---");
        }
    }
Example #2
0
    // FirstInit may be called from JSComponent!
    public static void FirstInit(JSEngine jse = null)
    {
        if (!initSuccess && !initFail)
        {
            if (jse == null)
            {
                GameObject jseGO = GameObject.Find("_JSEngine");
                if (jseGO == null)
                {
                    initFail = true;
                    Debug.LogError("_JSEngine gameObject not found. Drag a \"JSBinding/Prefabs/_JSEngine.prefab\" to the scene.");
                }
                else
                {
                    jse = jseGO.GetComponent <JSEngine>();
                }
            }

            if (jse != null)
            {
                // ! Don't destroy this GameObject on load
                DontDestroyOnLoad(jse.gameObject);
                inst = jse;

                JSMgr.InitJSEngine(jse.jsLoader, jse.OnInitJSEngine);
            }
        }
    }
    // 这个函数可能从 JSComponent 调用过来
    public static void FirstInit(JSEngine jse = null)
    {
        if (!initSuccess && !initFail)
        {
            if (jse == null)
            {
                var goEngine = new GameObject("_JSEngine");
                goEngine.AddComponent <JSEngine>();
                return;
            }

            if (jse != null)
            {
                DontDestroyOnLoad(jse.gameObject);
                inst = jse;

                JSFileLoader jsLoader = jse.gameObject.GetComponent <JSFileLoader>();
                if (jsLoader == null)
                {
                    jsLoader = jse.gameObject.AddComponent <JSFileLoader>();
                }
                JSMgr.InitJSEngine(jsLoader, jse.OnInitJSEngine);
            }
        }
    }
Example #4
0
    // FirstInit may be called from JSComponent!
    public static void FirstInit(JSEngine jse = null)
    {
        if (!initSuccess && !initFail)
        {
            if (jse == null)
            {
                GameObject jseGO = GameObject.Find("JSEngine");
                if (jseGO == null)
                {
                    initFail = true;
                    Debug.LogError("JSEngine gameObject not found.");
                }
                else
                {
                    jse = jseGO.GetComponent <JSEngine>();
                }
            }

            if (jse != null)
            {
                /*
                 * Don't destroy this GameObject on load
                 */
                DontDestroyOnLoad(jse.gameObject);
                inst = jse;
#if UNITY_EDITOR
                //编辑器模式下默认输出JSEngine统计数据
                inst.showStatistics = false;
#endif

                Stopwatch stopwatch = Stopwatch.StartNew();
                JSFileLoader.StartLoading();
                JSMgr.InitJSEngine(jse.OnInitJSEngine);
                JSFileLoader.EndLoading();
                stopwatch.Stop();
                Debug.Log("==============InitJSEngine: " + stopwatch.ElapsedMilliseconds + " ms");
            }
        }
    }