first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5387fe7f6935564ca5d01207bceeae6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26b6f12742203a24cb3b713c6e30e485
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Zenject;
|
||||
using TMPro;
|
||||
using YandexQuest.Models;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
public class Authorization : MonoBehaviour
|
||||
{
|
||||
[Inject] private readonly ClientDataService _clientDataService;
|
||||
[Inject] private readonly NetworkService _networkService;
|
||||
|
||||
[SerializeField] private TMP_InputField _codeInputField;
|
||||
[SerializeField] private Button _codeAcceptButton;
|
||||
[SerializeField] private TMP_Text _errorText;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var clientData = _clientDataService.data;
|
||||
if(clientData != null)
|
||||
{
|
||||
Debug.LogWarning($"данные клианта загружены: город - {clientData.city}, найдено тэгов - {clientData.games.Count}");
|
||||
return;
|
||||
}
|
||||
|
||||
_codeInputField.onValueChanged.AddListener(stringValue =>
|
||||
{
|
||||
if(stringValue.Length != 6)
|
||||
{
|
||||
_codeAcceptButton.interactable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_codeAcceptButton.interactable = true;
|
||||
}
|
||||
});
|
||||
|
||||
_codeAcceptButton.onClick.AddListener(async () =>
|
||||
{
|
||||
await SendCode(_codeInputField.text);
|
||||
});
|
||||
}
|
||||
|
||||
private async UniTask SendCode(string inputFieldText)
|
||||
{
|
||||
CityUniqueCode cityUniqueCode = null;
|
||||
_networkService.OnGetResponse += CheckResponseAdmin;
|
||||
cityUniqueCode = await _networkService.GetAsync<CityUniqueCode>($"auth/admin/{inputFieldText}");
|
||||
|
||||
async void CheckResponseAdmin(int responseCode)
|
||||
{
|
||||
_networkService.OnGetResponse -= CheckResponseAdmin;
|
||||
|
||||
if(responseCode == 0) Debug.LogError("Нет соединения с сервером");
|
||||
else if (responseCode == 404)
|
||||
{
|
||||
Client client = new Client();
|
||||
Debug.LogWarning("такого админа нет в базе. ищем город...");
|
||||
|
||||
_networkService.OnGetResponse += CheckResponse;
|
||||
client = await _networkService.GetAsync<Client>($"auth/{inputFieldText}");
|
||||
|
||||
void CheckResponse(int responseCode)
|
||||
{
|
||||
_networkService.OnGetResponse -= CheckResponse;
|
||||
|
||||
if(responseCode == 404)
|
||||
{
|
||||
Debug.LogError("такого кода нет в базе");
|
||||
}
|
||||
else if(responseCode == 0) Debug.LogError("Нет соединения с сервером");
|
||||
else if( responseCode == 200)
|
||||
{
|
||||
_clientDataService.data = client;
|
||||
Debug.Log(client.city.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(responseCode == 200)
|
||||
{
|
||||
Debug.Log(cityUniqueCode.city);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 463389b2b938e4b40af7aa639400f07a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
[SerializeField] CanvasGroup _splash;
|
||||
[SerializeField] GameObject _welcomeWarning;
|
||||
[SerializeField] GameObject _authorization;
|
||||
|
||||
private IEnumerator Start()
|
||||
{
|
||||
_authorization.SetActive(false);
|
||||
_welcomeWarning.SetActive(false);
|
||||
|
||||
yield return new WaitForSeconds(3);
|
||||
|
||||
_welcomeWarning.SetActive(true);
|
||||
_splash.DOFade(0, .5f)
|
||||
.SetEase(Ease.Linear)
|
||||
.OnComplete(() => _splash.gameObject.SetActive(false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca30badc3005aaa4ba9f9742c2f24e7a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04bdbd9e7e111794aa7215cad1df8f65
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YandexQuest.Models
|
||||
{
|
||||
public enum Cities
|
||||
{
|
||||
MoscowRedRose,
|
||||
MoscowCity,
|
||||
MoscowSkolkovo,
|
||||
|
||||
SaintPetersburg,
|
||||
Yekaterinburg,
|
||||
Novosibirsk,
|
||||
Kazan,
|
||||
Innopolis,
|
||||
RostovOnDon,
|
||||
NizhnyNovgorod,
|
||||
Simferopol,
|
||||
Vladivostok,
|
||||
Krasnodar,
|
||||
Samara,
|
||||
Chelyabinsk,
|
||||
Perm,
|
||||
Tula,
|
||||
Sochi,
|
||||
Ufa,
|
||||
Krasnoyarsk,
|
||||
Tumen,
|
||||
Voronezh,
|
||||
|
||||
Minsk,
|
||||
Serbia
|
||||
}
|
||||
|
||||
public enum Games
|
||||
{
|
||||
Surprise,
|
||||
Excursion,
|
||||
MasterClass,
|
||||
Entertainment,
|
||||
Sport,
|
||||
Kids,
|
||||
GoodDeeds,
|
||||
Mask,
|
||||
Duck,
|
||||
Butterfly
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class CityUniqueCode
|
||||
{
|
||||
public string id { get; set; }
|
||||
public Cities cityEnum { get; set; }
|
||||
public string city { get; set; }
|
||||
public int key { get; set; }
|
||||
public int adminKey { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Client
|
||||
{
|
||||
public string id { get; set; }
|
||||
public Cities city { get; set; }
|
||||
public List<Games> games { get; set; }
|
||||
public DateTime? gameFinishedDate { get; set; }
|
||||
public bool isAdmin { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Tag
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string descrition { get; set; }
|
||||
public string city { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e895fd4878ecfb41845f85fa2ec0d04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7f008ae683f35d499a87464412d1dc5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
|
||||
public class AppInstaller : MonoInstaller
|
||||
{
|
||||
public override void InstallBindings()
|
||||
{
|
||||
Container.Bind<NetworkService>().AsSingle().NonLazy();
|
||||
Container.Bind<ClientDataService>().AsSingle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d3998ba1b245ad4dbd50ff49b12acbe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4949eab5f44b3564690d3e185bc2c973
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YandexQuest.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class ClientDataService
|
||||
{
|
||||
public Client data
|
||||
{
|
||||
get
|
||||
{
|
||||
var prefsData = PlayerPrefs.GetString("data", string.Empty);
|
||||
return prefsData == string.Empty ? null : JsonConvert.DeserializeObject<Client>(prefsData);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
var prefsData = JsonConvert.SerializeObject(value);
|
||||
PlayerPrefs.SetString("data", prefsData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19de18a79e457284aa3ed60a493658c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,223 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
public class NetworkService
|
||||
{
|
||||
public event Action<int> OnGetResponse;
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
private string _apiUrl = "https://yandexquest.graff.tech/";
|
||||
#else
|
||||
private string _apiUrl = "http://localhost:5000/";
|
||||
#endif
|
||||
|
||||
public async UniTask<TValue> GetAsync<TValue>(string requestString)
|
||||
{
|
||||
using var getRequest = UnityWebRequest.Get(_apiUrl + requestString);
|
||||
getRequest.SetRequestHeader("Content-type", "application/json");
|
||||
UnityWebRequest operation = new UnityWebRequest();
|
||||
|
||||
try
|
||||
{
|
||||
operation = await getRequest.SendWebRequest();
|
||||
}
|
||||
catch { }
|
||||
|
||||
OnGetResponse?.Invoke((int)getRequest.responseCode);
|
||||
if(getRequest.responseCode != 200)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TValue result = JsonConvert.DeserializeObject<TValue>(operation.downloadHandler.text);
|
||||
return result;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Debug.LogError(ex.Message);
|
||||
OnGetResponse?.Invoke(-1);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask<TValue> GetAsync<TValue>(string requestString, params string[] query)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append(requestString);
|
||||
stringBuilder.Append("?");
|
||||
|
||||
for (int i = 0; i < query.Length; i++)
|
||||
{
|
||||
stringBuilder.Append(query[i]);
|
||||
if (i != query.Length - 1)
|
||||
stringBuilder.Append("&");
|
||||
}
|
||||
|
||||
using var getRequest = UnityWebRequest.Get(_apiUrl + stringBuilder.ToString());
|
||||
|
||||
getRequest.SetRequestHeader("Content-type", "application/json");
|
||||
UnityWebRequest operation = new UnityWebRequest();
|
||||
|
||||
try
|
||||
{
|
||||
operation = await getRequest.SendWebRequest();
|
||||
}
|
||||
catch { }
|
||||
|
||||
OnGetResponse?.Invoke((int)getRequest.responseCode);
|
||||
if(getRequest.responseCode != 200)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TValue result = JsonConvert.DeserializeObject<TValue>(operation.downloadHandler.text);
|
||||
return result;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Debug.LogError(ex.Message);
|
||||
OnGetResponse?.Invoke(-1);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask<TValue> GetAsync<TValue>(string requestString, Dictionary<string, string> headers = null, params string[] query)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append(requestString);
|
||||
stringBuilder.Append("?");
|
||||
|
||||
for (int i = 0; i < query.Length; i++)
|
||||
{
|
||||
stringBuilder.Append(query[i]);
|
||||
if (i != query.Length - 1)
|
||||
stringBuilder.Append("&");
|
||||
}
|
||||
|
||||
using var getRequest = UnityWebRequest.Get(_apiUrl + stringBuilder.ToString());
|
||||
if(headers != null)
|
||||
foreach(var header in headers)
|
||||
getRequest.SetRequestHeader(header.Key, header.Value);
|
||||
|
||||
getRequest.SetRequestHeader("Content-type", "application/json");
|
||||
UnityWebRequest operation = new UnityWebRequest();
|
||||
|
||||
try
|
||||
{
|
||||
operation = await getRequest.SendWebRequest();
|
||||
OnGetResponse?.Invoke((int)operation.responseCode);
|
||||
}
|
||||
catch { }
|
||||
|
||||
OnGetResponse?.Invoke((int)getRequest.responseCode);
|
||||
if(getRequest.responseCode != 200)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TValue result = JsonConvert.DeserializeObject<TValue>(operation.downloadHandler.text);
|
||||
return result;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Debug.LogError(ex.Message);
|
||||
OnGetResponse?.Invoke(-1);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask PostAsync<TValue> (string requestString, TValue data, Dictionary<string, string> headers = null)
|
||||
{
|
||||
string sendingData = JsonConvert.SerializeObject(data);
|
||||
using var postRequest = UnityWebRequest.Post(_apiUrl + requestString, sendingData);
|
||||
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
|
||||
postRequest.uploadHandler = new UploadHandlerRaw(dataBytes);
|
||||
postRequest.downloadHandler = new DownloadHandlerBuffer();
|
||||
|
||||
if(headers != null)
|
||||
{
|
||||
foreach(var header in headers)
|
||||
postRequest.SetRequestHeader(header.Key, header.Value);
|
||||
}
|
||||
|
||||
postRequest.SetRequestHeader("Content-Type", "application/json");
|
||||
UnityWebRequest operation = new UnityWebRequest();
|
||||
|
||||
try
|
||||
{
|
||||
operation = await postRequest.SendWebRequest();
|
||||
}
|
||||
catch { }
|
||||
|
||||
OnGetResponse?.Invoke((int)postRequest.responseCode);
|
||||
}
|
||||
|
||||
public async UniTask<TResponseValue> PostAsync<TSendingValue, TResponseValue> (string requestString, TSendingValue data)
|
||||
{
|
||||
string sendingData = JsonConvert.SerializeObject(data);
|
||||
using var postRequest = UnityWebRequest.Post(_apiUrl + requestString, sendingData);
|
||||
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
|
||||
postRequest.uploadHandler = new UploadHandlerRaw(dataBytes);
|
||||
postRequest.downloadHandler = new DownloadHandlerBuffer();
|
||||
postRequest.SetRequestHeader("Content-Type", "application/json");
|
||||
|
||||
UnityWebRequest operation = new UnityWebRequest();
|
||||
|
||||
try
|
||||
{
|
||||
operation = await postRequest.SendWebRequest();
|
||||
}
|
||||
catch { }
|
||||
|
||||
OnGetResponse?.Invoke((int)postRequest.responseCode);
|
||||
if(postRequest.responseCode == 0)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<TResponseValue>(operation.downloadHandler.text);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Debug.LogError(ex.Message);
|
||||
OnGetResponse?.Invoke(-1);
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask PutAsync<TValue>(string requestString, TValue data)
|
||||
{
|
||||
string sendingData = JsonConvert.SerializeObject(data);
|
||||
|
||||
using var putRequest = UnityWebRequest.Put(_apiUrl + requestString, sendingData);
|
||||
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
|
||||
putRequest.uploadHandler = new UploadHandlerRaw(dataBytes);
|
||||
putRequest.downloadHandler = new DownloadHandlerBuffer();
|
||||
putRequest.SetRequestHeader("Content-Type", "application/json");
|
||||
|
||||
UnityWebRequest operation = new UnityWebRequest();
|
||||
|
||||
try
|
||||
{
|
||||
operation = await putRequest.SendWebRequest();
|
||||
}
|
||||
catch { }
|
||||
|
||||
OnGetResponse?.Invoke((int)putRequest.responseCode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f7fe3e05c1138142a6dd3735bd45d56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5addb8f9f0955cf4da0abedac8e4e7c4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class UIMenu : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private UIMenu _nextMenu;
|
||||
[SerializeField] private UIMenu _previousMenu;
|
||||
|
||||
private RectTransform _rectTransfrom;
|
||||
private CanvasGroup _canvasGroup;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_rectTransfrom = GetComponent<RectTransform>();
|
||||
_canvasGroup = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
public void ShowNextMenu()
|
||||
{
|
||||
_nextMenu?.gameObject.SetActive(true);
|
||||
_canvasGroup.DOFade(0, .15f)
|
||||
.OnComplete(() => gameObject.SetActive(false));
|
||||
}
|
||||
|
||||
public void ShowPreviousMenu()
|
||||
{
|
||||
_previousMenu?.gameObject.SetActive(true);
|
||||
_canvasGroup.DOFade(0, .15f)
|
||||
.OnComplete(() => gameObject.SetActive(false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a468f888ee4600243962d9bb0212fe8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user