98 lines
3.6 KiB
C#
98 lines
3.6 KiB
C#
using MEC;
|
|
using Newtonsoft.Json;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameManager : DontDestroy<GameManager>
|
|
{
|
|
//작업 사이즈 : 2160x1080
|
|
public int MultyNum;
|
|
public eScene NowScene;
|
|
public bool Over;
|
|
|
|
private CoroutineHandle corExcel;
|
|
|
|
/// <summary>
|
|
/// 현재 엑셀 처리가 끝났는지 확인하는 부분.
|
|
/// </summary>
|
|
public bool isExcel { get { return _isExcel; } }
|
|
//멀티 쓰레드가 너무 빠르게 동작해 데이터 세팅이 끝나지 않았는데 씬이 먼져 넘어가버림
|
|
//그래서 이미지 데이터가 불러와 지지 않는 상태에서 로딩이 끝나버리는 버그가 발생해서 방식을 수정.
|
|
public bool _isExcel;
|
|
|
|
protected override void OnStart()
|
|
{
|
|
_isExcel = true;
|
|
Statics.version = PlayerPrefs.GetString("version");
|
|
DownlodeResp request = new DownlodeResp();
|
|
request.Request((data) =>
|
|
{
|
|
if(data.data != "")
|
|
{
|
|
string excelDatas = Crypto.Instance.Decompress(data.data);
|
|
string cryptoExcel = Crypto.Instance.Encrypt(excelDatas);
|
|
Statics.excelDatas = JsonConvert.DeserializeObject<ExcelDatas>(excelDatas);
|
|
corExcel = Timing.RunCoroutine(Statics.excelDatas.ToJson(DataSet));
|
|
Statics.version = data.version;
|
|
PlayerPrefs.SetString("e", cryptoExcel);
|
|
PlayerPrefs.SetString("version", data.version);
|
|
}
|
|
else
|
|
{
|
|
Statics.excelDatas = JsonConvert.DeserializeObject<ExcelDatas>(Crypto.Instance.Decrypt(PlayerPrefs.GetString("e")));
|
|
corExcel = Timing.RunCoroutine(Statics.excelDatas.ToJson(DataSet));
|
|
}
|
|
});
|
|
}
|
|
|
|
private void DataSet()
|
|
{
|
|
foreach (var data in Statics.excelDatas.unitData)
|
|
{
|
|
GameObject obj = Resources.Load<GameObject>($"Unit/{data.Value.name}");
|
|
if (obj != null)
|
|
{
|
|
obj.GetComponent<UnitCtrl>().DataSet(data.Key);
|
|
Statics.stringUnits.Add(data.Value.name, obj);
|
|
Statics.longUnits.Add(data.Value.index, obj);
|
|
}
|
|
}
|
|
//stringIcons
|
|
foreach (var data in Statics.excelDatas.equipmentData)
|
|
{
|
|
Texture2D obj = Resources.Load<Texture2D>($"EquipmentIcon/{data.Value.name}");
|
|
if (obj != null)
|
|
{
|
|
Statics.stringIcons.Add(data.Value.name, Sprite.Create(obj, new Rect(0, 0, obj.width, obj.height), new Vector2(0.5f, 0.5f)));
|
|
}
|
|
}
|
|
_isExcel = false;
|
|
}
|
|
|
|
//public float x = 2160f;
|
|
//public float y = 1080f;
|
|
//현재 등록되어 있는 Scene을 입력하면 현재 열려있는 씬이 무엇인지 NowScene을 통해 알 수 있게됩니다.
|
|
//File > BuildSettings에 등록한 Scene이름만 순서대로 추가해 주세요
|
|
public enum eScene
|
|
{
|
|
Title = 0,
|
|
Main,
|
|
Game,
|
|
Play
|
|
}
|
|
//등록한 다음씬으로 이동할수 있습니다
|
|
//GameManager.Instance.NextScene(GameManager.eScene.원하는 씬이름);
|
|
//이렇게 사용한다면 원하는 씬으로 넘어갈 수 있습니다.
|
|
//입력하지 않고 GameManager.Instance.NextScene();만 호출한다면 현재씬의 바로 다음씬으로 이동합니다.
|
|
public void NextScene(eScene GoingScene)
|
|
{
|
|
SceneManager.LoadScene((int)GoingScene);
|
|
}
|
|
public void NextScene()
|
|
{
|
|
SceneManager.LoadScene(((int)NowScene) + 1);
|
|
}
|
|
}
|