Ejemplo n.º 1
0
 private static void CallLuaObjectCallbacks(int tick)
 {
     foreach (var luaObject in _luaObjectTickCallbacks.Keys)
     {
         LuaManager.Call(
             _luaObjectTickCallbacks[luaObject],
             DynValue.NewNumber(0),  // I literally don't know why I need this
             DynValue.NewNumber(luaObject.Id),
             DynValue.NewNumber(tick)
             );
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Sets a keybind to call the provided function
        /// </summary>
        /// <param name="name">Name of the keybind</param>
        /// <param name="hotKey">Hotkey in string format, per example: ALT+CTRL+SHIFT+D</param>
        /// <param name="pressType">The key type, either key up or key down</param>
        /// <param name="function">LUA function to call</param>
        /// <param name="args">Optional arguments for the passed function</param>
        public void SetKeybind(string name, string hotKey, PressType pressType, DynValue function, params DynValue[] args)
        {
            if (pressType != PressType.Down && pressType != PressType.Up)
            {
                throw new ScriptRuntimeException("Key type must either be Down or Up.");
            }

            var modifierKeys = ModifierKeys.None;
            var key          = Key.System;
            var hotKeyParts  = hotKey.Split('+').Select(p => p.Trim());

            foreach (var hotKeyPart in hotKeyParts)
            {
                if (hotKeyPart == "ALT")
                {
                    modifierKeys |= ModifierKeys.Alt;
                }
                else if (hotKeyPart == "CTRL")
                {
                    modifierKeys |= ModifierKeys.Control;
                }
                else if (hotKeyPart == "SHIFT")
                {
                    modifierKeys |= ModifierKeys.Shift;
                }
                else
                {
                    Enum.TryParse(hotKeyPart, true, out key);
                }
            }

            if (key == Key.System)
            {
                throw new ScriptRuntimeException($"Hotkey '{hotKey}' couldn't be parsed.");
            }

            var hk    = new HotKey(key, modifierKeys);
            var model = args != null
                ? new KeybindModel("LUA-" + name, hk, pressType, () => LuaManager.Call(function, args))
                : new KeybindModel("LUA-" + name, hk, pressType, () => LuaManager.Call(function));

            KeybindManager.AddOrUpdate(model);

            var existing = _keybindModels.FirstOrDefault(k => k.Name == model.Name);

            if (existing != null)
            {
                _keybindModels.Remove(existing);
            }

            _keybindModels.Add(model);
        }
Ejemplo n.º 3
0
    void testLuaManager()
    {
        TextAsset file = Resources.Load <TextAsset>("function_lua");

        LuaManager.FunctionData data = new LuaManager.FunctionData();
        data.returnValueNum = 4;
        data.functionName   = "calc";
        ArrayList list = new ArrayList();

        list.Add(50.0f);
        list.Add(150.0f);
        data.argList = list;
        ArrayList returnList = gLuaManager.Call(file, data);
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds an action to be called when an axis is released.
 /// </summary>
 /// <param name="axisName">Te name of the axis.</param>
 /// <param name="action">The action to perform.</param>
 /// <param name="priority">The priority of the action.</param>
 public static void AddOnAxisReleased(string axisName, DynValue action, int priority = 0)
 {
     foreach (var profile in Profiles)
     {
         foreach (var axis in profile.Axes)
         {
             if (axis.Name == axisName)
             {
                 axis.AddOnReleased(() => LuaManager.Call(action), priority);
                 return;
             }
         }
     }
     InGameDebug.Log("No axis with name '" + axisName + "'.");
 }
Ejemplo n.º 5
0
 public static void AddOnTickListener(DynValue function)
 {
     Ticker.OnTick += n => LuaManager.Call(function, DynValue.NewNumber(n));
 }
Ejemplo n.º 6
0
 public void Invoke()
 {
     _luaManager.Call(Action);
 }