Files
Main/Assets/GameAssets/Resources/GameUI/Center/GameStartup.cs

148 lines
4.6 KiB
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
using Thousandto.Code.Logic;
using Thousandto.Core.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Thousandto.Code.Center
{
/// <summary>
/// 游戏启动类
/// </summary>
public static class GameStartup
{
#region//启动参数
//语言
private static string _paramLang = null;
//平台
private static int _paramPlatform = -1;
//是否使用Bundle
private static bool _paramUseBundle = false;
//当前调用跳转登录界面
private static bool _paramChangeToLogin = false;
#endregion
#region//记录Cache
private static GameCenterScript _centerScript;
#endregion
private static void PrintArgs(string[] args)
{
string arg = "";
if (args != null && args.Length > 0)
{
for (int i = 0; i < args.Length; i++)
{
arg += args[i] == null ? "NULL" : args[i];
arg += " ";
}
}
Debug.Log("StartupArgs:"+arg);
}
/// <summary>
/// 启动函数
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
PrintArgs(args);
ResetParams();
if (args != null && args.Length > 0)
{
for (int i = 0; i < args.Length; i++)
{
if (0 == string.Compare(args[i], "-lang", true))
{//语言
if (i < args.Length - 1)
{
string arg = args[i + 1];
if (!arg.StartsWith("-"))
{
if (0 == string.Compare(arg, "false", true))
{
_paramLang = null;
}
else
{
_paramLang = arg;
}
++i;
}
}
}
else if (0 == string.Compare(args[i], "-platform", true))
{//平台
if (i < args.Length - 1)
{
string arg = args[i + 1];
if (!arg.StartsWith("-"))
{
if (!int.TryParse(arg, out _paramPlatform))
{
_paramPlatform = -1;
}
++i;
}
}
}
else if (0 == string.Compare(args[i], "-usebundle", true))
{//是否使用bundle
_paramUseBundle = true;
}
else if (0 == string.Compare(args[i], "-tologin", true))
{//是否跳转
_paramChangeToLogin = true;
}
}
}
Execute();
}
//清理启动参数
private static void ResetParams()
{
_paramLang = null;
_paramPlatform = -1;
_paramUseBundle = false;
_paramChangeToLogin = false;
}
//运行Game
private static void Execute()
{
CreateGameCenterGo();
}
//创建游戏中心的对象
private static void CreateGameCenterGo()
{
GameObject go = GameObject.Find("[MainEntry]");
if (go == null)
{
UnityEngine.Debug.Log("CreateGameCenterGo++++++++++++++");
go = new GameObject("[MainEntry]");
go.SetActive(false);
go.AddComponent<GameUICenterScript>();
_centerScript = go.AddComponent<GameCenterScript>();
GameObject.DontDestroyOnLoad(go);
}
else
{
UnityEngine.Debug.Log("ChangeToLogin");
_centerScript = go.GetComponent<GameCenterScript>();
_centerScript.ChangeToLogin();
}
_centerScript.GameStart(_paramLang,_paramUseBundle,_paramPlatform);
go.SetActive(true);
}
}
}