有了时间系统,我们就能让枪械发射后能返回默认状态了

修改ShootCommand

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using FrameWorkDesign;

namespace ShootingEditor2D
{
public class ShootCommand : AbstractCommand
{
public static readonly ShootCommand Instance = new ShootCommand();
protected override void OnExecute()
{
//...

var timeSystem = this.GetSystem<ITimeSystem>();
timeSystem.AddTaskDelay(0.33f, () =>
{
gunSystem.CurrentGun.State.Value = GunState.Idle;
});
}
}
}

修改Gun脚本,开枪时添加状态判断

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using UnityEngine;
using FrameWorkDesign;

namespace ShootingEditor2D
{
public class Gun : MonoBehaviour,IController
{
//...
public void Shoot()
{
if (m_GunInfo.AmmoNumInGun.Value > 0 && m_GunInfo.State.Value == GunState.Idle)//
{
//...
}
}
//...
}
}