PJ/Assets/scripts/UI/Passes.cs

116 lines
3.6 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Collections;
using System.Collections.Generic;
public class Passes : MonoBehaviour
{
public static TextAsset csvFile;
int ActiveIsland;
public GameObject selecter;
public Image[] rewards;
public string[] dataLines;
public string[] reward;
public Sprite[] ValueType;
public Sprite[] Skin;
public Sprite[] Head;
public Sprite[] sword;
public Sprite[] npc;
public Slider pgrogress;
public Slider pgrogress2;
public Button[] Collect;
string[] rews;
[SerializeField] TMP_Text count1;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
csvFile = Resources.Load<TextAsset>("passes");
dataLines = csvFile.text.Split('\n');
}
void FixedUpdate()
{
ActiveIsland = selecter.GetComponent<LevelButtons>().Isl;
if(ActiveIsland == 0)
ActiveIsland = 1;
else if( ActiveIsland > 5)
ActiveIsland -= 1;
List<int> l = Currencies.Load("PassLevel");
try {pgrogress.value = l[ActiveIsland];}
catch {pgrogress.value = 0;}
string[] rews = dataLines[ActiveIsland].Split(';');
pgrogress.maxValue = int.Parse(rews[2]) * 5;
}
public void OpenPass()
{
ActiveIsland = selecter.GetComponent<LevelButtons>().Isl;
if(ActiveIsland == 0)
ActiveIsland = 1;
else if( ActiveIsland > 5)
ActiveIsland -= 1;
rews = dataLines[ActiveIsland].Split(';');
switch(rews[3])
{case "money":
rews[3] = "0";
break;
case "Metall":
rews[3] = "1";
break;}
rewards[0].sprite = ValueType[int.Parse(rews[3])];
count1.text = rews[4];
rewards[1].sprite = Skin[int.Parse(rews[5])];
rewards[2].sprite = Head[int.Parse(rews[6])];
rewards[3].sprite = sword[int.Parse(rews[7])];
//rewards[4].sprite = Skin[int.Parse(rews[8])]; //npc
pgrogress2.maxValue = int.Parse(rews[2]) * 5;
List<int> l = Currencies.Load("PassLevel");
try {pgrogress2.value = l[ActiveIsland];}
catch {pgrogress2.value = 0;}
for(int i = 0; i < Collect.Length; i++)
{
if(Currencies.CheckIndex("PassLevel",ActiveIsland) / int.Parse(rews[2]) > i)
Collect[i].gameObject.SetActive(true);
else
Collect[i].gameObject.SetActive(false);
if(i != Currencies.CheckIndex("CollectRewards", ActiveIsland))
Collect[i].interactable = false;
}
Debug.Log(Currencies.CheckIndex("CollectRewards", ActiveIsland));
}
public void CollectReward(int Num)
{
Currencies.SaveV("CollectRewards", ActiveIsland, Num);
OpenPass();
switch(Num)
{
case 1:
if(rews[3] == "0")
{
int m = PlayerPrefs.GetInt("Moneys");
m += int.Parse(rews[4]);
PlayerPrefs.SetInt("Moneys", m);
}
else if (rews[3] == "1")
{
int m = PlayerPrefs.GetInt("Metall");
m += int.Parse(rews[4]);
PlayerPrefs.SetInt("Metall", m);
}
break;
case 2:
Currencies.AddValue("HaveS", int.Parse(rews[5]));
break;
case 3:
Currencies.AddValue("HaveHe", int.Parse(rews[6]));
break;
case 4:
Currencies.AddValue("HaveSw", int.Parse(rews[7]));
break;
}
}
}