private void Response(IResponse response) { Info($"PieceView Response: {response}"); if (response.Failed) { _AudioSource.PlayOneShot(CancelClip); ReturnToStart(); return; } var battle = response.Request as Battle; if (battle != null) { _AudioSource.PlayOneShot(HitClip); ReturnToStart(); return; } var move = response.Request as MovePiece; if (move != null) { BoardView.MovePiece(this, Coord.Value); } }
protected override void Begin() { base.Begin(); Coord.Subscribe(c => Move()); SquareOver.Subscribe(sq => { if (sq != null) { BoardView.ShowSquares(Agent.Model.Card, sq); } }).AddTo(this); }
private void OnMouseDrag() { if (!_dragging) { return; } var mp = Input.mousePosition; var cursorPoint = new Vector3(mp.x, mp.y, _screenPoint.z); var cursorPosition = Camera.main.ScreenToWorldPoint(cursorPoint); transform.position = cursorPosition + _cursorOffset; transform.SetZ(-0.5f); _squareOver.Value = BoardView.TestRayCast(Input.mousePosition); }
public override void SetAgent(IPlayerView view, ICardAgent agent) { base.SetAgent(view, agent); _mana = FindTextChild("Mana"); _health = FindTextChild("Health"); _power = FindTextChild("Power"); if (_mana == null) { Error("No Mana text child for {0}", this); return; } if (_health == null) { Error("No Health text child for {0}", this); return; } if (_power == null) { Error("No Power text child for {0}", this); return; } base.MouseOver.Subscribe(v => _mouseOver.Value = v as ICardView).AddTo(this); Assert.IsNotNull(agent); agent.Power.Subscribe(p => _power.text = $"{p}").AddTo(this); agent.Health.Subscribe(p => _health.text = $"{p}").AddTo(this); agent.Model.ManaCost.Subscribe(p => _mana.text = $"{p}").AddTo(this); FindPiece().material = Owner.Value.Color == EColor.Black ? BoardView.BlackMaterial : BoardView.WhiteMaterial; SquareOver.Subscribe(sq => { if (sq != null) { BoardView.ShowSquares(Agent.Model, sq); } }).AddTo(this); Assert.IsTrue(IsValid); }
protected override void MouseUp(IBoardView board, Coord coord) { var player = PlayerView.Agent; var existing = BoardView.Get(coord); if (existing == null) { player.PushRequest(new MovePiece(PlayerModel, Agent.Model, coord), Response); return; } if (ReferenceEquals(existing, this)) { return; } // TODO: allow for mounting if (existing.SameOwner(this)) { return; } player.PushRequest(new Battle(PlayerModel, Agent.Model, existing.Agent.Model), Response); }
void Die() { Info($"{Agent.Model} died"); Commands.Do(() => _AudioSource.PlayOneShot(HitBothClip)); BoardView.Remove(this); }