修改
This commit is contained in:
77
Assets/Scripts/Fishing/New/View/Player/PlayerStateView.cs
Normal file
77
Assets/Scripts/Fishing/New/View/Player/PlayerStateView.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user