73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
using Convention;
|
|
using Demo.Game.Attr;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Demo.Game
|
|
{
|
|
namespace ConfigType
|
|
{
|
|
// SubWorld 配置
|
|
public class SubWorldConfig : ScriptLoadableConfig
|
|
{
|
|
public string project;
|
|
|
|
public override void Deserialize(BinaryReader reader)
|
|
{
|
|
project = BinarySerializeUtility.ReadString(reader);
|
|
base.Deserialize(reader);
|
|
}
|
|
|
|
public override void Serialize(BinaryWriter writer)
|
|
{
|
|
BinarySerializeUtility.WriteString(writer, project);
|
|
base.Serialize(writer);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Scriptable]
|
|
public class SubWorld : ScriptableObject
|
|
{
|
|
public static SubWorld Make()
|
|
{
|
|
return new GameObject().AddComponent<SubWorld>();
|
|
}
|
|
|
|
[Content, SerializeField] private string project;
|
|
[Content, SerializeField] private GameController SubWorldGameController;
|
|
|
|
protected override IEnumerator DoSomethingDuringApplyScript()
|
|
{
|
|
yield return base.DoSomethingDuringApplyScript();
|
|
var ir = SceneManager.LoadSceneAsync(Editor.EditorController.SceneName, LoadSceneMode.Additive);
|
|
ir.completed += x =>
|
|
{
|
|
SubWorldGameController = (from controller in FindObjectsByType<GameController>(FindObjectsSortMode.None)
|
|
where controller.RootSourcePath == project
|
|
select controller).First();
|
|
ConventionUtility.StartCoroutine(SubWorldGameController.GameInitBySubWorld(GetRoot().InputCatch));
|
|
};
|
|
}
|
|
|
|
public override IEnumerator UnloadScript()
|
|
{
|
|
yield return SubWorldGameController.GameExit();
|
|
yield return base.UnloadScript();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载附属场景
|
|
/// </summary>
|
|
/// <param name="project"></param>
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void Load(string project)
|
|
{
|
|
this.project = project;
|
|
}
|
|
}
|
|
}
|