Merge remote-tracking branch 'origin/Gameplay/main-gameplay' into Gameplay/siva-gameplay
This commit is contained in:
commit
c42db86e28
BIN
Assets/Artifacts/Sprites/Other/freepik__background__18020.png
Normal file
BIN
Assets/Artifacts/Sprites/Other/freepik__background__18020.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 77 KiB |
@ -0,0 +1,147 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34e3d7c5f315b46f9b3481e3ea797ffe
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 12
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMasterTextureLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: iPhone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: 5e97eb03825dee720800000000000000
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class Dice : MonoBehaviour, IBase, IBootLoader
|
||||
public class DiceView : MonoBehaviour, IBase
|
||||
{
|
||||
private Rigidbody rb;
|
||||
private bool rolling;
|
||||
@ -15,48 +16,49 @@ public class Dice : MonoBehaviour, IBase, IBootLoader
|
||||
[SerializeField] private float liftForce = 0.1f;
|
||||
|
||||
|
||||
private Action<int> onRollingComplete = null;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
rb.useGravity = false;
|
||||
}
|
||||
public void Initialize()
|
||||
{
|
||||
InterfaceManager.Instance?.RegisterInterface<Dice>(this);
|
||||
transform.localPosition = new Vector3(0, 20, 0);
|
||||
}
|
||||
|
||||
public void Roll()
|
||||
public void Roll(Action<int> onComplete)
|
||||
{
|
||||
if (!rolling)
|
||||
{
|
||||
onRollingComplete = onComplete;
|
||||
StartCoroutine(RollRoutine());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator RollRoutine()
|
||||
{
|
||||
rolling = true;
|
||||
|
||||
// MICRO DELAY → breaks physics sync between dice
|
||||
yield return new WaitForSeconds(Random.Range(0.01f, 0.06f));
|
||||
yield return new WaitForSeconds(UnityEngine.Random.Range(0.01f, 0.06f));
|
||||
|
||||
rb.useGravity = true;
|
||||
|
||||
// PER-DICE FORCE MULTIPLIER
|
||||
float spinMultiplier = Random.Range(0.8f, 1.25f);
|
||||
float spinMultiplier = UnityEngine.Random.Range(0.8f, 1.25f);
|
||||
|
||||
// RANDOM TORQUE
|
||||
rb.AddTorque(
|
||||
Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||
Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||
Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||
UnityEngine.Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||
UnityEngine.Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||
UnityEngine.Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||
ForceMode.Impulse
|
||||
);
|
||||
|
||||
// RANDOM SIDE FORCE
|
||||
Vector3 sideDir = new Vector3(
|
||||
Random.Range(-1f, 1f),
|
||||
UnityEngine.Random.Range(-1f, 1f),
|
||||
0f,
|
||||
Random.Range(-1f, 1f)
|
||||
UnityEngine.Random.Range(-1f, 1f)
|
||||
).normalized;
|
||||
|
||||
rb.AddForce(sideDir * sideForce, ForceMode.Impulse);
|
||||
@ -71,6 +73,8 @@ public class Dice : MonoBehaviour, IBase, IBootLoader
|
||||
//TODO: Use the dice value as needed
|
||||
Debug.Log($"Dice rolled: {value}");
|
||||
|
||||
onRollingComplete?.Invoke(value);
|
||||
|
||||
ResetDice();
|
||||
}
|
||||
|
||||
@ -237,6 +237,18 @@ PrefabInstance:
|
||||
propertyPath: m_Layer
|
||||
value: 3
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1804238606659730488, guid: 7a038d77e6ef54ce4b627bc5bf3ed17d, type: 3}
|
||||
propertyPath: liftForce
|
||||
value: 0.25
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1804238606659730488, guid: 7a038d77e6ef54ce4b627bc5bf3ed17d, type: 3}
|
||||
propertyPath: sideForce
|
||||
value: 0.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1804238606659730488, guid: 7a038d77e6ef54ce4b627bc5bf3ed17d, type: 3}
|
||||
propertyPath: baseSpinForce
|
||||
value: 2000
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 1804238606659730489, guid: 7a038d77e6ef54ce4b627bc5bf3ed17d, type: 3}
|
||||
propertyPath: m_RootOrder
|
||||
value: 0
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
2128
Assets/Prefabs/UI/Player V AI Popup .prefab
Normal file
2128
Assets/Prefabs/UI/Player V AI Popup .prefab
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0f4457742bfd4c61bd436792af64064
|
||||
guid: b04f48863fc6c4f75821857086cea347
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
4441
Assets/Prefabs/UI/Player V Player Popup.prefab
Normal file
4441
Assets/Prefabs/UI/Player V Player Popup.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Prefabs/UI/Player V Player Popup.prefab.meta
Normal file
7
Assets/Prefabs/UI/Player V Player Popup.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fd2ca927610f4ed9a93f6bb3ec71a1d
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15980
Assets/Scenes/Game.unity
15980
Assets/Scenes/Game.unity
File diff suppressed because it is too large
Load Diff
@ -5,4 +5,9 @@ using UnityEngine;
|
||||
public static class Ludo_3D_Constants
|
||||
{
|
||||
public const int Max_Dice_Rolls = 6;
|
||||
|
||||
public const string Player1_Name = "Player1";
|
||||
public const string Player2_Name = "Player2";
|
||||
public const string Player3_Name = "Player3";
|
||||
public const string Player4_Name = "Player4";
|
||||
}
|
||||
40
Assets/Scripts/Gameplay/GameModeHandler.cs
Normal file
40
Assets/Scripts/Gameplay/GameModeHandler.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum GameModeType
|
||||
{
|
||||
PVP,
|
||||
Bot,
|
||||
}
|
||||
|
||||
public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
{
|
||||
private GameplayManager gameplayManager;
|
||||
|
||||
public GameModeType GameModeType
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
InterfaceManager.Instance.RegisterInterface<GameModeHandler>(this);
|
||||
}
|
||||
|
||||
public void InitializeData()
|
||||
{
|
||||
gameplayManager = InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
|
||||
}
|
||||
|
||||
public void InitPVPModeData(List<PlayerType> types)
|
||||
{
|
||||
GameModeType = GameModeType.PVP;
|
||||
gameplayManager.InitPlayerTypesForPVP(types);
|
||||
}
|
||||
|
||||
public void InitBotModeData(PlayerType selectedPlayer, int botCount)
|
||||
{
|
||||
GameModeType = GameModeType.Bot;
|
||||
gameplayManager.InitPlayerTypesForBotMatch(selectedPlayer, botCount);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Gameplay/GameModeHandler.cs.meta
Normal file
11
Assets/Scripts/Gameplay/GameModeHandler.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d8a94cfc31bb45f9a403db0c1f4c116
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -43,6 +43,8 @@ public enum BotMove
|
||||
|
||||
public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
{
|
||||
[SerializeField] DiceRollHandler diceRollHandler;
|
||||
|
||||
[SerializeField] private int diceValue = 0;
|
||||
|
||||
[SerializeField] private TextMeshProUGUI diceText;
|
||||
@ -59,8 +61,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
private int currentPlayerTurnIndex = 0;
|
||||
private List<PlayerType> allPlayerTypes = new List<PlayerType>();
|
||||
private List<PlayerType> botTypesInGame = new List<PlayerType>();
|
||||
private List<PlayerType> playerRankings = new List<PlayerType>();
|
||||
|
||||
public List<PlayerType> PlayerTypesCollection => allPlayerTypes;
|
||||
|
||||
// private Dictionary<PlayerTypes, > playerPawnsDict = new Dictionary<PlayerTypes, List<PlayerPawn>>();
|
||||
private Dictionary<PlayerType, PlayerGameData> playerGameDatasDict = new Dictionary<PlayerType, PlayerGameData>();
|
||||
@ -71,14 +73,19 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
private TilesManager tilesManager;
|
||||
|
||||
private int diceRolledValue;
|
||||
public bool CanRollDice
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
private bool CanRollDiceAgain = false; // used for when you get a 6 or when you reach the finish point
|
||||
private int diceSixRollCounter = 0;
|
||||
|
||||
private List<PlayerPawn> availPlayers = new List<PlayerPawn>();
|
||||
private bool canSwitchPlayer = false;
|
||||
|
||||
public bool CanRollDiceForUser
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
public List<PlayerType> PlayerTypesCollection => allPlayerTypes;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
InterfaceManager.Instance?.RegisterInterface<GameplayManager>(this);
|
||||
@ -89,20 +96,16 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
{
|
||||
tilesManager = InterfaceManager.Instance.GetInterfaceInstance<TilesManager>();
|
||||
|
||||
CanRollDice = true;
|
||||
CanRollDiceForUser = true;
|
||||
|
||||
// initialize the player list from UI.
|
||||
|
||||
// InitPlayerTypesForLAN(null);
|
||||
InitPlayerTypesForBotMatch(PlayerType.Player1, 3);
|
||||
}
|
||||
|
||||
// TODO :: Call when the UI selection is made and game starts
|
||||
public void InitPlayerTypesForLAN(List<PlayerType> types)
|
||||
public void InitPlayerTypesForPVP(List<PlayerType> types)
|
||||
{
|
||||
// TODO :: 2P, 3P, 4P
|
||||
allPlayerTypes = new List<PlayerType> { PlayerType.Player1, PlayerType.Player2, PlayerType.Player3, PlayerType.Player4 };
|
||||
// allPlayerTypes = new List<PlayerType> { PlayerType.Player1, PlayerType.Player3 };
|
||||
allPlayerTypes = new List<PlayerType>(types);
|
||||
|
||||
playerBaseHandler.InitPlayerTypes(allPlayerTypes);
|
||||
InitCurrentGamePlayerInfo();
|
||||
@ -223,10 +226,13 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDiceInteracted()
|
||||
{
|
||||
diceRollHandler.HandleDiceViewForUser();
|
||||
}
|
||||
|
||||
public void RollDiceForPlayer(int rolledVal)
|
||||
{
|
||||
if (botTypesInGame.Contains(currentPlayerTypeTurn)) return;
|
||||
|
||||
OnDiceRolled(rolledVal);
|
||||
OnNoMovesLeft();
|
||||
}
|
||||
@ -254,12 +260,12 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
return false;
|
||||
}
|
||||
|
||||
private void RollDiceForBot()
|
||||
private void RollDiceForBot(int rolledVal)
|
||||
{
|
||||
Debug.Log($"CallTest: RollDiceForBot");
|
||||
|
||||
// OnDiceRolled(diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue);
|
||||
OnDiceRolled(diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue);
|
||||
OnDiceRolled(rolledVal);
|
||||
|
||||
SelectPawnFromBotBase();
|
||||
|
||||
@ -420,9 +426,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
}
|
||||
}
|
||||
|
||||
private List<PlayerPawn> availPlayers = new List<PlayerPawn>();
|
||||
private bool canSwitchPlayer = false;
|
||||
|
||||
public void OnDiceRolled(int rolledVal)
|
||||
{
|
||||
SetCanRollDiceForUser(false);
|
||||
@ -542,7 +545,14 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
private void CheckDiceRollForBot(PlayerPawn playerPawn)
|
||||
{
|
||||
if (CanRollDiceAgain)
|
||||
RollDiceForBot();
|
||||
{
|
||||
HandleDiceRoll();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleDiceRoll()
|
||||
{
|
||||
diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal));
|
||||
}
|
||||
|
||||
public void OnPawnSelected(PlayerPawn playerPawn)
|
||||
@ -686,7 +696,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
if (botTypesInGame.Contains(currentPlayerTypeTurn)) // TODO :: Double check calling of the function
|
||||
{
|
||||
Debug.Log($"Invoking RollDiceForBot");
|
||||
Invoke(nameof(RollDiceForBot), 1f);
|
||||
Invoke(nameof(HandleDiceRoll), 1f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -890,7 +900,21 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
CanRollDiceAgain = false;
|
||||
|
||||
if (allPlayerTypes.Contains(currentPlayerTypeTurn))
|
||||
{
|
||||
playerRankings.Add(currentPlayerTypeTurn);
|
||||
allPlayerTypes.Remove(currentPlayerTypeTurn);
|
||||
}
|
||||
|
||||
if (allPlayerTypes.Count == 1)
|
||||
{
|
||||
// Game is over
|
||||
playerRankings.Add(allPlayerTypes[0]);
|
||||
allPlayerTypes.Remove(0);
|
||||
|
||||
// Show Game Over panel
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchPlayer();
|
||||
|
||||
@ -924,6 +948,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
{
|
||||
// if (botTypesInGame.Contains(playerType)) return;
|
||||
|
||||
CanRollDice = state;
|
||||
CanRollDiceForUser = state;
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,6 +104,7 @@ public class PlayerPawn : MonoBehaviour
|
||||
// when he is defeated
|
||||
public void MoveBackToHome(Transform transformData)
|
||||
{
|
||||
Debug.Log($"MoveBackToHome");
|
||||
transform.position = transformData.position;
|
||||
transform.rotation = transformData.rotation;
|
||||
SetPlayerState(PlayerState.InHome);
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DiceRoller : MonoBehaviour
|
||||
public class DiceRollHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private DiceView diceView;
|
||||
[SerializeField] private int diceTestValue = 0;
|
||||
|
||||
private InputManager inputManager;
|
||||
@ -11,27 +13,32 @@ public class DiceRoller : MonoBehaviour
|
||||
private void OnMouseDown()
|
||||
{
|
||||
inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>() : inputManager;
|
||||
if (!inputManager.GameplayManager.CanRollDice) return;
|
||||
|
||||
OnDiceRolled();
|
||||
// RollDiceOnClick();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
inputManager = inputManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>() : inputManager;
|
||||
if (!inputManager.GameplayManager.CanRollDice) return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
OnDiceRolled();
|
||||
}
|
||||
|
||||
private void OnDiceRolled()
|
||||
public void OnUserDiceRollComplete(int rolledVal)
|
||||
{
|
||||
SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>();
|
||||
soundManager?.PlayGameSoundClip(SoundType.Dice);
|
||||
|
||||
int currentRolledVal = // Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1);
|
||||
diceTestValue != 0 ? diceTestValue : Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1);
|
||||
inputManager.SetDiceRollValue(currentRolledVal);
|
||||
inputManager.SetDiceRollValue(rolledVal);
|
||||
}
|
||||
|
||||
public void HandleDiceViewForUser()
|
||||
{
|
||||
if (!inputManager.GameplayManager.CanRollDiceForUser) return;
|
||||
|
||||
diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal));
|
||||
}
|
||||
|
||||
public void HandleDiceViewForBot(Action<int> onComplete)
|
||||
{
|
||||
diceView.Roll(onComplete: onComplete);
|
||||
}
|
||||
}
|
||||
8
Assets/Scripts/State.meta
Normal file
8
Assets/Scripts/State.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7e3406fc0f8a4b3abf3913c7655f3f1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Scripts/State/GameManager.cs
Normal file
43
Assets/Scripts/State/GameManager.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
|
||||
public enum GameState
|
||||
{
|
||||
InMenu,
|
||||
InGame,
|
||||
}
|
||||
|
||||
public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
{
|
||||
private UIManager uiManager;
|
||||
|
||||
public GameState GameState
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
InterfaceManager.Instance.RegisterInterface<GameManager>(this);
|
||||
}
|
||||
|
||||
public void InitializeData()
|
||||
{
|
||||
uiManager = InterfaceManager.Instance.GetInterfaceInstance<UIManager>();
|
||||
|
||||
GameState = GameState.InMenu;
|
||||
OnGameStateChanged(GameState);
|
||||
}
|
||||
|
||||
public void OnGameStateChanged(GameState gameState)
|
||||
{
|
||||
switch (gameState)
|
||||
{
|
||||
case GameState.InMenu:
|
||||
uiManager.OnInMenuScreen();
|
||||
break;
|
||||
case GameState.InGame:
|
||||
uiManager.OnInGameScreen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/State/GameManager.cs.meta
Normal file
11
Assets/Scripts/State/GameManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39da8f399f9774587bd1d0c7977e556b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -57,6 +57,12 @@ public class ScreenManager : MonoBehaviour, IBase, IBootLoader
|
||||
}
|
||||
}
|
||||
|
||||
public void HideAllScreens()
|
||||
{
|
||||
foreach (var screenPair in screensDict)
|
||||
if (screenPair.Value.isActiveAndEnabled) screenPair.Value.Hide();
|
||||
}
|
||||
|
||||
// public void OnScreenEventExecute(ScreenResultEvent screenResultEvent)
|
||||
// {
|
||||
// switch (screenResultEvent)
|
||||
|
||||
42
Assets/Scripts/UI/Managers/UIManager.cs
Normal file
42
Assets/Scripts/UI/Managers/UIManager.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
||||
{
|
||||
private GameplayManager gameplayManager;
|
||||
private ScreenManager screenManager;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
InterfaceManager.Instance.RegisterInterface<UIManager>(this);
|
||||
}
|
||||
|
||||
public void InitializeData()
|
||||
{
|
||||
gameplayManager = InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
|
||||
}
|
||||
|
||||
public void OnDiceViewInteracted()
|
||||
{
|
||||
gameplayManager.OnDiceInteracted();
|
||||
}
|
||||
|
||||
public void OnInMenuScreen()
|
||||
{
|
||||
screenManager = screenManager == null ? InterfaceManager.Instance.GetInterfaceInstance<ScreenManager>() : screenManager;
|
||||
screenManager.HideAllScreens();
|
||||
screenManager.ShowScreen(ScreenType.MenuScreen);
|
||||
}
|
||||
|
||||
public void OnInGameScreen()
|
||||
{
|
||||
screenManager.HideAllScreens();
|
||||
screenManager.ShowScreen(ScreenType.InGameHUDScreen);
|
||||
}
|
||||
|
||||
public void UpdateSelectedPlayerCount(int playersCount)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Managers/UIManager.cs.meta
Normal file
11
Assets/Scripts/UI/Managers/UIManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bebcbb45c745a4006be9ef5b25e12cd5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -10,8 +10,7 @@ public enum ScreenType
|
||||
LoadingScreen,
|
||||
LevelsScreen,
|
||||
InGameHUDScreen,
|
||||
MenuHUDScreen,
|
||||
GlobalHUDScreen
|
||||
MenuScreen,
|
||||
}
|
||||
|
||||
public class ScreenBase : UIBase, IUIBase
|
||||
|
||||
@ -21,7 +21,7 @@ public class InstructionsPopup : PopupBase
|
||||
private void OnClick_closeBtn()
|
||||
{
|
||||
ScreenManager screenManager = InterfaceManager.Instance?.GetInterfaceInstance<ScreenManager>();
|
||||
screenManager.ShowScreen(ScreenType.MenuHUDScreen);
|
||||
screenManager.ShowScreen(ScreenType.MenuScreen);
|
||||
|
||||
soundManager = soundManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>() : soundManager;
|
||||
soundManager?.PlayGameSoundClip(SoundType.ButtonClick);
|
||||
|
||||
@ -29,7 +29,7 @@ public class OptionsPopup : PopupBase
|
||||
private void OnClick_closeBtn()
|
||||
{
|
||||
ScreenManager screenManager = InterfaceManager.Instance?.GetInterfaceInstance<ScreenManager>();
|
||||
screenManager.ShowScreen(ScreenType.MenuHUDScreen);
|
||||
screenManager.ShowScreen(ScreenType.MenuScreen);
|
||||
|
||||
Hide();
|
||||
}
|
||||
|
||||
@ -20,16 +20,18 @@ public class PvAIModePopup : PopupBase
|
||||
|
||||
private ScreenManager screenManager;
|
||||
private SoundManager soundManager;
|
||||
private GameModeHandler gameModeHandler;
|
||||
|
||||
private int selectedPlayerCount;
|
||||
public int SelectedPlayerCount => selectedPlayerCount;
|
||||
private PlayerType playerType;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
twoPlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(2));
|
||||
threePlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(3));
|
||||
fourPlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(4));
|
||||
playBtn.onClick.AddListener(OnClick_playBtn);
|
||||
closeBtn.onClick.AddListener(OnClick_closeBtn);
|
||||
playBtn.onClick.AddListener(OnClick_PlayButton);
|
||||
closeBtn.onClick.AddListener(OnClick_CloseButton);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@ -45,9 +47,9 @@ public class PvAIModePopup : PopupBase
|
||||
selectedPlayerCount = count;
|
||||
}
|
||||
|
||||
private void OnClick_playBtn()
|
||||
private void OnClick_PlayButton()
|
||||
{
|
||||
playerName = playerNameInput.text;
|
||||
playerName = string.IsNullOrWhiteSpace(playerNameInput.text) ? Ludo_3D_Constants.Player1_Name : playerNameInput.text;
|
||||
|
||||
soundManager = soundManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>() : soundManager;
|
||||
soundManager?.PlayGameSoundClip(SoundType.ButtonClick);
|
||||
@ -57,11 +59,14 @@ public class PvAIModePopup : PopupBase
|
||||
Debug.Log($"Starting PVP Mode with {selectedPlayerCount} players:");
|
||||
Debug.Log($"Player 1: {playerName}");
|
||||
|
||||
gameModeHandler = gameModeHandler == null ? InterfaceManager.Instance.GetInterfaceInstance<GameModeHandler>() : gameModeHandler;
|
||||
gameModeHandler.InitBotModeData(playerType, selectedPlayerCount - 1);
|
||||
}
|
||||
private void OnClick_closeBtn()
|
||||
|
||||
private void OnClick_CloseButton()
|
||||
{
|
||||
screenManager = screenManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<ScreenManager>() : screenManager;
|
||||
screenManager.ShowScreen(ScreenType.MenuHUDScreen);
|
||||
screenManager.ShowScreen(ScreenType.MenuScreen);
|
||||
|
||||
soundManager = soundManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>() : soundManager;
|
||||
soundManager?.PlayGameSoundClip(SoundType.ButtonClick);
|
||||
|
||||
232
Assets/Scripts/UI/Pages/PopUp/PvPModePopup.cs
Normal file
232
Assets/Scripts/UI/Pages/PopUp/PvPModePopup.cs
Normal file
@ -0,0 +1,232 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PvPModePopup : PopupBase
|
||||
{
|
||||
[Header("Buttons")]
|
||||
[SerializeField] private Button twoPlayerBtn;
|
||||
[SerializeField] private Button threePlayerBtn;
|
||||
[SerializeField] private Button fourPlayerBtn;
|
||||
[SerializeField] private Button switchBtn;
|
||||
[SerializeField] private Button playBtn;
|
||||
[SerializeField] private Button closeBtn;
|
||||
|
||||
[Header("Input Field")]
|
||||
[SerializeField] private TMP_InputField playerOneNameInput;
|
||||
[SerializeField] private TMP_InputField playerTwoNameInput;
|
||||
[SerializeField] private TMP_InputField playerThreeNameInput;
|
||||
[SerializeField] private TMP_InputField playerFourNameInput;
|
||||
|
||||
[Header("Player Names")]
|
||||
private string playerOneName;
|
||||
private string playerTwoName;
|
||||
private string playerThreeName;
|
||||
private string playerFourName;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private GameObject playerNameInputParent1;
|
||||
[SerializeField] private GameObject playerNameInputParent2;
|
||||
|
||||
[Header("Placeholders")]
|
||||
[SerializeField] private TMP_Text playerOnePlaceholder;
|
||||
[SerializeField] private TMP_Text playerTwoPlaceholder;
|
||||
[SerializeField] private TMP_Text playerThreePlaceholder;
|
||||
[SerializeField] private TMP_Text playerFourPlaceholder;
|
||||
|
||||
private ScreenManager screenManager;
|
||||
private SoundManager soundManager;
|
||||
private GameModeHandler gameModeHandler;
|
||||
|
||||
private int selectedPlayerCount;
|
||||
public int SelectedPlayerCount => selectedPlayerCount;
|
||||
|
||||
[Header("Horizontal Rows (P1–P4)")]
|
||||
public List<GameObject> rows;
|
||||
private int hiddenIndex = 0;
|
||||
|
||||
Dictionary<PlayerType, string> playerNameMap = new();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
twoPlayerBtn.onClick.AddListener(OnClick_TwoPlayerBtn);
|
||||
threePlayerBtn.onClick.AddListener(OnClick_ThreePlayerBtn);
|
||||
fourPlayerBtn.onClick.AddListener(OnClick_FourPlayerBtn);
|
||||
playBtn.onClick.AddListener(OnClick_PlayBtn);
|
||||
closeBtn.onClick.AddListener(OnClick_CloseBtn);
|
||||
switchBtn.onClick.AddListener(OnClick_SwitchBtn);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
twoPlayerBtn.onClick.RemoveListener(OnClick_TwoPlayerBtn);
|
||||
threePlayerBtn.onClick.RemoveListener(OnClick_ThreePlayerBtn);
|
||||
fourPlayerBtn.onClick.RemoveAllListeners();
|
||||
playBtn.onClick.RemoveListener(OnClick_PlayBtn);
|
||||
closeBtn.onClick.RemoveListener(OnClick_CloseBtn);
|
||||
switchBtn.onClick.RemoveListener(OnClick_SwitchBtn);
|
||||
}
|
||||
|
||||
private void OnClick_TwoPlayerBtn()
|
||||
{
|
||||
switchBtn.gameObject.SetActive(true);
|
||||
selectedPlayerCount = 2;
|
||||
playerNameInputParent2.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnClick_ThreePlayerBtn()
|
||||
{
|
||||
switchBtn.gameObject.SetActive(true);
|
||||
selectedPlayerCount = 3;
|
||||
playerNameInputParent1.SetActive(true);
|
||||
playerNameInputParent2.SetActive(true);
|
||||
UpdateInputFieldsVisibility();
|
||||
}
|
||||
|
||||
private void OnClick_FourPlayerBtn()
|
||||
{
|
||||
switchBtn.gameObject.SetActive(false);
|
||||
selectedPlayerCount = 4;
|
||||
playerNameInputParent1.SetActive(true);
|
||||
playerNameInputParent2.SetActive(true);
|
||||
UpdateInputFieldsVisibility();
|
||||
}
|
||||
|
||||
private void UpdateInputFieldsVisibility()
|
||||
{
|
||||
playerOneNameInput.transform.parent.gameObject.SetActive(true);
|
||||
playerTwoNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 3);
|
||||
playerThreeNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 2);
|
||||
playerFourNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 4);
|
||||
}
|
||||
|
||||
private void OnClick_PlayBtn()
|
||||
{
|
||||
int logicalIndex = 0;
|
||||
|
||||
foreach (GameObject row in rows)
|
||||
{
|
||||
if (!row.activeSelf)
|
||||
continue;
|
||||
|
||||
TMP_InputField input = row.GetComponentInChildren<TMP_InputField>();
|
||||
|
||||
PlayerType playerType = (PlayerType)logicalIndex;
|
||||
|
||||
string playerName = string.IsNullOrWhiteSpace(input.text)
|
||||
? playerType.ToString()
|
||||
: input.text;
|
||||
|
||||
playerNameMap[playerType] = playerName;
|
||||
logicalIndex++;
|
||||
}
|
||||
|
||||
// playerOneName = string.IsNullOrWhiteSpace(playerOneNameInput.text) ? Ludo_3D_Constants.Player1_Name : playerOneNameInput.text;
|
||||
// playerTwoName = string.IsNullOrWhiteSpace(playerTwoNameInput.text) ? Ludo_3D_Constants.Player1_Name : playerTwoNameInput.text;
|
||||
// playerThreeName = string.IsNullOrWhiteSpace(playerThreeNameInput.text) ? Ludo_3D_Constants.Player1_Name : playerThreeNameInput.text;
|
||||
// playerFourName = string.IsNullOrWhiteSpace(playerFourNameInput.text) ? Ludo_3D_Constants.Player1_Name : playerFourNameInput.text;
|
||||
|
||||
playerOneName = playerNameMap.GetValueOrDefault(PlayerType.Player1, Ludo_3D_Constants.Player1_Name);
|
||||
playerTwoName = playerNameMap.GetValueOrDefault(PlayerType.Player2, Ludo_3D_Constants.Player2_Name);
|
||||
playerThreeName = playerNameMap.GetValueOrDefault(PlayerType.Player3, Ludo_3D_Constants.Player3_Name);
|
||||
playerFourName = playerNameMap.GetValueOrDefault(PlayerType.Player4, Ludo_3D_Constants.Player4_Name);
|
||||
|
||||
|
||||
soundManager = soundManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>() : soundManager;
|
||||
soundManager?.PlayGameSoundClip(SoundType.ButtonClick);
|
||||
|
||||
//TODO: Start PVP Game with the selected player count and names
|
||||
Debug.Log($"Starting PVP Mode with {selectedPlayerCount} players:");
|
||||
Debug.Log($"Player 1: {playerOneName}");
|
||||
Debug.Log($"Player 2: {playerTwoName}");
|
||||
|
||||
if (selectedPlayerCount >= 3)
|
||||
Debug.Log($"Player 3: {playerThreeName}");
|
||||
if (selectedPlayerCount == 4)
|
||||
Debug.Log($"Player 4: {playerFourName}");
|
||||
|
||||
InitPlayers();
|
||||
}
|
||||
|
||||
private void InitPlayers()
|
||||
{
|
||||
// update logic based on UpdateInputFieldsVisibility()
|
||||
List<PlayerType> playerTypes = new List<PlayerType>();
|
||||
if (playerOneNameInput.gameObject.activeInHierarchy)
|
||||
playerTypes.Add(PlayerType.Player1);
|
||||
|
||||
if (playerTwoNameInput.gameObject.activeInHierarchy)
|
||||
playerTypes.Add(PlayerType.Player2);
|
||||
|
||||
if (playerThreeNameInput.gameObject.activeInHierarchy)
|
||||
playerTypes.Add(PlayerType.Player3);
|
||||
|
||||
if (playerFourNameInput.gameObject.activeInHierarchy)
|
||||
playerTypes.Add(PlayerType.Player4);
|
||||
|
||||
gameModeHandler = gameModeHandler == null ? InterfaceManager.Instance.GetInterfaceInstance<GameModeHandler>() : gameModeHandler;
|
||||
gameModeHandler.InitPVPModeData(playerTypes);
|
||||
}
|
||||
|
||||
private void OnClick_SwitchBtn()
|
||||
{
|
||||
if (SelectedPlayerCount == 2)
|
||||
{
|
||||
if (playerNameInputParent1.activeSelf)
|
||||
{
|
||||
playerNameInputParent1.SetActive(false);
|
||||
playerNameInputParent2.SetActive(true);
|
||||
playerOnePlaceholder.text = "Player 1";
|
||||
playerThreePlaceholder.text = "Player 2";
|
||||
}
|
||||
else
|
||||
{
|
||||
playerNameInputParent1.SetActive(true);
|
||||
playerNameInputParent2.SetActive(false);
|
||||
playerTwoPlaceholder.text = "Player 1";
|
||||
playerFourPlaceholder.text = "Player 2";
|
||||
}
|
||||
}
|
||||
else if (SelectedPlayerCount == 3)
|
||||
{
|
||||
hiddenIndex = (hiddenIndex + 1) % rows.Count;
|
||||
UpdateRows();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRows()
|
||||
{
|
||||
int visiblePlayerIndex = 1;
|
||||
|
||||
for (int i = 0; i < rows.Count; i++)
|
||||
{
|
||||
bool isHidden = (i == hiddenIndex);
|
||||
rows[i].SetActive(!isHidden);
|
||||
|
||||
if (!isHidden)
|
||||
{
|
||||
TMP_InputField input =
|
||||
rows[i].GetComponentInChildren<TMP_InputField>();
|
||||
|
||||
TMP_Text placeholder = input.placeholder as TMP_Text;
|
||||
if (placeholder != null)
|
||||
{
|
||||
placeholder.text = $"Player {visiblePlayerIndex}";
|
||||
visiblePlayerIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClick_CloseBtn()
|
||||
{
|
||||
screenManager = screenManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<ScreenManager>() : screenManager;
|
||||
screenManager.ShowScreen(ScreenType.MenuScreen);
|
||||
|
||||
soundManager = soundManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>() : soundManager;
|
||||
soundManager?.PlayGameSoundClip(SoundType.ButtonClick);
|
||||
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
@ -12,18 +12,19 @@ public class GameHUDS : ScreenBase
|
||||
[SerializeField] private TMP_Text diceCountText;
|
||||
[SerializeField] private TMP_Text playerTurnText;
|
||||
|
||||
SoundManager soundManager;
|
||||
private SoundManager soundManager;
|
||||
private UIManager uiManager;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
pauseBtn.onClick.AddListener(OnClick_pauseBtn);
|
||||
diceBtn.onClick.AddListener(OnClick_diceBtn);
|
||||
diceBtn.onClick.AddListener(OnClick_DiceBtn);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
pauseBtn.onClick.RemoveListener(OnClick_pauseBtn);
|
||||
diceBtn.onClick.RemoveListener(OnClick_diceBtn);
|
||||
diceBtn.onClick.RemoveListener(OnClick_DiceBtn);
|
||||
}
|
||||
|
||||
private void OnClick_pauseBtn()
|
||||
@ -37,9 +38,9 @@ public class GameHUDS : ScreenBase
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void OnClick_diceBtn()
|
||||
private void OnClick_DiceBtn()
|
||||
{
|
||||
Dice dice = InterfaceManager.Instance?.GetInterfaceInstance<Dice>();
|
||||
dice?.Roll();
|
||||
uiManager = uiManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<UIManager>() : uiManager;
|
||||
uiManager.OnDiceViewInteracted();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,93 +0,0 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PvPModePopup : PopupBase
|
||||
{
|
||||
[Header("Buttons")]
|
||||
[SerializeField] private Button twoPlayerBtn;
|
||||
[SerializeField] private Button threePlayerBtn;
|
||||
[SerializeField] private Button fourPlayerBtn;
|
||||
[SerializeField] private Button playBtn;
|
||||
[SerializeField] private Button closeBtn;
|
||||
|
||||
[Header("Input Field")]
|
||||
[SerializeField] private TMP_InputField playerOneNameInput;
|
||||
[SerializeField] private TMP_InputField playerTwoNameInput;
|
||||
[SerializeField] private TMP_InputField playerThreeNameInput;
|
||||
[SerializeField] private TMP_InputField playerFourNameInput;
|
||||
|
||||
[Header("Player Names")]
|
||||
private string playerOneName;
|
||||
private string playerTwoName;
|
||||
private string playerThreeName;
|
||||
private string playerFourName;
|
||||
|
||||
private ScreenManager screenManager;
|
||||
private SoundManager soundManager;
|
||||
private int selectedPlayerCount;
|
||||
public int SelectedPlayerCount => selectedPlayerCount;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
twoPlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(2));
|
||||
threePlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(3));
|
||||
fourPlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(4));
|
||||
playBtn.onClick.AddListener(OnClick_playBtn);
|
||||
closeBtn.onClick.AddListener(OnClick_closeBtn);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
twoPlayerBtn.onClick.RemoveAllListeners();
|
||||
threePlayerBtn.onClick.RemoveAllListeners();
|
||||
fourPlayerBtn.onClick.RemoveAllListeners();
|
||||
playBtn.onClick.RemoveAllListeners();
|
||||
closeBtn.onClick.RemoveAllListeners();
|
||||
}
|
||||
private void OnPlayerCountSelected(int count)
|
||||
{
|
||||
selectedPlayerCount = count;
|
||||
UpdateInputFieldsVisibility();
|
||||
}
|
||||
|
||||
private void UpdateInputFieldsVisibility()
|
||||
{
|
||||
playerOneNameInput.transform.parent.gameObject.SetActive(true);
|
||||
playerTwoNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 2);
|
||||
playerThreeNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 3);
|
||||
playerFourNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 4);
|
||||
}
|
||||
|
||||
private void OnClick_playBtn()
|
||||
{
|
||||
playerOneName = playerOneNameInput.text;
|
||||
playerTwoName = playerTwoNameInput.text;
|
||||
playerThreeName = playerThreeNameInput.text;
|
||||
playerFourName = playerFourNameInput.text;
|
||||
|
||||
soundManager = soundManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>() : soundManager;
|
||||
soundManager?.PlayGameSoundClip(SoundType.ButtonClick);
|
||||
|
||||
//TODO: Start PVP Game with the selected player count and names
|
||||
Debug.Log($"Starting PVP Mode with {selectedPlayerCount} players:");
|
||||
Debug.Log($"Player 1: {playerOneName}");
|
||||
Debug.Log($"Player 2: {playerTwoName}");
|
||||
if (selectedPlayerCount >= 3)
|
||||
Debug.Log($"Player 3: {playerThreeName}");
|
||||
if (selectedPlayerCount == 4)
|
||||
Debug.Log($"Player 4: {playerFourName}");
|
||||
|
||||
}
|
||||
|
||||
private void OnClick_closeBtn()
|
||||
{
|
||||
screenManager = screenManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<ScreenManager>() : screenManager;
|
||||
screenManager.ShowScreen(ScreenType.MenuHUDScreen);
|
||||
|
||||
soundManager = soundManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>() : soundManager;
|
||||
soundManager?.PlayGameSoundClip(SoundType.ButtonClick);
|
||||
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user