1.全阶段异步加载与AB包预加载2.node加载无效的问题依然存在

This commit is contained in:
2025-10-06 16:09:52 +08:00
parent 8f8dfcbb64
commit 334f55a250
27 changed files with 1274 additions and 1220 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 200725c262851254db49e0c1a5729c77
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Demo.ScriptableObject), true)]
public class SOEditor : Convention.AbstractCustomEditor
{
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e4af2f5018ef1934cb4055d18185a75c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -11,18 +11,8 @@ namespace Demo.Game
return new GameObject().AddComponent<PrefabRootObject>();
}
private List<IEnumerator> AssetBundleLoadings = new();
private List<string> AssetBundles = new();
private List<GameObject> Prefabs = new();
public override IEnumerator LoadScript(string script)
{
yield return base.LoadScript(script);
foreach (var loading in AssetBundleLoadings)
{
yield return loading;
}
}
private readonly List<string> AssetBundles = new();
private readonly List<GameObject> Prefabs = new();
public override IEnumerator UnloadScript()
{
@@ -45,36 +35,31 @@ namespace Demo.Game
<param name=""ab""></param>
<param name=""prefab""></param>
")]
public void Load(string ab, string prefab)
public IEnumerator Load(string ab, string prefab)
{
IEnumerator Foo()
AssetBundle assetBundle = null;
yield return this.LoadAssetBundle(ab, x => assetBundle = x);
GameObject prefabObject = null;
if (assetBundle != null)
{
AssetBundle assetBundle = null;
yield return this.LoadAssetBundle(ab, x => assetBundle = x);
GameObject prefabObject = null;
if (assetBundle != null)
var ir = assetBundle.LoadAssetAsync<GameObject>(prefab);
yield return ir;
if (ir.asset != null)
{
var ir = assetBundle.LoadAssetAsync<GameObject>(prefab);
yield return ir;
if (ir.asset != null)
{
prefabObject = Instantiate(ir.asset as GameObject);
Prefabs.Add(prefabObject);
prefabObject.transform.SetParent(transform);
AssetBundles.Add(ab);
}
else
{
Debug.LogError($"Load Prefab failed", this);
}
prefabObject = Instantiate(ir.asset as GameObject);
Prefabs.Add(prefabObject);
prefabObject.transform.SetParent(transform);
AssetBundles.Add(ab);
}
else
{
Debug.LogError($"Load AssetBundle failed", this);
Debug.LogError($"Load Prefab failed", this);
}
}
AssetBundleLoadings.Add(Foo());
else
{
Debug.LogError($"Load AssetBundle failed", this);
}
}
}
}

View File

@@ -59,9 +59,9 @@ namespace Demo.Game
</summary>
<param name=""ab""></param>
")]
public void Load(string ab)
public IEnumerator Load(string ab)
{
SkyAssetBundleLoading = this.LoadAssetBundle(ab, x =>
yield return this.LoadAssetBundle(ab, x =>
{
SkyAssetBundlePath = ab;
SkyAssetBundle = x;

View File

@@ -117,7 +117,7 @@ namespace Demo.Game
yield return null;
// Setup Game Rules
// Setup Game Rules (Main)
if (Editor.EditorController.instance.MainGameController == this)
{
ScriptableObject.FastScriptableObjectTypen = content.ScriptableObjectTypen;
@@ -126,11 +126,23 @@ namespace Demo.Game
SongOffset = (float)MainConfig.FindItem(nameof(SongOffset), SongOffset);
SetupSongDuration = GameContent.instance.SetupSongDuration;
SetSongCurrentTime = GameContent.instance.SetSongCurrentTime;
}
// Setup Game Rules
{
foreach (var ab in ((string)MainConfig.FindItem(nameof(AssetBundle), "")).Split(';'))
{
if (string.IsNullOrEmpty(ab))
continue;
StartCoroutine(AssetBundlesLoadHelper.LoadAssetBundleAsync(ab.Trim(), null));
}
IsHideTrackRender = (bool)MainConfig.FindItem(nameof(IsHideTrackRender), false);
IsAutoPlay = GameContent.instance.IsAutoPlay;
WhichOpenScript = (string)MainConfig.FindItem(nameof(WhichOpenScript), WhichOpenScript);
// Open Project
WhichOpenProject = (string)MainConfig.FindItem(nameof(WhichOpenProject), WhichOpenProject);
if (string.IsNullOrEmpty(WhichOpenProject) == false)
{
string path = string.Format($"{WhichOpenProject}", $"\"{Editor.EditorController.instance.PersistentDataPath}\"") ;
string path = string.Format($"{WhichOpenProject}", $"\"{Editor.EditorController.instance.PersistentDataPath}\"");
try
{
System.Diagnostics.Process.Start(path);
@@ -141,55 +153,51 @@ namespace Demo.Game
Debug.LogException(ex, this);
}
}
CurrentProjectDefaultFileStyle = content.CurrentProjectDefaultFileStyle;
}
MainConfig.SaveProperties();
yield return null;
// Load Root Object
{
while (MainConfig.Contains("root") == false)
{
IsHideTrackRender = (bool)MainConfig.FindItem(nameof(IsHideTrackRender), false);
IsAutoPlay = GameContent.instance.IsAutoPlay;
WhichOpenScript = (string)MainConfig.FindItem(nameof(WhichOpenScript), WhichOpenScript);
CurrentProjectDefaultFileStyle = content.CurrentProjectDefaultFileStyle;
}
yield return null;
MainConfig.SaveProperties();
// Load Root Object
{
while (MainConfig.Contains("root") == false)
string defaultRootPath = "root" + CurrentProjectDefaultFileStyle switch
{
string defaultRootPath = "root" + CurrentProjectDefaultFileStyle switch
ProjectDefaultFileStyle.PY => ".py",
_ => ".cpp"
};
if (content.IsCreateNewProject)
{
MainConfig["root"] = defaultRootPath;
if (MainConfig.CreateFile(defaultRootPath))
{
ProjectDefaultFileStyle.PY => ".py",
_ => ".cpp"
};
if (content.IsCreateNewProject)
{
MainConfig["root"] = defaultRootPath;
if (MainConfig.CreateFile(defaultRootPath))
{
MainConfig.SaveProperties();
break;
}
MainConfig.SaveProperties();
break;
}
Debug.LogError($"{nameof(defaultRootPath)} is cannt create or config's root property is not exist", this);
StartCoroutine(GameExit());
yield break;
}
var rootFileName = (string)MainConfig.FindItem("root");
var rootObject = new ToolFile(Path.Combine(content.RootSourceDir, rootFileName));
rootObject.MustExistsPath();
var rootGameObject = new GameObject(rootObject.GetName(true)).AddComponent<RootObject>();
rootGameObject.transform.SetParent(transform);
rootGameObject.ScriptName = rootObject.GetName(true);
rootGameObject.audioSystem = MainAudio;
rootGameObject.EnableScript(content.RootSourceDir, rootObject.GetFullPath(), this);
try
{
yield return rootGameObject.LoadScript(rootObject.LoadAsText());
}
finally
{
MainObject = rootGameObject;
}
Debug.LogError($"{nameof(defaultRootPath)} is cannt create or config's root property is not exist", this);
StartCoroutine(GameExit());
yield break;
}
var rootFileName = (string)MainConfig.FindItem("root");
var rootObject = new ToolFile(Path.Combine(content.RootSourceDir, rootFileName));
rootObject.MustExistsPath();
var rootGameObject = new GameObject(rootObject.GetName(true)).AddComponent<RootObject>();
rootGameObject.transform.SetParent(transform);
rootGameObject.ScriptName = rootObject.GetName(true);
rootGameObject.audioSystem = MainAudio;
rootGameObject.EnableScript(content.RootSourceDir, rootObject.GetFullPath(), this);
try
{
yield return rootGameObject.LoadScript(rootObject.LoadAsText());
}
finally
{
MainObject = rootGameObject;
}
}
}

View File

@@ -569,6 +569,9 @@ namespace Demo
MyHierarchyItem.GetHierarchyItem().title = this.ScriptName + $"<{scriptType}>";
MyHierarchyItem.GetHierarchyItem().target = this;
MyHierarchyItem.GetHierarchyItem().ButtonGameObject.GetComponent<Editor.UI.RightClick>().ScriptObjectMenu = OnHierarchyItemRightClick;
var parentHierarchyItem = MyHierarchyItem.GetParent();
if (parentHierarchyItem != null)
parentHierarchyItem.GetPropertyListItem().RefreshChilds();
}
public ScriptableObject FindWithPath(string path, bool isMustExist = true)
@@ -639,6 +642,48 @@ namespace Demo
return result;
}
public IEnumerator LoadSubScriptAsync([In] string type, [In] string path, [Opt] Action<ScriptableObject> callback)
{
// 判断类型是否合法
if (DefaultInstantiate.GetScriptableObjectInstantiate().TryGetValue(type, out var creater) == false)
{
Debug.LogError($"{type} is not exist or {type}'s Instantiater is not valid", this);
callback?.Invoke(null);
yield break;
}
// 生成对象
var child = creater();
// 路径预处理
if (path.Replace('\\', '/').ToLower().StartsWith("project/"))
path = $"{new ToolFile(GetRoot().SourcePath) | path[5..]}";
// 获取文件
ToolFile file;
if (File.Exists(path))
file = new(path);
else
file = new ToolFile(SourcePath) | path;
// 找不到脚本
if (file.Exists() == false)
{
Debug.LogError($"{file}<{path}> is not found", this);
callback?.Invoke(null);
yield break;
}
child.ScriptName = file.GetName(true);
child.transform.SetParent(this.transform);
child.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
child.transform.localScale = Vector3.one;
child.EnableScript(file.GetCurrentDirName(), Path.Combine(file.GetCurrentDirName(), file.GetName(false)), type, this);
// Add Child
Childs.Add(child);
// Load Child Script
yield return child.LoadScript(file.LoadAsText());
callback?.Invoke(child);
}
/// <summary>
/// 加载子脚本
/// </summary>
@@ -651,49 +696,9 @@ namespace Demo
<param name=""type"">指定类型</param>
<param name=""path"">指定脚本,可用决定路径或与当前脚本目录的相对路径</param>
")]
[return:ReturnMayNull]
public ScriptableObject LoadSubScript(string type, string path)
public IEnumerator LoadSubScript([In] string type, [In] string path)
{
// 判断类型是否合法
if (DefaultInstantiate.GetScriptableObjectInstantiate().TryGetValue(type, out var creater) == false)
{
Debug.LogError($"{type} is not exist or {type}'s Instantiater is not valid", this);
return null;
}
// 生成对象
var child = creater();
// 路径预处理
if (path.Replace('\\', '/').ToLower().StartsWith("project/"))
path = $"{new ToolFile(GetRoot().SourcePath) | path[5..]}";
// 获取文件
ToolFile file;
if (File.Exists(path))
file = new(path);
else
file = new ToolFile(SourcePath)| path;
// 找不到脚本
if (file.Exists() == false)
{
Debug.LogError($"{file}<{path}> is not found", this);
return null;
}
child.ScriptName = file.GetName(true);
child.transform.SetParent(this.transform);
child.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
child.transform.localScale = Vector3.one;
child.EnableScript(file.GetCurrentDirName(), Path.Combine(file.GetCurrentDirName(), file.GetName(false)), type, this);
// Add Child
Childs.Add(child);
// Load Child Script
if (gameObject.activeInHierarchy)
StartCoroutine(child.LoadScript(file.LoadAsText()));
else
GetRoot().GetComponent<MonoBehaviour>().StartCoroutine(child.LoadScript(file.LoadAsText()));
return child;
yield return LoadSubScriptAsync(type, path, null);
}
public object DynamicBindingTarget { get; protected set; } = null;
@@ -705,6 +710,8 @@ namespace Demo
Break
}
// TODO : 过多的逻辑都挤在这里, 需要拆分
// TODO : 如何统计整个游戏关卡是否加载完成, 尤其是此处的resultEnumerator与ILoadAssetBundle, 将会同时存在多条异步加载的时间线
private IEnumerator ParseScript2Expr(string script)
{
// 预处理
@@ -816,9 +823,21 @@ namespace Demo
MethodInvokerCache[this.GetType()].Add(command, commandInfo);
}
Debug.Log($"in line \"{expr}\" of \"{ScriptPath}\", {command} is try to invoke", this);
IEnumerator resultEnumerator = null;
try
{
if (ConventionUtility.TryInvokeMember(commandInfo, this, out var _, paramsList) == false)
// 调用成功
if (ConventionUtility.TryInvokeMember(commandInfo, this, out var invokeResult, paramsList) == true)
{
Debug.Log($"in line \"{expr}\" of \"{ScriptPath}\", {command} is invoke succeed", this);
// 尤其用于加载子类时
if (invokeResult != null && invokeResult is IEnumerator _resultEnumerator)
{
resultEnumerator = _resultEnumerator;
}
}
// 调用失败
else
{
MethodInvokerCache[this.GetType()].Remove(command);
var attr = commandInfo.GetCustomAttribute<ScriptableCallAttribute>();
@@ -827,10 +846,6 @@ namespace Demo
else
Debug.LogError($"in line \"{expr}\" of \"{ScriptPath}\", {command} is failed to invoke, see: {attr.Description}", this);
}
else
{
Debug.Log($"in line \"{expr}\" of \"{ScriptPath}\", {command} is invoke succeed", this);
}
}
catch (Exception ex)
{
@@ -838,7 +853,7 @@ namespace Demo
Debug.LogException(ex, this);
yield break;
}
yield return null;
yield return resultEnumerator;
}
}
@@ -988,13 +1003,12 @@ namespace Demo
private static Dictionary<string, IEnumerator> AssetBundleLoading = new();
private static PropertiesWindow.ItemEntry AssetBundlesItemEntry = null;
public static IEnumerator LoadAssetBundle(this IAssetBundleLoader self, string ab, Action<AssetBundle> callback)
public static IEnumerator LoadAssetBundleAsync(string ab, Action<AssetBundle> callback)
{
Debug.Log($"{self.SharedInterfaceScriptObject.ScriptName}.{nameof(LoadAssetBundle)}({ab})", self.SharedInterfaceScriptObject);
if (AssetBundleCounter.TryGetValue(ab, out var result))
{
result.referenceCounter++;
callback(result.assetBundle);
callback?.Invoke(result.assetBundle);
yield break;
}
if (AssetBundleLoading.TryGetValue(ab, out var tir))
@@ -1003,7 +1017,7 @@ namespace Demo
if (AssetBundleCounter.TryGetValue(ab, out result))
{
result.referenceCounter++;
callback(result.assetBundle);
callback?.Invoke(result.assetBundle);
yield break;
}
}
@@ -1047,13 +1061,19 @@ namespace Demo
loadingHierarchyItem.title = $"{ab}<Failed>";
}
AssetBundleLoading.Remove(ab);
callback(x);
callback?.Invoke(x);
});
AssetBundleLoading.Add(ab, ir);
yield return ir;
AssetBundleLoading.Remove(ab);
}
public static IEnumerator LoadAssetBundle(this IAssetBundleLoader self, string ab, Action<AssetBundle> callback)
{
Debug.Log($"{self.SharedInterfaceScriptObject.ScriptName}.{nameof(LoadAssetBundle)}({ab})", self.SharedInterfaceScriptObject);
yield return LoadAssetBundleAsync(ab, callback);
}
public static IEnumerator UnloadAssetBundle(this IAssetBundleLoader self, string ab)
{
// Editor中暂时忽略卸载功能

View File

@@ -128,17 +128,19 @@ namespace Demo.Game
childFileStream.Close();
}
//不刷新世界,直接加载
var targetChildSO = so.LoadSubScript(type, childFile);
// 打开手动编辑
try
so.StartCoroutine(so.LoadSubScriptAsync(type, childFile, targetChildSO =>
{
DefaultScriptUtility.OpenScriptFile(targetChildSO);
}
catch (Exception ex)
{
Debug.LogError($"Cannt open {childFile}", so);
Debug.LogException(ex, so);
}
// 打开手动编辑
try
{
DefaultScriptUtility.OpenScriptFile(targetChildSO);
}
catch (Exception ex)
{
Debug.LogError($"Cannt open {childFile}", so);
Debug.LogException(ex, so);
}
}));
}
}
else

View File

@@ -56,6 +56,12 @@ namespace Demo.Game
}
}
public override void ResetEnterGameStatus()
{
base.ResetEnterGameStatus();
UpdateEntry(0, 0);
}
public override IEnumerator UnloadScript()
{
Content = 0;
@@ -71,18 +77,8 @@ namespace Demo.Game
return (currentTime - Entries[Content].TimePoint) / (Entries[Content + 1].TimePoint - Entries[Content].TimePoint);
}
if (Entries.Count == 0)
if (Entries.Count <= 1)
return;
if (Entries.Count == 1)
{
UpdateEntry(0, 0);
return;
}
// TODO : 删除后存在问题
if (Entries[0].TimePoint <= 0 && tickType == TickType.Reset)
{
UpdateEntry(0, 0);
}
switch (tickType)
{
case TickType.Reset:

View File

@@ -11,18 +11,8 @@ namespace Demo.Game
return new GameObject().AddComponent<ParticleEffect>();
}
private List<IEnumerator> AssetBundleLoadings = new();
private List<string> AssetBundles = new();
private List<GameObject> Prefabs = new();
public override IEnumerator LoadScript(string script)
{
yield return base.LoadScript(script);
foreach (var loading in AssetBundleLoadings)
{
yield return loading;
}
}
private readonly List<string> AssetBundles = new();
private readonly List<GameObject> Prefabs = new();
public override IEnumerator UnloadScript()
{
@@ -45,9 +35,9 @@ namespace Demo.Game
<param name=""ab""></param>
<param name=""prefab""></param>
")]
public void Load(string ab, string prefab)
public IEnumerator Load(string ab, string prefab)
{
AssetBundleLoadings.Add(this.LoadAssetBundle(ab, x =>
yield return this.LoadAssetBundle(ab, x =>
{
GameObject sub = Instantiate(x.LoadAsset<GameObject>(prefab));
sub.SetActive(false);
@@ -55,7 +45,7 @@ namespace Demo.Game
sub.transform.SetParent(transform);
sub.transform.localPosition = Vector3.zero;
AssetBundles.Add(ab);
}));
});
}
public override void OnBegin()

View File

@@ -12,18 +12,10 @@ namespace Demo.Game
return new GameObject().AddComponent<ParticleJudgement>();
}
private List<IEnumerator> AssetBundleLoadings = new();
[Content, SerializeField] private Dictionary<IInteraction.JudgementLevel, string> AssetBundles = new();
[Content, SerializeField] private Dictionary<IInteraction.JudgementLevel, GameObject> Prefabs = new();
[Content, SerializeField] private Dictionary<IInteraction.JudgementLevel, float> Durations = new();
public override IEnumerator LoadScript(string script)
{
yield return base.LoadScript(script);
foreach (var loading in AssetBundleLoadings)
yield return loading;
}
public override IEnumerator UnloadScript()
{
yield return base.UnloadScript();
@@ -47,26 +39,20 @@ namespace Demo.Game
<param name=""prefab""></param>
<param name=""duration"">判定效果会现形的持续时间</param>
")]
public void Load(string level, string ab, string prefab, string duration)
public IEnumerator Load(string level, string ab, string prefab, string duration)
{
var levelId = (IInteraction.JudgementLevel)int.Parse(level);
IEnumerator Foo()
{
AssetBundle assetBundle = null;
var ir = this.LoadAssetBundle(ab, x => assetBundle = x);
yield return ir;
var req = assetBundle.LoadAssetAsync<GameObject>(prefab);
yield return req;
GameObject sub = Instantiate(req.asset as GameObject);
sub.SetActive(false);
Prefabs.Add(levelId, sub);
sub.transform.SetParent(transform);
AssetBundles.Add(levelId, ab);
Durations.Add(levelId, float.Parse(duration));
}
AssetBundleLoadings.Add(Foo());
AssetBundle assetBundle = null;
yield return this.LoadAssetBundle(ab, x => assetBundle = x);
var req = assetBundle.LoadAssetAsync<GameObject>(prefab);
yield return req;
GameObject sub = Instantiate(req.asset as GameObject);
sub.SetActive(false);
Prefabs.Add(levelId, sub);
sub.transform.SetParent(transform);
AssetBundles.Add(levelId, ab);
Durations.Add(levelId, float.Parse(duration));
}
private void CreateParticle(GameObject prefab)

View File

@@ -52,17 +52,13 @@ namespace Demo.Game
</summary>
<param name=""ab""></param>
")]
public void Load(string ab)
public IEnumerator Load(string ab)
{
var ir = this.LoadAssetBundle(ab, x =>
yield return this.LoadAssetBundle(ab, x =>
{
MaterialAssetBundlePath = ab;
MaterialAssetBundle = x;
});
if (gameObject.activeInHierarchy)
StartCoroutine(ir);
else
GetRoot().StartCoroutine(ir);
}
/// <summary>

View File

@@ -28,7 +28,6 @@ namespace Demo.Game
[Content] public AssetBundle LinesAssetBundle;
[Content] public string LineMaterial;
[Content] public Material MyLineMaterial;
IEnumerator AssetBundleLoading;
public abstract Vector3 EvaluateClipFromPosition(float time);
@@ -42,7 +41,6 @@ namespace Demo.Game
this.GetOrAddComponent<MeshFilter>();
MyMeshRenderer = this.GetOrAddComponent<MeshRenderer>();
MyMeshRenderer.enabled = true;
yield return AssetBundleLoading;
if (string.IsNullOrEmpty(LinesAssetBundlePath) == false)
{
var ir = LinesAssetBundle.LoadAssetAsync<Material>(LineMaterial);
@@ -85,9 +83,9 @@ namespace Demo.Game
}
[ScriptableCall(DependOnSplineCoreUtility.LoadSplineDescription)]
public void LoadSpline(string path)
public IEnumerator LoadSpline(string path)
{
this.LoadSplineTool(path);
yield return this.LoadSplineTool(path);
}
@@ -103,9 +101,9 @@ namespace Demo.Game
<param name=""ab""></param>
<param name=""material""></param>
")]
public void LoadMaterial(string ab, string material)
public IEnumerator LoadMaterial(string ab, string material)
{
AssetBundleLoading = this.LoadAssetBundle(ab, x =>
yield return this.LoadAssetBundle(ab, x =>
{
LinesAssetBundlePath = ab;
LinesAssetBundle = x;

View File

@@ -20,9 +20,9 @@ namespace Demo.Game
/// </summary>
/// <param name="path">对象路径, 不存在时则立刻加载</param>
[ScriptableCall(DependOnSplineCoreUtility.LoadSplineDescription)]
public void LoadSpline(string path)
public IEnumerator LoadSpline(string path)
{
this.LoadSplineTool(path);
yield return this.LoadSplineTool(path);
}
/// <summary>

View File

@@ -22,7 +22,7 @@ namespace Demo.Game
public interface IDependOnSplineCore : IScriptableObject
{
SplineCore MySplineCore { get; set; }
void LoadSpline(string path);
IEnumerator LoadSpline(string path);
}
public static class DependOnSplineCoreUtility
@@ -38,14 +38,14 @@ namespace Demo.Game
/// 加载并绑定到新样条线
/// </summary>
/// <param name="path">对象相对路径,若对象不存在则作为脚本相对路径加载</param>
public static void LoadSplineTool(this IDependOnSplineCore self, string path)
public static IEnumerator LoadSplineTool(this IDependOnSplineCore self, string path)
{
var spline = self.SharedInterfaceScriptObject.FindWithPath(path, false);
if (spline == null)
spline = self.SharedInterfaceScriptObject.LoadSubScript(nameof(SplineCore), path);
if (spline != null)
yield return self.SharedInterfaceScriptObject.LoadSubScriptAsync(nameof(SplineCore), path, x => spline = x);
if (spline is SplineCore sc)
{
self.MySplineCore = spline as SplineCore;
self.MySplineCore = sc;
}
else
{
@@ -158,13 +158,15 @@ namespace Demo.Game
</summary>
<param name=""path"">脚本位置</param>
")]
public void LoadNode(string path)
public IEnumerator LoadNode(string path)
{
var node = LoadSubScript(nameof(SplineNode), path);
if (node != null)
yield return LoadSubScriptAsync(nameof(SplineNode), path, node =>
{
MySplineNodes.Add(node as SplineNode);
}
if (node != null)
{
MySplineNodes.Add(node as SplineNode);
}
});
}
/// <summary>

View File

@@ -16,6 +16,11 @@ namespace Demo.Game
protected override abstract void UpdateData(float data);
public override IEnumerator LoadScript(string script)
{
yield return base.LoadScript(script);
}
public override IEnumerator UnloadScript()
{
MySplineCore = null;
@@ -51,14 +56,15 @@ namespace Demo.Game
</summary>
<param name=""path"">脚本位置</param>
")]
public void Load(string path)
public IEnumerator Load(string path)
{
var spline = FindWithPath(path, false);
if (spline == null)
spline = LoadSubScript(nameof(SplineCore), path);
if (spline != null)
MySplineCore = FindWithPath(path, false) as SplineCore;
if (MySplineCore == null)
{
MySplineCore = spline as SplineCore;
yield return LoadSubScriptAsync(nameof(SplineCore), path, x =>
{
MySplineCore = x as SplineCore;
});
}
}
}