-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFavoritePrefScript.cs
More file actions
63 lines (57 loc) · 1.63 KB
/
FavoritePrefScript.cs
File metadata and controls
63 lines (57 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class FavoritePrefScript : MonoBehaviour
{
public RawImage img;
public TMP_Text name;
public GameObject close;
public int index;
public Dish dish;
public GameObject pref;
public void OpenReceipt()
{
var AM = AppManager.Instance;
AM.currentDish = dish;
AM.SwitchScreen(4);
}
public async void ScrollCellContent(Dish _dish)
{
dish = _dish;
name.text = _dish.name;
img.texture = await LoadImg(dish.img[0].url);
}
async Task<Texture> LoadImg(string endpoint)
{
using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(endpoint))
{
await request.SendWebRequest();
var texture = DownloadHandlerTexture.GetContent(request);
return texture;
}
}
public async void Dislike()
{
var AM = AppManager.Instance;
var DPP = AM.dishesPlayerPrefs;
dish.like = false;
for (int i = 0; i < DPP.likedDishes.Count; i++)
{
if (DPP.likedDishes[i].id == dish.id)
{
DPP.likedDishes.Remove(DPP.likedDishes[i]);
}
}
await new WaitForSeconds(.5f);
if (!dish.like)
{
string s = JsonUtility.ToJson(DPP);
PlayerPrefs.SetString("dish", s);
PlayerPrefs.Save();
}
Destroy(pref);
AM.screens[6].GetComponent<FonFavoriteScript>().OnEnable();
}
}