Example #1
0
        private void GoLoaded(UnityObject unityObj)
        {
            --_concurrentCount;
            if (_loadingGoes.ContainsKey(unityObj.Address))
            {
                var loadingGo = _loadingGoes[unityObj.Address].Dequeue();
                var sceneName = _sceneDescription.Scenes[loadingGo.SceneIndex].SceneName;

                if (_unloadingScene.ContainsKey(sceneName))
                {
                    _unloadingScene[sceneName].Enqueue(unityObj);

                    RequestForUnload();
                }
                else
                {
                    _streamingGo.GoLoaded(loadingGo.SceneIndex, loadingGo.GoIndex, unityObj);
                    var data = _sceneDescription.Scenes[loadingGo.SceneIndex].Objects[loadingGo.GoIndex];
                    var go   = unityObj.AsGameObject;
                    go.transform.localPosition    = data.Position.ShiftedPosition();
                    go.transform.localEulerAngles = data.Rotation;
                    go.transform.localScale       = data.Scale;
                    unityObj.SceneObjAttr.Id      = data.Id;

                    var multiTag = go.GetComponent <MultiTagBase>();
                    if (multiTag != null)
                    {
                        multiTag.renderId = data.RenderId;
                    }

                    if (!loadedGoes.ContainsKey(data.Id))
                    {
                        loadedGoes.Add(data.Id, go);
                    }

                    if (!SharedConfig.IsServer)
                    {
                        // 烘焙贴图数据的复原
                        var mrs = go.GetComponentsInChildren <MeshRenderer>();
                        foreach (MeshRenderer mr in mrs)
                        {
                            if (mr != null)
                            {
                                Transform tr       = mr.transform;
                                string    pos      = tr.position.WorldPosition().ToString("F4");
                                string    identify = string.Format("{0}|{1}", tr.name, pos);
                                ScenesLightmapData.MeshRecord record;
                                _scenesLightmapRecords.recordsDict.TryGetValue(identify, out record);
                                if (record != null)
                                {
                                    mr.lightmapScaleOffset = record.lightMapScaleOffset;

                                    // request lightmap to apply
                                    LevelManager levelManager = _requestHandler as LevelManager;
                                    if (levelManager != null)
                                    {
                                        List <AssetInfo> infos = new List <AssetInfo> {
                                            new AssetInfo(record.bundleName, record.colorMapAssetName)
                                        };
                                        if (!string.IsNullOrEmpty(record.dirMapAssetName))
                                        {
                                            infos.Add(new AssetInfo(record.bundleName, record.dirMapAssetName));
                                        }
                                        levelManager.assetManager.LoadAssetsAsync(mr, infos, LightmapLoaded);
                                    }
                                }
                            }
                        }

                        // 室内灯光剔除组件的应用
                        ScenesIndoorCullData.IndoorCullRecord indoorCullRecord;
                        _scenesIndoorCullRecords.recordsDict.TryGetValue(data.Id, out indoorCullRecord);
                        if (indoorCullRecord != null)
                        {
                            HouseLightsCull cull = go.GetComponent <HouseLightsCull>();
                            if (cull == null)
                            {
                                cull = go.gameObject.AddComponent <HouseLightsCull>();
                            }
                            cull.Clear();
                            cull.id              = indoorCullRecord.id;
                            cull.bakeId          = indoorCullRecord.bakeId;
                            cull.bound           = indoorCullRecord.bounds;
                            cull.lightIndexes    = indoorCullRecord.lights;
                            cull.refProbeIndexes = indoorCullRecord.refProbes;
                            cull.SetGetLightsFunc(GetLights);
                            cull.SetGetRefProbesFunc(GetReflectionProbes);
                        }
                    }
                    RequestForLoad();
                }
            }
        }
Example #2
0
        private void GoLoaded(UnityObject unityObj)
        {
            --_concurrentCount;
            if (_loadingGoes.ContainsKey(unityObj.Address))
            {
                var loadingGo = _loadingGoes[unityObj.Address].Dequeue();
                var sceneName = _sceneDescription.Scenes[loadingGo.SceneIndex].SceneName;

                if (_unloadingScene.ContainsKey(sceneName))
                {
                    _unloadingScene[sceneName].Enqueue(unityObj);
                    RequestForUnload();
                }
                else
                {
                    _streamingGo.GoLoaded(loadingGo.SceneIndex, loadingGo.GoIndex, unityObj);
                    var data = _sceneDescription.Scenes[loadingGo.SceneIndex].Objects[loadingGo.GoIndex];
                    var go   = unityObj.AsGameObject;
                    go.transform.localPosition    = data.Position.ShiftedPosition();
                    go.transform.localEulerAngles = data.Rotation;
                    go.transform.localScale       = data.Scale;
                    unityObj.SceneObjAttr.Id      = data.Id;

                    Transform prefabTf = null;
                    if (go.transform.childCount > 0)
                    {
                        prefabTf = go.transform.GetChild(0);

                        // 还原各个 AbstractSaveMono
                        string errorStr = data.LoadCompDatas(prefabTf);
                        if (!string.IsNullOrEmpty(errorStr))
                        {
                            _logger.Error(errorStr);
                        }
                    }

                    if (!loadedGoes.ContainsKey(data.Id))
                    {
                        loadedGoes.Add(data.Id, go);
                    }

                    if (!SharedConfig.IsServer)
                    {
                        // 烘焙贴图数据的复原
                        TryApplyLightmaps(data.Id);

                        // 室内灯光剔除组件的应用
                        IndoorCullRecord indoorCullRecord;
                        _scenesIndoorCullRecords.recordsDict.TryGetValue(data.Id, out indoorCullRecord);
                        if (indoorCullRecord != null)
                        {
                            HouseLightsCull cull = go.GetComponent <HouseLightsCull>();
                            if (cull == null)
                            {
                                cull = go.gameObject.AddComponent <HouseLightsCull>();
                            }
                            cull.Clear();
                            cull.id              = indoorCullRecord.id;
                            cull.bakeId          = indoorCullRecord.bakeId;
                            cull.bound           = indoorCullRecord.bounds;
                            cull.lightIndexes    = indoorCullRecord.lights;
                            cull.refProbeIndexes = indoorCullRecord.refProbes;
                            cull.SetGetLightsFunc(GetLightsFun);
                            cull.SetGetRefProbesFunc(GetReflectionProbesFun);
                        }
                    }
                    if (hideImportObject)
                    {
                        checkObjectVisible(go, data);
                    }
                    RequestForLoad();
                }
            }
        }