| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255 |
- using UnityEngine;
- using System.Collections;
- using LuaInterface;
- using System.Collections.Generic;
- using System;
- public class GameMgr : SingletonMono<GameMgr>
- {
- public const string VersionUpdateState = "VersionUpdateState";
- public const string LoginState = "LoginState";
- public const string LoadingState = "LoadingState";
- public const string BattleState = "BattleState";
- public static int RandSeed = 100000;
- public float mGameSpeed = 1.0f;
- private bool mIsSingle = false;
- private string mGameVersion;
- public string GameVersion
- {
- get { return mGameVersion; }
- }
- private string mResVersion;
- public string ResVersion
- {
- get { return mResVersion; }
- }
- public bool IsSingle
- {
- get { return mIsSingle; }
- }
- public float GameSpeed
- {
- get { return mGameSpeed; }
- }
- private LuaFunction OnSceneLoaded2Lua;
- private LuaFunction mPlayStoryLuaFun;
- private static GameMgr instance;
- public static new GameMgr Instance
- {
- get { return instance; }
- }
- private bool mIsStartDungeon = false;
- public bool InStartDungeon
- {
- get { return mIsStartDungeon; }
- }
- private bool mIsEditorMode = false;
- public bool IsEditorMode
- {
- get { return mIsEditorMode; }
- }
- public GameObject CreateMaleRoot
- {
- get { return CreateRoleMgr.Instance.MaleRoot; }
- }
- public GameObject CreateFemaleRoot
- {
- get { return CreateRoleMgr.Instance.FemaleRoot; }
- }
- public GameObject CreateShowRoot
- {
- get { return CreateRoleMgr.Instance.ShowRoot; }
- }
- public eNetType NetStatus
- {
- get { return DeviceInfo.GetNetType(); }
- }
- private MainCharacter mCharacterInfo;
- public MainCharacter CharacterInfo
- {
- get { return mCharacterInfo; }
- }
- public string DeviceId
- {
- get { return DeviceInfo.m_deviceId; }
- }
- public string CurLangKey
- {
- get { return ConfigMgr.CurLangKey; }
- set { ConfigMgr.CurLangKey = value; }
- }
- public bool IsMobileDevice
- {
- get
- {
- #if UNITY_EDITOR
- return false;
- #elif UNITY_ANDROID || UNITY_IPHONE
- return true;
- #else
- return false;
- #endif
- }
- }
- public bool IsBadDevice
- {
- get { return DeviceInfo.m_DeviceState == DeviceInfo.eDeviceState.BAD_DEVICE; }
- }
- public bool IsNormalDevice
- {
- get { return DeviceInfo.m_DeviceState == DeviceInfo.eDeviceState.NORMAL_DEVICE; }
- }
- public bool IsGoodDevice
- {
- get { return DeviceInfo.m_DeviceState == DeviceInfo.eDeviceState.GOOD_DEVICE; }
- }
- NPack.MersenneTwister rand = null;
- private SceneType mEnterSceneType = 0;
- private BattleSubMode mbossMode = BattleSubMode.None;
- private bool bInited = false;
- private void Awake()
- {
- #if !UNITY_EDITOR
- DebugHelper.LogLevel = LogLevel.Error;
- #endif
- instance = this;
- DontDestroyOnLoad(this.gameObject);
- rand = new NPack.MersenneTwister(int.MaxValue);
- }
- bool bPaused = false;
- float mPausedTime = 0;
- private void OnApplicationFocus(bool focus)
- {
- if (bPaused && focus)
- {
- float pausePassedTime = Time.realtimeSinceStartup - mPausedTime;
- // if (pausePassedTime >= 300) //切后台5分钟网络重新连接
- // {
- // NetworkMgr.Instance.Resume();
- // }
- }
- }
- private void OnApplicationPause(bool pause)
- {
- bPaused = pause;
- if (bPaused)
- {
- mPausedTime = Time.realtimeSinceStartup;
- GameSettings.Instance.Save();
- }
- }
- protected override void OnApplicationQuit()
- {
- GameSettings.Instance.Save();
- base.OnApplicationQuit();
- }
- private void InitSDK_E()
- {
- StartCoroutine(initSdk_E());
- }
- private IEnumerator initSdk_E()
- {
- SDKMgr.Instance.Init();
- yield return null;
- }
- private void Start()
- {
- if (bInited) return;
- SDKMgr.Instance.ReportActivation(SDKMgr.Instance.GetInt64TimeStamp());
- Screen.sleepTimeout = SleepTimeout.NeverSleep;
- QualitySettings.vSyncCount = 0;
- RegisterEvents();
- #if UNITY_IOS && !UNITY_EDITOR
- InitSDK_E();
- #endif
- //InitSDK_E();
- StartDetector();
- DeviceInfo.GetDeviceState();
- if (DeviceInfo.m_DeviceState <= DeviceInfo.eDeviceState.NORMAL_DEVICE)
- {
- Application.targetFrameRate = 60;
- BattleMgr.c_updateFPS = 15;
- }
- else
- {
- Application.targetFrameRate = 60;
- BattleMgr.c_updateFPS = 30;
- }
- Input.multiTouchEnabled = false;
- //启用日志
- StartLog();
- //读取Apk设置文件
- //yield return StartCoroutine(ReadVersionFile());
- //InitData();
- //InitBuildConfig();
- //InitData();
- LaunchLoadMgr lanuchLoadMgr = new LaunchLoadMgr();
- lanuchLoadMgr.StartLaunch(OnLanuchLoadCompleted, OnAssetMapInitComplete);
- //检测非法修改
- AntiCheatMgr.Instance.GetOrCreateAnti(EnAntiCheatType.enSystemTime).Init(AntiCheatCfg.c_fTimeSysteCheckTime);
- AntiCheatMgr.Instance.GetOrCreateAnti(EnAntiCheatType.enScaleTime).Init(AntiCheatCfg.c_fTimeScaleCheckTime);
-
- bInited = true;
- }
- public void DoTaskByCorutine(Func<IEnumerator> func)
- {
- StartCoroutine(func.Invoke());
- }
- private void OnLanuchLoadCompleted(bool success)
- {
- EnterLuaLogin(false);
- }
- private void OnAssetMapInitComplete()
- {
- CheckVersion();
- InitBugly();
- }
- private void CheckVersion()
- {
- mGameVersion = Application.version;
- int versionCodeInt = 0;// Wenting.Lebian.LeBianSDK.instance.GetResVerCode();
- VersionCode versionCode1;
- if (versionCodeInt <= 0)
- {
- versionCode1 = mGameVersion;
- }
- else
- {
- versionCode1 = (VersionCode)(uint)versionCodeInt;
- }
- VersionCode versionCode2 = AssetsMgr.Instance.resVersionCode;
- if (versionCode1 < versionCode2)
- {
- mResVersion = versionCode2.ToString();
- }
- else
- {
- mResVersion = versionCode1.ToString();
- }
- }
- void InitBugly()
- {
- #if BUGLY
- #if UNITY_IPHONE || UNITY_IOS
- string channel = ""; //Wenting.Lebian.LeBianSDK.instance.GetClientChId();
- BuglyAgent.ConfigDefault(channel, mResVersion, string.Empty, 0);
- BuglyAgent.InitWithAppId("3e7f97a53b");
- BuglyAgent.EnableExceptionHandler();
- #elif UNITY_ANDROID
- string channel = "";//Wenting.Lebian.LeBianSDK.instance.GetClientChId();
- BuglyAgent.ConfigDefault(channel, mResVersion, string.Empty, 0);
- #if LEBIAN_YUN_CLIENT
- BuglyAgent.InitWithAppId("96a729256a");
- #else
- BuglyAgent.InitWithAppId("c7177b1ae7");
- #endif
- BuglyAgent.EnableExceptionHandler();
- #endif
- #endif
- }
- public void StartDetector()
- {
- DataCheatingDetector.StartDetection(OnDataCheatingDetected);
- SpeedHackDetector.StartDetection(OnSpeedHackDetected);
- }
- bool speedHackDetected = false;
- bool dataCheatingDetected = false;
- void OnDataCheatingDetected()
- {
- dataCheatingDetected = true;
- //LocalPlayerInfo.SendCheat(ECheatType.CHEAT_DATA);
- DebugHelper.LogError("Data Cheating Detected!");
- }
- void OnSpeedHackDetected()
- {
- speedHackDetected = true;
- //LocalPlayerInfo.SendCheat(ECheatType.CHEAT_SPEED);
- DebugHelper.LogError("Speed hack Detected!");
- }
- private void Update()
- {
- AntiCheatMgr.Instance.Update();
- ResourceMgr.Instance.Update();
- TimerManager.Instance.Update();
- NetworkMgr.Instance.Update();
- UpdateFPS();
- CheckIsReturnBtn();
- #if UNITY_EDITOR || OPENGM
- if (Input.GetMouseButtonDown(0))
- {
- Rect validRect = SafeRectCheck.Instance.safeArea;
- validRect.width = validRect.height * 0.025f;
- validRect.y = validRect.height + validRect.y - validRect.width;
- validRect.height = validRect.width;
- if (validRect.Contains(Input.mousePosition))
- {
- mouseDown = true;
- dragged = false;
- mouseDownTime = Time.time;
- mouseDownPos = Input.mousePosition;
- }
- else
- {
- clickCount = 0;
- }
- }
- if (mouseDown && !dragged && Vector3.Distance(Input.mousePosition, mouseDownPos) >= 5.0f)
- {
- dragged = true;
- }
- if (Input.GetMouseButtonUp(0))
- {
- if (mouseDown)
- {
- mouseDown = false;
- if (dragged)
- {
- clickCount = 0;
- }
- else
- {
- dragged = false;
- Rect validRect = SafeRectCheck.Instance.safeArea;
- validRect.width = validRect.height * 0.025f;
- validRect.y = validRect.height + validRect.y - validRect.width;
- validRect.height = validRect.width;
- if (Time.time - mouseDownTime < 2 && validRect.Contains(Input.mousePosition))
- {
- clickCount = clickCount + 1;
- if (clickCount >= 2)
- {
- clickCount = 0;
- var pLuaState = LuaMgr.GetMainState();
- if (null != pLuaState)
- {
- LuaMgr.GetMainState().DoString("local curUIId = ManagerContainer.LuaUIMgr:GetCurUIId()\nManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIGM, nil, curUIId)");
- }
- }
- }
- else
- {
- clickCount = 0;
- }
- }
- }
- }
- }
- // private void OnGUI() {
- // Rect validRect = SafeRectCheck.Instance.safeArea;
- // validRect.width = validRect.height * 0.025f;
- // validRect.y = SafeRectCheck.Instance.screenHeight - validRect.height - validRect.y;
- // validRect.height = validRect.width;
- // GUI.DrawTexture(validRect, Texture2D.whiteTexture);
- // }
- private int clickCount = 0;
- private bool mouseDown = false;
- private bool dragged = false;
- private float mouseDownTime = 0f;
- private Vector2 mouseDownPos = Vector2.zero;
- #else
- }
- #endif
- protected override void Dispose()
- {
- base.Dispose();
- }
- private const float m_FrameUpdateInterval = 0.5f;
- private float m_FrameUpdateTime = 0f;
- private float m_MaxTimeAccumulator = 0;
- private int m_FrameCounter = 0;
- private int m_MaxFrameTime = 0;
- public int maxFrameTime
- {
- get { return m_MaxFrameTime; }
- }
- private void UpdateFPS()
- {
- float deltaTime = Time.deltaTime;
- if (deltaTime > 0)
- {
- m_FrameUpdateTime -= deltaTime;
- m_MaxTimeAccumulator += Time.timeScale / deltaTime;
- m_FrameCounter++;
- }
- if (m_FrameUpdateTime <= 0)
- {
- m_MaxFrameTime = Mathf.RoundToInt(m_MaxTimeAccumulator / m_FrameCounter);
- m_FrameUpdateTime = m_FrameUpdateInterval;
- m_MaxTimeAccumulator = 0;
- m_FrameCounter = 0;
- }
- }
- private void CheckIsReturnBtn()
- {
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- mOnClickReturnBtn.Call(this);
- }
- }
- void EnterLuaLogin(bool relogin)
- {
- if (mCharacterInfo == null)
- {
- mCharacterInfo = new MainCharacter();
- }
- LuaMgr.Instance.EnterLogin(relogin);
- }
- void DisposeCharactorInfo()
- {
- mCharacterInfo.Dispose();
- mCharacterInfo = null;
- }
- void OnLogout(CoreEvent<int> ce)
- {
- }
- public void SetOnSceneLoadedLuaFunc(LuaFunction func)
- {
- OnSceneLoaded2Lua = func;
- }
- public void ReLogin()
- {
- ShutDownBattle(false);//清空战斗数据 逻辑 (等待loading界面完成 清空战斗实例)
- DisposeCharactorInfo();
- EnterLuaLogin(true);
- }
- public void ReLoginClearData()
- {
- ClearMainCharacter();
- ActorDataMgr.Instance.Clear();
- DisposeBattle();//销毁战斗实例
- BattleMgr.Instance.ClearSkillDirty();//销毁待更新技能
- SceneMgr.Instance.LoadMainScene("relogin");
- }
- void ClearMainCharacter()
- {
- if (mCharacterInfo != null)
- {
- mCharacterInfo.Clear();
- }
- }
- public void SetLuaPlayStoryFunc(LuaFunction func)
- {
- mPlayStoryLuaFun = func;
- }
- public void LoadCurrentBattle()
- {
- GameStateCtrl.Instance.GotoState(LoadingState);
- }
- public void CloseLoading()
- {
- if (BattleMgr.Instance.Battle == null) return;
- if (BattleMgr.Instance.Battle.IsBossBattle && BattleMgr.Instance.Battle.SubBattleMode == BattleSubMode.NewbieBoss)
- {
- BattleMgr.Instance.StartStoryScript();
- }
- }
- public void SetTeamData(LuaTable teamParam, LuaTable tbIsForce)
- {
- if (mCharacterInfo != null)
- {
- mCharacterInfo.SetTeamActors(teamParam);
- bool bIsForce = false;//是否强制同步
- if (tbIsForce[1] != null)
- {
- bool.TryParse(tbIsForce[1].ToString(), out bIsForce);
- }
- BattleMgr.Instance.SyncTeams(bIsForce);
- }
- }
- public void RefreshTeamData()
- {
- for (int idx = 0; idx < mCharacterInfo.TeamActors.Count; idx++)
- {
- ActorDataMgr.Instance.RefreshFellowActorData(mCharacterInfo.TeamActors[idx].ID, mCharacterInfo.TeamActors[idx].BaseId);
- }
- }
- public void UpdateTeamSkills(LuaTable skillsParam)
- {
- if (mCharacterInfo != null)
- {
- BattleMgr.Instance.UpdateTeamSkills(skillsParam);
- }
- }
- /// <summary>
- /// 完成角色创建
- /// </summary>
- /// <param name="modelGo"></param>
- public void CreateRoleViewComplete(GameObject modelGo)
- {
- BattleMgr.Instance.OnLoadRoleCompleted(modelGo, false, false);
- }
- /// <summary>
- /// 角色形象更新完成
- /// </summary>
- /// <param name="modelGo"></param>
- public void RefreshRoleViewComplete(GameObject modelGo, bool isNew)
- {
- BattleMgr.Instance.OnLoadRoleCompleted(modelGo, true, isNew);
- }
- /// <summary>
- /// 时装或者其它功能更新了角色形象,战斗内需要自行调用形象更新 参数 是否为转职后的新角色
- /// </summary>
- public void NotifyRefreshRoleView()
- {
- BattleMgr.Instance.NotifyRefreshRoleView();
- }
- public void SetMapLevelId(int mapId, int levelId)
- {
- if (mCharacterInfo == null) return;
- if (mCharacterInfo.CurMapId != mapId)
- {
- mCharacterInfo.CurMapId = mapId;
- mCharacterInfo.CurLevelId = levelId;
- }
- else
- {
- if (mCharacterInfo.CurLevelId != levelId)
- {
- mCharacterInfo.CurLevelId = levelId;
- BattleMgr.Instance.EnterNextBattle();
- }
- }
- //BattleMgr.Instance?.SetMapLevelId(mapId,levelId);
- Debug.Log($"=========SetMapLevelId============={mCharacterInfo.CurMapId} --- {mCharacterInfo.CurLevelId}");
- }
- public void PreloadCreateRoleScene()
- {
- mEnterSceneType = SceneType.CreateRoleScene;
- CreateRoleMgr.Instance.LoadScene();
- }
- public void GotoLogin()
- {
- BattleMgr.Instance.ShutDownCurrentBattle();
- }
- //进入公会大厅
- public void PreloadGuildLobby()
- {
- mEnterSceneType = SceneType.GuildLobbyScene;
- BattleMgr.Instance.ShutDownCurrentBattle();
- GuildLobbyMgr.Instance.EnterGuildLobby();
- }
- public void PreloadAllFellows(ActorData[] actors)
- {
- if (actors == null || actors.Length == 0) return;
- for (int idx = 0; idx < actors.Length; idx++)
- {
- var actor = actors[idx];
- if (actor != null)
- {
- BattlePrepareManager.Instance.PrecacheModel(actor.AvatarData.prefab, actor.AType);
- BattlePrepareManager.Instance.PrecacheAnimatorCtrl(actor.ShowAnimCtrlName);
- }
- }
- }
- public void PreloadBattle(LuaTable teamParam)
- {
- mEnterSceneType = SceneType.NormalBattleScene;
- GuildLobbyMgr.Instance.Clear();
- mCharacterInfo.SetTeamActors(teamParam);
- LogicBattleStartInfo startInfo = new LogicBattleStartInfo(mCharacterInfo.CurMapId, mCharacterInfo.CurLevelId);
- Debug.Log($"============PreloadBattle=========={mCharacterInfo.CurMapId} --- {mCharacterInfo.CurLevelId}");
- BattleMgr.Instance.ShutDownCurrentBattle();
- BattleMgr.Instance.StartBattle(startInfo);
- }
- public List<ActorData> StartNewbieBossBattle(int sceneId, int roleSex)
- {
- mEnterSceneType = SceneType.BossBattleScene;
- BattleMgr.Instance.ShutDownCurrentBattle();
- return BattleMgr.Instance.StartNewbieBossBattle(sceneId, roleSex);
- }
- public void PreloadViewTeam(ActorData[] teamActors, string sceneName, LuaTable tbl)
- {
- mEnterSceneType = SceneType.TowerBattleScene;
- BattleMgr.Instance.ShutDownCurrentBattle();
- PreviewTeamMgr.Instance.LoadPreviewActorsAndScene(teamActors, sceneName, tbl);
- }
- public void PreloadVersusBattle(BattleSubMode mode,
- ActorData[] teamActors,
- ActorData[] enemyActors,
- string sceneName,
- float maxFightingTime,
- BattleEndCondition[] endConds,
- GvGMark[] OurMarks,
- GvGMark[] EnemyMarks,
- bool IsPresspoint,
- int nPresspoint)
- {
- mEnterSceneType = SceneType.TowerBattleScene;
- BattleMgr.Instance.ShutDownCurrentBattle();
- BattleMgr.Instance.StartVersusBattle(mode, teamActors, enemyActors, sceneName, maxFightingTime, endConds, OurMarks, EnemyMarks, IsPresspoint, nPresspoint);
- }
- public void PreloadBossBattle(ActorData[] actors,
- int bossId,
- int sceneId,
- BattleEndCondition[] endConds)
- {
- mEnterSceneType = SceneType.BossBattleScene;
- BattleMgr.Instance.ShutDownCurrentBattle();
- BattleMgr.Instance.StartBossBattle(actors, bossId, sceneId, endConds);
- }
- public bool PreloadTimeBattle(LuaTable luaTbl,
- BattleSubMode mode,
- float maxFightingTime,
- string sceneName,
- string bgmMusic,
- ActorData[] ourActors,
- ActorData[] enemyActors,
- ServerFighterParam[] fighterParams,
- BattleEndCondition[] endConds,
- ValType[] factors,
- int nRestoreSp,
- GvGMark[] OurMarks,
- GvGMark[] EnemyMarks
- )
- {
- mEnterSceneType = SceneType.TimeBattleScene;
- return BattleMgr.Instance.StartTimeBattle(luaTbl, mode, maxFightingTime, sceneName, bgmMusic, ourActors, enemyActors, fighterParams, endConds, factors, nRestoreSp, OurMarks, EnemyMarks);
- }
- public bool ReplayTimeBattle(LuaTable luaTbl, BattleSubMode mode, float maxFightingTime, string sceneName, string bgmMusic, string battleRecordStr)
- {
- mEnterSceneType = SceneType.TimeBattleScene;
- return BattleMgr.Instance.ReplayTimeBattle(luaTbl, mode, maxFightingTime, sceneName, bgmMusic, battleRecordStr);
- }
- public void ForceStopBattle()
- {
- BattleMgr.Instance.ForceStopBattle();
- }
- //关闭清空战斗
- public void ShutDownBattle(bool bIsDispose = true)
- {
- BattleMgr.Instance.ShutDownCurrentBattle(bIsDispose);
- }
- //销毁战斗
- public void DisposeBattle()
- {
- BattleMgr.Instance.DisposeCurrentBattle();
- }
- public void SetGameSpeed(float speed)
- {
- BattleMgr.Instance.SetSpeedUp(speed);
- }
- public void SaveGameSpeed(float speed)
- {
- mGameSpeed = speed;
- BattleMgr.Instance.SetSpeedUp(speed);
- }
- public float GetGameSpeed()
- {
- return BattleMgr.speed_up_rate;
- }
- private void OnLoadComplete(CoreEvent<bool> ce)
- {
- #if USE_LUA
- if (OnSceneLoaded2Lua != null)
- {
- OnSceneLoaded2Lua.Call(this, mEnterSceneType, BattleMgr.Instance.Battle != null ? BattleMgr.Instance.Battle.SubBattleMode : BattleSubMode.None);
- }
- #else
- EnterBattleState();
- #endif
- }
- public int Random(int min, int max)
- {
- return max > min ? rand.Next(min, max) : min;
- }
- public uint CalcPassedTime(long timeStr)
- {
- ulong time = (ulong)timeStr;
- time = TimerManager.Instance.serverTime - time;
- if (time > uint.MaxValue)
- {
- return uint.MaxValue;
- }
- else if (time < 0)
- {
- return 0;
- }
- else
- {
- return (uint)time;
- }
- }
- public void QuitGame(bool isShowView = false)
- {
- //需要打开退出页面
- if (isShowView)
- {
- //如果sdk有就打开
- if (SDKMgr.Instance.CheckHasModul(SDKModulType.EXIT_VIEW))
- {
- SDKMgr.Instance.OpenModul(SDKModulType.EXIT_VIEW);
- }
- else
- {
- if (!SDKMgr.Instance.Exit())
- {
- KillApplication();
- }
- }
- }
- else
- {
- if (!SDKMgr.Instance.Exit())
- {
- KillApplication();
- }
- }
- }
- private void KillApplication()
- {
- // 游戏需要保存数据的在这里保存
- GameSettings.Instance.Save();
- if (SDKMgr.Instance.Quit()) return;
- #if UNITY_EDITOR
- UnityEditor.EditorApplication.isPlaying = false;
- #else
- Application.Quit();
- #endif
- }
- public void PlayDialog(int dialogueType, int dialogueId = 0)
- {
- if (mPlayStoryLuaFun != null)
- mPlayStoryLuaFun.Call(this, dialogueType, dialogueId);
- }
- public void RequestHttpServer(string url, LuaFunction luaFunc_)
- {
- StartCoroutine(DoRequestHttpServer(url, luaFunc_));
- }
- IEnumerator DoRequestHttpServer(string url, LuaFunction luaFunc_)
- {
- if (string.IsNullOrEmpty(url))
- {
- yield break;
- }
- WWW httpReq = new WWW(url);
- yield return httpReq;
- if (!string.IsNullOrEmpty(httpReq.error))
- {
- DebugHelper.LogError("DoRequestHttpServer failed:{0}[url = {1}]", httpReq.error,url);
- httpReq.Dispose();
- httpReq = null;
- yield break;
- }
- string content = httpReq.text;
- httpReq.Dispose();
- httpReq = null;
- if (luaFunc_ != null)
- {
- luaFunc_.Call(content);
- }
- }
- public void CleanUnusedAssets()
- {
- StartCoroutine(UnloadAssets_Coroutine());
- }
- public void OpenUrl(string url)
- {
- if (string.IsNullOrEmpty(url)) return;
- SDKMgr.Instance.OpenWebview(url);
- //Application.OpenURL(url);
- }
- public void EnableAntiAliasing()
- {
- if (DeviceInfo.m_DeviceState == DeviceInfo.eDeviceState.NORMAL_DEVICE)
- {
- QualitySettings.antiAliasing = 2;
- }
- else if (DeviceInfo.m_DeviceState == DeviceInfo.eDeviceState.GOOD_DEVICE)
- {
- QualitySettings.antiAliasing = 4;
- }
- //DebugHelper.LogError("antiAliasing" + QualitySettings.antiAliasing);
- }
- public void DisableAntiAliasing()
- {
- QualitySettings.antiAliasing = 0;
- //DebugHelper.LogError("antiAliasing" + QualitySettings.antiAliasing);
- }
- IEnumerator UnloadAssets_Coroutine()
- {
- yield return 0;
- yield return Resources.UnloadUnusedAssets();
- System.GC.Collect();
- }
- #region inner_methods
- private void RegisterEvents()
- {
- EventMgr.AddEventListener<int>(ECoreEventType.EID_Logout, OnLogout);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_LOAD_COMPLETE, OnLoadComplete);
- //EventMgr.AddEventListener<bool,string>(ECoreEventType.EID_SDK_INIT_RESULT, OnSdkInitRet);
- //EventMgr.AddEventListener<bool, UserInfo>(ECoreEventType.EID_SDK_LOGIN_RESULT_NEW, OnSdkLoginRet);
- //EventMgr.AddEventListener<bool, UserInfo>(ECoreEventType.EID_SDK_SWITCH_ACCOUNT_NEW, OnSdkSwitchAccount);
- //EventMgr.AddEventListener<bool>(ECoreEventType.EID_SDK_LOGOUT, OnSdkLogout);
- //EventMgr.AddEventListener<bool>(ECoreEventType.EID_SDK_EXIT, OnSdkExit);
- //EventMgr.AddEventListener<bool>(ECoreEventType.EID_SDK_PAY_SUCCESS, OnSdkPaySuccess);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_SDK_PAY_CANCEL, OnSdkPayCancel);
- //EventMgr.AddEventListener<bool>(ECoreEventType.EID_SDK_PAY_FAILED, OnSdkPayFailed);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_SDK_QUESTION_REWARD_RESULT, OnSdkQuestionRewardResult);
- SDKEventUtil.AddListener(SDKCBEnum.EXIT_SUCCESS_CB, OnSdkExit);
- SDKEventUtil.AddListener(SDKCBEnum.INIT_FAILED_CB, OnSdkInitFail);
- SDKEventUtil.AddListener(SDKCBEnum.INIT_SUCCESS_CB, OnSdkInitSuccess);
- SDKEventUtil.AddListener(SDKCBEnum.LOGIN_FAILED_CB, OnSdkLoginFail);
- SDKEventUtil.AddListener(SDKCBEnum.LOGIN_SUCCESS_CB, OnSdkLoginSuccess);
- SDKEventUtil.AddListener(SDKCBEnum.LOGOUT_SUCCESS_CB, OnSdkLogoutSuccess);
- SDKEventUtil.AddListener(SDKCBEnum.PAY_FAILED_CB, OnSdkPayFailed);
- SDKEventUtil.AddListener(SDKCBEnum.PAY_SUCCESS_CB, OnSdkPaySuccess);
- SDKEventUtil.AddListener(SDKCBEnum.SWITCH_FAILED_CB, OnSdkSwitchAccountFailed);
- SDKEventUtil.AddListener(SDKCBEnum.SWITCH_SUCCESS_CB, OnSdkSwitchAccountSuccess);
- SDKEventUtil.AddListener(SDKCBEnum.CAN_ENTER_SERVER_JUDGE_CB, OnSdkCanEnterServerJudge);
- }
- private void UnRegisterEvents()
- {
- EventMgr.RemoveEventListener<int>(ECoreEventType.EID_Logout, OnLogout);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_LOAD_COMPLETE, OnLoadComplete);
- //EventMgr.RemoveEventListener<bool,string>(ECoreEventType.EID_SDK_INIT_RESULT, OnSdkInitRet);
- //EventMgr.RemoveEventListener<bool, UserInfo>(ECoreEventType.EID_SDK_LOGIN_RESULT_NEW, OnSdkLoginRet);
- //EventMgr.RemoveEventListener<bool, UserInfo>(ECoreEventType.EID_SDK_SWITCH_ACCOUNT_NEW, OnSdkSwitchAccount);
- //EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_SDK_LOGOUT, OnSdkLogout);
- //EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_SDK_EXIT, OnSdkExit);
- //EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_SDK_PAY_SUCCESS, OnSdkPaySuccess);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_SDK_PAY_CANCEL, OnSdkPayCancel);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_SDK_PAY_FAILED, OnSdkPayFailed);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_SDK_QUESTION_REWARD_RESULT, OnSdkQuestionRewardResult);
- SDKEventUtil.RemoveListener(SDKCBEnum.EXIT_SUCCESS_CB, OnSdkExit);
- SDKEventUtil.RemoveListener(SDKCBEnum.INIT_FAILED_CB, OnSdkInitFail);
- SDKEventUtil.RemoveListener(SDKCBEnum.INIT_SUCCESS_CB, OnSdkInitSuccess);
- SDKEventUtil.RemoveListener(SDKCBEnum.LOGIN_FAILED_CB, OnSdkLoginFail);
- SDKEventUtil.RemoveListener(SDKCBEnum.LOGIN_SUCCESS_CB, OnSdkLoginSuccess);
- SDKEventUtil.RemoveListener(SDKCBEnum.LOGOUT_SUCCESS_CB, OnSdkLogoutSuccess);
- SDKEventUtil.RemoveListener(SDKCBEnum.PAY_FAILED_CB, OnSdkPayFailed);
- SDKEventUtil.RemoveListener(SDKCBEnum.PAY_SUCCESS_CB, OnSdkPaySuccess);
- SDKEventUtil.RemoveListener(SDKCBEnum.SWITCH_FAILED_CB, OnSdkSwitchAccountFailed);
- SDKEventUtil.RemoveListener(SDKCBEnum.SWITCH_SUCCESS_CB, OnSdkSwitchAccountSuccess);
- SDKEventUtil.RemoveListener(SDKCBEnum.CAN_ENTER_SERVER_JUDGE_CB, OnSdkCanEnterServerJudge);
- }
- private void StartLog()
- {
- DebugHelper debugHelper = this.gameObject.GetComponent<DebugHelper>();
- if (debugHelper == null)
- {
- this.gameObject.AddComponent<DebugHelper>();
- }
- DebugHelper.enableLog = true;
- DebugHelper.BeginLogs();
- }
- private IEnumerator ReadVersionFile()
- {
- string path = FileSystem.LocalPackagePath;
- #if !UNITY_STANDALONE_WIN
- #if UNITY_EDITOR //editor
- path = string.Format("{0}/", Application.dataPath);
- #elif UNITY_ANDROID && !UNITY_EDITOR//android release;
- path = FileSystem.LocalPackagePath;
- #elif UNITY_IPHONE && !UNITY_EDITOR //ios release;
- path = FileSystem.LocalPackagePath;
- #else //pc release;
- path = Application.dataPath;
- #endif
- #else
- path = FileSystem.LocalPackagePath;
- #endif
- //热更地址从新整合的配置中提取
- string UpdateFilePath = string.Format("{0}appbuildconfig.xml", path);
- WWW www = new WWW(UpdateFilePath);
- DebugHelper.Log("ReadUpdateFile : LocalPackagePath {0}", UpdateFilePath);
- yield return www;
- if (www.error == null)
- {
- DebugHelper.Log("ReadUpdateFile : {0}", www.text);
- www.Dispose();
- www = null;
- }
- else
- {
- DebugHelper.LogError("ReadUpdateFile {0} , {1}", www.error, UpdateFilePath);
- www.Dispose();
- www = null;
- }
- }
- #endregion
- #region ACCOUNT_SDK
- //private SDKMgr SdkManager = SDKMgr.Instance;
- private LuaFunction mSdkInitedLuaCB = null;
- private LuaFunction mSdkLoginedLuaCB = null;
- private LuaFunction mSdkLogoutLuaCB = null;
- private LuaFunction mSdkPayLuaCB = null;
- private LuaFunction msdkQuestionLuaCB = null;
- private LuaFunction mSdkCanEnterServerJudgeCB = null;
- private LuaFunction mOnClickReturnBtn = null;
- public void SdkInitFunc(LuaFunction func)
- {
- mSdkInitedLuaCB = func;
- //mSdkInitedLuaCB.Call(this, true, "");
- }
- public void SdkLoginFunc(LuaFunction func)
- {
- mSdkLoginedLuaCB = func;
- }
- public void SdkLogoutFunc(LuaFunction func)
- {
- mSdkLogoutLuaCB = func;
- }
- public void SdkPayFunc(LuaFunction func)
- {
- mSdkPayLuaCB = func;
- }
- public void SdkQuestionFunc(LuaFunction func)
- {
- msdkQuestionLuaCB = func;
- }
- public void SdkCanEnterServerJudgeFunc(LuaFunction func)
- {
- mSdkCanEnterServerJudgeCB = func;
- }
- public void SetmOnClickReturnBtnCb(LuaFunction cb)
- {
- mOnClickReturnBtn = cb;
- }
- public void SdkInit()
- {
- SDKMgr.Instance.Init();
- }
- public void SdkLogin()
- {
- SDKMgr.Instance.Login();
- }
- public void SdkPay(int goodsId, string goodsName, string goodsDesc,
- int count, float amount,
- string cpOrderId, string extrasParams)
- {
-
- int decimalVal = 1000;
- int tempVal = Mathf.FloorToInt((amount + 0.0005f) * decimalVal);
- amount = (float)tempVal / decimalVal;
- if (string.IsNullOrEmpty(goodsName))
- {
- goodsName = "初心者";
- }
- SDKMgr.Instance.Pay(goodsId, goodsName, goodsDesc,
- count, amount,
- cpOrderId, extrasParams);
- //Debug.Log($"goodsId = {goodsId} ==== goodsName = {goodsName} ===== goodsDesc = {goodsDesc} ===== count = {count} ===== amount = {amount} ====== cpOrderId = {cpOrderId} ==== extrasParams = {extrasParams}");
- }
- public void SdkLogout()
- {
- SDKMgr.Instance.Logout();
- }
- public void SdkExit()
- {
- }
- public void SdkShowToolbar()
- {
- //int ret = quicksdk.QuickSDK.getInstance().showToolBar(quicksdk.ToolbarPlace.QUICK_SDK_TOOLBAR_MID_LEFT);
- //DebugHelper.LogError("SdkShowToolbar:" + ret);
- }
- public void SdkHideToolBar()
- {
- //SdkManager.SdkHideToolBar();
- }
- private void OnSdkInitFail(object obj)
- {
- if (mSdkInitedLuaCB != null)
- {
- mSdkInitedLuaCB.Call(this, false, SDKMgr.Instance.GetSDKName());
- }
- }
- private void OnSdkInitSuccess(object obj)
- {
- if (mSdkInitedLuaCB != null)
- {
- mSdkInitedLuaCB.Call(this, true, SDKMgr.Instance.GetSDKName());
- }
- }
- private void OnSdkLoginFail(object obj)
- {
- if (mSdkLoginedLuaCB != null)
- {
- mSdkLoginedLuaCB.Call(this, false, "", "", false);
- SDKMgr.Instance.ReportRoleEnterFail();
- }
- }
- private void OnSdkLoginSuccess(object obj)
- {
- if (mSdkLoginedLuaCB != null)
- {
- if (obj != null)
- {
- UserInfo userInfo = (UserInfo)obj;
- mSdkLoginedLuaCB.Call(this, true, userInfo.uid, userInfo.token, false);
- SDKMgr.Instance.ReportIdentification(SDKMgr.Instance.GetInt64TimeStamp());
- }
- else
- {
- mSdkLoginedLuaCB.Call(this, true, "", "", false);
- }
- }
- }
- private void OnSdkSwitchAccountFailed(object obj)
- {
- if (mSdkLoginedLuaCB != null)
- {
- UserInfo userInfo = (UserInfo)obj;
- mSdkLoginedLuaCB.Call(this, false, userInfo.uid, userInfo.token, true);
- }
- }
- private void OnSdkSwitchAccountSuccess(object obj)
- {
- if (mSdkLoginedLuaCB != null)
- {
- UserInfo userInfo = (UserInfo)obj;
- mSdkLoginedLuaCB.Call(this, true, userInfo.uid, userInfo.token, true);
- }
- }
- private void OnSdkLogoutSuccess(object obj)
- {
- if (mSdkLogoutLuaCB != null)
- {
- mSdkLogoutLuaCB.Call(this);
- }
- }
- private void OnSdkExit(object obj)
- {
- KillApplication();
- }
- private void OnSdkPaySuccess(object obj)
- {
- if (mSdkPayLuaCB != null)
- {
- mSdkPayLuaCB.Call(this, true);
- }
- }
- private void OnSdkPayCancel(CoreEvent<bool> ce)
- {
- if (mSdkPayLuaCB != null)
- {
- mSdkPayLuaCB.Call(this, false);
- }
- }
- private void OnSdkPayFailed(object obj)
- {
- if (mSdkPayLuaCB != null)
- {
- mSdkPayLuaCB.Call(this, false);
- }
- }
- private void OnSdkQuestionRewardResult(CoreEvent<bool> ce)
- {
- if (msdkQuestionLuaCB != null)
- {
- msdkQuestionLuaCB.Call(this, true);
- }
- }
- private void OnSdkCanEnterServerJudge(object obj)
- {
- if (mSdkCanEnterServerJudgeCB != null)
- {
- mSdkCanEnterServerJudgeCB.Call(this, "" + obj);
- }
- }
- #endregion
- #region 新加
- private Dictionary<int, int> mDifAttrs = new Dictionary<int, int>();
- public void ClearDifAttr()
- {
- mDifAttrs.Clear();
- }
- public void AddDifAttr(int type,int attr)
- {
- mDifAttrs.Add(type, attr);
- }
- public void AddDifAttrs(Dictionary<object, object> difAttrs)
- {
- foreach (var item in difAttrs)
- {
- mDifAttrs.Add((int)item.Key,(int)item.Value);
- }
- }
- public Dictionary<int, int> GetDifAttrs()
- {
- return mDifAttrs;
- }
- #endregion
- }
|