Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 public void SetReferencePath(string path)
 {
     GameLogger.GetInstance().Output($"Csv Path:{path}");
     _referencePath = path;
 }
Exemplo n.º 9
0
 public void SetResPath(string path)
 {
     GameLogger.GetInstance().Output($"Res Path:{path}");
     _resPath = path;
 }
Exemplo n.º 10
0
 private void UpdateLoaded( )
 {
     GameLogger.GetInstance( ).Trace("SceneManager.Loaded Scene:{0}", _cache.GetSceneName( ));
     SceneManager.LoadScene(_cache.GetSceneName( ));
 }
 public override void Start( )
 {
     GameLogger.GetInstance( ).Trace($"Try download: {SceneName}, path: {AbPath}");
     AssetBundleMgr.GetInstance( ).AsyncLoad(AbPath, AsyncLoadCallBack, null);
 }