192 lines
5.6 KiB
C#
192 lines
5.6 KiB
C#
|
using Axibug.Resources;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Reflection;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Axibug.Runtime
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
[DisallowMultipleComponent]
|
|||
|
[AddComponentMenu("Axibug/Base")]
|
|||
|
public class BaseComponent : GameComponent
|
|||
|
{
|
|||
|
private const int DefaultDpi = 96; // default windows dpi
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
private bool m_EditorResourceMode = true;
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
private string m_TextHelperTypeName = "Axibug.Runtime.DefaultTextHelper";
|
|||
|
[SerializeField]
|
|||
|
private string m_LogHelperTypeName = "Axibug.Runtime.DefaultLogHelper";
|
|||
|
[SerializeField]
|
|||
|
private string m_VersionHelperTypeName = "Axibug.Runtime.DefaultVersionHelper";
|
|||
|
[SerializeField]
|
|||
|
private string m_JsonHelperTypeName = "Axibug.Runtime.DefaultJsonHelper";
|
|||
|
|
|||
|
//<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;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <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;
|
|||
|
|
|||
|
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));
|
|||
|
}
|
|||
|
|
|||
|
AxibugLog.ILogHelper logHelper = (AxibugLog.ILogHelper)Activator.CreateInstance(logHelperType);
|
|||
|
if (logHelper == null)
|
|||
|
{
|
|||
|
throw new GameException(Utility.Text.Format("Can not create log helper instance '{0}'.", m_LogHelperTypeName));
|
|||
|
}
|
|||
|
|
|||
|
AxibugLog.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));
|
|||
|
}
|
|||
|
|
|||
|
Axibug.Version.IVersionHelper versionHelper = (Axibug.Version.IVersionHelper)Activator.CreateInstance(versionHelperType);
|
|||
|
if (versionHelper == null)
|
|||
|
{
|
|||
|
throw new GameException(Utility.Text.Format("Can not create version helper instance '{0}'.", m_VersionHelperTypeName));
|
|||
|
}
|
|||
|
|
|||
|
Axibug.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();
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
FrameworkEntry.Shutdown();
|
|||
|
}
|
|||
|
|
|||
|
internal void Shutdown()
|
|||
|
{
|
|||
|
Destroy(gameObject);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|