Example #1
0
        public void Update()
        {
            foreach (var key in _removeObjs)
            {
                UiBase uibase = _uiInses[key];
                uibase.Destroy();
                _uiInses.Remove(key);
            }
            _removeObjs.Clear();

            foreach (var one in _addObjs.Values)
            {
                _uiInses.Add(one.GetUiComplexType(), one);

                // 开始资源加载
                GameLogger.GetInstance().Trace("-- ui open:" + one.GetType());
                var uiAb = UiFactory.GetInstance().GetAssetBundle(one.GetUiType());
                if (uiAb != null)
                {
                    AssetBundleMgr.GetInstance().AsyncLoad(uiAb, AsyncLoadCallBack, one.GetUiComplexType());
                }
                else
                {
                    // 空界面,做逻辑切换用的,不需要gameobject表现
                    one.AttachGameObject(null);
                }
            }

            _addObjs.Clear();
            foreach (var one in _uiInses)
            {
                one.Value.Update();
            }
        }
Example #2
0
        public UiBase Create(UiType uiType, ulong sn)
        {
            switch (uiType)
            {
            case UiType.LoadingBar:
                return(new UiLoadBar());

            case UiType.Roles:
                return(new UiRoles());

            case UiType.Login:
                return(new UiLogin());

            case UiType.RoleCreate:
                return(new UiRoleCreate());

            case UiType.RoleSelect:
                return(new UiRoleSelect());

            case UiType.ModalBox0:
                return(new ModalBox0());

            case UiType.ModalBox1:
                return(new ModalBox1());

            default:
                GameLogger.GetInstance().Debug($" !!!!! can't found handler. uiType:{uiType}");
                break;
            }

            return(null);
        }
Example #3
0
        public UiBase OpenUi(UiType uiType, ulong sn)
        {
            UiComplexType key = new UiComplexType(uiType, sn);

            if (_uiInses.ContainsKey(key))
            {
                _uiInses[key].Show();
                return(_uiInses[key]);
            }

            if (_addObjs.ContainsKey(key))
            {
                return(_addObjs[key]);
            }

            UiBase uiIns = UiFactory.GetInstance().Create(uiType, sn);

            if (uiIns == null)
            {
                GameLogger.GetInstance().Output("!!!! OpenUi Error. Create ui == null. uiType:" + uiType);
                return(null);
            }

            _addObjs.Add(uiIns.GetUiComplexType(), uiIns);
            return(uiIns);
        }
Example #4
0
        private IEnumerator TimerChange()
        {
            while (true)
            {
                yield return(new WaitForSeconds(1.0f));

                GameLogger.GetInstance().Debug($"player position:{gameObject.transform.position}");
            }
        }
Example #5
0
        public void CloseAll()
        {
            foreach (var one in _uiInses.Values)
            {
                _removeObjs.Add(one.GetUiComplexType());
            }

            GameLogger.GetInstance().Trace("-- ui close all");
        }
        private void Awake( )
        {
            _instatnce = this;
            _cache     = AsyncLoaderCache.GetInstance( );

            GameLogger.GetInstance( ).Trace("Unity:AsyncSceneLoader Awake");

            // 通知:一个新场景开始加载了
            EventDispatcher.GetInstance( ).Broadcasting(eEventType.AsyncLoaderScene);
        }
        private const int MaxTryNum     = 3;  // 最多重试次数

        private void Update( )
        {
            // 下载量充足,增加新的下载
            if (_loadingQueue.Count < MaxWorkingCnt)
            {
                int cnt = MaxWorkingCnt - _waitingQueue.Count;

                for (int i = 0; i < cnt; i++)
                {
                    if (_waitingQueue.Count <= 0)
                    {
                        break;
                    }

                    string url = _waitingQueue.Dequeue( );
                    _loadingQueue.Add(new LoadingAbInfo(url));
                }
            }

            // 检查下载状态
            for (var index = _loadingQueue.Count - 1; index >= 0; index--)
            {
                LoadingAbInfo info = _loadingQueue[index];
                if (info.State == LoadStateType.Loding)
                {
                    continue;
                }

                // 三次都没有下载下来
                if (info.ErrorCount >= MaxTryNum)
                {
                    GameLogger.GetInstance( )
                    .Output(string.Format("!!!!! AssetBundle CreateFromWWW failed: {0}\n\t ErrorCount >= {1}",
                                          info.Url, MaxTryNum));
                    _loadingQueue.RemoveAt(index);
                    continue;
                }

                StartCoroutine(OnAssetLoadStart(info));
            }

            // 检查request的完成情况
            List <string> tmpKeys = new List <string>(_requests.Keys);

            foreach (var one in tmpKeys)
            {
                AsyncLoadRequest request = _requests[one];
                if (request.CompletedCallback( ))
                {
                    _requests.Remove(one);
                }
            }
        }
Example #8
0
        public void CloseUi(UiType uiType, ulong sn)
        {
            UiComplexType key = new UiComplexType(uiType, sn);

            // 处理删除的UI
            if (!_uiInses.ContainsKey(key))
            {
                return;
            }

            GameLogger.GetInstance().Trace("-- ui remove:" + _uiInses[key].GetType());
            _removeObjs.Add(key);
        }
Example #9
0
        public string GetString(string name)
        {
            name = name.ToLower();
            if (!_head.ContainsKey(name))
            {
#if !Editor
                GameLogger.GetInstance( ).Output("!!!!! GetInt is error. name:" + name);
#endif
                return("");
            }

            return(_values[_head[name]]);
        }
Example #10
0
        public void OpenModalBox1(string title, string tips, Action closeAction)
        {
            ModalBox1 modal = OpenUi(UiType.ModalBox1) as ModalBox1;

            if (modal == null)
            {
                GameLogger.GetInstance().Debug(" !!!!! create modal1 is failed.");
                return;
            }

            modal.Tip         = tips;
            modal.Title       = title;
            modal.CloseAction = closeAction;
        }
Example #11
0
        public ModalBox0 OpenModalBox0(string title, string tips)
        {
            ModalBox0 modal = OpenUi(UiType.ModalBox0) as ModalBox0;

            if (modal == null)
            {
                GameLogger.GetInstance().Debug(" !!!!! create modal0 is failed.");
                return(null);
            }

            modal.Title = title;
            modal.Tip   = tips;
            return(modal);
        }
Example #12
0
        public bool GetBool(string name)
        {
            name = name.ToLower();

            if (!_head.ContainsKey(name))
            {
#if !Editor
                GameLogger.GetInstance( ).Output("!!!!! GetBool is error. name:" + name);
#endif
                return(false);
            }

            return(int.Parse(_values[_head[name]]) >= 1);
        }
Example #13
0
        private void MsgPlayer(Google.Protobuf.IMessage msg)
        {
            Proto.SyncPlayer proto = msg as Proto.SyncPlayer;
            if (proto == null)
            {
                return;
            }

            GameLogger.GetInstance().Debug($"sync player sn:{proto.Player.Sn}");

            if (_mainPlayer == null)
            {
                _mainPlayer = new Player();
            }

            _mainPlayer.Parse(proto.Player);
        }
Example #14
0
        private void MsgEnterWorld(Google.Protobuf.IMessage msg)
        {
            Proto.EnterWorld protoEnter = msg as Proto.EnterWorld;
            if (protoEnter == null)
            {
                return;
            }

            GameLogger.GetInstance().Debug($"Enter world. world id:{protoEnter.WorldId}");
            ResourceWorld refMap = ResourceAll.GetInstance().MapMgr.GetReference((int)protoEnter.WorldId);

            if (refMap == null)
            {
                return;
            }

            LoadScene(refMap.AbPath, refMap.ResName, (int)protoEnter.WorldId);
        }
        public void LoadFromMemory(MemoryStream ms)
        {
            _maps.Clear();

            bool         isLoadedHead = false;
            StreamReader sr           = new StreamReader(ms, Encoding.UTF8);

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                if (line == null)
                {
                    break;
                }

                if (line.Length == 0)
                {
                    continue;
                }

                if (!isLoadedHead)
                {
                    LoadHead(line);
                    isLoadedHead = true;
                    continue;
                }

                T obj = new T();
                obj.AttackHead(_head);
                if (!obj.LoadProperty(line))
                {
#if !Editor
                    GameLogger.GetInstance().Output($"!!!!! LoadProperty is error. line:{line}");
#endif
                    continue;
                }
                obj.LoadAfter();
                _maps.Add(obj.GetId(), obj);
            }

            OnAfterReload();
        }
Example #16
0
        public bool LoadProperty(string line)
        {
            string[] properties = CvsAnalysis.GetInstance().GetProperty(line);

            if (properties.Length != _head.Count)
            {
#if !Editor
                GameLogger.GetInstance( ).Output("!!!!! load file is error.");
#endif
                return(false);
            }

            foreach (var one in properties)
            {
                _values.Add(one);
            }

            _id = int.Parse(_values[0]);

            return(true);
        }
        private IEnumerator OnAssetLoadStart(LoadingAbInfo info)
        {
#if TRACE
            //float timeBegin = Time.realtimeSinceStartup;
            //GameLogger.GetInstance().Trace( "AssetBundle CreateFromWWW Star: {0}", info.Url );
#endif

            info.State = LoadStateType.Loding;
            yield return(null);

            var url = MakeUrl(info.Url);
            WWW www = new WWW(url);
            while (!www.isDone)
            {
                info.Progress = www.progress;
                yield return(null);
            }

            // 加载失败了
            if (!string.IsNullOrEmpty(www.error))
            {
                GameLogger.GetInstance( ).Trace("AssetBundle CreateFromWWW failed: {0}\n\t{1}", url, www.error);
                UrlLoadCompleted(info, null);
                yield break;
            }

            AssetBundle ab = www.assetBundle;
            if (ab == null)
            {
                GameLogger.GetInstance( ).Trace("AssetBundle CreateFromWWW failed: {0}\n\tab == null", url);
                UrlLoadCompleted(info, null);
                yield break;
            }

#if TRACE
            //GameLogger.GetInstance().Trace( "### Load {0} successful, time = {1}", info.Url, Time.realtimeSinceStartup - timeBegin );
#endif

            UrlLoadCompleted(info, ab);
        }
        private void UrlLoadCompleted(LoadingAbInfo info, AssetBundle ab)
        {
            if (ab == null)
            {
                if (info.ErrorCount >= MaxTryNum)
                {
                }
                else
                {
                    // 再试几次下载
                    info.State       = LoadStateType.Start;
                    info.ErrorCount += 1;
                }
                //GameLogger.GetInstance( ).Debug( "!!!!! Failed..UrlLoadCompleted:" + info.Url );
                return;
            }

            GameLogger.GetInstance( ).Debug("UrlLoadCompleted:" + info.Url);

            // 缓存起来
            _cacheMgr.Add(info.Url, ab);

            // 修改下载数据状态
            info.State = LoadStateType.Completed;

            // 通知Request,有一个AB下载完成
            if (!_loadedCallback.ContainsKey(info.Url))
            {
                throw new Exception($"!!!UrlLoadCompleted failed. Url:{info.Url}");
            }

            // 回调
            _loadedCallback[info.Url].DynamicInvoke(info.Url, ab);
            _loadedCallback.Remove(info.Url);

            // 加载完成
            _loadingQueue.Remove(info);
        }
 public override void Start( )
 {
     GameLogger.GetInstance( ).Trace($"Try download: {SceneName}, path: {AbPath}");
     AssetBundleMgr.GetInstance( ).AsyncLoad(AbPath, AsyncLoadCallBack, null);
 }
Example #20
0
 private void UpdateLoaded( )
 {
     GameLogger.GetInstance( ).Trace("SceneManager.Loaded Scene:{0}", _cache.GetSceneName( ));
     SceneManager.LoadScene(_cache.GetSceneName( ));
 }
Example #21
0
 public void SetReferencePath(string path)
 {
     GameLogger.GetInstance().Output($"Csv Path:{path}");
     _referencePath = path;
 }
Example #22
0
 public void SetResPath(string path)
 {
     GameLogger.GetInstance().Output($"Res Path:{path}");
     _resPath = path;
 }
Example #23
0
        private void AsyncLoadCallBack(object context, AssetBundle ab)
        {
            UiComplexType key = (UiComplexType)context;

            UiBase uiObj = null;

            if (_uiInses.ContainsKey(key))
            {
                uiObj = _uiInses[key];
            }

            if (uiObj == null && _addObjs.ContainsKey(key))
            {
                uiObj = _addObjs[key];
            }

            // 回调的时候,界面已经没有了
            if (uiObj == null)
            {
                return;
            }

            Canvas canvas = FindObjectOfType <Canvas>();

            if (canvas == null)
            {
                string canvasUrl = _urlCanvas;
                //if (key.UiType == UiType.LoadingBar || key.UiType == UiType.Login)
                //{
                //    // 登录和加载界面的背影略有不同
                //    canvasUrl = _urlCanvasBg;
                //}

                AssetBundle abBg = AssetBundleMgr.GetInstance().GetAb(canvasUrl);
                if (abBg == null)
                {
                    GameLogger.GetInstance().Debug($"!!!!!GetAb failed. {canvasUrl}");
                    return;
                }

                GameObject canvasObj = MonoBehaviour.Instantiate(abBg.LoadAsset(abBg.GetAllAssetNames()[0])) as GameObject;
                if (canvasObj == null)
                {
                    return;
                }

                canvasObj.transform.Rotate(0, 0, 0);
                canvas = canvasObj.GetComponent <Canvas>();
            }

            // 对像挂在 canvas 之下
            GameObject obj =
                MonoBehaviour.Instantiate(ab.LoadAsset(ab.GetAllAssetNames()[0]), canvas.transform) as GameObject;

            if (obj == null)
            {
                return;
            }

            obj.transform.Rotate(0, 0, 0);
            //obj.transform.localScale = new Vector3( 1, 1, 1 );
            uiObj.AttachGameObject(obj);
        }