コード例 #1
0
ファイル: RegionBase.cs プロジェクト: Namerian/WorldStreaming
        void IRegionEventHandler.CreateSubScene(eSubSceneMode subSceneMode, eSubSceneType subSceneType)
        {
            string subScenePath = WorldUtility.GetSubScenePath(gameObject.scene.path, Id, subSceneMode, subSceneType);
            string subScenePathFull = WorldUtility.GetFullPath(subScenePath);

            if (GetSubSceneRoot(subSceneType) != null)
            {
                return;
            }
            else if (System.IO.File.Exists(subScenePathFull))
            {
                Debug.LogFormat("SubScene \"{0}\" already exists but is not loaded!", subScenePath);
                return;
            }
            else
            {
                var rootGO = new GameObject(WorldUtility.GetSubSceneRootName(subSceneMode, subSceneType), typeof(SubScene));
                rootGO.GetComponent<SubScene>().Initialize(subSceneMode, subSceneType);

                var root = rootGO.transform;
                root.SetParent(transform, false);
            }
        }
コード例 #2
0
        void IWorldEventHandler.ExportSubScenes()
        {
            if (!editorSubScenesLoaded)
            {
                return;
            }

            //clear subScene folder
            ((IWorldEventHandler)this).ClearSubSceneFolder();

            //create folder, in case it does not exist
            string scenePath = gameObject.scene.path;
            string folderPath = scenePath.Remove(scenePath.LastIndexOf('.'));
            string parentFolderPath = folderPath.Remove(folderPath.LastIndexOf('/'));
            if (!UnityEditor.AssetDatabase.IsValidFolder(folderPath))
            {
                UnityEditor.AssetDatabase.CreateFolder(parentFolderPath, gameObject.scene.name);
            }

            //finding all the regions
            var regions = new List<RegionBase>();
            for (int i = 0; i < transform.childCount; i++)
            {
                var region = transform.GetChild(i).GetComponent<RegionBase>();

                if (region != null)
                {
                    regions.Add(region);
                }
            }

            foreach (var region in regions)
            {
                foreach (var subSceneType in Enum.GetValues(typeof(eSubSceneType)).Cast<eSubSceneType>())
                {
                    foreach (var subSceneMode in region.AvailableSubSceneModes)
                    {
                        var root = region.GetSubSceneRoot(subSceneType, subSceneMode);

                        if (!root || root.childCount == 0) //if root is null or empty there is no need to create a subScene
                        {
                            continue;
                        }

                        //paths
                        string subScenePath = WorldUtility.GetSubScenePath(gameObject.scene.path, region.Id, subSceneMode, subSceneType);
                        //string subScenePathFull = WorldUtility.GetFullPath(subScenePath);

                        //moving copy to subScene
                        root.SetParent(null, false);
                        var subScene = UnityEditor.SceneManagement.EditorSceneManager.NewScene(UnityEditor.SceneManagement.NewSceneSetup.EmptyScene, UnityEditor.SceneManagement.NewSceneMode.Additive);
                        UnityEditor.SceneManagement.EditorSceneManager.MoveGameObjectToScene(root.gameObject, subScene);

                        //saving and closing the sub scene
                        UnityEditor.SceneManagement.EditorSceneManager.SaveScene(subScene, subScenePath);
                        UnityEditor.SceneManagement.EditorSceneManager.CloseScene(subScene, true);

                        //add subScene to buildsettings
                        var buildSettingsScenes = UnityEditor.EditorBuildSettings.scenes.ToList();
                        buildSettingsScenes.Add(new UnityEditor.EditorBuildSettingsScene(subScenePath, true));
                        UnityEditor.EditorBuildSettings.scenes = buildSettingsScenes.ToArray();

                        // if (root.childCount != 0)
                        // {
                        //     foreach (var superRegionType in Enum.GetValues(typeof(eSuperRegionType)).Cast<eSuperRegionType>())
                        //     {
                        //         //duplicating
                        //         var rootCopyGO = Instantiate(root.gameObject, root.position, Quaternion.identity);
                        //         rootCopyGO.name = root.name;
                        //         rootCopyGO.transform.Translate(Vector3.Scale(worldSize, SUPERREGION_OFFSETS[superRegionType]));
                        //     }
                        // }
                    }
                }
            }

            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(gameObject.scene);
            editorSubScenesLoaded = false;
        }
コード例 #3
0
        void IWorldEventHandler.ImportSubScenes()
        {
            if (editorSubScenesLoaded)
            {
                return;
            }

            var regions = new List<RegionBase>();

            for (int i = 0; i < transform.childCount; i++)
            {
                var region = transform.GetChild(i).GetComponent<RegionBase>();

                if (region)
                {
                    regions.Add(region);
                }
            }

            foreach (var region in regions)
            {
                foreach (var subSceneType in Enum.GetValues(typeof(eSubSceneType)).Cast<eSubSceneType>())
                {
                    foreach (var subSceneMode in region.AvailableSubSceneModes)
                    {
                        if (region.GetSubSceneRoot(subSceneType, subSceneMode) != null)
                        {
                            Debug.LogErrorFormat("The \"{0}\" of Region \"{1}\" is already loaded!", WorldUtility.GetSubSceneRootName(subSceneMode, subSceneType), region.name);
                            continue;
                        }

                        //paths
                        string subScenePath = WorldUtility.GetSubScenePath(gameObject.scene.path, region.Id, subSceneMode, subSceneType);
                        string subScenePathFull = WorldUtility.GetFullPath(subScenePath);

                        Scene subScene = new Scene();

                        if (System.IO.File.Exists(subScenePathFull))
                        {
                            subScene = UnityEditor.SceneManagement.EditorSceneManager.OpenScene(subScenePath, UnityEditor.SceneManagement.OpenSceneMode.Additive);
                        }

                        //move subScene content to open world scene
                        if (subScene.IsValid())
                        {
                            var rootGO = subScene.GetRootGameObjects()[0];
                            UnityEditor.SceneManagement.EditorSceneManager.MoveGameObjectToScene(rootGO, this.gameObject.scene);

                            var root = rootGO.transform;
                            root.SetParent(region.transform, false);

                            if (!root.gameObject.activeSelf)
                            {
                                root.gameObject.SetActive(true);
                            }
                        }

                        //end: close subScene
                        UnityEditor.SceneManagement.EditorSceneManager.CloseScene(subScene, true);
                    }
                }
            }


            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(gameObject.scene);
            editorSubScenesLoaded = true;
        }