Ejemplo n.º 1
0
        void Start()
        {
            OCSceneConfig config = OCGenerator.GetSceneConfig(sceneName);

            if (config.IsStreamScene)
            {
                var ocDataFilePath = MultiScene.GetOCDataFilePath(config.GetSceneAssetPath(), config.SceneNamePattern);
                if (!File.Exists(ocDataFilePath))
                {
                    EditorUtility.DisplayDialog("文件不存在", string.Format("OC 数据文件 {0} 不存在!", ocDataFilePath), "确定");
                    return;
                }
                int    TileDimension = config.TileDimension;
                byte[] data          = null;
                using (var fileStream = File.Open(ocDataFilePath, FileMode.Open))
                {
                    data = new byte[fileStream.Length];
                    if (fileStream.Read(data, 0, data.Length) != data.Length)
                    {
                        EditorUtility.DisplayDialog("文件读取失败", string.Format("读取 OC 数据文件 {0} 失败!", ocDataFilePath), "确定");
                        return;
                    }
                }

                streamScene = new MultiScene(config.GetSceneAssetPath(), config.SceneNamePattern, TileDimension, config.TileSize, data);

                //streamScene.Load ();

                foreach (var index in config.indices)
                {
                    if (index.x == _tileX && index.y == _tileY)
                    {
                        int tileDimension = config.TileDimension;
                        for (int x = 0; x < tileDimension; ++x)
                        {
                            for (int y = 0; y < tileDimension; ++y)
                            {
                                if (index.x >= 0 && index.y >= 0)
                                {
                                    if (Math.Abs(x - index.x) > 1 || Math.Abs(y - index.y) > 1)
                                    {
                                        continue;
                                    }
                                }

                                //sceneNames.Add(String.Format("{0}/{1}.unity", config.GetSceneAssetPath(),
                                //String.Format(config.SceneNamePattern, x, y)));
                                streamScene.Load(x, y);
                            }
                        }
                        //streamScene.Load (index.x, index.y);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public string GetOCDataFileName()
        {
            string fileName;

            if (IsStreamScene)
            {
                fileName = MultiScene.GetOCDataFileName(SceneNamePattern);
            }
            else
            {
                fileName = SingleScene.GetOCDataFileName(SceneNamePattern);
            }

            return(fileName);
        }
Ejemplo n.º 3
0
        public void Do()
        {
            if (config.IsStreamScene)
            {
                var ocDataFilePath = MultiScene.GetOCDataFilePath(config.GetSceneAssetPath(), config.SceneNamePattern);
                if (!File.Exists(ocDataFilePath))
                {
                    EditorUtility.DisplayDialog("文件不存在", string.Format("OC 数据文件 {0} 不存在!", ocDataFilePath), "确定");
                    return;
                }
                int    TileDimension = config.TileDimension;
                byte[] data          = null;
                using (var fileStream = File.Open(ocDataFilePath, FileMode.Open))
                {
                    data = new byte[fileStream.Length];
                    if (fileStream.Read(data, 0, data.Length) != data.Length)
                    {
                        EditorUtility.DisplayDialog("文件读取失败", string.Format("读取 OC 数据文件 {0} 失败!", ocDataFilePath), "确定");
                        return;
                    }
                }

                streamScene = new MultiScene(config.GetSceneAssetPath(), config.SceneNamePattern, TileDimension, config.TileSize, data);
                for (int i = 0; i < config.TileDimension; i++)
                {
                    for (int j = 0; j < config.TileDimension; j++)
                    {
                        streamScene.Load(i, j);
                    }
                }
            }
            else
            {
                singleScene = new OC.SingleScene(config.GetSceneAssetPath(), config.SceneNamePattern, Index.InValidIndex);
                singleScene.TestLoad();
            }

            //var name = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
            //SingleScene scene = new OC.SingleScene("", name, null);
            //scene.Load();

            int width  = _width;
            int height = _height;

            RenderTexture renderTex = RenderTexture.GetTemporary(width, height, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

            RenderTexture.active = renderTex;
            cam.targetTexture    = renderTex;

            Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false);

            if (config.IsStreamScene)
            {
                foreach (var tile in streamScene.tileMap)
                {
                    var scene = tile.Value as SingleScene;

                    for (int v = 0; v < scene.volumelList.Count; v++)
                    {
                        string title  = "test volume " + v + "/" + scene.volumelList.Count;
                        string info   = "";
                        var    volume = scene.volumelList[v];

                        int finalCellCount = volume.cellList.Count;

                        for (int i = 0; i < finalCellCount; i++)
                        {
                            info = "cell " + i + "/" + finalCellCount;
                            bool bCancel = EditorUtility.DisplayCancelableProgressBar(title, info, (float)i / finalCellCount);
                            if (bCancel)
                            {
                                break;
                            }
                            var cell = volume.cellList[i];
                            MoveCamera(scene, tex, cell.aabb.center);
                        }
                    }
                }
            }
            else
            {
                for (int v = 0; v < singleScene.volumelList.Count; v++)
                {
                    string title  = "test volume " + v + "/" + singleScene.volumelList.Count;
                    string info   = "";
                    var    volume = singleScene.volumelList[v];

                    int finalCellCount = volume.cellList.Count;

                    for (int i = 0; i < finalCellCount; i++)
                    {
                        info = "cell " + i + "/" + finalCellCount;
                        bool bCancel = EditorUtility.DisplayCancelableProgressBar(title, info, (float)i / finalCellCount);
                        if (bCancel)
                        {
                            break;
                        }
                        var cell = volume.cellList[i];
                        MoveCamera(singleScene, tex, cell.aabb.center);
                    }
                }
            }


            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 4
0
        private void RotateCameraDir(Vector3 forward, HashSet <RenderableObj> ret)
        {
            Camera.main.transform.forward = forward.normalized;

            OCProfiler.Start();

            HashSet <MeshRenderer> visList = null;

            if (Config.SoftRenderer)
            {
                if (owner.owner.Owner == null)
                {
                    var renders = owner.owner.treeMesh.GetWithinFrustum(Camera.main);
                    visList = owner.owner._renderer.GetVisibleModels(renders);
                }
                else
                {
                    var renders = owner.owner.Owner.treeMesh.GetWithinFrustum(Camera.main);
                    visList = owner.owner._renderer.GetVisibleModels(renders);
                }
            }
            else
            {
                visList = owner.owner._renderer.GetVisibleModels();
            }
            var calcVisTime = OCProfiler.Stop();

            OCProfiler.Start();
            foreach (var mr in visList)
            {
                RenderableObj renderObj = null;
                if (owner.owner.Owner == null)
                {
                    renderObj = owner.owner.GetRenderableObjectByMeshRenderer(mr);
                }
                else
                {
                    MultiScene world = owner.owner.Owner as MultiScene;
                    renderObj = world.GetRenderableObjectByMeshRenderer(mr);
                }

                if (renderObj == null)
                {
                    string log = string.Format("batch mode renderObj name:{0}, scene name: {1} is null!", mr.gameObject.name, mr.gameObject.scene.name);
                    Debug.LogError(log);
                    continue;
                }

                if (!visibleModelList.Contains(renderObj))
                {
                    visibleModelList.Add(renderObj);
                }

                if (ret != null && !ret.Contains(renderObj))
                {
                    ret.Add(renderObj);
                }
            }

            var updateVisTime = OCProfiler.Stop();
        }