コード例 #1
0
ファイル: ScriptBot.cs プロジェクト: xdedss/TankJS
    public IEnumerator RequestActionAsync(GameInformation info)
    {
        IsRunning    = true;
        ActionResult = 0;
        threadContext.ctx.Eval("info=" + ObjectToJson(info));
        watch.Restart();
        threadContext.AsyncTimedEval(Script.Parse(Configurations.AITNOWEU + " = update()"), Configurations.ScriptTimeout, () => {
            IsRunning = false;
            watch.Stop();
            try
            {
                //ActionResult = res.As<int>();
                ActionResult = threadContext.ctx.Eval(Configurations.AITNOWEU).As <int>();
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }, (err) => {
            IsRunning = false;
            watch.Stop();
            if (err is JSException)
            {
                HandleJSError(err as JSException);
            }
            else
            {
                HandleError(err);
            }
        });
        while (IsRunning)
        {
            yield return(0);
        }
        var time = Mathf.CeilToInt(1000f * watch.ElapsedTicks / (float)Stopwatch.Frequency);

        UnityEngine.Debug.Log(string.Format("Async eval completed in {0} ms", time));
        DebugMessage(string.Format("-------- {0} ms --------", time));
    }