Commit daeef97a authored by Abdulrahman Mohammed's avatar Abdulrahman Mohammed

Done with Multiplayer and Gameplay

parent 4495e681
......@@ -13,5 +13,5 @@ MonoBehaviour:
m_Name: GameSetting
m_EditorClassIdentifier: Assembly-CSharp::GameSetting
<MaxAnimalsInRound>k__BackingField: 20
<TimeOfRound>k__BackingField: 30
<TimeOfRound>k__BackingField: 5
<NumberOfRounds>k__BackingField: 5
......@@ -70,7 +70,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 1.31}
m_SizeDelta: {x: 2.5, y: 1.25}
m_SizeDelta: {x: 4.27, y: 1.25}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!223 &5506813468715940269
Canvas:
......@@ -147,6 +147,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e1003c22d83309742a57d43140729116, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::LookAtCamera
ShowTopMostFoldoutHeaderGroup: 1
_cam: {fileID: 0}
--- !u!1 &1501786898965488615
GameObject:
m_ObjectHideFlags: 0
......@@ -747,7 +749,40 @@ MonoBehaviour:
_score:
m_InternalValue: 0
isNPC: 1
_NPCsId: 0
_NPCsId:
utf8LengthInBytes: 0
bytes:
offset0000:
byte0000: 0
byte0001: 0
byte0002: 0
byte0003: 0
byte0004: 0
byte0005: 0
byte0006: 0
byte0007: 0
byte0008: 0
byte0009: 0
byte0010: 0
byte0011: 0
byte0012: 0
byte0013: 0
byte0014: 0
byte0015: 0
byte0016: 0
byte0017: 0
byte0018: 0
byte0019: 0
byte0020: 0
byte0021: 0
byte0022: 0
byte0023: 0
byte0024: 0
byte0025: 0
byte0026: 0
byte0027: 0
byte0028: 0
byte0029: 0
--- !u!114 &4343223469952472967
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -898,6 +933,40 @@ MonoBehaviour:
byte0027: 0
byte0028: 0
byte0029: 0
playerID:
utf8LengthInBytes: 0
bytes:
offset0000:
byte0000: 0
byte0001: 0
byte0002: 0
byte0003: 0
byte0004: 0
byte0005: 0
byte0006: 0
byte0007: 0
byte0008: 0
byte0009: 0
byte0010: 0
byte0011: 0
byte0012: 0
byte0013: 0
byte0014: 0
byte0015: 0
byte0016: 0
byte0017: 0
byte0018: 0
byte0019: 0
byte0020: 0
byte0021: 0
byte0022: 0
byte0023: 0
byte0024: 0
byte0025: 0
byte0026: 0
byte0027: 0
byte0028: 0
byte0029: 0
nameText: {fileID: 7462257593087947900}
avatar:
--- !u!1001 &97846783079897831
......
......@@ -1812,6 +1812,15 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: eed983e626aa84642aca502efe530d72, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::TagGeneration
_animalProperties:
- {fileID: 11400000, guid: ba49ab0ffd1e5f947b131bc56fb61faa, type: 2}
- {fileID: 11400000, guid: d0cff163ca026c74b8900eca3bfbe4a9, type: 2}
- {fileID: 11400000, guid: 4b160f0ac0bdd5b42ad01a593cf2894d, type: 2}
- {fileID: 11400000, guid: aede0ffd3c1e09445a39f5b8a5f40568, type: 2}
- {fileID: 11400000, guid: 489e7b2410467b5478e7479a243f9888, type: 2}
- {fileID: 11400000, guid: c5a46d38ee8ca2f46927676a9c31b7b7, type: 2}
- {fileID: 11400000, guid: d3547736a5d0c7540bbd29c28348d080, type: 2}
- {fileID: 11400000, guid: c5751bd233fcb604aab73e364bf81882, type: 2}
--- !u!1 &626162506
GameObject:
m_ObjectHideFlags: 0
......@@ -2087,6 +2096,7 @@ MonoBehaviour:
<cursorVisible>k__BackingField: {fileID: 2129732306}
<MatchManager>k__BackingField: {fileID: 1559894302}
<LeaderboardUI>k__BackingField: {fileID: 803451462}
<cam>k__BackingField: {fileID: 1835655405}
--- !u!114 &764357413
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -3893,18 +3903,17 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: aae5a095cd37db74f90a8fc0cd6a1bc4, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::AnimalsSpawner
spawnRadius: 32.1
debugMode: 0
animalsParent: {fileID: 1824897285}
animalsPrefab:
- {fileID: 7987493137821725887, guid: 28d7b110eacfe554cb177ef86d76bd7c, type: 3}
- {fileID: 7193057044126680390, guid: c6e0651bc44ba9f409a5d42ea5643f6f, type: 3}
- {fileID: 1698350363645929408, guid: 6fef511f71c2f88418c14e5a4afb8f11, type: 3}
- {fileID: 1677546864663295365, guid: 0078a2e176b908c45aa883f048fc43a4, type: 3}
- {fileID: 873965636843474627, guid: 68bd54ad24006f94dbb146eb2fe9591e, type: 3}
- {fileID: 2175243213733850576, guid: 6e1553e4833547f42b69e41a89cd6513, type: 3}
- {fileID: 7987493137821725887, guid: 28d7b110eacfe554cb177ef86d76bd7c, type: 3}
- {fileID: 7193057044126680390, guid: c6e0651bc44ba9f409a5d42ea5643f6f, type: 3}
- {fileID: 3824715583433605288, guid: fbf52492f3d40c646b67885c3076a67d, type: 3}
- {fileID: 8074876253474731934, guid: 65e893d6d8280ff4eba19d6987deed16, type: 3}
- {fileID: 2175243213733850576, guid: 6e1553e4833547f42b69e41a89cd6513, type: 3}
spawnRadius: 32.1
debugMode: 0
animalsParent: {fileID: 1824897285}
_correctAnimal: []
_incorrectAnimal: []
--- !u!1 &1366928035
......
This diff is collapsed.
......@@ -18,7 +18,7 @@ public class AppInit : MonoBehaviour
private async void Join()
{
FadeWithText.Instance.ShowMessage("جاري التحميل...", false);
FadeWithText.Instance.ShowMessage("جاري التهيئة...", false);
await AuthenticationRequest.StartAuth();
FadeWithText.Instance.FadeOut();
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
......@@ -7,21 +8,53 @@ public class AnimalsQuestionGenerator : MonoBehaviour
{
public List<Enum> randomTags { get; private set; } = new List<Enum>();
[SerializeField] StringBuilder textBuilder = new StringBuilder();
[SerializeField] AnimalProperties[] _animalProperties;
public Dictionary<string, List<Enum>> AnimalsEnumToList { get; private set; } = new Dictionary<string, List<Enum>>();
string prevQuestion;
private void Awake()
{
HandleAniamls();
GengenerateNewQuestions(1);
}
private void HandleAniamls()
{
for (int i = 0; i < _animalProperties.Length; i++)
{
var list = AddAnimalTagsToList(_animalProperties[i]);
if (!AnimalsEnumToList.ContainsKey(_animalProperties[i].name))
{
AnimalsEnumToList.Add(_animalProperties[i].name, list);
}
}
}
List<Enum> AddAnimalTagsToList(AnimalProperties animalProperties)
{
var animalTag = new List<Enum>
{
animalProperties.AnimalType,
animalProperties.FoodType,
animalProperties.Environment,
animalProperties.SpecialAbilities,
animalProperties.Reproduction
};
return animalTag;
}
public void GengenerateNewQuestions(int numberOfTags)
{
string currentQuestionText = "";
do
{
AddRandomTagToList(numberOfTags);
currentQuestionText = BuildQuestionString();
}
while (!CheckIfTagsIsCorrect() || currentQuestionText == prevQuestion);
......@@ -31,6 +64,8 @@ public class AnimalsQuestionGenerator : MonoBehaviour
currentQuestionText = currentQuestionText.Replace("_", " ");
GameHUD.Instance.Question.Value = currentQuestionText;
}
private string BuildQuestionString()
{
textBuilder.Clear();
......@@ -46,35 +81,49 @@ public class AnimalsQuestionGenerator : MonoBehaviour
{
randomTags.Clear();
if (numberOfTag >= 1)
{
var animalTypes = (AnimalType[])Enum.GetValues(typeof(AnimalType));
randomTags.Add(animalTypes[UnityEngine.Random.Range(0, animalTypes.Length)]);
}
var dictionaryValueToList = new List<List<Enum>>(AnimalsEnumToList.Values);
if (numberOfTag >= 2)
{
var foodTypes = (FoodType[])Enum.GetValues(typeof(FoodType));
randomTags.Add(foodTypes[UnityEngine.Random.Range(0, foodTypes.Length)]);
}
int randomIndexFromAnimalList = UnityEngine.Random.Range(0, dictionaryValueToList.Count);
if (numberOfTag >= 3)
{
var environments = (Environment[])Enum.GetValues(typeof(Environment));
randomTags.Add(environments[UnityEngine.Random.Range(0, environments.Length)]);
}
var selectedList = dictionaryValueToList[randomIndexFromAnimalList];
if (numberOfTag >= 4)
{
var abilities = (SpecialAbilities[])Enum.GetValues(typeof(SpecialAbilities));
randomTags.Add(abilities[UnityEngine.Random.Range(0, abilities.Length)]);
}
var tmpList = new List<Enum>(selectedList);
if (numberOfTag >= 5)
for (int i = 0; i < numberOfTag && tmpList.Count > 0; i++)
{
var reproductions = (Reproduction[])Enum.GetValues(typeof(Reproduction));
randomTags.Add(reproductions[UnityEngine.Random.Range(0, reproductions.Length)]);
randomTags.Add(tmpList[0]);
tmpList.RemoveAt(0);
}
//if (numberOfTag >= 1)
//{
// var animalTypes = (AnimalType[])Enum.GetValues(typeof(AnimalType));
// randomTags.Add(animalTypes[UnityEngine.Random.Range(0, animalTypes.Length)]);
//}
//if (numberOfTag >= 2)
//{
// var foodTypes = (FoodType[])Enum.GetValues(typeof(FoodType));
// randomTags.Add(foodTypes[UnityEngine.Random.Range(0, foodTypes.Length)]);
//}
//if (numberOfTag >= 3)
//{
// var environments = (Environment[])Enum.GetValues(typeof(Environment));
// randomTags.Add(environments[UnityEngine.Random.Range(0, environments.Length)]);
//}
//if (numberOfTag >= 4)
//{
// var abilities = (SpecialAbilities[])Enum.GetValues(typeof(SpecialAbilities));
// randomTags.Add(abilities[UnityEngine.Random.Range(0, abilities.Length)]);
//}
//if (numberOfTag >= 5)
//{
// var reproductions = (Reproduction[])Enum.GetValues(typeof(Reproduction));
// randomTags.Add(reproductions[UnityEngine.Random.Range(0, reproductions.Length)]);
//}
}
bool CheckIfTagsIsCorrect()
......
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
public class AnimalsSpawner : MonoBehaviour
{
[SerializeField] GameObject[] animalsPrefab;
[Header("Spwan Settings")]
[SerializeField] float spawnRadius;
[SerializeField] bool debugMode;
[Header("Animals Settings")]
[SerializeField] Transform animalsParent;
[SerializeField] GameObject[] animalsPrefab;
[SerializeField] List<GameObject> _correctAnimal = new List<GameObject>();
[SerializeField] List<GameObject> _incorrectAnimal = new List<GameObject>();
......@@ -34,33 +35,29 @@ public class AnimalsSpawner : MonoBehaviour
foreach (GameObject animal in animalsPrefab)
{
var animalTagToEnumList = AddAnimalTagsToList(animal.GetComponent<AnimalDetails>().animalProperties);
foreach (Enum tag in randomTags)
{
if (animalTagToEnumList.Contains(tag))
GameManager.Instance.AnimalsQuestionGenerator.AnimalsEnumToList.TryGetValue(animal.GetComponent<AnimalDetails>().animalProperties.name,out List<Enum> enumList);
bool correct = randomTags.All(tag => enumList.Contains(tag));
if (correct)
_correctAnimal.Add(animal);
else
{
_incorrectAnimal.Add(animal);
break;
}
}
}
SpawnAnimals();
}
List<Enum> AddAnimalTagsToList(AnimalProperties animalProperties)
{
var animalTag = new List<Enum>
{
animalProperties.AnimalType,
animalProperties.FoodType,
animalProperties.Environment,
animalProperties.SpecialAbilities,
animalProperties.Reproduction
};
//List<Enum> AddAnimalTagsToList(AnimalProperties animalProperties)
//{
// var animalTag = new List<Enum>
//{
// animalProperties.AnimalType,
// animalProperties.FoodType,
// animalProperties.Environment,
// animalProperties.SpecialAbilities,
// animalProperties.Reproduction
//};
return animalTag;
}
// return animalTag;
//}
void SpawnAnimals()
{
if (_correctAnimal.Count > 0 && _incorrectAnimal.Count > 0)
......@@ -95,9 +92,3 @@ public class AnimalsSpawner : MonoBehaviour
}
}
}
//bool correct = randomTags.All(tag => animalTagToEnumList.Contains(tag));
//if (correct)
// _correctAnimal.Add(animal);
//else
// _incorrectAnimal.Add(animal);
\ No newline at end of file
......@@ -43,12 +43,19 @@ public class MatchManager : NetworkBehaviour
_currentMatch++;
_transitionManager.onTransitionCutPointReached += ChangeRound;
ShowFadeMenuClientRpc(false);
StopNPC(true);
}
else
{
_scoreManager.ShowWinMenu();
foreach (NPCsMovement npc in NPCsParent.GetComponentsInChildren<NPCsMovement>())
{
npc.DestroyByServer();
}
}
DestroyAnimals();
StopNPC(true);
}
[Rpc(SendTo.ClientsAndHost)]
void UpdateTimeClientRpc(float _currentTimer)
......@@ -75,7 +82,6 @@ public class MatchManager : NetworkBehaviour
matchRoundText.text = _currentMatch;
_currentTimer = GameManager.Instance.GameSetting.TimeOfRound;
}
void DestroyAnimals()
{
foreach (Health animal in animalsParent.GetComponentsInChildren<Health>())
......
......@@ -19,15 +19,7 @@ public class ScoreManager : NetworkBehaviour
}
private void RestartGame()
{
RestartServerRpc();
}
[Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)]
void RestartServerRpc()
{
RestartByServer();
}
void RestartByServer()
if (IsServer)
{
foreach (var client in NetworkManager.Singleton.ConnectedClientsList)
{
......@@ -35,12 +27,13 @@ public class ScoreManager : NetworkBehaviour
}
if (NetworkManager.Singleton != null)
NetworkManager.Singleton.SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
}
}
private void LeaveRound()
{
SceneManager.LoadScene(0);
NetworkManager.Singleton.Shutdown();
ApprovRequest.Instance.LeavePlayer();
}
public void ShowWinMenu()
......
......@@ -24,6 +24,9 @@ public class HandlePlayersConnection : NetworkBehaviour
yield return new WaitForSeconds(3);
if (IsServer)
{
if (LobbyHeart.Instance != null)
Destroy(LobbyHeart.Instance.gameObject);
foreach (var _player in _approvRequest.clientData)
{
PlayerNetworkData playerData = new PlayerNetworkData
......@@ -47,8 +50,9 @@ public class HandlePlayersConnection : NetworkBehaviour
PlayerAvatar = npc.Value.playerAvatar,
};
NetworkObject npcObject = Instantiate(npcPrefab,npcParent.transform);
NetworkObject npcObject = Instantiate(npcPrefab);
npcObject.Spawn();
npcObject.transform.SetParent(npcParent);
npcObject.GetComponent<PlayerDetails>().InitPlayerData(playerData);
}
}
......
using DG.Tweening;
using System.Threading.Tasks;
using TMPro;
using Unity.Netcode;
using Unity.Services.Lobbies;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using Unity.Services.Lobbies.Models;
public class LobbyRoom : NetworkBehaviour
{
......@@ -10,11 +14,14 @@ public class LobbyRoom : NetworkBehaviour
[SerializeField] TextMeshProUGUI lobbyCode;
[SerializeField] Button startButton;
[SerializeField] Button exitButton;
[SerializeField] Button addNPC;
[SerializeField] Button removeNPC;
[field: SerializeField] NetworkList<PlayerLobbyData> playersData = new NetworkList<PlayerLobbyData>();
int _currentNPCs;
int _currentReadyPlayer;
[SerializeField] int _currentNPCs;
[SerializeField] int _currentPlayer;
[SerializeField] ApprovRequest _approvRequest;
......@@ -22,6 +29,9 @@ public class LobbyRoom : NetworkBehaviour
{
startButton.onClick.AddListener(StartGameClientRpc);
exitButton.onClick.AddListener(LeaveLobby);
addNPC.onClick.AddListener(AddNPCs);
removeNPC.onClick.AddListener(RemoveNPCs);
}
public override void OnNetworkSpawn()
......@@ -34,6 +44,9 @@ public class LobbyRoom : NetworkBehaviour
if (IsServer)
{
addNPC.gameObject.SetActive(true);
removeNPC.gameObject.SetActive(true);
NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
NetworkManager.Singleton.OnClientDisconnectCallback += OnClientDisConnected;
......@@ -42,7 +55,13 @@ public class LobbyRoom : NetworkBehaviour
OnClientConnected(client);
}
}
else
{
addNPC.gameObject.SetActive(false);
removeNPC.gameObject.SetActive(false);
}
}
public override void OnNetworkDespawn()
{
playersData.OnListChanged -= UpdateList;
......@@ -74,6 +93,73 @@ public class LobbyRoom : NetworkBehaviour
}
}
}
async void AddNPCs()
{
FadeWithText.Instance.ShowMessage("جاري اضافة لاعب الي...", false);
_currentNPCs++;
addNPC.interactable = false;
UpdateLobbyOptions updateLobby = new UpdateLobbyOptions();
updateLobby.Data = new Dictionary<string, DataObject>
{
{"NPCsCount",new DataObject(DataObject.VisibilityOptions.Public,value: _currentNPCs.ToString()) }
};
bool isUpdated = await LobbyRequest.UpdateLobby(updateLobby);
if (isUpdated)
{
ulong NPCsId = (ulong)Random.Range(1000, 9999);
playersData.Add(new PlayerLobbyData
{
clientId = NPCsId,
playerName = "NPC#" + NPCsId,
playerAvatar = 4,
isReady = true,
isNPC = true,
});
FadeWithText.Instance.FadeOut();
}
else
{
_currentNPCs--;
FadeWithText.Instance.ShowMessage("حدث خطأ في اضافة لاعب الي", true);
}
}
private async void RemoveNPCs()
{
FadeWithText.Instance.ShowMessage("جاري اضافة لاعب الي...", false);
_currentNPCs--;
addNPC.interactable = false;
UpdateLobbyOptions updateLobby = new UpdateLobbyOptions();
updateLobby.Data = new Dictionary<string, DataObject>
{
{"NPCsCount",new DataObject(DataObject.VisibilityOptions.Public,value: _currentNPCs.ToString()) }
};
bool isUpdated = await LobbyRequest.UpdateLobby(updateLobby);
if (isUpdated)
{
for (int i = 0; i < playersData.Count; i++)
{
if (playersData[i].isNPC)
{
OnClientDisConnected(playersData[i].clientId);
break;
}
}
FadeWithText.Instance.FadeOut();
}
else
{
_currentNPCs++;
FadeWithText.Instance.ShowMessage("حدث خطأ في حذف اللاعب الالي", true);
}
}
private void UpdateList(NetworkListEvent<PlayerLobbyData> newList)
{
for (int i = 0; i < playersSlot.Length; i++)
......@@ -93,9 +179,15 @@ public class LobbyRoom : NetworkBehaviour
startButton.interactable = CheckIfAllPlayerIsReady();
bool CheckIfAllReady = CheckIfAllPlayerIsReady();
ChangeButtonClientRpc(CheckIfAllReady);
UpdateNPCButtons();
}
}
void UpdateNPCButtons()
{
_currentPlayer = NetworkManager.Singleton.ConnectedClientsIds.Count;
addNPC.interactable = _currentNPCs + _currentPlayer < 4;
removeNPC.interactable = _currentNPCs > 0;
}
[Rpc(SendTo.ClientsAndHost)]
void ChangeButtonClientRpc(bool CheckIfAllReady)
{
......@@ -104,10 +196,9 @@ public class LobbyRoom : NetworkBehaviour
private bool CheckIfAllPlayerIsReady()
{
if (playersData.Count < 2) return false;
if (playersData.Count < 4) return false;
foreach (var player in playersData)
{
if (!player.isReady) return false;
}
return true;
......@@ -120,30 +211,18 @@ public class LobbyRoom : NetworkBehaviour
public void IsButtonClicked(ulong clientId, bool isBusy)
{
if (!isBusy)
{
AddNpc();
}
else
SetPlayerReadyServerRpc(clientId);
}
void AddNpc()
{
ulong NPCsId = (ulong)Random.Range(1000, 9999);
playersData.Add(new PlayerLobbyData
{
clientId = NPCsId,
playerName = "NPC#" + NPCsId,
playerAvatar = 4,
isReady = true,
isNPC = true,
});
}
public void RemoveRpc(ulong slotId)
{
OnClientDisConnected(slotId);
//if (!isBusy)
//{
// AddNpc();
//}
//else
// SetPlayerReadyServerRpc(clientId);
}
[Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)]
void SetPlayerReadyServerRpc(ulong clientId)
{
......@@ -167,7 +246,6 @@ public class LobbyRoom : NetworkBehaviour
private void StartGameClientRpc()
{
FadeWithText.Instance.ShowMessage("جاري الدخول...", false);
if (IsServer)
{
for (int i = 0; i < playersData.Count; i++)
......
......@@ -17,7 +17,7 @@ public class LobbyList : MonoBehaviour
private async void RefreshLobbyList()
{
refreshButton.interactable = false;
FadeWithText.Instance.ShowMessage("جاري التحميل", false);
FadeWithText.Instance.ShowMessage("جاري البحث عن مبارايات...", false);
QueryResponse list = await LobbyRequest.CurrentLobbies();
DestroyLastLobbysList();
......@@ -30,6 +30,8 @@ public class LobbyList : MonoBehaviour
string playersCount = $"{npcCounter}/{lobby.MaxPlayers}";
lobbyDetails.AddDetailsToLobby(lobby.Name, playersCount, lobby.Id, lobby.Data["RelayCode"].Value);
lobbyDetails.gameObject.SetActive(npcCounter < lobby.MaxPlayers);
}
StartCoroutine(FadeOutAfterDelay());
}
......
......@@ -21,23 +21,24 @@ public class LobbySlot : MonoBehaviour
private void Start()
{
readyButton.onClick.AddListener(Ready);
removeButton.onClick.AddListener(RemoveNpc);
// removeButton.onClick.AddListener(RemoveNpcs);
_lobbyRoom = FindAnyObjectByType<LobbyRoom>();
removeButton.gameObject.SetActive(false);
}
public void AddData(PlayerLobbyData playerLobbyData)
{
_isBusy = true;
bool localClient = NetworkManager.Singleton.LocalClientId == playerLobbyData.clientId;
bool npc = playerLobbyData.isNPC && NetworkManager.Singleton.IsServer;
// bool npc = playerLobbyData.isNPC && NetworkManager.Singleton.IsServer;
removeButton.gameObject.SetActive(npc);
_slotId = playerLobbyData.clientId;
_isNPC = playerLobbyData.isNPC;
readyButton.interactable = localClient || npc && !_isBusy;
removeButton.interactable = localClient || npc;
readyButton.interactable = localClient; // || npc && !_isBusy;
// removeButton.interactable = localClient || npc;
ChangeAvatar(playerLobbyData.playerAvatar);
playerName.text = playerLobbyData.playerName.ToString();
......@@ -71,24 +72,23 @@ public class LobbySlot : MonoBehaviour
_lobbyRoom.IsButtonClicked(_slotId,_isBusy);
}
private void RemoveNpc()
{
_lobbyRoom.RemoveRpc(_slotId);
//private void RemoveNpc()
//{
// _lobbyRoom.RemoveRpc(_slotId);
}
//}
public void ClearData()
{
ChangeAvatar(0);
readyButton.GetComponent<Image>().color = Color.white;
readyButton.GetComponentInChildren<TextMeshProUGUI>().text = "Add NPC";
readyButton.GetComponentInChildren<TextMeshProUGUI>().text = "No Player";
playerName.text = " ";
_isNPC = false;
_isBusy = false;
// removeButton.gameObject.SetActive(false);
_slotId = (ulong)0000;
readyButton.interactable = NetworkManager.Singleton.IsServer;
removeButton.gameObject.SetActive(false);
//readyButton.interactable = NetworkManager.Singleton.IsServer;
//removeButton.gameObject.SetActive(false);
}
}
......@@ -2,7 +2,6 @@
using System.Threading.Tasks;
using Unity.Services.Authentication;
using Unity.Services.Core;
using Unity.VisualScripting;
using UnityEngine;
public enum AuthState
......
......@@ -21,5 +21,6 @@ public class LobbyHeart : MonoBehaviour
private void OnDestroy()
{
StopCoroutine(_heartCoroutine);
_ = LobbyRequest.RemoveLobby();
}
}
......@@ -80,7 +80,6 @@ public static class LobbyRequest
public static async Task RemovePlayerFromLobby(string playerId)
{
if (_currentLobby == null) return;
Debug.Log("Remmove");
try
{
if (playerId == AuthenticationService.Instance.PlayerId)
......@@ -135,7 +134,28 @@ public static class LobbyRequest
}
return string.Empty;
}
public static async Task<bool> UpdateLobby(UpdateLobbyOptions options)
{
try
{
await LobbyService.Instance.UpdateLobbyAsync(_currentLobby.Id, options);
return true;
}
catch (LobbyServiceException ex)
{
if(ex.Reason == LobbyExceptionReason.RateLimited)
{
Debug.LogException(ex);
Debug.Log("Rate Limit");
}
return false;
}
catch (Exception ex)
{
Debug.LogException(ex);
return false;
}
}
}
......@@ -262,7 +262,6 @@ public class AnimalAi : NetworkBehaviour
{
return NavMesh.SamplePosition(pos, out NavMeshHit hit, 2, NavMesh.AllAreas);
}
public void HitHunter() // call from animation attack event
{
HitHunterServerRpc();
......@@ -271,7 +270,6 @@ public class AnimalAi : NetworkBehaviour
[Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Everyone)]
void HitHunterServerRpc()
{
HitHunterClientRpc();
}
[Rpc(SendTo.ClientsAndHost)]
......
using System;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
......@@ -79,4 +80,9 @@ public class NPCsMovement : MonoBehaviour
if (_agent != null)
_agent.isStopped = status;
}
public void DestroyByServer()
{
if (NetworkManager.Singleton.IsServer)
GetComponent<NetworkObject>().Despawn(true);
}
}
......@@ -9,6 +9,7 @@ public class PlayerDetails : NetworkBehaviour
public NetworkVariable<PlayerNetworkData> playerNetworkData = new NetworkVariable<PlayerNetworkData>(default, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
public NetworkVariable<FixedString32Bytes> PlayerName = new NetworkVariable<FixedString32Bytes>("Null", readPerm: NetworkVariableReadPermission.Everyone, writePerm: NetworkVariableWritePermission.Owner);
[SerializeField] FixedString32Bytes playerID;
[SerializeField] RTLTextMeshPro nameText;
[SerializeField] string avatar;
......@@ -17,8 +18,13 @@ public class PlayerDetails : NetworkBehaviour
if (IsServer)
{
this.playerNetworkData.Value = playerNetworkData;
playerID = playerNetworkData.PlayerAuthId;
}
}
public FixedString32Bytes GetPlayerId()
{
return this.playerID;
}
public override void OnNetworkSpawn()
{
playerNetworkData.OnValueChanged += UpdatedData;
......
......@@ -20,6 +20,10 @@ public class HumanHealth : NetworkBehaviour
_currentHealth = maxHealth;
slider.maxValue = maxHealth;
}
public override void OnNetworkSpawn()
{
if (!IsOwner) slider.gameObject.SetActive(false);
}
public void TakeDamage(AnimalAi animalAi)
{
TakeDamageServerRpc(animalAi.GetComponent<NetworkObject>());
......
using RTLTMPro;
using System.Collections;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
public class Score : NetworkBehaviour
......@@ -7,7 +8,7 @@ public class Score : NetworkBehaviour
[field: SerializeField] public NetworkVariable<int> _score = new NetworkVariable<int>(readPerm: NetworkVariableReadPermission.Everyone, writePerm: NetworkVariableWritePermission.Server);
[SerializeField] bool isNPC;
RaycastWeapon _raycastWeapon;
[SerializeField] ulong _NPCsId;
[SerializeField] FixedString32Bytes _NPCsId;
string _playerName;
private void OnEnable()
{
......@@ -35,23 +36,23 @@ public class Score : NetworkBehaviour
newScore = Mathf.Max(0, newScore);
_score.Value = newScore;
if (isNPC)
GameManager.Instance.LeaderboardUI.AddPlayerToLeaderboard("NPC#" + _NPCsId, _score.Value, _NPCsId);
GameManager.Instance.LeaderboardUI.AddPlayerToLeaderboard("NPC#" + _NPCsId, _score.Value, ulong.Parse(_NPCsId.ToString()));
else
GameManager.Instance.LeaderboardUI.AddPlayerToLeaderboard(_playerName, _score.Value, OwnerClientId);
}
IEnumerator InitScore()
{
yield return new WaitForSeconds(1);
if (isNPC)
if (isNPC && IsServer)
{
_NPCsId = (ulong)Random.Range(1000, 9999);
GameManager.Instance.LeaderboardUI.AddPlayerToLeaderboard("NPC#" + _NPCsId, 0, _NPCsId);
_NPCsId = GetComponent<PlayerDetails>().GetPlayerId();
GameManager.Instance.LeaderboardUI.AddPlayerToLeaderboard("NPC#" + _NPCsId, 0, ulong.Parse(_NPCsId.ToString()));
GetComponentInChildren<RTLTextMeshPro>().text = $"NPC#{_NPCsId}";
}
if (TryGetComponent<PlayerDetails>(out PlayerDetails playerDetails))
else
{
_playerName = playerDetails.playerNetworkData.Value.playerName.ToString();
_playerName = GetComponent<PlayerDetails>().playerNetworkData.Value.playerName.ToString();
GameManager.Instance.LeaderboardUI.AddPlayerToLeaderboard(_playerName, 0, OwnerClientId);
}
......
using Unity.Netcode;
using UnityEngine;
public class LookAtCamera : MonoBehaviour
public class LookAtCamera : NetworkBehaviour
{
Camera _cam;
[SerializeField] Camera _cam;
void Start()
public override void OnNetworkSpawn()
{
_cam = Camera.main;
}
......
......@@ -2,36 +2,53 @@
using UnityEngine;
using DG.Tweening;
using RTLTMPro;
class AnimalPropertiesProgress
{
public int maxVisibleCharacters;
public bool isDone;
}
public class TypewriterEffect : MonoBehaviour
{
[SerializeField] float typeDuration;
[SerializeField] List<AnimalProperties> animalDetailsList = new List<AnimalProperties>();
Dictionary<AnimalProperties, AnimalPropertiesProgress> animalPropertiesList = new Dictionary<AnimalProperties, AnimalPropertiesProgress>();
RTLTextMeshPro _textMeshProUGUI;
AnimalDetails _currentAnimal;
AnimalDetails _currentAnimalScript;
Tween currentTween;
void Start()
{
_textMeshProUGUI = GetComponent<RTLTextMeshPro>();
}
public void ShowAnimalDetails(AnimalDetails animalDetails)
}
public void ShowAnimalDetails(AnimalDetails animalDetailsScript)
{
if (_currentAnimal == animalDetails) return;
_currentAnimal = animalDetails;
if (_currentAnimalScript == animalDetailsScript) return;
_currentAnimalScript = animalDetailsScript;
_textMeshProUGUI.maxVisibleCharacters = 0;
if (!animalDetailsList.Contains(animalDetails.animalProperties))
if (!animalPropertiesList.ContainsKey(animalDetailsScript.animalProperties))
{
animalDetailsList.Add(animalDetails.animalProperties);
WriteText(animalDetails);
_textMeshProUGUI.maxVisibleCharacters = 0;
currentTween = DOTween.To(() => _textMeshProUGUI.maxVisibleCharacters, x => _textMeshProUGUI.maxVisibleCharacters = x, _textMeshProUGUI.text.Length, typeDuration)
.SetEase(Ease.Linear);
animalPropertiesList.Add(animalDetailsScript.animalProperties, new AnimalPropertiesProgress());
}
else
var value = animalPropertiesList[animalDetailsScript.animalProperties];
WriteText(animalDetailsScript);
if (value.isDone)
{
WriteText(animalDetails);
_textMeshProUGUI.maxVisibleCharacters = _textMeshProUGUI.text.Length;
return;
}
currentTween?.Kill();
currentTween = DOVirtual.Int(value.maxVisibleCharacters, _textMeshProUGUI.text.Length, typeDuration, (newValue) =>
{
value.maxVisibleCharacters = newValue;
_textMeshProUGUI.maxVisibleCharacters = newValue;
}).SetEase(Ease.Linear).OnComplete(() => { value.isDone = true; });
}
void WriteText(AnimalDetails animalDetails)
{
......@@ -42,7 +59,7 @@ public class TypewriterEffect : MonoBehaviour
}
public void HideText()
{
_currentAnimal = null;
_currentAnimalScript = null;
_textMeshProUGUI.text = " ";
if (currentTween != null && currentTween.IsActive())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment