/* 文件名:ObjectController.nut 路径:User/Controller/ObjectController.nut 创建日期:2024-12-21 14:16 文件用途: */ //输入指令集 class InputInstructionSpecial { //指令表 InstructionArray = null; //指令等待帧数 WaitFrame = null; //动态数据 DynamicData = null; constructor(gInstructionArray, gWaitFrame) { this.InstructionArray = gInstructionArray; this.WaitFrame = gWaitFrame; DynamicData = { CurrentIndex = 0, Time = 0 }; } //指令集更新 function OnUpdate(Dt) { //比对值 local Match = false; //获取最新的按键键值 } } class Object_Controller { //控制对象 Parent = null; //控制器是否启用 Enabled = true; constructor(gParent) { this.Parent = gParent.weakref(); Move_Instruction_Horizontal = []; Move_Instruction_Vertical = []; } //启用控制器 function Enable() { this.Enabled = true; } //关闭控制器 function Disable() { this.Enabled = false; } //横向移动方向List Move_Instruction_Horizontal = null; //纵向移动方向List Move_Instruction_Vertical = null; //检查按键与移动方向 function CheckMove(Key, Flag, Buffer) { //上 0 下 1 左 2 右 3 local Move_Index = Buffer.find(Flag); if (Input.GetGameKeyCode(Key)) { if (Move_Index == null) Buffer.push(Flag); } else { if (Move_Index != null) Buffer.remove(Move_Index); } } //方向移动控制 function MoveControl(Dt) { //上 0 下 1 左 2 右 3 CheckMove("OPTION_HOTKEY_MOVE_UP", 0, Move_Instruction_Vertical); CheckMove("OPTION_HOTKEY_MOVE_DOWN", 1, Move_Instruction_Vertical); CheckMove("OPTION_HOTKEY_MOVE_LEFT", 2, Move_Instruction_Horizontal); CheckMove("OPTION_HOTKEY_MOVE_RIGHT", 3, Move_Instruction_Horizontal); //获取横向移动方向 local Move_Horizontal = Move_Instruction_Horizontal.len() ? Move_Instruction_Horizontal.top() : null; //获取纵向移动方向 local Move_Vertical = Move_Instruction_Vertical.len() ? Move_Instruction_Vertical.top() : null; local X = 0, Y = 0; if (Move_Horizontal == 2) X = -1; else if (Move_Horizontal == 3) X = 1; if (Move_Vertical == 0) Y = -1; else if (Move_Vertical == 1) Y = 1; //至少有一个方向才会调用 Parent.Move(Dt, X, Y); } //控制器更新 function OnUpdate(Dt) { if (!this.Enabled) return; //方向移动控制 MoveControl(Dt); } }