You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
4.0 KiB
C#
114 lines
4.0 KiB
C#
using Entitas;
|
|
using UnityEngine;
|
|
using Game;
|
|
public class InputSystem : IExecuteSystem, IInitializeSystem
|
|
{
|
|
public void Initialize()
|
|
{
|
|
}
|
|
public void Execute()
|
|
{
|
|
BuildFunctionKey();
|
|
}
|
|
private static void BuildFunctionKey()
|
|
{
|
|
BuildPlayerAction();
|
|
if (!Util.IsControl()) return;
|
|
BuildMove();
|
|
BuildJump();
|
|
BuildTest();
|
|
}
|
|
private static void BuildTest()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.I))
|
|
{
|
|
var master = Util.GetMaster();
|
|
// var castDir = master.move.moveDir;
|
|
// castDir = new Vector3(castDir.x, 0, castDir.z);//忽略y
|
|
// var rotf = Util.Vec3ToRot(castDir);
|
|
// Util.CastEffect(GameConst.EffectHitKill, master.Pos(), rotf, targetEntity: master.ID());
|
|
// Util.SetTimeScaleEffect(0, 1, 0.8f);
|
|
// Util.SetAberrationEffect(1, 0, 0.7f);
|
|
// Util.SetFovEffect(0.9f, 1, 0.7f);
|
|
// Util.EntityShake(master, 7);
|
|
|
|
foreach (var item in Util.GetAllEnemies())
|
|
{
|
|
var entity = Util.GetEntity(item);
|
|
entity.SetPos(master.Pos() + Vector3.up * 3);
|
|
}
|
|
}
|
|
}
|
|
private static void BuildPlayerAction()
|
|
{
|
|
foreach (var item in GameSetting.KeyMap)
|
|
{
|
|
var functionKey = item.Key;
|
|
if (Input.GetKeyDown(item.Value))
|
|
{
|
|
EventManager.Instance.SendEvent<PPlayerInput>(EEvent.PlayerInput, new PPlayerInput()
|
|
{
|
|
Key = functionKey,
|
|
Action = EKeyActionType.Press,
|
|
});
|
|
}
|
|
if (Input.GetKeyUp(item.Value))
|
|
{
|
|
EventManager.Instance.SendEvent<PPlayerInput>(EEvent.PlayerInput, new PPlayerInput()
|
|
{
|
|
Key = functionKey,
|
|
Action = EKeyActionType.Release,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
private static void BuildMove()
|
|
{
|
|
var leftPress = Input.GetKey(GameSetting.KeyMap[EFunctionKey.Left]);
|
|
var rightPress = Input.GetKey(GameSetting.KeyMap[EFunctionKey.Right]);
|
|
var upPress = Input.GetKey(GameSetting.KeyMap[EFunctionKey.Up]);
|
|
var downPress = Input.GetKey(GameSetting.KeyMap[EFunctionKey.Down]);
|
|
var horizonPress = leftPress != rightPress;
|
|
var verticalPress = upPress != downPress;
|
|
var command = EMoveCommand.Stop;
|
|
var commandType = EMoveCommandType.Move;
|
|
|
|
if (horizonPress && verticalPress)
|
|
if (upPress)
|
|
command = leftPress ? EMoveCommand.UpLeft : EMoveCommand.UpRight;
|
|
else
|
|
command = leftPress ? EMoveCommand.DownLeft : EMoveCommand.DownRight;
|
|
else if (horizonPress || verticalPress)
|
|
if (horizonPress)
|
|
command = leftPress ? EMoveCommand.Left : EMoveCommand.Right;
|
|
else
|
|
command = upPress ? EMoveCommand.Up : EMoveCommand.Down;
|
|
else
|
|
commandType = EMoveCommandType.Stop;
|
|
|
|
SendMoveInputEvent(command, commandType);
|
|
}
|
|
private static void BuildJump()
|
|
{
|
|
var jumpPress = Input.GetKeyDown(GameSetting.KeyMap[EFunctionKey.Jump]);
|
|
if (jumpPress)
|
|
{
|
|
SendMoveInputEvent(EMoveCommand.Jump, EMoveCommandType.FunctionKey);
|
|
}
|
|
var jumpRelease = Input.GetKeyUp(GameSetting.KeyMap[EFunctionKey.Jump]);
|
|
if (jumpRelease)
|
|
{
|
|
SendMoveInputEvent(EMoveCommand.JumpRelease, EMoveCommandType.FunctionKey);
|
|
}
|
|
}
|
|
private static void SendMoveInputEvent(EMoveCommand command, EMoveCommandType commandType)
|
|
{
|
|
var entityID = Util.GetMasterID();
|
|
EventManager.Instance.SendEvent(EEvent.EntityMoveInput, new PEntityMoveInput()
|
|
{
|
|
EntityID = entityID,
|
|
Command = command,
|
|
CommandType = commandType,
|
|
});
|
|
}
|
|
} |