static void _UpdateSceneAssetNames(OpenWorldSettings settings)
        {
            GetOpenWorldSceneAssetsInDirectory(settings, out settings.openWorldSettingsSceneAsset, out settings.sceneAssets_0, out settings.sceneAssets_1);
            AddScenesToBuildSettings(settings);
            UpdateWorldNamesPerSceneList(settings.sceneAssets_0, ref settings.worldSceneNames_0);
            UpdateWorldNamesPerSceneList(settings.sceneAssets_1, ref settings.worldSceneNames_1);

            int l = settings.sceneAssets_0.Length;

            if (l != settings.worldSceneGrids.Length)
            {
                settings.worldSceneGrids = new Vector2Int[l];
            }

            for (int i = 0; i < l; i++)
            {
                if (settings.sceneAssets_0[i] != null)
                {
                    string[] xy = (settings.worldSceneNames_0[i].Split(keySplit, StringSplitOptions.None)[0].Split('@')[0]).Split('_');
                    settings.worldSceneGrids[i] = new Vector2Int(int.Parse(xy[0]), int.Parse(xy[1]));
                }
                else
                {
                    settings.worldSceneGrids[i] = new Vector2Int(-1, -1);
                }
            }
        }
 public static string GetDirectory(OpenWorldSettings settings)
 {
     if (!settings.scenesListDirectory.EndsWith("/"))
     {
         return(settings.scenesListDirectory + "/");
     }
     return(settings.scenesListDirectory);
 }
        public static void UpdateSceneAssetNames()
        {
            OpenWorldSettings settings = GameSettings.GetSettings <OpenWorldSettings>();

            if (settings != null)
            {
                _UpdateSceneAssetNames(settings);
            }
        }
        public static string Grid2Scene(OpenWorldSettings settings, Vector2Int grid, int lod, bool debug)
        {
            string scene = settings.Grid2Scene(grid, lod, debug);

            if (scene != null)
            {
                return(GetDirectory(settings) + scene + ".unity");
            }
            return(scene);
        }
        static void AddScenesToBuildSettings(OpenWorldSettings settings)
        {
            EditorBuildSettingsScene[] buildScenes = EditorBuildSettings.scenes;

            List <EditorBuildSettingsScene> finalScenes = new List <EditorBuildSettingsScene>();

            // add all non open world scenes taht were already in the build settings...
            for (int i = 0; i < buildScenes.Length; i++)
            {
                string path = buildScenes[i].path;

                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }

                if (path.Contains(OpenWorld.openWorldSceneKey) || path.Contains(OpenWorld.openWorldSettingsScene))
                {
                    continue;
                }

                finalScenes.Add(buildScenes[i]);
            }


            // add the settings scene
            finalScenes.Add(new EditorBuildSettingsScene(AssetDatabase.GetAssetPath(settings.openWorldSettingsSceneAsset), true));

            // add lod0 and lod1 scenes...
            for (int i = 0; i < settings.sceneAssets_0.Length; i++)
            {
                finalScenes.Add(new EditorBuildSettingsScene(AssetDatabase.GetAssetPath(settings.sceneAssets_0[i]), true));
            }
            for (int i = 0; i < settings.sceneAssets_1.Length; i++)
            {
                finalScenes.Add(new EditorBuildSettingsScene(AssetDatabase.GetAssetPath(settings.sceneAssets_1[i]), true));
            }

            EditorBuildSettings.scenes = finalScenes.ToArray();
        }
        static void GetOpenWorldSceneAssetsInDirectory(OpenWorldSettings settings, out SceneAsset openWorldSettingsSceneAsset, out SceneAsset[] lod0s, out SceneAsset[] lod1s)
        {
            openWorldSettingsSceneAsset = null;

            List <SceneAsset> sceneAssets0 = new List <SceneAsset>();
            List <SceneAsset> sceneAssets1 = new List <SceneAsset>();
            string            dir          = GetDirectory(settings);

            if (Directory.Exists(dir))
            {
                int           unityDirectoryLength = Application.dataPath.Length - 6;
                DirectoryInfo di = new DirectoryInfo(dir);
                foreach (FileInfo file in di.GetFiles())
                {
                    string name = file.FullName;
                    if (!name.EndsWith(".meta"))
                    {
                        if (name.EndsWith(".unity"))
                        {
                            bool isSettingsScene = name.Contains(OpenWorld.openWorldSettingsScene);
                            bool isCellScene     = !isSettingsScene && name.Contains(OpenWorld.openWorldSceneKey);
                            if (isSettingsScene || isCellScene)
                            {
                                SceneAsset asset = AssetDatabase.LoadAssetAtPath <SceneAsset>(name.Substring(unityDirectoryLength));
                                if (isCellScene)
                                {
                                    (name.Contains(OpenWorld.lod0Check) ? sceneAssets0 : sceneAssets1).Add(asset);
                                }
                                else
                                {
                                    openWorldSettingsSceneAsset = asset;
                                }
                            }
                        }
                    }
                }
            }
            lod0s = sceneAssets0.ToArray();
            lod1s = sceneAssets1.ToArray();
        }