81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using Fantasy.Entitas;
|
|
using Fantasy.Entitas.Interface;
|
|
using Fantasy.Event;
|
|
|
|
namespace NBF
|
|
{
|
|
/// <summary>
|
|
/// 状态显示层组件
|
|
/// </summary>
|
|
public class PlayerStateView : Entity
|
|
{
|
|
private readonly Dictionary<PlayerState, PlayerStageViewBase> _stageViews =
|
|
new Dictionary<PlayerState, PlayerStageViewBase>();
|
|
|
|
private PlayerStageViewBase _currentStateView;
|
|
private Player _player;
|
|
|
|
public PlayerStageViewBase CurrentStateView => _currentStateView;
|
|
|
|
public void Awake()
|
|
{
|
|
_player = GetParent<Player>();
|
|
_stageViews.Add(PlayerState.Idle, new PlayerStageViewIdle());
|
|
_stageViews.Add(PlayerState.Prepare, new PlayerStageViewPrepare());
|
|
_stageViews.Add(PlayerState.Throw, new PlayerStageViewThrow());
|
|
_stageViews.Add(PlayerState.Fishing, new PlayerStageViewFishing());
|
|
_stageViews.Add(PlayerState.Fight, new PlayerStageViewFight());
|
|
foreach (var playerStageView in _stageViews.Values)
|
|
{
|
|
playerStageView.Init(_player);
|
|
}
|
|
|
|
OnStageChange();
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
_currentStateView?.Update();
|
|
}
|
|
|
|
public void OnStageChange()
|
|
{
|
|
if (_currentStateView != null)
|
|
{
|
|
_currentStateView.Exit();
|
|
}
|
|
|
|
_currentStateView = _stageViews.GetValueOrDefault(_player.State);
|
|
_currentStateView?.Enter(_player.StateParams, _player.PreviousState);
|
|
}
|
|
}
|
|
|
|
public class PlayerStateViewComponentAwakeSystem : AwakeSystem<PlayerStateView>
|
|
{
|
|
protected override void Awake(PlayerStateView self)
|
|
{
|
|
self.Awake();
|
|
}
|
|
}
|
|
|
|
public class PlayerStateViewComponentUpdateSystem : UpdateSystem<PlayerStateView>
|
|
{
|
|
protected override void Update(PlayerStateView self)
|
|
{
|
|
self.Update();
|
|
}
|
|
}
|
|
|
|
public class OnPlayerStageChange : EventSystem<PlayerStateChangeEvent>
|
|
{
|
|
protected override void Handler(PlayerStateChangeEvent self)
|
|
{
|
|
var stateView = self.Player.GetComponent<PlayerStateView>();
|
|
if (stateView != null)
|
|
{
|
|
stateView.OnStageChange();
|
|
}
|
|
}
|
|
}
|
|
} |