using System.Collections.Generic; using Fantasy.Entitas; using Fantasy.Entitas.Interface; using Fantasy.Event; namespace NBF { /// /// 状态显示层组件 /// public class PlayerStateView : Entity { private readonly Dictionary _stageViews = new Dictionary(); private PlayerStageViewBase _currentStateView; private Player _player; public void Awake() { _player = GetParent(); _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 { protected override void Awake(PlayerStateView self) { self.Awake(); } } public class PlayerStateViewComponentUpdateSystem : UpdateSystem { protected override void Update(PlayerStateView self) { self.Update(); } } public class OnPlayerStageChange : EventSystem { protected override void Handler(PlayerStateChangeEvent self) { var stateView = self.Player.GetComponent(); if (stateView != null) { stateView.OnStageChange(); } } } }