Exemple #1
0
        void ReadJsonConfig(string sceneName)
        {
            //open scene to get
            var config = OCGenerator.GetSceneConfig(sceneName);

            cellSize    = config.CellSize;
            IsFrameBake = config.ComputePerframe;

            indices = config.indices;

            IsStreamScene     = config.IsStreamScene;
            maxPlayAreaHeight = config.MaxPlayerHeight;
            minPlayAreaHeight = config.MinPlayerHeight;
            IsMergeCell       = config.MergeCell;
            cellMergeWeight   = config.MergeCellWeight;
            mergeDistance     = config.MergeObjectDistance;
            mergeObjectSize   = config.MergeObjectSize;
            IsMergeObjectID   = config.MergeObjectID;
            frameCellCount    = config.PerframeExecCount;
            assetPath         = config.SceneAssetPath;
        }
        /*public static void OpenScenes(string name)
         * {
         *  OCSceneConfig config = OCGenerator.GetSceneConfig(name);
         *  string path = config.GetSceneAssetPath();
         *  path += "/";
         *
         *
         *  if (config.IsStreamScene)
         *  {
         *      int tileDim = config.TileDimension;
         *      int tileSize = config.TileSize;
         *
         *      var mainScene = SceneManager.GetSceneByName("AdditiveScene.unity");
         *      if(mainScene.isLoaded == false)
         *          EditorSceneManager.OpenScene(path + "AdditiveScene.unity", OpenSceneMode.Additive);
         *
         *      foreach (var index in config.indices)
         *      {
         *          string sceneName = string.Format("{0} {1}x{2}", name, index.x , index.y);
         *          string scenePath = path + sceneName + ".unity";
         *
         *          var scene = SceneManager.GetSceneByName(sceneName);
         *          if (scene.isLoaded == false)
         *              EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
         *      }
         *
         *  }
         *  else
         *  {
         *      EditorSceneManager.OpenScene(path + name +".unity");
         *  }
         * }*/

        public static void GenerateTestStreamScenes(string name)
        {
            OCSceneConfig config = OCGenerator.GetSceneConfig(name);
            string        path   = config.GetSceneAssetPath();

            path += "/";

            int tileDim  = config.TileDimension;
            int tileSize = config.TileSize;

            var template = Resources.Load("root") as GameObject;

            var mainScene = EditorSceneManager.OpenScene(path + "AdditiveScene.unity");

            foreach (var root in mainScene.GetRootGameObjects())
            {
                GameObject.DestroyImmediate(root);
            }
            var mainCamera = Resources.Load("MainCamera") as GameObject;
            var cam        = GameObject.Instantiate(mainCamera);


            for (int i = 0; i < tileDim; i++)
            {
                for (int j = 0; j < tileDim; j++)
                {
                    string sceneName = string.Format("{0} {1}x{2}", name, i, j);
                    string scenePath = path + sceneName + ".unity";
                    var    scene     = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);

                    EditorSceneManager.SetActiveScene(scene);

                    foreach (var root in scene.GetRootGameObjects())
                    {
                        GameObject.DestroyImmediate(root);
                    }

                    var templateGO = GameObject.Instantiate(template);
                    templateGO.transform.localScale = new Vector3(tileSize / 10, tileSize / 10, tileSize / 10);
                    templateGO.transform.position   = new Vector3(i * tileSize, 0, j * tileSize);
                    var     pos         = templateGO.transform.position;
                    float   offsetValue = -tileSize * tileDim * 0.5f;
                    Vector3 offset      = new Vector3(offsetValue, 0, offsetValue);
                    templateGO.transform.position = pos + offset;

                    var coms = templateGO.GetComponentsInChildren <MeshRenderer>();

                    int count = 0;
                    foreach (var com in coms)
                    {
                        var idcom = com.gameObject.GetComponent <GameObjectID>();
                        if (idcom == null)
                        {
                            idcom = com.gameObject.AddComponent <GameObjectID>();
                        }

                        idcom.GUID = count;
                        count++;
                    }

                    EditorSceneManager.SaveScene(scene);
                }
            }

            //EditorSceneManager.SaveOpenScenes();
        }
Exemple #3
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal("Scene");
            sceneName = EditorGUILayout.TextField("场景名字", sceneName);
            assetPath = EditorGUILayout.TextField("场景路径", assetPath);
            if (GUILayout.Button("打开场景"))
            {
                OCGenerator.OpenScene(sceneName, new Index(tileX, tileY));
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("base setting");
            processNumber = EditorGUILayout.IntField("进程数", processNumber);
            cellSize      = EditorGUILayout.FloatField("Cell大小", cellSize);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("Screen");
            screenWidth  = EditorGUILayout.IntField("屏幕宽", screenWidth);
            screenHeight = EditorGUILayout.IntField("屏幕高", screenHeight);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("Player");
            maxPlayAreaHeight = EditorGUILayout.Slider("玩家最大可到达高度", maxPlayAreaHeight, 0, 10);
            minPlayAreaHeight = EditorGUILayout.Slider("玩家最小不可到达高度", minPlayAreaHeight, 0, 10);
            GUILayout.EndHorizontal();

            IsFrameBake    = EditorGUILayout.BeginToggleGroup("分帧烘焙", IsFrameBake);
            frameCellCount = EditorGUILayout.IntField("每帧烘焙cell的个数", frameCellCount);
            EditorGUILayout.EndToggleGroup();

            IsMergeCell     = EditorGUILayout.BeginToggleGroup("是否融合Cell", IsMergeCell);
            cellMergeWeight = EditorGUILayout.Slider("融合相似度", cellMergeWeight, 0, 1);
            EditorGUILayout.EndToggleGroup();

            IsMergeObjectID = EditorGUILayout.BeginToggleGroup("是否融合GUID", IsMergeObjectID);
            GUILayout.BeginHorizontal("Merge Object");
            mergeObjectSize = EditorGUILayout.FloatField("对象大小", mergeObjectSize);
            mergeDistance   = EditorGUILayout.FloatField("对象距离", mergeDistance);
            GUILayout.EndHorizontal();
            EditorGUILayout.EndToggleGroup();


            //----------------
            IsStreamScene = EditorGUILayout.BeginToggleGroup("是否是流式场景", IsStreamScene);

            IsBakeOne = EditorGUILayout.BeginToggleGroup("只烘焙一小块地形(流式)", IsBakeOne);
            GUILayout.BeginHorizontal("tile index");

            tileX = EditorGUILayout.IntField("宽度索引(流式)", tileX);

            tileY = EditorGUILayout.IntField("高度索引(流式)", tileY);
            if (GUILayout.Button("烘焙单块(流式)"))
            {
                if (IsBakeOne)
                {
                    OCGenerator.TestBakeOneTile(sceneName, tileX, tileY);
                }
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.EndToggleGroup(); //end IsBakeOne
            EditorGUILayout.EndToggleGroup(); //end IsStreamScene


            /*for (int i = 0; i < indices.Count; i++)
             * {
             *  var index = indices[i];
             *  Vector2 tile = new Vector2(index.x, index.y);
             *  EditorGUILayout.Vector2Field("bake tile", tile);
             *
             * }*/


            bTest = EditorGUILayout.BeginToggleGroup("测试", bTest);

            if (GUILayout.Button("创建测试所用的场景"))
            {
                OCGenerator.GenerateTestStreamScenes(sceneName);
            }

            GUILayout.BeginHorizontal("Json");

            if (GUILayout.Button("创建Json文件"))
            {
                OCGenerator.TestCreateScensJson();
            }

            if (GUILayout.Button("写Json配置"))
            {
                //OCGenerator.OpenScenes(sceneName);

                OCGenerator.WriteJsonConfig(sceneName, IsStreamScene, screenWidth, screenHeight, maxPlayAreaHeight, minPlayAreaHeight, cellSize,
                                            IsFrameBake, frameCellCount, IsMergeCell, cellMergeWeight, IsMergeObjectID, mergeDistance, mergeObjectSize, indices);
            }
            if (GUILayout.Button("读Json配置"))
            {
                //OCGenerator.OpenScenes(sceneName);
                ReadJsonConfig(sceneName);
            }

            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal("test");
            if (GUILayout.Button("根据进程数生成配置文件"))
            {
                OCGenerator.TestGenerateOCGenMapConfigFile(sceneName, processNumber);
            }

            if (GUILayout.Button("TestInitConfig(open scenes and generate ID)"))
            {
                OCGenerator.TestInitOCGeneration(sceneName);
            }

            if (GUILayout.Button("程序化自动测试数据"))
            {
                OCSceneConfig config = OCGenerator.GetSceneConfig(sceneName);
                PVSTest       test   = new PVSTest(Camera.main, config);
                test.Test();
            }


            /*if (GUILayout.Button("打开场景并加载OC数据"))
             * {
             *  OCGenerator.OpenScenes(sceneName);
             *  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);
             *      //for (int i = 0; i < TileDimension; i++)
             *          //for (int j = 0; j < TileDimension; j++)
             *              //streamScene.Load(i, j);
             *      foreach(var index in config.indices )
             *      {
             *          streamScene.Load(index.x, index.y);
             *      }
             *
             *  }
             *  else
             *  {
             *
             *      singleScene = new OC.SingleScene(config.GetSceneAssetPath(), config.SceneNamePattern, Index.InValidIndex);
             *      singleScene.TestLoad();
             *  }
             *
             * }*/
            GUILayout.EndHorizontal();

            /*GUILayout.BeginHorizontal("OC");
             * if (GUILayout.Button("打开OC"))
             * {
             *  OCSceneConfig config = OCGenerator.GetSceneConfig(sceneName);
             *  if (config.IsStreamScene)
             *  {
             *      if (streamScene == null)
             *          Debug.LogError("stream scene is null!");
             *      else
             *      {
             *          streamScene.DoCulling(Camera.main.transform.position);
             *      }
             *  }
             *  else
             *  {
             *      if (singleScene == null)
             *          Debug.LogError("stream scene is null!");
             *      else
             *      {
             *          singleScene.DoCulling(Camera.main.transform.position);
             *      }
             *  }
             *
             * }
             * if (GUILayout.Button("关闭OC"))
             * {
             *  OCSceneConfig config = OCGenerator.GetSceneConfig(sceneName);
             *  if (config.IsStreamScene)
             *  {
             *      if (streamScene == null)
             *          Debug.LogError("stream scene is null!");
             *      else
             *      {
             *          streamScene.UndoCulling();
             *      }
             *  }
             *  else
             *  {
             *      if (singleScene == null)
             *          Debug.LogError("stream scene is null!");
             *      else
             *      {
             *          singleScene.UndoCulling();
             *      }
             *  }
             * }
             *
             * GUILayout.EndHorizontal();*/
            if (GUILayout.Button("TestApplyOCData"))
            {
                OCGenerator.TestApplyOCData(sceneName);
            }


            EditorGUILayout.EndToggleGroup();



            GUILayout.Label("烘焙", EditorStyles.boldLabel);

            GUILayout.BeginHorizontal("bake");

            if (GUILayout.Button("产生所有场景ID并保存"))
            {
                OCGenerator.OpenAllScenesAndGernerateGUID(sceneName);
            }

            jsonI = EditorGUILayout.IntField("第几个Json配置文件", jsonI);
            if (GUILayout.Button("烘焙配置文件"))
            {
                //EditorSceneManager.SaveOpenScenes();

                //OCGenerator.WriteJsonConfig(sceneName, IsStreamScene, screenWidth, screenHeight, maxPlayAreaHeight, minPlayAreaHeight, cellSize,
                //IsFrameBake, frameCellCount, IsMergeCell, cellMergeWeight, IsMergeObjectID, mergeDistance, mergeObjectSize, indices);

                OCGenerator.TestGenerateOCData(jsonI);
            }

            GUILayout.EndHorizontal();

            if (GUILayout.Button("烘焙所有"))
            {
                //OCGenerator.WriteJsonConfig(sceneName, IsStreamScene, screenWidth, screenHeight, maxPlayAreaHeight, minPlayAreaHeight, cellSize,
                //IsFrameBake, frameCellCount, IsMergeCell, cellMergeWeight, IsMergeObjectID, mergeDistance, mergeObjectSize, indices);
                //EditorSceneManager.SaveOpenScenes();
                OCGenerator.TestBakeAll(sceneName);
                //OCGenerator.TestMergeOCDataForStreamScene();
            }

            if (GUILayout.Button("融合OC数据"))
            {
                OCGenerator.TestMergeOCDataForStreamScene();
            }
        }