| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241 |
- 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();
- #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;
- }
- }
- 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;
- 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 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
- }
|