// -------------------------------------------------------------------------------------------- public void OnDragFromUnitView(UnitView unitView, Vector2 prevDragPosition, Vector2 dragDelta) { if (_selectedUnit != null && unitView.Unit != _selectedUnit) { return; } if (_game.board.RaycastToPlane(_game.gameCamera.ScreenPointToRay(prevDragPosition + dragDelta), out Vector3 worldPos)) { BoardTile boardTile = _game.board.GetBoardTileAtPosition(worldPos); if (boardTile != null && boardTile != _prevBoardTile) { _prevBoardTile = boardTile; } } if (_pathSelectionView.IsBuilt) { _pathSelectionView.PathTo(_prevBoardTile); } if (_useSkillView.IsBuilt) { _useSkillView.TargetTowardTile(_prevBoardTile); } }
// -------------------------------------------------------------------------------------------- protected override void Build() { UnitView.CreateForGame(_game, this, _data, (UnitView view) => { _view = view; }); _owner.PlayerTurnStarted += Player_PlayerTurnStarted; _owner.PlayerTurnEnded += Player_PlayerTurnEnded; }
// -------------------------------------------------------------------------------------------- public void OnSelectedUnitView(UnitView unitView) { // TODO: show some sort of context menu for the unit here // TODO: for now, just destroy any visible views if (_pathSelectionView.IsBuilt) { _pathSelectionView.Destroy(); } if (_useSkillView.IsBuilt) { _useSkillView.Destroy(); } }
// -------------------------------------------------------------------------------------------- public void OnPointerDownOverUnitView(UnitView unitView) { _selectedUnit = unitView.Unit; _pathSelectionView.unit = _selectedUnit; _useSkillView.unit = _selectedUnit; _prevBoardTile = unitView.Unit.BoardTile; if (_selectedUnit.CanMove && !_pathSelectionView.IsBuilt) { // only show the UnitPathSelectionView if the unit can move _pathSelectionView.Render(AppManager.Transform); } if (_selectedUnit.CanUseSkill && !_useSkillView.IsBuilt) { // only show the UnitUseSkillView if the unit can use its skill _useSkillView.Render(AppManager.Transform); } }
// -------------------------------------------------------------------------------------------- public static void CreateForGame(Game game, Unit unit, UnitData data, InstantiateDelegate callback) { AppManager.AssetManager.Load(data.prefabPath, (bool successful, GameObject payload) => { if (successful) { GameObject viewGo = Instantiate(payload, unit.Transform, false); UnitView view = viewGo.GetComponent <UnitView>(); view.Unit = unit; view._healthBarView = new UIUnitHealthBarView(game, unit); _unitToView.Add(unit, view); callback(view); } }); }
// -------------------------------------------------------------------------------------------- public static bool TryGetView(Unit unit, out UnitView view) { return(_unitToView.TryGetValue(unit, out view)); }
// -------------------------------------------------------------------------------------------- public void OnSelectedUnitView(UnitView unitView) { }
// -------------------------------------------------------------------------------------------- public void OnPointerDownOverUnitView(UnitView unitView) { }
// -------------------------------------------------------------------------------------------- public void OnDragFromUnitView(UnitView unitView, Vector2 prevDragPosition, Vector2 dragDelta) { }