209 lines
6.3 KiB
C#
209 lines
6.3 KiB
C#
|
using CaoCao.Resources;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Reflection;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace CaoCao.Runtime
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
[DisallowMultipleComponent]
|
|||
|
[AddComponentMenu("CaoCao/Base")]
|
|||
|
public class BaseComponent : GameComponent
|
|||
|
{
|
|||
|
private const int DefaultDpi = 96; // default windows dpi
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
private bool m_EditorResourceMode = true;
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
private string m_TextHelperTypeName = "CaoCao.Runtime.DefaultTextHelper";
|
|||
|
[SerializeField]
|
|||
|
private string m_LogHelperTypeName = "CaoCao.Runtime.DefaultLogHelper";
|
|||
|
[SerializeField]
|
|||
|
private string m_VersionHelperTypeName = "CaoCao.Runtime.DefaultVersionHelper";
|
|||
|
[SerializeField]
|
|||
|
private string m_JsonHelperTypeName = "CaoCao.Runtime.DefaultJsonHelper";
|
|||
|
[SerializeField]
|
|||
|
private string m_LoginServerIP = "103.73.119.145";
|
|||
|
|
|||
|
//<2F>ȸ<EFBFBD><C8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public Assembly m_Assembly;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ʹ<EFBFBD>ñ༭<C3B1><E0BCAD><EFBFBD><EFBFBD>Դģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>༭<EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public bool EditorResourceMode
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return m_EditorResourceMode;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
m_EditorResourceMode = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public string LoginServerIP => m_LoginServerIP;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
protected override void Awake()
|
|||
|
{
|
|||
|
base.Awake();
|
|||
|
|
|||
|
m_Assembly = null;
|
|||
|
Debug.Log($"m_LoginServerIP = {m_LoginServerIP}");
|
|||
|
|
|||
|
InitTextHelper();
|
|||
|
InitVersionHelper();
|
|||
|
InitLogHelper();
|
|||
|
InitJsonHelper();
|
|||
|
|
|||
|
Utility.Converter.ScreenDpi = Screen.dpi;
|
|||
|
if (Utility.Converter.ScreenDpi <= 0)
|
|||
|
{
|
|||
|
Utility.Converter.ScreenDpi = DefaultDpi;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//private void Start()
|
|||
|
//{
|
|||
|
// //<2F><><EFBFBD>ٿ<EFBFBD><D9BF><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>ȸ<EFBFBD><C8B8>º<EFBFBD><C2BA><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
|
|||
|
// if (!EditorResourceMode)
|
|||
|
// {
|
|||
|
// AssetBundleManager.Init();
|
|||
|
// AssetManager.Init();
|
|||
|
// PoolsManager.Init();
|
|||
|
// PrefabManager.Init(gameObject);
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
private void InitTextHelper()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(m_TextHelperTypeName))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Type textHelperType = Utility.Assembly.GetType(m_TextHelperTypeName);
|
|||
|
if (textHelperType == null)
|
|||
|
{
|
|||
|
Log.Error("Can not find text helper type '{0}'.", m_TextHelperTypeName);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Utility.Text.ITextHelper textHelper = (Utility.Text.ITextHelper)Activator.CreateInstance(textHelperType);
|
|||
|
if (textHelper == null)
|
|||
|
{
|
|||
|
Log.Error("Can not create text helper instance '{0}'.", m_TextHelperTypeName);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Utility.Text.SetTextHelper(textHelper);
|
|||
|
}
|
|||
|
|
|||
|
private void InitLogHelper()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(m_LogHelperTypeName))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Type logHelperType = Utility.Assembly.GetType(m_LogHelperTypeName);
|
|||
|
if (logHelperType == null)
|
|||
|
{
|
|||
|
throw new GameException(Utility.Text.Format("Can not find log helper type '{0}'.", m_LogHelperTypeName));
|
|||
|
}
|
|||
|
|
|||
|
CaoCaoLog.ILogHelper logHelper = (CaoCaoLog.ILogHelper)Activator.CreateInstance(logHelperType);
|
|||
|
if (logHelper == null)
|
|||
|
{
|
|||
|
throw new GameException(Utility.Text.Format("Can not create log helper instance '{0}'.", m_LogHelperTypeName));
|
|||
|
}
|
|||
|
|
|||
|
CaoCaoLog.SetLogHelper(logHelper);
|
|||
|
}
|
|||
|
|
|||
|
private void InitVersionHelper()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(m_VersionHelperTypeName))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Type versionHelperType = Utility.Assembly.GetType(m_VersionHelperTypeName);
|
|||
|
if (versionHelperType == null)
|
|||
|
{
|
|||
|
throw new GameException(Utility.Text.Format("Can not find version helper type '{0}'.", m_VersionHelperTypeName));
|
|||
|
}
|
|||
|
|
|||
|
CaoCao.Version.IVersionHelper versionHelper = (CaoCao.Version.IVersionHelper)Activator.CreateInstance(versionHelperType);
|
|||
|
if (versionHelper == null)
|
|||
|
{
|
|||
|
throw new GameException(Utility.Text.Format("Can not create version helper instance '{0}'.", m_VersionHelperTypeName));
|
|||
|
}
|
|||
|
|
|||
|
CaoCao.Version.SetVersionHelper(versionHelper);
|
|||
|
}
|
|||
|
|
|||
|
private void InitJsonHelper()
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(m_JsonHelperTypeName))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Type jsonHelperType = Utility.Assembly.GetType(m_JsonHelperTypeName);
|
|||
|
if (jsonHelperType == null)
|
|||
|
{
|
|||
|
Log.Error("Can not find JSON helper type '{0}'.", m_JsonHelperTypeName);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Utility.Json.IJsonHelper jsonHelper = (Utility.Json.IJsonHelper)Activator.CreateInstance(jsonHelperType);
|
|||
|
if (jsonHelper == null)
|
|||
|
{
|
|||
|
Log.Error("Can not create JSON helper instance '{0}'.", m_JsonHelperTypeName);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Utility.Json.SetJsonHelper(jsonHelper);
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
FrameworkEntry.Update(Time.deltaTime, Time.unscaledDeltaTime);
|
|||
|
//if (!EditorResourceMode)
|
|||
|
// PrefabManager.Update();
|
|||
|
|
|||
|
#if UNITY_EDITOR
|
|||
|
if (Input.GetKey(KeyCode.KeypadMultiply) && Input.GetKeyDown(KeyCode.G))
|
|||
|
{
|
|||
|
var go = GameObject.Find("UIMgr(Clone)/Canvas/NodeUI");
|
|||
|
if (go)
|
|||
|
{
|
|||
|
var prefab = UnityEngine.Resources.Load("Prefab/GMPanel");
|
|||
|
var uiGo = GameObject.Instantiate(prefab, go.transform,false) as GameObject;
|
|||
|
}
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
FrameworkEntry.Shutdown();
|
|||
|
}
|
|||
|
|
|||
|
internal void Shutdown()
|
|||
|
{
|
|||
|
Destroy(gameObject);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|