ScriptVar ApiDebug(ScriptVM vm)
        {
            var str = string.Empty;

            for (int i = 0, iMax = vm.GetParamsCount(); i < iMax; i++)
            {
                str += " " + vm.GetParamByID(i).AsString;
            }
            Debug.LogFormat("[SCRIPT: {0}]{1}", Time.time, str);
            return(new ScriptVar());
        }
        ScriptVar ApiCallWithDelay(ScriptVM vm)
        {
            var count    = vm.GetParamsCount();
            var pTimeout = vm.GetParamByID(0);
            var pEvent   = vm.GetParamByID(1);

            if (count < 2 || !pTimeout.IsNumber || !pEvent.IsString)
            {
                _vm.SetRuntimeError("(nTimeout, sFuncName[, param1, param2]) parameters required");
                return(new ScriptVar());
            }
            ScriptVar?param1 = null;

            if (count > 2)
            {
                param1 = vm.GetParamByID(2);
            }
            ScriptVar?param2 = null;

            if (count > 3)
            {
                param2 = vm.GetParamByID(3);
            }
            ScriptVar?param3 = null;

            if (count > 4)
            {
                param3 = vm.GetParamByID(4);
            }
            ScriptVar?param4 = null;

            if (count > 5)
            {
                param4 = vm.GetParamByID(5);
            }

            CallFunctionWithDelay(pEvent.AsString, pTimeout.AsNumber, param1, param2, param3, param4);

            return(new ScriptVar());
        }
 /// <summary>
 /// Will be raised on attempt of publish host api methods to script engine.
 /// Override it to register custom api.
 /// </summary>
 /// <param name="vm">Script engine instance.</param>
 protected virtual void OnAttachHostFunctions(ScriptVM vm)
 {
     _vm.RegisterHostFunction("callWithDelay", ApiCallWithDelay);
     _vm.RegisterHostFunction("debug", ApiDebug);
 }
Пример #4
0
 /// <summary>
 /// Initialization for specified ScriptVM.
 /// </summary>
 public Vars(ScriptVM vm)
 {
     _vm = vm;
 }
Пример #5
0
 /// <summary>
 /// Initialization for specified ScriptVM.
 /// </summary>
 public Vars(ScriptVM vm)
 {
     _vm = vm;
 }