328 lines
10 KiB
C#
328 lines
10 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
namespace ZXKFramework
|
|
{
|
|
public class Game : MonoSingleton<Game>
|
|
{
|
|
[Header("======Asset")]
|
|
public ResLoadType resLoadType = ResLoadType.Resources;
|
|
[HideInInspector]
|
|
public IRes res = null;
|
|
|
|
//[Header("======Save")]
|
|
//public string saveDirPath = string.Empty;
|
|
//public SaveManagerType saveManagerType = SaveManagerType.PlayerPrefs;
|
|
//[HideInInspector]
|
|
//public ISave save = null;
|
|
|
|
[Header("======Sound")]
|
|
//public string soundDirPath = string.Empty;
|
|
//public ResLoadType soundResLoadType = ResLoadType.Resources;
|
|
public SoundType soundType = SoundType.Base;
|
|
[HideInInspector]
|
|
public bool sceneObjFindAudioClip = false;
|
|
[HideInInspector]
|
|
public ISound sound = null;
|
|
|
|
[Header("======Pool")]
|
|
//public string poolDirPath = string.Empty;
|
|
//public ResLoadType poolResLoadType = ResLoadType.Resources;
|
|
public ObjectPoolType objectPoolType = ObjectPoolType.Base;
|
|
[HideInInspector]
|
|
public IObjectPool objectPool = null;
|
|
|
|
[Header("======FSM")]
|
|
public FSMType fSMType = FSMType.Base;
|
|
[HideInInspector]
|
|
public IFSM fsm = null;
|
|
|
|
[Header("======Event")]
|
|
public EventMangerType eventManagerType = EventMangerType.Base;
|
|
[HideInInspector]
|
|
public IEventManager eventManager = null;
|
|
|
|
[Header("======IEnumerator")]
|
|
public IEnumeratorManagerType iEnumeratorManagerType = IEnumeratorManagerType.Base;
|
|
[HideInInspector]
|
|
public IIECoroutine IEnumeratorManager = null;
|
|
|
|
//[Header("======HTTP")]
|
|
//public HttpManagerType httpManagerType = HttpManagerType.Base;
|
|
//[HideInInspector]
|
|
//public IHttp httpManager = null;
|
|
|
|
//[Header("======UI")]
|
|
//public string uiDirPath = string.Empty;
|
|
//private GameObject canvas = null;
|
|
//public ResLoadType uiResLoadType = ResLoadType.Resources;
|
|
//private UIManagerType uiManagerType = UIManagerType.Base;
|
|
[HideInInspector]
|
|
public bool canvasTransformFindUI = true;
|
|
[HideInInspector]
|
|
public IUIManager uiManager = null;
|
|
|
|
//[Header("======Tip")]
|
|
//public TipManagerType tipManagerType = TipManagerType.None;
|
|
//[HideInInspector]
|
|
//public ITipManager tipManager = null;
|
|
|
|
//[Header("======Animator")]
|
|
//public GameObject animatorParent = null;
|
|
//public AnimatorManagerType animatorManagerType = AnimatorManagerType.Animator;
|
|
//[HideInInspector]
|
|
//public IAnimatorManager animatorManager = null;
|
|
|
|
[Header("======Language")]
|
|
public LanguageType languageType = LanguageType.Chinese;
|
|
|
|
[Header("======Adapter")]
|
|
public PlatformType platformType = PlatformType.PC;
|
|
public OperatingType operatingType = OperatingType.Touch;
|
|
[HideInInspector]
|
|
public IAdapter adapterManager = null;
|
|
|
|
[Header("======Scene")]
|
|
public SceneManagerType sceneManagerType = SceneManagerType.Base;
|
|
[HideInInspector]
|
|
public IScene sceneManager = null;
|
|
public string directLoadNextScene;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
DontDestroyOnLoad(gameObject);
|
|
FSMInit();
|
|
EventManagerInit();
|
|
ResInit();
|
|
//SaveInit();
|
|
//AnimatorManagerInit();
|
|
//HttpManagerInit();
|
|
IEManagerInit();
|
|
SceneMangerInit();
|
|
SoundInit();
|
|
ObjectPoolInit();
|
|
UIManagerInit();
|
|
if (!string.IsNullOrEmpty(directLoadNextScene)) sceneManager?.LoadLevel(directLoadNextScene);
|
|
}
|
|
|
|
private void ResInit()
|
|
{
|
|
res = GetRes(resLoadType);
|
|
}
|
|
|
|
public IRes GetRes(ResLoadType moduleResLoadType)
|
|
{
|
|
switch (moduleResLoadType)
|
|
{
|
|
case ResLoadType.Resources:
|
|
return new ResResources();
|
|
//case ResLoadType.Assetbundle:
|
|
// return new ResAssetBundle();
|
|
case ResLoadType.StreamingAssets:
|
|
return new ResStreamingAssets();
|
|
//case ResLoadType.Url:
|
|
// return new ResUrl();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
//private void AnimatorManagerInit()
|
|
//{
|
|
// switch (animatorManagerType)
|
|
// {
|
|
// case AnimatorManagerType.Animator:
|
|
// {
|
|
// animatorManager = new AnimatorManager();
|
|
// }
|
|
// break;
|
|
// case AnimatorManagerType.Animation:
|
|
// {
|
|
// animatorManager = new AnimationManager();
|
|
// }
|
|
// break;
|
|
// }
|
|
// if (animatorParent != null)
|
|
// {
|
|
// animatorManager?.Init(animatorParent);
|
|
// }
|
|
//}
|
|
|
|
private void SoundInit()
|
|
{
|
|
switch (soundType)
|
|
{
|
|
case SoundType.Base:
|
|
{
|
|
GameObject soundManager = new GameObject("SoundManager");
|
|
soundManager.transform.SetParent(transform);
|
|
sound = soundManager.AddComponent<AudioManager>();
|
|
sound.SetResType(res);
|
|
//sound.Init(soundDirPath);
|
|
sound.Init(null);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
//private void SaveInit()
|
|
//{
|
|
// switch (saveManagerType)
|
|
// {
|
|
// case SaveManagerType.PlayerPrefs:
|
|
// {
|
|
// save = new SavePlayerPrefs();
|
|
// }
|
|
// break;
|
|
// case SaveManagerType.Text:
|
|
// {
|
|
// save = new SaveText();
|
|
// }
|
|
// break;
|
|
// }
|
|
// save?.Init(saveDirPath);
|
|
//}
|
|
|
|
private void SceneMangerInit()
|
|
{
|
|
switch (sceneManagerType)
|
|
{
|
|
case SceneManagerType.Base:
|
|
{
|
|
sceneManager = new SceneManager();
|
|
}
|
|
break;
|
|
case SceneManagerType.AssetsBundle:
|
|
{
|
|
sceneManager = new SceneABManager();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void ObjectPoolInit()
|
|
{
|
|
switch (objectPoolType)
|
|
{
|
|
case ObjectPoolType.Base:
|
|
GameObject poolManager = new GameObject("ObjectPoolManager");
|
|
poolManager.transform.SetParent(transform);
|
|
objectPool = poolManager.AddComponent<ObjectPool>();
|
|
//objectPool.SetResType(GetRes(poolResLoadType));
|
|
//objectPool.Init(poolDirPath);
|
|
objectPool.Init(null);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
private void FSMInit()
|
|
{
|
|
switch (fSMType)
|
|
{
|
|
case FSMType.Base:
|
|
fsm = new FSM();
|
|
break;
|
|
}
|
|
}
|
|
|
|
//private void HttpManagerInit()
|
|
//{
|
|
// switch (httpManagerType)
|
|
// {
|
|
// case HttpManagerType.Base:
|
|
// httpManager = new Http();
|
|
// break;
|
|
// }
|
|
//}
|
|
|
|
private void IEManagerInit()
|
|
{
|
|
switch (iEnumeratorManagerType)
|
|
{
|
|
case IEnumeratorManagerType.Base:
|
|
IEnumeratorManager = new IECoroutine();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void EventManagerInit()
|
|
{
|
|
switch (eventManagerType)
|
|
{
|
|
case EventMangerType.Base:
|
|
eventManager = new EventManager();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void UIManagerInit()
|
|
{
|
|
uiManager = new UIManager();
|
|
switch (operatingType)
|
|
{
|
|
case OperatingType.FirstPerson:
|
|
case OperatingType.Hardware:
|
|
case OperatingType.Touch:
|
|
Transform tf = transform.Find("Canvas_TouchHardware");
|
|
if (tf)
|
|
{
|
|
tf.gameObject.SetActive(true);
|
|
uiManager.Init(tf.gameObject, null);
|
|
}
|
|
break;
|
|
case OperatingType.VR:
|
|
Transform tf2 = transform.Find("Canvas_VRFP");
|
|
if (tf2)
|
|
{
|
|
tf2.gameObject.SetActive(true);
|
|
uiManager.Init(tf2.gameObject, null);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
public void AdapterInit()
|
|
{
|
|
switch (operatingType)
|
|
{
|
|
case OperatingType.FirstPerson:
|
|
adapterManager = new AdapterFirstPerson();
|
|
break;
|
|
case OperatingType.VR:
|
|
adapterManager = new AdapterVR();
|
|
break;
|
|
case OperatingType.Touch:
|
|
adapterManager = new AdapterTouch();
|
|
break;
|
|
case OperatingType.Hardware:
|
|
adapterManager = new AdapterHardware();
|
|
break;
|
|
}
|
|
adapterManager?.Init();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
fsm?.Update();
|
|
uiManager?.OnUpdate();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
fsm?.Destroy();
|
|
uiManager?.Destroy();
|
|
}
|
|
|
|
public void SendEvent(string eventName, object data = null)
|
|
{
|
|
MVC.SendEvent(eventName, data);
|
|
}
|
|
|
|
public void RegisterController(string eventName, Type controllerType)
|
|
{
|
|
MVC.RegisterController(eventName, controllerType);
|
|
}
|
|
}
|
|
}
|