Пример #1
0
    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);
        }
    }
Пример #2
0
    // 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));
        }
    }