Beispiel #1
0
        public List <ICommand> GetNextCommands()
        {
            try
            {
                var result = new List <ICommand>();
                foreach (ParsedCommandSpec rawCmd in _processQueue.Take().Commands)
                {
                    // Don't print full command, if it is really long for performance reasons
                    string payloadStr = rawCmd.Body.Length > 100 ? "of " + rawCmd.Body.Length + " bytes" : BitConverter.ToString(rawCmd.Body);
                    Log.DebugFormat("{0} - Received command {1} with content {2}", Endpoint, rawCmd.Name, payloadStr);

                    var cmd = CommandParser.Parse(_protocolVersion ?? ProtocolVersion.Minimum, rawCmd);
                    if (cmd is VersionCommand verCmd)
                    {
                        _protocolVersion = verCmd.ProtocolVersion;
                        // TODO - log version info
                    }
                    else if (cmd is InitializationCompleteCommand)
                    {
                        OnInitComplete?.Invoke(this);
                    }
                    result.AddIfNotNull(cmd);
                }

                return(result);
            }
            catch (ArgumentException)
            {
                //discard as was malformed
                return(new List <ICommand>());
            }
        }
Beispiel #2
0
    /// <summary>
    /// 同步加载场景UI(Resources)
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public GameObject LoadSceneUIFromResouces(SceneUIType type, OnInitComplete onInitComplete = null)
    {
        GameObject obj = ResourcesManager.Instance.Load(ResourceType.UIScene, string.Format("UI_Root_{0}", type));

        CurrentUIScene = obj.GetComponent <UISceneViewBase>();
        CurrentUIScene.OnInitComplete = onInitComplete;
        return(obj);
    }
Beispiel #3
0
        static void OnDbInitComplete()
        {
            DataBaseProxy.Instance.OnInitialized -= OnDbInitComplete;
            CommandSequence sequence = new CommandSequence(_initStoragesCommands.ToArray());

            sequence.OnComplete += () => OnInitComplete.Invoke();
            CommandManager.Execute(sequence);
        }
Beispiel #4
0
        protected void OnDbInitComplete()
        {
            _dbProxy.OnInitialized -= OnDbInitComplete;
            CommandSequence sequence = new CommandSequence(_initStoragesCommands.ToArray());

            sequence.OnComplete += () =>
            {
                OnInitComplete.Invoke();
            };
            CommandManager.Execute(sequence);
        }
Beispiel #5
0
    /// <summary>
    /// 异步加载场景UI(Assetbundle)
    /// </summary>
    /// <param name="type"></param>
    /// <param name="onLoadComplete">加载完毕回调</param>
    /// <param name="onInitComplete">场景UI初始化完毕回调</param>
    public void LoadSceneUIAsync(SceneUIType type, OnLoadComplete onLoadComplete, OnInitComplete onInitComplete = null)
    {
        string strUIName = string.Format("ui_root_{0}", type.ToString().ToLower());
        string path      = string.Format("download/{0}/prefab/uiprefab/uiscenes/{1}.drb", ConstDefine.GAME_NAME, strUIName);

        Debug.Log("打开场景UI: " + strUIName);

        AssetBundleManager.Instance.LoadOrDownload(path, strUIName, (GameObject go) =>
        {
            Debug.Log("场景UI资源加载完毕");
            go             = UnityEngine.Object.Instantiate(go);
            CurrentUIScene = go.GetComponent <UISceneViewBase>();
            CurrentUIScene.OnInitComplete = onInitComplete;
            if (onLoadComplete != null)
            {
                onLoadComplete(go);
            }
        });
    }
Beispiel #6
0
    /// <summary>
    /// 同步加载场景UI(Assetbundle)
    /// </summary>
    /// <param name="type"></param>
    /// <param name="onInitComplete"></param>
    /// <returns></returns>
    public GameObject LoadSceneUIFromAssetBundle(SceneUIType type, OnInitComplete onInitComplete = null)
    {
        foreach (KeyValuePair <SceneUIType, UISceneViewBase> pair in m_UISceneDic)
        {
            if (pair.Value != null)
            {
                pair.Value.gameObject.SetActive(false);
            }
        }

        GameObject ret = null;

        if (m_UISceneDic.ContainsKey(type) && m_UISceneDic[type] != null)
        {
            CurrentUIScene = m_UISceneDic[type];
            CurrentUIScene.gameObject.SetActive(true);
            ret = CurrentUIScene.gameObject;
        }
        else
        {
            string strUIName = string.Format("ui_root_{0}", type.ToString().ToLower());
            string path      = string.Format("download/{0}/prefab/uiprefab/uiscenes/{1}.drb", ConstDefine.GAME_NAME, strUIName);
            Debug.Log("打开场景UI: " + strUIName);
            float time = Time.realtimeSinceStartup;
            ret = AssetBundleManager.Instance.LoadAssetBundle <GameObject>(path, strUIName);
            Debug.Log("加载场景UI资源耗时" + (Time.realtimeSinceStartup - time).ToString() + "秒");
            ret            = UnityEngine.Object.Instantiate(ret);
            CurrentUIScene = ret.GetComponent <UISceneViewBase>();
            if (CurrentUIScene.persistenceType == UIScenePersistenceType.LoadSceneHide)
            {
                UnityEngine.Object.DontDestroyOnLoad(ret);
            }

            m_UISceneDic[type]            = CurrentUIScene;
            CurrentUIScene.OnInitComplete = onInitComplete;
        }
        return(ret);
    }
Beispiel #7
0
    public void ClearAndReloadScene()
    {
        //unsub all from the events of the game
        if (OnInitComplete != null)
        {
            foreach (var d in OnInitComplete.GetInvocationList())
            {
                OnInitComplete -= (d as InitCompleteAction);
            }
        }

        if (OnGameLoad != null)
        {
            foreach (var d in OnGameLoad.GetInvocationList())
            {
                OnGameLoad -= (d as GameLoadAction);
            }
        }

        if (OnGameStart != null)
        {
            foreach (var d in OnGameStart.GetInvocationList())
            {
                OnGameStart -= (d as GameStartAction);
            }
        }

        if (OnGameEnd != null)
        {
            foreach (var d in OnGameEnd.GetInvocationList())
            {
                OnGameEnd -= (d as GameEndAction);
            }
        }

        SceneManager.LoadScene(0);
    }
 private void InitCompleted()
 {
     _initializing = false;
     OnInitComplete?.Invoke(this, new EventArgs());
 }