using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine.Events;
|
using UnityEngine;
|
|
|
public class SnxxzGame : SingletonMonobehaviour<SnxxzGame>
|
{
|
private event UnityAction m_UpdateActions;
|
private event UnityAction m_LateUpdateActions;
|
private event UnityAction m_OnDrawGizmosActions;
|
private event UnityAction onApplicationOutEvent;
|
|
private void Awake()
|
{
|
#if UNITY_EDITOR
|
gameObject.AddMissingComponent<RuntimeLogUtility>();
|
#endif
|
|
TargetBriefInfo.Init();
|
ExperienceGetBehaviour.Init();
|
SpGetBehaviour.Init();
|
BossAreaMark.Init();
|
HeroNearDeathBehaviour.Init();
|
HeroRoundGird.Instance.Init(40, 40);
|
}
|
|
private void Update()
|
{
|
float _realTime = Time.realtimeSinceStartup;
|
Vector4 _timeVec4 = new Vector4(_realTime * .05f, _realTime, _realTime * 2f, _realTime * 3f);
|
Shader.SetGlobalVector("_RealTime", _timeVec4);
|
|
if (m_UpdateActions != null)
|
{
|
m_UpdateActions();
|
}
|
}
|
|
private void LateUpdate()
|
{
|
if (m_LateUpdateActions != null)
|
{
|
m_LateUpdateActions();
|
}
|
}
|
|
#if UNITY_EDITOR
|
private void OnDrawGizmos()
|
{
|
if (m_OnDrawGizmosActions != null)
|
{
|
m_OnDrawGizmosActions();
|
}
|
|
Gizmos.color = Color.black;
|
|
if (RuntimeLogUtility.s_ShowMapLine)
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
int row = 50;
|
int column = 50;
|
float size = 0.5f;
|
|
float _startX = (int)_hero.Pos.x - 12.5f;
|
float _startZ = (int)_hero.Pos.z - 12.5f;
|
|
if (_hero != null)
|
{
|
Vector3 _start;
|
Vector3 _end;
|
|
for (int i = 0; i < row + 1; ++i)
|
{
|
_start = new Vector3(_startX, _hero.Pos.y + 0.001f, _startZ + i * size);
|
_end = new Vector3(_startX + column * .5f, _hero.Pos.y + 0.001f, _startZ + i * size);
|
|
Gizmos.DrawLine(_start, _end);
|
}
|
|
for (int i = 0; i < column + 1; ++i)
|
{
|
_start = new Vector3(_startX + i * size, _hero.Pos.y + 0.001f, _startZ);
|
_end = new Vector3(_startX + i * size, _hero.Pos.y + 0.001f, _startZ + row * .5f);
|
|
Gizmos.DrawLine(_start, _end);
|
}
|
}
|
}
|
}
|
#endif
|
|
protected sealed override void OnDestroy()
|
{
|
base.OnDestroy();
|
m_UpdateActions = null;
|
m_LateUpdateActions = null;
|
m_OnDrawGizmosActions = null;
|
}
|
|
public void AddUpdateAction(UnityAction method)
|
{
|
m_UpdateActions += method;
|
}
|
|
public void RemoveUpdateAction(UnityAction method)
|
{
|
m_UpdateActions -= method;
|
}
|
|
public void AddLateUpdateAction(UnityAction method)
|
{
|
m_LateUpdateActions += method;
|
}
|
|
public void RemoveLateUpdateAction(UnityAction method)
|
{
|
m_LateUpdateActions -= method;
|
}
|
|
public void AddOnDrawGizmosAction(UnityAction method)
|
{
|
m_OnDrawGizmosActions += method;
|
}
|
|
public void RemoveOnDrawGizmosAction(UnityAction method)
|
{
|
m_OnDrawGizmosActions -= method;
|
}
|
|
public void AddApplicationOutAction(UnityAction method)
|
{
|
onApplicationOutEvent += method;
|
}
|
|
public void RemoveApplicationOutAction(UnityAction method)
|
{
|
onApplicationOutEvent -= method;
|
}
|
|
public void StartTimePause(float lastTime)
|
{
|
StopTimePause();
|
StartCoroutine("DoTimePause", lastTime);
|
}
|
|
private void StopTimePause()
|
{
|
StopCoroutine("TimePause");
|
Time.timeScale = 1;
|
}
|
|
private IEnumerator DoTimePause(float lastTime)
|
{
|
Time.timeScale = 0;
|
float _startTime = Time.realtimeSinceStartup;
|
while (Time.realtimeSinceStartup - _startTime < lastTime)
|
{
|
yield return null;
|
}
|
Time.timeScale = 1;
|
}
|
|
private void OnApplicationQuit()
|
{
|
if (MaterialUtility.m_HudMaterial != null)
|
{
|
MaterialUtility.m_HudMaterial.SetTexture("_Tex1", null);
|
MaterialUtility.m_HudMaterial.SetTexture("_Tex2", null);
|
}
|
|
GameNetSystem.Instance.Disconnect();
|
|
if (onApplicationOutEvent != null)
|
{
|
onApplicationOutEvent();
|
}
|
}
|
|
private void OnApplicationPause(bool pause)
|
{
|
if (!Application.isEditor)
|
{
|
if (!pause)
|
{
|
ResolutionUtility.AdjustResolution();
|
}
|
}
|
}
|
|
private void OnApplicationFocus(bool focus)
|
{
|
if (focus)
|
{
|
PlayerDatas.Instance.RequestWorldTick();
|
ynmbxxjUtil.Instance.SendShowFloatWin();
|
}
|
else
|
ynmbxxjUtil.Instance.SendHideFloatWin();
|
}
|
|
public void MovingCamera(bool start, int type)
|
{
|
if (start)
|
{
|
StartCoroutine("Co_MovingCamera", type);
|
}
|
else
|
{
|
StopCoroutine("Co_MovingCamera");
|
}
|
}
|
|
public void ResetCamera(bool start)
|
{
|
if (start)
|
{
|
StartCoroutine("Co_ResetCamera");
|
}
|
else
|
{
|
StopCoroutine("Co_ResetCamera");
|
}
|
}
|
|
public void StopAllCameraCo()
|
{
|
StopCoroutine("Co_ResetCamera");
|
StopCoroutine("Co_MovingCamera");
|
}
|
|
private IEnumerator Co_MovingCamera(int _type)
|
{
|
var _areaCamera = AreaCameraConfig.Get(_type);
|
|
if (_areaCamera == null
|
|| GA_Hero.s_MapSwitching)
|
{
|
yield break;
|
}
|
|
CameraController.Instance.AcceptInput = true;
|
|
CameraController.Instance.ZoomDamping = 0.5f;
|
CameraController.Instance.RotationDamping = 0.5f;
|
|
CameraController.Instance.sceneDistance = CameraController.Instance.Distance = _areaCamera.Distance * Constants.F_DELTA;
|
CameraController.Instance.rotationX = _areaCamera.RotX * Constants.F_DELTA;
|
CameraController.Instance.rotationY = _areaCamera.RotY * Constants.F_DELTA;
|
|
float _time = 2f;
|
while (_time > 0 && !GA_Hero.s_MapSwitching)
|
{
|
_time -= Time.deltaTime;
|
yield return null;
|
}
|
|
if (GA_Hero.s_MapSwitching)
|
{
|
yield break;
|
}
|
|
CameraController.Instance.AcceptInput = false;
|
|
CameraController.Instance.Distance = _areaCamera.Distance * Constants.F_DELTA;
|
CameraController.Instance.rotationX = _areaCamera.RotX * Constants.F_DELTA;
|
CameraController.Instance.rotationY = _areaCamera.RotY * Constants.F_DELTA;
|
|
CameraController.Instance.ZoomDamping = 0.1f;
|
CameraController.Instance.RotationDamping = 0.02f;
|
}
|
|
private IEnumerator Co_ResetCamera()
|
{
|
CameraController.Instance.AcceptInput = true;
|
|
CameraController.Instance.ZoomDamping = 0.5f;
|
CameraController.Instance.RotationDamping = 0.5f;
|
|
CameraController.Instance.sceneDistance = CameraController.Instance.Distance = 9;
|
CameraController.Instance.rotationX = -45;
|
CameraController.Instance.rotationY = 40;
|
|
float _time = 2f;
|
while (_time > 0)
|
{
|
_time -= Time.deltaTime;
|
yield return null;
|
}
|
|
CameraController.Instance.AcceptInput = false;
|
|
CameraController.Instance.Distance = 9;
|
CameraController.Instance.rotationX = -45;
|
CameraController.Instance.rotationY = 40;
|
|
CameraController.Instance.ZoomDamping = 0.1f;
|
CameraController.Instance.RotationDamping = 0.02f;
|
}
|
}
|