private byte[] EngineReadFileProxy(string filePath) { try { // Todo: load from bundle #if LoadDataTableFromCache filePath = Path.GetFullPath(filePath).ToLower(); byte[] bytes; if (CachedTables.TryGetValue(filePath, out bytes)) { return(bytes); } else { return(null); } #else byte[] buffer = null; buffer = File.ReadAllBytes(filePath); return(buffer); #endif } catch (Exception e) { LogicSystem.LogErrorFromGfx("Exception:{0}\n{1}", e.Message, e.StackTrace); return(null); } }
internal void Update() { try { // if we are fisrt time start game, extract and loading game first if (!m_IsDataFileExtracted && !m_IsDataFileExtractedPaused) { StartCoroutine(HandleGameLoading()); m_IsDataFileExtracted = true; } // if fully initialized, tick game if (m_IsInit) { // only for debug { bool isLastHitUi = (UICamera.lastHit.collider != null); LogicSystem.IsLastHitUi = isLastHitUi; //DebugConsole.IsLastHitUi = isLastHitUi; } #if UNITY_WEBGL m_WebSocket.Tick(); #endif GameControler.TickGame(); ScriptManager.Instance.Tick(true); } // Todo: try move to ui root ClickNpcManager.Instance.Tick(); } catch (Exception ex) { LogicSystem.LogErrorFromGfx("GameLogic.Update throw exception:{0}\n{1}", ex.Message, ex.StackTrace); Debug.LogError(string.Format("GameLogic.Update throw exception:{0}\n{1}", ex.Message, ex.StackTrace)); } // simple frame counter try { m_TimeLeft -= UnityEngine.Time.deltaTime; m_Accum += UnityEngine.Time.timeScale / UnityEngine.Time.deltaTime; ++m_Frames; if (m_TimeLeft <= 0) { m_TimeLeft = c_UpdateInterval; m_Accum = 0; m_Frames = 0; } } catch (System.Exception ex) { ArkCrossEngine.LogicSystem.LogErrorFromGfx("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
private void OnTriggerExit(UnityEngine.Collider collider) { try { //Debug.Log("ontriggerexit"); } catch (System.Exception ex) { LogicSystem.LogErrorFromGfx("Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
internal void RestartLogic() { try { LogicSystem.SetLoadingBarScene("LoadingBar"); // change scene to login LogicSystem.PublishLogicEvent("ge_change_scene", "game", 0); m_IsInit = true; } catch (Exception ex) { LogicSystem.LogErrorFromGfx("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
// Use this for initialization void Awake() { try { //LogicSystem.EventChannelForGfx.Subscribe("arena_info_result", "arena", OnArenaInfo); //LogicSystem.EventChannelForGfx.Subscribe("match_group_result", "arena", OnMatchGroupResult); //LogicSystem.EventChannelForGfx.Subscribe<int>("start_challenge_result", "arena", OnStartChallengeResult); //LogicSystem.EventChannelForGfx.Subscribe<ulong, int, ulong, int, bool>("challenge_result", "arena", OnChallengeResult); //LogicSystem.EventChannelForGfx.Subscribe("query_rank_result", "arena", OnQueryRankResult); //LogicSystem.EventChannelForGfx.Subscribe("change_partners_result", "arena", OnChangePartnersResult); //LogicSystem.EventChannelForGfx.Subscribe("query_history_result", "arena", OnQueryHistory); //LogicSystem.EventChannelForGfx.Subscribe<int, int, int>("buy_fight_count_result", "arena", OnBuyFightCountResult); } catch (System.Exception ex) { LogicSystem.LogErrorFromGfx("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
private void StartLogic() { try { ArkProfiler.Start("StartLogic"); // initialize all sub system of game, load data from world system GameControler.InitLogic(); // start game logic thread GameControler.StartLogic(); // load ui data table from disk UIManager.Instance.Init(); // store name of loading bar scene to game logic thread LogicSystem.SetLoadingBarScene("LoadingBar"); #if LoadDataTableFromCache //CleanupCachedTables(); #endif // manual change to loading scene if not in shipping mode if (!GlobalVariables.Instance.IsPublish) { UnityEngine.SceneManagement.SceneManager.LoadScene("Loading"); } ArkProfiler.Stop("StartLogic"); m_IsInit = true; // unload all windows, then show login window LogicSystem.EventChannelForGfx.Publish("ge_show_login", "ui"); } catch (System.Exception ex) { // at this time, logic queue may not initialize yet UnityEngine.Debug.LogErrorFormat("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace); LogicSystem.LogErrorFromGfx("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
private void OnTriggerEnter(UnityEngine.Collider collider) { try { if (!IsStopped) { UnityEngine.GameObject obj = collider.gameObject; if (null != obj) { if (obj == LogicSystem.PlayerSelf) { UIManager.Instance.ShowWindowByName(WindowName); } } } } catch (System.Exception ex) { LogicSystem.LogErrorFromGfx("Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
private void OnTriggerExit(UnityEngine.Collider collider) { try { if (!IsStopped) { UnityEngine.GameObject obj = collider.gameObject; if (null != obj) { if (obj == LogicSystem.PlayerSelf) { LogicSystem.SendStoryMessage(MessageName, 0); } } } } catch (System.Exception ex) { LogicSystem.LogErrorFromGfx("Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
// Use this for initialization internal void Start() { UnityEngine.Application.targetFrameRate = 30; #if (UNITY_IOS || UNITY_ANDROID) && !(UNITY_EDITOR) QualitySettings.vSyncCount = 2; #endif try { if (!GameControler.IsInited) { // register to game thread ArkProfiler.RegisterOutput(LogicSystem.LogFromGfx); // register to gfx thread, output to game console ArkProfiler.RegisterOutput2(UnityEngine.Debug.Log); // register file read handler FileReaderProxy.RegisterReadFileHandler(EngineReadFileProxy, EngineFileExistsProxy); /// Unity Editor: <path_to_project_folder>/Assets /// iOS player: <path_to_player_app_bundle>/<AppName.app>/Data (this folder is read only, use Application.persistentDataPath to save data). /// Android: Normally it would point directly to the APK. The exception is if you are running a split binary build in which case it points to the the OBB instead. string dataPath = UnityEngine.Application.dataPath; /// Point to data path which have write permission string persistentDataPath = Application.persistentDataPath; /// Point to readonly data, note some platofrm like android points to compressed apk, witch cant be directory accesssed, use www. etc instead string streamingAssetsPath = UnityEngine.Application.streamingAssetsPath; /// Point to temp data path, may clean by system string tempPath = UnityEngine.Application.temporaryCachePath; LogicSystem.LogFromGfx("dataPath:{0} persistentDataPath:{1} streamingAssetsPath:{2} tempPath:{3}", dataPath, persistentDataPath, streamingAssetsPath, tempPath); Debug.Log(string.Format("dataPath:{0} persistentDataPath:{1} streamingAssetsPath:{2} tempPath:{3}", dataPath, persistentDataPath, streamingAssetsPath, tempPath)); // store log in tempPath, others to persistentDataPath #if !UNITY_EDITOR GlobalVariables.Instance.IsDevice = true; #else // if in editor, use streamingAssetsPath instead GlobalVariables.Instance.IsDevice = false; #endif #if UNITY_ANDROID || UNITY_WEBGL if (!UnityEngine.Application.isEditor) { streamingAssetsPath = persistentDataPath + "/Tables"; } #endif #if UNITY_WEBGL // init web socket before gamelogic initialize m_WebSocket = new WebGLSocket(); ArkCrossEngine.Network.WebSocketWrapper.Instance.SetInstance(m_WebSocket); #endif LogSystem.OnOutput2 = (Log_Type type, string msg) => { #if DEBUG if (Log_Type.LT_Error == type) { UnityEngine.Debug.LogError(msg); } else if (Log_Type.LT_Info != type) { UnityEngine.Debug.LogWarning(msg); } #endif }; GameControler.Init(tempPath, streamingAssetsPath); NormLog.Instance.Init(); NormLog.Instance.Record(GameEventCode.GameStart); LogicSystem.LogFromGfx("game log saved to: {0}", tempPath); } // try preload all skills used by npc in spec scene, also character LogicSystem.OnAfterLoadScene += AfterLoadScene; } catch (Exception ex) { LogicSystem.LogErrorFromGfx("GameLogic.Start throw exception:{0}\n{1}", ex.Message, ex.StackTrace); Debug.Log(string.Format("GameLogic.Start throw exception:{0}\n{1}", ex.Message, ex.StackTrace)); } }
private IEnumerator HandleGameLoadingNonEditor() { LogicSystem.UpdateLoadingTip("加载配置数据"); string srcPath = UnityEngine.Application.streamingAssetsPath; string destPath = UnityEngine.Application.persistentDataPath + "/Tables"; Debug.Log(srcPath); Debug.Log(destPath); if (!srcPath.Contains("://")) { srcPath = "file://" + srcPath; } string listPath = srcPath + "/list.txt"; WWW listData = new WWW(listPath); yield return(listData); string listTxt = listData.text; if (null != listTxt) { using (StringReader sr = new StringReader(listTxt)) { string numStr = sr.ReadLine(); float totalNum = 50; if (null != numStr) { numStr = numStr.Trim(); if (numStr.StartsWith(BOMMarkUtf8)) { numStr = numStr.Remove(0, BOMMarkUtf8.Length); } totalNum = (float)int.Parse(numStr); if (totalNum <= 0) { totalNum = 50; } } for (float num = 1; ; num += 1) { string path = sr.ReadLine(); if (null != path) { path = path.Trim(); string url = srcPath + "/" + path; //Debug.Log("extract " + url); string filePath = Path.Combine(destPath, path); string dir = Path.GetDirectoryName(filePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } WWW temp = new WWW(url); yield return(temp); if (null != temp.bytes) { try { #if LoadDataTableFromCache byte[] newAlloced = new byte[temp.bytes.Length]; temp.bytes.CopyTo(newAlloced, 0); CachedTables.Add(Path.GetFullPath(filePath).ToLower(), newAlloced); #else File.WriteAllBytes(filePath, temp.bytes); #endif } catch (System.Exception ex) { LogicSystem.LogErrorFromGfx("ExtractDataFileAndStartGame copy config failed. ex:{0} st:{1}", ex.Message, ex.StackTrace); } } else { //Debug.Log(path + " can't load"); } temp.Dispose(); temp = null; } else { break; } LogicSystem.UpdateLoadingProgress(0.8f + 0.2f * num / totalNum); } sr.Close(); } listData = null; } else { Debug.Log("Can't load list.txt"); } }
// Update is called once per frame void Update() { UnityEngine.GameObject _gameobject = LogicSystem.PlayerSelf; try { if (gameObject != LogicSystem.PlayerSelf) { return; } if (Input.GetKeyDown(m_AttackKey)) { GfxSkillSystem.Instance.StartAttack(_gameobject, UnityEngine.Vector3.zero); } if (Input.GetKeyUp(m_AttackKey)) { GfxSkillSystem.Instance.StopAttack(_gameobject); } if (Input.GetKeyDown(m_SkillAKey)) { GfxSkillSystem.Instance.PushSkill(_gameobject, SkillCategory.kSkillA, UnityEngine.Vector3.zero); } if (Input.GetKeyUp(m_SkillAKey)) { GfxSkillSystem.Instance.BreakSkill(_gameobject, SkillCategory.kSkillA); } if (Input.GetKeyDown(m_SkillBKey)) { GfxSkillSystem.Instance.PushSkill(_gameobject, SkillCategory.kSkillB, UnityEngine.Vector3.zero); } if (Input.GetKeyUp(m_SkillBKey)) { GfxSkillSystem.Instance.BreakSkill(_gameobject, SkillCategory.kSkillB); } if (Input.GetKeyDown(m_SkillCKey)) { GfxSkillSystem.Instance.PushSkill(_gameobject, SkillCategory.kSkillC, UnityEngine.Vector3.zero); } if (Input.GetKeyUp(m_SkillCKey)) { GfxSkillSystem.Instance.BreakSkill(_gameobject, SkillCategory.kSkillC); } if (Input.GetKeyDown(m_SkillDKey)) { GfxSkillSystem.Instance.PushSkill(_gameobject, SkillCategory.kSkillD, UnityEngine.Vector3.zero); } if (Input.GetKeyUp(m_SkillDKey)) { GfxSkillSystem.Instance.BreakSkill(_gameobject, SkillCategory.kSkillD); } if (Input.GetKeyDown(m_SkillQKey)) { GfxSkillSystem.Instance.PushSkill(_gameobject, SkillCategory.kSkillQ, UnityEngine.Vector3.zero); } if (Input.GetKeyUp(m_SkillQKey)) { GfxSkillSystem.Instance.BreakSkill(_gameobject, SkillCategory.kSkillQ); } if (Input.GetKeyDown(m_SkillEKey)) { GfxSkillSystem.Instance.PushSkill(_gameobject, SkillCategory.kSkillE, UnityEngine.Vector3.zero); } if (Input.GetKeyUp(m_SkillEKey)) { GfxSkillSystem.Instance.BreakSkill(_gameobject, SkillCategory.kSkillE); } if (Input.GetKeyUp(m_SkillEX)) { GfxSkillSystem.Instance.PushSkill(_gameobject, SkillCategory.kEx, UnityEngine.Vector3.zero); } if (Input.GetKeyUp(m_ChangeInput)) { SkillControlMode mode; if (DFMUiRoot.InputMode == InputType.Joystick) { PlayerPrefs.SetString(DFMUiRoot.INPUT_MODE, DFMUiRoot.INPUT_MODE_TOUCH); DFMUiRoot.InputMode = InputType.Touch; mode = SkillControlMode.kTouch; } else { PlayerPrefs.SetString(DFMUiRoot.INPUT_MODE, DFMUiRoot.INPUT_MODE_JOYSTICK); DFMUiRoot.InputMode = InputType.Joystick; mode = SkillControlMode.kJoystick; } GfxSkillSystem.Instance.ChangeSkillControlMode(_gameobject, mode); } if (Input.GetKeyUp(KeyCode.F9)) { BuyFightCount(); } if (Input.GetKeyUp(KeyCode.F10)) { } if (Input.GetKeyUp(KeyCode.F11)) { } if (Input.GetKeyUp(KeyCode.F2)) { } if (Input.GetKeyUp(KeyCode.R)) { } } catch (System.Exception ex) { LogicSystem.LogErrorFromGfx("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }