102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
|
using Thousandto.CoreSDK;
|
|||
|
using Thousandto.UpdateForm.Form;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Thousandto.UpdateForm.Center
|
|||
|
{
|
|||
|
public class UpdateCenter : MonoBehaviour
|
|||
|
{
|
|||
|
//窗体名称
|
|||
|
private static string CN_FORM_NAME = "[UILauncherForm]";
|
|||
|
//窗体资源路径
|
|||
|
private static string CN_FORM_ASSET_PATH = "LauncherUI/Form/Prefabs/UILauncherForm";
|
|||
|
|
|||
|
|
|||
|
#region MonoBehaviour函数
|
|||
|
|
|||
|
void Awake()
|
|||
|
{
|
|||
|
//屏幕常亮
|
|||
|
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
|||
|
}
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
LoadUpdateForm();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region //界面初始化
|
|||
|
|
|||
|
public static void LoadUpdateForm()
|
|||
|
{
|
|||
|
var formScript = CreateNode<UIUpdateForm>(CN_FORM_NAME, CN_FORM_ASSET_PATH);
|
|||
|
var sdkRoot = CreateNode<SDKRootScript>("SDK_Object", string.Empty);
|
|||
|
var sdkScript = sdkRoot.gameObject.GetComponent<FuncellSDKScript>();
|
|||
|
if (sdkScript == null)
|
|||
|
{
|
|||
|
sdkRoot.gameObject.AddComponent<FuncellSDKScript>();
|
|||
|
}
|
|||
|
DontDestroyOnLoad(formScript.gameObject);
|
|||
|
DontDestroyOnLoad(sdkRoot.gameObject);
|
|||
|
}
|
|||
|
|
|||
|
private static T CreateNode<T>(string name,string assetpath)
|
|||
|
where T : MonoBehaviour
|
|||
|
{
|
|||
|
//先判断现在有没有.
|
|||
|
var exist = GameObject.Find(name);
|
|||
|
if (exist)
|
|||
|
{
|
|||
|
var te = exist.GetComponent<T>();
|
|||
|
if (te == null)
|
|||
|
{
|
|||
|
te = exist.AddComponent<T>();
|
|||
|
}
|
|||
|
exist.SetActive(true);
|
|||
|
return te;
|
|||
|
|
|||
|
}
|
|||
|
GameObject go;
|
|||
|
//没有的话,就进行加载
|
|||
|
if (string.IsNullOrEmpty(assetpath))
|
|||
|
{
|
|||
|
go = new GameObject(name);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var asset = Resources.Load<GameObject>(assetpath);
|
|||
|
if (asset != null)
|
|||
|
{
|
|||
|
go = GameObject.Instantiate(asset) as GameObject;
|
|||
|
go.name = name;
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
throw new System.Exception("加载["+ name + "]资源失败:" + assetpath);
|
|||
|
}
|
|||
|
}
|
|||
|
if (go != null)
|
|||
|
{
|
|||
|
var t = go.GetComponent<T>();
|
|||
|
if (t == null)
|
|||
|
{
|
|||
|
t = go.AddComponent<T>();
|
|||
|
}
|
|||
|
go.SetActive(true);
|
|||
|
return t;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
throw new System.Exception("实例化[" + name + "]对象失败:" + assetpath);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|