212 lines
6.2 KiB
C#
212 lines
6.2 KiB
C#
using Newtonsoft.Json;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class GameInit : MonoBehaviour
|
|
{
|
|
public static GameInit Instance;
|
|
|
|
public static GameMode GameMode { get; private set; }
|
|
|
|
//public GameMode _GameMode;
|
|
|
|
public GameObject TipsObject;
|
|
|
|
public static InfoIni InfoIni { get; private set; }
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
private bool showlog;
|
|
void Start()
|
|
{
|
|
File.WriteAllText(Application.streamingAssetsPath + "/start.ini", "1");
|
|
|
|
using (StreamReader reader = new StreamReader(InterfaceManager.ConfigureApiPath))
|
|
{
|
|
//InterfaceManager.IpAddress = reader.ReadLine();
|
|
var _txt = reader.ReadToEnd();
|
|
InterfaceManager.API_DIC = JsonConvert.DeserializeObject<Dictionary<string, string>>(_txt);
|
|
InterfaceManager.IpAddress = InterfaceManager.API_DIC["IPADDRESS"];
|
|
Debug.Log("--默认接口地址:" + InterfaceManager.API_DIC["IPADDRESS"]);
|
|
}
|
|
|
|
using (StreamReader reader = new StreamReader(Application.streamingAssetsPath + "/info.ini"))
|
|
{
|
|
var _res = reader.ReadLine();
|
|
Debug.Log("--前端参数:"+_res);
|
|
|
|
if (string.IsNullOrEmpty(_res))
|
|
{
|
|
TipsObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
var _split_semicolon = _res.Split(';');
|
|
if (_split_semicolon.Length == 3)
|
|
{
|
|
var _split_comma = _split_semicolon[1].Split(',');
|
|
if (_split_comma.Length == 8)
|
|
{
|
|
InfoIni = new InfoIni()
|
|
{
|
|
scene_name = _split_comma[0],
|
|
type = _split_comma[1],
|
|
exam_id = _split_comma[2],
|
|
user_id = _split_comma[3],
|
|
user_name = _split_comma[4],
|
|
token = _split_comma[5],
|
|
user_time = float.Parse(_split_comma[6]),
|
|
class_id = _split_comma[7],
|
|
};
|
|
}
|
|
else
|
|
{
|
|
InfoIni = new InfoIni();
|
|
for (int i = 0; i < _split_comma.Length; i++)
|
|
{
|
|
Custom(i, _split_comma[i]);
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(InfoIni.type))
|
|
{
|
|
GameMode = (GameMode)(int.Parse(InfoIni.type));
|
|
SceneManager.LoadScene(1);
|
|
}
|
|
else
|
|
{
|
|
TipsObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TipsObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
//var args = System.Environment.GetCommandLineArgs();
|
|
//if (args.Length <= 1)
|
|
//{
|
|
// TipsObject.SetActive(true);
|
|
//}
|
|
//else
|
|
//{
|
|
// if (args.Contains("showlog"))
|
|
// {
|
|
// showlog = true;
|
|
// }
|
|
|
|
// if (args.Contains("Exam") || args.Contains("exam"))
|
|
// {
|
|
// argus = "启动考核模式\n";
|
|
// GameMode = GameMode.Examination;
|
|
|
|
// SceneManager.LoadScene(1, LoadSceneMode.Single);
|
|
// //SceneManager.LoadScene(1, LoadSceneMode.Additive);
|
|
// }
|
|
// else if (args.Contains("Tutorial") || args.Contains("tutorial"))
|
|
// {
|
|
// argus = "启动教学模式\n";
|
|
// GameMode = GameMode.Tutorial;
|
|
|
|
// SceneManager.LoadScene(1, LoadSceneMode.Single);
|
|
// //SceneManager.LoadScene(1, LoadSceneMode.Additive);
|
|
// }
|
|
// else
|
|
// {
|
|
|
|
// }
|
|
// for (int i = 0; i < args.Length; i++)
|
|
// {
|
|
// argus = argus + args[i] + "\n";
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
//GameMode = _GameMode;
|
|
////若接收到启动参数,正常启动
|
|
//using (StreamReader reader = new StreamReader(InterfaceManager.ConfigPath))
|
|
//{
|
|
// InterfaceManager.IpAddress = reader.ReadLine();
|
|
//}
|
|
DontDestroyOnLoad(this);
|
|
//SceneManager.LoadScene(1, LoadSceneMode.Additive);
|
|
//否则退出系统
|
|
}
|
|
|
|
public void AppQuit()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
|
|
public void Custom(int _index, string _param)
|
|
{
|
|
switch (_index)
|
|
{
|
|
case 0:
|
|
InfoIni.scene_name = _param;
|
|
break;
|
|
case 1:
|
|
InfoIni.type = _param;
|
|
break;
|
|
case 2:
|
|
InfoIni.exam_id = _param;
|
|
break;
|
|
case 3:
|
|
InfoIni.user_id = _param;
|
|
break;
|
|
case 4:
|
|
InfoIni.user_name = _param;
|
|
break;
|
|
case 5:
|
|
InfoIni.token = _param;
|
|
break;
|
|
case 6:
|
|
InfoIni.user_time = float.Parse(_param);
|
|
break;
|
|
case 7:
|
|
InfoIni.class_id = _param;
|
|
break;
|
|
case 8:
|
|
InfoIni.exam_class_id = _param;
|
|
break;
|
|
case 9:
|
|
|
|
break;
|
|
case 10:
|
|
InterfaceManager.IpAddress = InterfaceManager.API_DIC["IPADDRESS"] = InfoIni.url = _param;
|
|
Debug.Log("--更新接口地址:" + InterfaceManager.API_DIC["IPADDRESS"]);
|
|
break;
|
|
case 11: break;
|
|
case 12: break;
|
|
case 13:
|
|
break;
|
|
case 14: break;
|
|
case 15: break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
string argus;
|
|
private void OnGUI()
|
|
{
|
|
if (showlog)
|
|
{
|
|
//new Rect(10, 10, 200, 100),
|
|
GUILayout.TextArea(argus);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
File.WriteAllText(Application.streamingAssetsPath + "/start.ini", "0");
|
|
}
|
|
}
|