void OnDisable() { if (_current == this) { _current = null; } }
void Awake() { instance = this; gameManager = GameManager.Instance; DOTween.Init(); Screen.sleepTimeout = SleepTimeout.NeverSleep; #if UNITY_STANDALONE_WIN Screen.SetResolution(1280, 720, false); #endif Application.targetFrameRate = AppConst.GameFrameRate; DontDestroyOnLoad(gameObject); //加入输入输出管理器 inputMgr = gameObject.AddComponent <InputMgr>(); #if SHOW_FPS fpsHelperObj = new GameObject("FpsHelperObj"); fpsHelper = fpsHelperObj.AddComponent <FPSHelper>(); GameObject.DontDestroyOnLoad(fpsHelperObj); #endif if (AppConst.isLocalGameServer) { var ServerObj = new GameObject("SimulateServer"); ServerObj.AddComponent <ColaFramework.NetWork.SimulateServer>(); GameObject.DontDestroyOnLoad(ServerObj); } #if BUILD_DEBUG_LOG || UNITY_EDITOR #if UNITY_2017_1_OR_NEWER Debug.unityLogger.logEnabled = true; #else Debug.unityLogger.logEnabled = true; #endif #else #if UNITY_2017_1_OR_NEWER Debug.unityLogger.logEnabled = false; #else Debug.logger.logEnabled = false; #endif #endif #if WETEST_SDK gameObject.AddComponent <WeTest.U3DAutomation.U3DAutomationBehaviour>(); #endif #if OUTPUT_LOG GameObject logHelperObj = new GameObject("LogHelperObj"); logHelper = logHelperObj.AddComponent <LogHelper>(); GameObject.DontDestroyOnLoad(logHelperObj); Application.logMessageReceived += logHelper.LogCallback; #endif //初始化多线程工具 ColaLoom.Initialize(); StreamingAssetHelper.SetAssetPathDir(assetPath); }
/// <summary> /// 连接服务器 /// </summary> /// <param name="currIP"></param> /// <param name="currPort"></param> public void Connect(string currIP, int currPort) { if (!IsConnceted) { this.currIP = currIP; this.currPort = currPort; ColaLoom.RunAsync(_onConnet); } }
private void UpdateUI() { ColaLoom.QueueOnMainThread(() => { this._text.text = Time.realtimeSinceStartup.ToString(); ColaFramework.Timer.RunPerSecond((time) => { this._text.text = Time.realtimeSinceStartup.ToString(); }, null); }); }
/// <summary> /// 在Android平台上,从(apk包中的) Assets目录复制文件至指定目录 /// 注意:只能在子线程中调用 /// </summary> /// <param name="sourceDir">源目录,是以 assets 为根目录的相对路径</param> /// <param name="destDir">目标目录</param> /// <param name="title">进度对话框标题</param> /// <returns></returns> public static void CopyAssetDirectoryInThread(String sourceDir, String destDir, Action <bool> callback) { StreamingAssetHelper.sourceDir = sourceDir; StreamingAssetHelper.destDir = assetPath != null?Path.Combine(assetPath, destDir) : null; StreamingAssetHelper.callback = callback; if (StreamingAssetHelper.destDir != null) { ColaLoom.RunAsync(CopyAssetDirectory); } }
private void UpdateUI() { ColaLoom.QueueOnMainThread(() => { this._text.text = Time.realtimeSinceStartup.ToString(); TimeHelper.SetRepeatTimer(() => { this._text.text = Time.realtimeSinceStartup.ToString(); }, 1); }); }
/// <summary> /// 初始化ColaLoom多线程工具,只在游戏开始调用一次就好 /// </summary> public static void Initialize() { if (!initialized) { if (!Application.isPlaying) { return; } initialized = true; var g = new GameObject("ColaLoom"); DontDestroyOnLoad(g); _current = g.AddComponent <ColaLoom>(); } }
void Awake() { instance = this; InitPath(); gameManager = GameManager.GetInstance(); Screen.sleepTimeout = SleepTimeout.NeverSleep; #if UNITY_STANDALONE_WIN Screen.SetResolution(1280, 720, false); #endif DontDestroyOnLoad(gameObject); //加入输入输出管理器 inputMgr = gameObject.AddComponent <InputMgr>(); #if SHOW_FPS fpsHelperObj = new GameObject("FpsHelperObj"); fpsHelper = fpsHelperObj.AddComponent <FPSHelper>(); GameObject.DontDestroyOnLoad(fpsHelperObj); #endif #if BUILD_DEBUG_LOG || UNITY_EDITOR #if UNITY_2017 Debug.unityLogger.logEnabled = true; #else Debug.unityLogger.logEnabled = true; #endif #else #if UNITY_2017 Debug.unityLogger.logEnabled = false; #else Debug.logger.logEnabled = false; #endif #endif #if WETEST_SDK gameObject.AddComponent <WeTest.U3DAutomation.U3DAutomationBehaviour>(); #endif #if OUTPUT_LOG GameObject logHelperObj = new GameObject("LogHelperObj"); logHelper = logHelperObj.AddComponent <LogHelper>(); GameObject.DontDestroyOnLoad(logHelperObj); Application.logMessageReceived += logHelper.LogCallback; #endif //初始化多线程工具 ColaLoom.Initialize(); StreamingAssetHelper.SetAssetPathDir(AssetPath); }
/// <summary> /// 在Android平台上,从(apk包中的) Assets目录复制文件至指定目录 /// 注意:只能在主线程中调用 /// </summary> /// <param name="sourceDir">源目录,是以 assets 为根目录的相对路径</param> /// <param name="destDir">目标目录</param> /// <param name="title">进度对话框标题</param> /// <returns></returns> public static void CopyAssetDirectory() { ColaLoom.QueueOnMainThread(() => { Debug.Log("CopyAssetDirectory, sourceDir = " + sourceDir + ", destDir = " + destDir); AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActitivy = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); Debug.Log("CopyAssetDirectory before execute"); bool ret = currentActitivy.Call <bool>("copyAssets", sourceDir, destDir); callback(ret); Debug.Log("CopyAssetDirectory finished"); }); }
void Awake() { instance = this; gameManager = GameManager.Instance; DOTween.Init(); Screen.sleepTimeout = SleepTimeout.NeverSleep; #if UNITY_STANDALONE_WIN Screen.SetResolution(1280, 720, false); #endif Application.targetFrameRate = AppConst.GameFrameRate; DontDestroyOnLoad(gameObject); //加入输入输出管理器 inputMgr = gameObject.AddComponent <InputMgr>(); #if SHOW_FPS fpsHelperObj = new GameObject("FpsHelperObj"); fpsHelper = fpsHelperObj.AddComponent <FPSHelper>(); GameObject.DontDestroyOnLoad(fpsHelperObj); #endif #if BUILD_DEBUG_LOG || UNITY_EDITOR #if UNITY_2017_1_OR_NEWER Debug.unityLogger.logEnabled = true; #else Debug.unityLogger.logEnabled = true; #endif #else #if UNITY_2017_1_OR_NEWER Debug.unityLogger.logEnabled = false; #else Debug.logger.logEnabled = false; #endif #endif #if OUTPUT_LOG GameObject logHelperObj = new GameObject("LogHelperObj"); logHelper = logHelperObj.AddComponent <LogHelper>(); GameObject.DontDestroyOnLoad(logHelperObj); Application.logMessageReceived += logHelper.LogCallback; #endif //初始化多线程工具 ColaLoom.Initialize(); }
private void _onConnect_Sucess(IAsyncResult iar) { try { Socket client = (Socket)iar.AsyncState; client.EndConnect(iar); receiveThread = new Thread(new ThreadStart(_onReceiveSocket)); receiveThread.IsBackground = true; receiveThread.Start(); isConnected = true; Debug.Log("连接成功"); ColaLoom.QueueOnMainThread(StartPingServer); OnConnected?.Invoke(); } catch (Exception _e) { OnErrorCode?.Invoke((int)NetErrorEnum.ConnnectedError); _close(); } }
// Use this for initialization void Start() { ColaLoom.Initialize(); _text = this.transform.Find("Text").GetComponent <Text>(); ColaLoom.RunAsync(UpdateUI); }
void Awake() { _current = this; initialized = true; }