Commit daeef97a authored by Abdulrahman Mohammed's avatar Abdulrahman Mohammed

Done with Multiplayer and Gameplay

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