83 lines
2.9 KiB
C#
83 lines
2.9 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.IO;
|
||
|
|
using System.Linq;
|
||
|
|
using Convention;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.SceneManagement;
|
||
|
|
|
||
|
|
namespace Demo.Game
|
||
|
|
{
|
||
|
|
public class SubWorld : ScriptableObject
|
||
|
|
{
|
||
|
|
public static SubWorld Make()
|
||
|
|
{
|
||
|
|
return new GameObject().AddComponent<SubWorld>();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Content, SerializeField] private string project;
|
||
|
|
[Content, SerializeField] private GameController SubWorldGameController;
|
||
|
|
|
||
|
|
public override IEnumerator LoadScript(string script)
|
||
|
|
{
|
||
|
|
yield return base.LoadScript(script);
|
||
|
|
/*
|
||
|
|
// Load
|
||
|
|
var content = GameContent.instance;
|
||
|
|
// Always
|
||
|
|
content.IsCreateNewProject = false;
|
||
|
|
// Push Content
|
||
|
|
var oldContentRootSourceDir = content.RootSourceDir;
|
||
|
|
var oldSetupSongDuration = content.SetupSongDuration;
|
||
|
|
var oldSetSongCurrentTime = content.SetSongCurrentTime;
|
||
|
|
// Setting New
|
||
|
|
content.RootSourceDir = Path.Combine(PlatformIndicator.StreamingAssetsPath, project) + "/";
|
||
|
|
content.SetupSongDuration = (x, y) => { };
|
||
|
|
content.SetSongCurrentTime = x => { };
|
||
|
|
var ir = SceneManager.LoadSceneAsync(Editor.EditorController.SceneName, LoadSceneMode.Additive);
|
||
|
|
ir.completed += x =>
|
||
|
|
{
|
||
|
|
SubWorldGameController = (from controller in FindObjectsOfType<GameController>()
|
||
|
|
where controller.RootSourcePath == project
|
||
|
|
select controller).First();
|
||
|
|
};
|
||
|
|
yield return ir;
|
||
|
|
// Pull Content
|
||
|
|
content.RootSourceDir = oldContentRootSourceDir;
|
||
|
|
content.SetupSongDuration = oldSetupSongDuration;
|
||
|
|
content.SetSongCurrentTime = oldSetSongCurrentTime;
|
||
|
|
*/
|
||
|
|
var ir = SceneManager.LoadSceneAsync(Editor.EditorController.SceneName, LoadSceneMode.Additive);
|
||
|
|
IEnumerator after = null;
|
||
|
|
ir.completed += x =>
|
||
|
|
{
|
||
|
|
SubWorldGameController = (from controller in FindObjectsOfType<GameController>()
|
||
|
|
where controller.RootSourcePath == project
|
||
|
|
select controller).First();
|
||
|
|
after = SubWorldGameController.GameInitBySubWorld(GetRoot().InputCatch);
|
||
|
|
};
|
||
|
|
yield return ir;
|
||
|
|
yield return after;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override IEnumerator UnloadScript()
|
||
|
|
{
|
||
|
|
yield return SubWorldGameController.GameExit();
|
||
|
|
yield return base.UnloadScript();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 加载附属场景
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="project"></param>
|
||
|
|
[ScriptableCall(@"
|
||
|
|
<summary>
|
||
|
|
加载附属场景
|
||
|
|
</summary>
|
||
|
|
<param name=""project""></param>
|
||
|
|
")]
|
||
|
|
public void Load(string project)
|
||
|
|
{
|
||
|
|
this.project = project;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|