88 lines
1.8 KiB
C#
Raw Normal View History

2026-01-21 20:27:45 +05:30
using System;
using DG.Tweening;
using UnityEngine;
public enum PlayerState
{
InHome,
InSafeZone,
Moving,
InFinishingPath,
HasFinished
}
public class PlayerPawn : MonoBehaviour
{
[SerializeField] private PlayerState playerState;
private bool canSelectPlayerFromHome;
2026-01-26 19:48:55 +05:30
private GameplayManager gameplayManager;
2026-01-21 20:27:45 +05:30
public int CurrentTileIndex
{
get; private set;
}
2026-01-23 12:46:59 +05:30
public int PlayerId
{
get; private set;
}
2026-01-26 19:48:55 +05:30
public PlayerType PlayerType
2026-01-26 13:03:50 +05:30
{
get; private set;
}
2026-01-21 20:27:45 +05:30
public void SetPlayerSelectionState(bool state)
{
canSelectPlayerFromHome = state;
if (canSelectPlayerFromHome)
{
2026-01-26 19:48:55 +05:30
// TODO :: Play animation for selecting any of the players
2026-01-21 20:27:45 +05:30
}
}
public void MoveToTile(Vector3 startingPoint, Action onComplete, int tileIndex)
{
CurrentTileIndex = tileIndex;
transform.DOMove(startingPoint, 0.1f).onComplete = () => onComplete?.Invoke();
}
2026-01-23 13:33:16 +05:30
public void MoveToCustomTilePosition(Vector3 targetPoint)
{
transform.DOMove(targetPoint, 0.1f);
}
2026-01-21 20:27:45 +05:30
// when he is defeated
public void MoveBackToHome()
{
}
public PlayerState GetPlayerState() => playerState;
public void SetPlayerState(PlayerState state)
{
playerState = state;
}
private void OnMouseDown()
{
if (!canSelectPlayerFromHome) return;
SetGameplayManager();
gameplayManager.OnPawnSelected(this);
}
private void SetGameplayManager()
{
gameplayManager = gameplayManager ?? InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
}
2026-01-23 12:46:59 +05:30
2026-01-26 19:48:55 +05:30
public void Init(int id, PlayerType playerType)
2026-01-23 12:46:59 +05:30
{
PlayerId = id;
2026-01-26 13:03:50 +05:30
PlayerType = playerType;
2026-01-23 12:46:59 +05:30
}
2026-01-21 20:27:45 +05:30
}