void OnSceneLoaded(Scene scene, LoadSceneMode mode) { Debug.Log("OnSceneLoaded: " + scene.name + " LoadSceneMode:" + mode); // AsyncLoaderScene if (scene.name.Equals(AsyncLoader.SceneLoader)) { var scrpts = Camera.main.gameObject.GetComponent <AsyncLoader>(); if (scrpts == null) { Camera.main.gameObject.AddComponent <AsyncLoader>(); } return; } _isLoadedMap = true; int mapId = AsyncLoaderCache.GetInstance().GetMapId(); if (mapId <= 0) { return; } _currentWorld = new World(ResourceAll.GetInstance().MapMgr.GetReference(mapId)); // 触发一个场景加载完毕的事件 EventDispatcher.GetInstance().Broadcasting <int>(eEventType.SceneLoadCompleted, mapId); // 初始化角色位置 if (_mainPlayer != null && Camera.main.gameObject != null) { // 增加一个相机跟随组件 CameraFollowBehaviour cTrack = Camera.main.gameObject.GetComponent <CameraFollowBehaviour>(); if (cTrack == null) { cTrack = Camera.main.gameObject.AddComponent <CameraFollowBehaviour>(); } if (_mainPlayer.GetGameObject() != null) { cTrack.Target = _mainPlayer.GetGameObject().GetComponent <Transform>(); } } // 场景加载完成之后,处理缓存的协议 HandlerCacheMsg(); }
protected void AsyncLoadModelCallBack(object context, AssetBundle asset) { _3dObj = Object.Instantiate(asset.LoadAsset(asset.GetAllAssetNames()[0])) as GameObject; if (_3dObj == null) { return; } // GameObjectEntity 需要先false,再true 才有效果 // GameObjectEntity 才会进入EntityManager _3dObj.SetActive(false); Transform transform = _3dObj.GetComponent <Transform>(); transform.position = _position; transform.Rotate(0, 0, 0); transform.localScale = new Vector3(1, 1, 1); _3dObj.AddComponent <GameObjectEntity>(); var moveComponent = _3dObj.AddComponent <MoveComponent>(); moveComponent.AttachRole(this); var roleComponent = _3dObj.AddComponent <RoleUpdateComponent>(); roleComponent.AttachRole(this); _3dObj.SetActive(true); if (_sn == GameMain.GetInstance().MainPlayer.Sn) { GameMain.GetInstance().MainPlayer.SetGameObject(_3dObj); _3dObj.name = "MainPlayer"; Object.DontDestroyOnLoad(_3dObj); CameraFollowBehaviour cTrack = Camera.main.gameObject.GetComponent <CameraFollowBehaviour>(); if (cTrack != null) { cTrack.Target = _3dObj.GetComponent <Transform>(); } } else { _3dObj.name = "Sync_" + _name; } }