Exemplo n.º 1
0
 void OnDisable()
 {
     if (_current == this)
     {
         _current = null;
     }
 }
Exemplo n.º 2
0
    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);
    }
Exemplo n.º 3
0
 /// <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);
     }
 }
Exemplo n.º 4
0
 private void UpdateUI()
 {
     ColaLoom.QueueOnMainThread(() =>
     {
         this._text.text = Time.realtimeSinceStartup.ToString();
         ColaFramework.Timer.RunPerSecond((time) =>
         {
             this._text.text = Time.realtimeSinceStartup.ToString();
         }, null);
     });
 }
Exemplo n.º 5
0
    /// <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);
        }
    }
Exemplo n.º 6
0
 private void UpdateUI()
 {
     ColaLoom.QueueOnMainThread(() =>
     {
         this._text.text = Time.realtimeSinceStartup.ToString();
         TimeHelper.SetRepeatTimer(() =>
         {
             this._text.text = Time.realtimeSinceStartup.ToString();
         }, 1);
     });
 }
Exemplo n.º 7
0
 /// <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>();
     }
 }
Exemplo n.º 8
0
    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);
    }
Exemplo n.º 9
0
    /// <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");
        });
    }
Exemplo n.º 10
0
    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();
    }
Exemplo n.º 11
0
        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();
            }
        }
Exemplo n.º 12
0
 // Use this for initialization
 void Start()
 {
     ColaLoom.Initialize();
     _text = this.transform.Find("Text").GetComponent <Text>();
     ColaLoom.RunAsync(UpdateUI);
 }
Exemplo n.º 13
0
 void Awake()
 {
     _current    = this;
     initialized = true;
 }