异步加载已修复, Config更新正推动

This commit is contained in:
2025-12-18 15:11:33 +08:00
parent 1436080fd6
commit ab60b35be2
20 changed files with 190 additions and 132 deletions

View File

@@ -1,5 +1,6 @@
using Convention; using Convention;
using Demo.Game.Attr; using Demo.Game.Attr;
using Demo.Game.ConfigType;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -37,6 +38,10 @@ namespace Demo.Game
[Scriptable] [Scriptable]
public class SkyUpdatement : Updatement<int>, IAssetBundleLoader public class SkyUpdatement : Updatement<int>, IAssetBundleLoader
{ {
protected override ScriptLoadableConfig MakeConfig()
{
return new SkyUpdatementConfig();
}
public static SkyUpdatement Make() public static SkyUpdatement Make()
{ {
return new GameObject().AddComponent<SkyUpdatement>(); return new GameObject().AddComponent<SkyUpdatement>();

View File

@@ -250,7 +250,7 @@ namespace Demo.Game
} }
yield break; yield break;
} }
yield return Foo(rootGameObject.ParseFromScriptFile2Expr(rootObject));//ConventionUtility.AvoidFakeStop(rootGameObject.ParseFromScriptFile2Expr(rootObject)); yield return ConventionUtility.AvoidFakeStop(rootGameObject.ParseFromScriptFile2Expr(rootObject));//Foo(rootGameObject.ParseFromScriptFile2Expr(rootObject));
int applyDownCount = 0; int applyDownCount = 0;
void NDFS(ScriptableObject current) void NDFS(ScriptableObject current)
{ {
@@ -264,6 +264,7 @@ namespace Demo.Game
IEnumerator NDFSFoo() IEnumerator NDFSFoo()
{ {
yield return current.ApplyScript(); yield return current.ApplyScript();
current.ResetEnterGameStatus();
applyDownCount--; applyDownCount--;
} }
ConventionUtility.StartCoroutine(NDFSFoo()); ConventionUtility.StartCoroutine(NDFSFoo());
@@ -291,6 +292,27 @@ namespace Demo.Game
using var stream = new FileInfo(projectBinaryFile).OpenRead(); using var stream = new FileInfo(projectBinaryFile).OpenRead();
using var reader = new BinaryReader(stream); using var reader = new BinaryReader(stream);
rootGameObject.Config.Deserialize(reader); rootGameObject.Config.Deserialize(reader);
int applyDownCount = 0;
void NDFS(ScriptableObject current)
{
foreach (var child in current.Childs)
{
NDFS(child);
}
if (current.IsScriptApply == false)
{
applyDownCount++;
IEnumerator NDFSFoo()
{
yield return current.ApplyScript();
current.ResetEnterGameStatus();
applyDownCount--;
}
ConventionUtility.StartCoroutine(NDFSFoo());
}
}
NDFS(rootGameObject);
yield return new WaitUntil(() => applyDownCount == 0);
} }
float loadRootObjectEndTime = Time.realtimeSinceStartup; float loadRootObjectEndTime = Time.realtimeSinceStartup;
float loadRootObjectElapsed = (loadRootObjectEndTime - loadRootObjectStartTime) * 1000f; float loadRootObjectElapsed = (loadRootObjectEndTime - loadRootObjectStartTime) * 1000f;

View File

@@ -38,12 +38,12 @@ namespace Demo.Game
public class ScriptLoadableConfig public class ScriptLoadableConfig
{ {
[Content] public int UID = -1; [Content] public int UID = -1;
[Content] public Vector3 EnterGameLocalPosition = Vector3.zero, EnterGameEulerAngles = Vector3.zero, EnterGameLocalScaling = Vector3.zero; [Content] public Vector3 EnterGameLocalPosition = Vector3.zero, EnterGameEulerAngles = Vector3.zero, EnterGameLocalScaling = Vector3.one;
[Content] public bool IsSetObjectDisable = false; [Content] public bool IsSetObjectDisable = false;
[Content] public int UpdatePerFrame = 1; [Content] public int UpdatePerFrame = 1;
[Setting] public string ScriptName = ""; [Setting] public string ScriptName = "";
private string[] ChildTypes = null; private int[] ChildTypes = null;
private ScriptLoadableConfig[] childs = null; private ScriptLoadableConfig[] childs = null;
[Setting] public ScriptableObject target; [Setting] public ScriptableObject target;
@@ -57,12 +57,12 @@ namespace Demo.Game
IsSetObjectDisable = BinarySerializeUtility.ReadBool(reader); IsSetObjectDisable = BinarySerializeUtility.ReadBool(reader);
UpdatePerFrame = BinarySerializeUtility.ReadInt(reader); UpdatePerFrame = BinarySerializeUtility.ReadInt(reader);
ScriptName = BinarySerializeUtility.ReadString(reader); ScriptName = BinarySerializeUtility.ReadString(reader);
ChildTypes = BinarySerializeUtility.DeserializeStringArray(reader); ChildTypes = BinarySerializeUtility.DeserializeIntArray(reader);
int childCount = ChildTypes.Length; int childCount = ChildTypes.Length;
childs = new ScriptLoadableConfig[childCount]; childs = new ScriptLoadableConfig[childCount];
for (int i = 0; i < childCount; i++) for (int i = 0; i < childCount; i++)
{ {
var scriptObject = DefaultInstantiate.GetScriptableObjectInstantiate()[ChildTypes[i]].Invoke(); var scriptObject = DefaultInstantiate.GetScriptableObjectInstantiate()[DefaultInstantiate.ScriptableObjectID2Typename[ChildTypes[i]]].Invoke();
scriptObject.EnableScript(target); scriptObject.EnableScript(target);
childs[i] = scriptObject.Config; childs[i] = scriptObject.Config;
childs[i].Deserialize(reader); childs[i].Deserialize(reader);
@@ -78,7 +78,7 @@ namespace Demo.Game
BinarySerializeUtility.WriteInt(writer, UpdatePerFrame); BinarySerializeUtility.WriteInt(writer, UpdatePerFrame);
BinarySerializeUtility.WriteString(writer, ScriptName); BinarySerializeUtility.WriteString(writer, ScriptName);
childs = (from child in target.Childs select child.Config).ToArray(); childs = (from child in target.Childs select child.Config).ToArray();
ChildTypes = (from child in childs select child.GetType().Name).ToArray(); ChildTypes = (from child in childs select DefaultInstantiate.ScriptableObjectTypename2ID[child.target.GetType().Name]).ToArray();
BinarySerializeUtility.SerializeArray(writer, ChildTypes); BinarySerializeUtility.SerializeArray(writer, ChildTypes);
foreach (var child in childs) foreach (var child in childs)
{ {
@@ -133,7 +133,7 @@ namespace Demo.Game
[Convention.RScript.Variable.Attr.Method] [Convention.RScript.Variable.Attr.Method]
public void SetLocalPosition(float x, float y, float z) public void SetLocalPosition(float x, float y, float z)
{ {
Config.EnterGameLocalPosition = new(x, y, z); Config.EnterGameLocalPosition = transform.localPosition = new(x, y, z);
} }
/// <summary> /// <summary>
/// 设置欧拉角 /// 设置欧拉角
@@ -144,7 +144,7 @@ namespace Demo.Game
[Convention.RScript.Variable.Attr.Method] [Convention.RScript.Variable.Attr.Method]
public void SetLocalEulerAngles(float x, float y, float z) public void SetLocalEulerAngles(float x, float y, float z)
{ {
Config.EnterGameEulerAngles = new(x, y, z); Config.EnterGameEulerAngles = transform.localEulerAngles = new(x, y, z);
} }
/// <summary> /// <summary>
/// 设置缩放 /// 设置缩放
@@ -155,7 +155,7 @@ namespace Demo.Game
[Convention.RScript.Variable.Attr.Method] [Convention.RScript.Variable.Attr.Method]
public void SetLocalScaling(float x, float y, float z) public void SetLocalScaling(float x, float y, float z)
{ {
Config.EnterGameLocalScaling = new(x, y, z); Config.EnterGameLocalScaling = transform.localScale= new(x, y, z);
} }
/// <summary> /// <summary>
@@ -166,6 +166,7 @@ namespace Demo.Game
public void SetObjectDisable() public void SetObjectDisable()
{ {
Config.IsSetObjectDisable = true; Config.IsSetObjectDisable = true;
gameObject.SetActive(false);
} }
/// <summary> /// <summary>
@@ -678,11 +679,14 @@ namespace Demo.Game
MyHierarchyItem.Release(); MyHierarchyItem.Release();
MyHierarchyItem = null; MyHierarchyItem = null;
} }
if (this /*防假空*/)
{
this.isEnableScript = false; this.isEnableScript = false;
this.Parent = null; this.Parent = null;
this.name = "<Unload>"; this.name = "<Unload>";
} }
} }
}
public virtual void ResetEnterGameStatus() public virtual void ResetEnterGameStatus()
{ {

View File

@@ -7,6 +7,7 @@ using Dreamteck.Splines;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using UnityEngine; using UnityEngine;
@@ -32,26 +33,33 @@ namespace Demo
SharedModule.instance.OpenCustomMenu(item, result.ToArray()); SharedModule.instance.OpenCustomMenu(item, result.ToArray());
} }
private static Dictionary<string, Func<ScriptableObject>> s_ScriptableObjectInstantiate; static DefaultInstantiate()
public static Dictionary<string, Func<ScriptableObject>> GetScriptableObjectInstantiate()
{
//return s_ScriptableObjectInstantiate ??= new Dictionary<string, Func<ScriptableObject>>(GameObjectInstantiate
// .Union(DDTInstantiate)
// .Union(TickUpdatementInstantiate)
// .Union(MaterialUpdatementInstantiate)
// .Union(SplineInstantiate)
// .Union(JudgementInstantiate)
// .Union(SingleVolumeInstantiate));
if (s_ScriptableObjectInstantiate == null)
{ {
s_ScriptableObjectInstantiate = new(); s_ScriptableObjectInstantiate = new();
ScriptableObjectTypename2ID = new();
ScriptableObjectID2Typename = new();
int cnt = 0;
foreach (var type in Utility.SeekType(x => x.IsSubclassOf(typeof(ScriptableObject)) && x.GetCustomAttribute<Attr.ScriptableAttribute>() != null)) foreach (var type in Utility.SeekType(x => x.IsSubclassOf(typeof(ScriptableObject)) && x.GetCustomAttribute<Attr.ScriptableAttribute>() != null))
{ {
var attr = type.GetCustomAttribute<Attr.ScriptableAttribute>(); var attr = type.GetCustomAttribute<Attr.ScriptableAttribute>();
s_ScriptableObjectInstantiate.Add(type.Name, () => (ScriptableObject)ConventionUtility.InvokeMember(type.GetMethod(attr.generaterName), null)); s_ScriptableObjectInstantiate.Add(type.Name, () => (ScriptableObject)ConventionUtility.InvokeMember(type.GetMethod(attr.generaterName), null));
} }
var typelist = s_ScriptableObjectInstantiate.Keys.ToList();
typelist.Sort();
foreach (var type in typelist)
{
ScriptableObjectTypename2ID.Add(type, cnt);
ScriptableObjectID2Typename.Add(cnt, type);
cnt++;
} }
}
private static Dictionary<string, Func<ScriptableObject>> s_ScriptableObjectInstantiate;
public readonly static Dictionary<string, int> ScriptableObjectTypename2ID;
public readonly static Dictionary<int, string> ScriptableObjectID2Typename;
public static Dictionary<string, Func<ScriptableObject>> GetScriptableObjectInstantiate()
{
return s_ScriptableObjectInstantiate; return s_ScriptableObjectInstantiate;
} }
} }

View File

@@ -32,12 +32,15 @@ namespace Demo.Game
[Scriptable] [Scriptable]
public class SubWorld : ScriptableObject public class SubWorld : ScriptableObject
{ {
protected override ConfigType.ScriptLoadableConfig MakeConfig()
{
return new ConfigType.SubWorldConfig();
}
public static SubWorld Make() public static SubWorld Make()
{ {
return new GameObject().AddComponent<SubWorld>(); return new GameObject().AddComponent<SubWorld>();
} }
[Content, SerializeField] private string project;
[Content, SerializeField] private GameController SubWorldGameController; [Content, SerializeField] private GameController SubWorldGameController;
protected override IEnumerator DoSomethingDuringApplyScript() protected override IEnumerator DoSomethingDuringApplyScript()
@@ -47,7 +50,7 @@ namespace Demo.Game
ir.completed += x => ir.completed += x =>
{ {
SubWorldGameController = (from controller in FindObjectsByType<GameController>(FindObjectsSortMode.None) SubWorldGameController = (from controller in FindObjectsByType<GameController>(FindObjectsSortMode.None)
where controller.RootSourcePath == project where controller.RootSourcePath == GetConfig<ConfigType.SubWorldConfig>().project
select controller).First(); select controller).First();
ConventionUtility.StartCoroutine(SubWorldGameController.GameInitBySubWorld(GetRoot().InputCatch)); ConventionUtility.StartCoroutine(SubWorldGameController.GameInitBySubWorld(GetRoot().InputCatch));
}; };
@@ -66,7 +69,7 @@ namespace Demo.Game
[Convention.RScript.Variable.Attr.Method] [Convention.RScript.Variable.Attr.Method]
public void Load(string project) public void Load(string project)
{ {
this.project = project; GetConfig<ConfigType.SubWorldConfig>().project = project;
} }
} }
} }

View File

@@ -1,5 +1,6 @@
using Convention; using Convention;
using Demo.Editor.UI; using Demo.Editor.UI;
using Demo.Game.ConfigType;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@@ -115,39 +116,9 @@ namespace Demo.Game
public DataType Position = default; public DataType Position = default;
public MathExtension.EaseCurveType easeCurveType = MathExtension.EaseCurveType.Linear; public MathExtension.EaseCurveType easeCurveType = MathExtension.EaseCurveType.Linear;
} }
[Serializable]
public struct UpdatementCompiledEntries: IDisposable
{
public NativeArray<float> TimePoints;
public NativeArray<DataType> Positions;
public NativeArray<MathExtension.EaseCurveType> EaseCurveTypes;
public readonly int Count;
public UpdatementCompiledEntries(NativeArray<float> timePoints,
NativeArray<DataType> positions,
NativeArray<MathExtension.EaseCurveType> easeCurveTypes,
int count)
{
TimePoints = timePoints;
Positions = positions;
EaseCurveTypes = easeCurveTypes;
Count = count;
}
public void Dispose()
{
if (TimePoints.IsCreated)
TimePoints.Dispose();
if (Positions.IsCreated)
Positions.Dispose();
if (EaseCurveTypes.IsCreated)
EaseCurveTypes.Dispose();
}
}
public int Content = 0; public int Content = 0;
private readonly List<UpdatementEntry> Entries = new(); private readonly List<UpdatementEntry> Entries = new();
public UpdatementCompiledEntries CompiledEntries;
protected abstract void UpdateData(DataType data); protected abstract void UpdateData(DataType data);
protected abstract DataType Lerp(DataType begin, DataType end, float t); protected abstract DataType Lerp(DataType begin, DataType end, float t);
@@ -170,18 +141,15 @@ namespace Demo.Game
private void BuildupCompiledEntriesAndReleaseEntries() private void BuildupCompiledEntriesAndReleaseEntries()
{ {
Entries.Sort((x, y) => x.TimePoint.CompareTo(y.TimePoint)); Entries.Sort((x, y) => x.TimePoint.CompareTo(y.TimePoint));
CompiledEntries = new( GetConfig<UpdatementConfig<DataType>>().TimePoints = new NativeArray<float>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
new NativeArray<float>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), GetConfig<UpdatementConfig<DataType>>().Positions = new NativeArray<DataType>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
new NativeArray<DataType>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), GetConfig<UpdatementConfig<DataType>>().EaseCurveTypes = new NativeArray<MathExtension.EaseCurveType>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
new NativeArray<MathExtension.EaseCurveType>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory),
Entries.Count
);
int index = 0; int index = 0;
foreach (var item in Entries) foreach (var item in Entries)
{ {
CompiledEntries.TimePoints[index] = item.TimePoint; GetConfig<UpdatementConfig<DataType>>().TimePoints[index] = item.TimePoint;
CompiledEntries.Positions[index] = item.Position; GetConfig<UpdatementConfig<DataType>>().Positions[index] = item.Position;
CompiledEntries.EaseCurveTypes[index] = item.easeCurveType; GetConfig<UpdatementConfig<DataType>>().EaseCurveTypes[index] = item.easeCurveType;
index++; index++;
} }
Entries.Clear(); Entries.Clear();
@@ -190,10 +158,10 @@ namespace Demo.Game
private void UpdateEntry(int start, float percent) private void UpdateEntry(int start, float percent)
{ {
int head = start; int head = start;
int tail = Mathf.Min(start + 1, CompiledEntries.Count - 1); int tail = Mathf.Min(start + 1, GetConfig<UpdatementConfig<DataType>>().TimePoints.Length - 1);
UpdateData(Lerp(CompiledEntries.Positions[start], UpdateData(Lerp(GetConfig<UpdatementConfig<DataType>>().Positions[start],
CompiledEntries.Positions[tail], GetConfig<UpdatementConfig<DataType>>().Positions[tail],
MathExtension.Evaluate(Mathf.Clamp01(percent), CompiledEntries.EaseCurveTypes[head]))); MathExtension.Evaluate(Mathf.Clamp01(percent), GetConfig<UpdatementConfig<DataType>>().EaseCurveTypes[head])));
} }
protected override IEnumerator DoSomethingDuringApplyScript() protected override IEnumerator DoSomethingDuringApplyScript()
@@ -209,7 +177,7 @@ namespace Demo.Game
public override void ResetEnterGameStatus() public override void ResetEnterGameStatus()
{ {
base.ResetEnterGameStatus(); base.ResetEnterGameStatus();
if (CompiledEntries.Count <= 1) if (GetConfig<UpdatementConfig<DataType>>().TimePoints.Length <= 1)
return; return;
UpdateEntry(0, 0); UpdateEntry(0, 0);
} }
@@ -217,7 +185,9 @@ namespace Demo.Game
public override IEnumerator UnloadScript() public override IEnumerator UnloadScript()
{ {
Content = 0; Content = 0;
CompiledEntries = default; GetConfig<UpdatementConfig<DataType>>().TimePoints.Dispose();
GetConfig<UpdatementConfig<DataType>>().Positions.Dispose();
GetConfig<UpdatementConfig<DataType>>().EaseCurveTypes.Dispose();
yield return base.UnloadScript(); yield return base.UnloadScript();
} }
@@ -227,12 +197,12 @@ namespace Demo.Game
float GetPercentValue() float GetPercentValue()
{ {
if (Content + 1 == CompiledEntries.Count) if (Content + 1 == GetConfig<UpdatementConfig<DataType>>().TimePoints.Length)
return 1; return 1;
return (currentTime - CompiledEntries.TimePoints[Content]) / (CompiledEntries.TimePoints[Content + 1] - CompiledEntries.TimePoints[Content]); return (currentTime - GetConfig<UpdatementConfig<DataType>>().TimePoints[Content]) / (GetConfig<UpdatementConfig<DataType>>().TimePoints[Content + 1] - GetConfig<UpdatementConfig<DataType>>().TimePoints[Content]);
} }
if (CompiledEntries.Count <= 1) if (GetConfig<UpdatementConfig<DataType>>().TimePoints.Length <= 1)
return; return;
switch (tickType) switch (tickType)
{ {
@@ -240,17 +210,17 @@ namespace Demo.Game
case TickType.Start: case TickType.Start:
{ {
Content = 0; Content = 0;
while (Content + 1 < CompiledEntries.Count && CompiledEntries.TimePoints[Content + 1] < currentTime) while (Content + 1 < GetConfig<UpdatementConfig<DataType>>().TimePoints.Length && GetConfig<UpdatementConfig<DataType>>().TimePoints[Content + 1] < currentTime)
Content++; Content++;
UpdateEntry(Content, GetPercentValue()); UpdateEntry(Content, GetPercentValue());
} }
break; break;
default: default:
if (CompiledEntries.TimePoints[0] > currentTime) if (GetConfig<UpdatementConfig<DataType>>().TimePoints[0] > currentTime)
return; return;
if (Content + 1 < CompiledEntries.Count && CompiledEntries.TimePoints[Content + 1] < currentTime) if (Content + 1 < GetConfig<UpdatementConfig<DataType>>().TimePoints.Length && GetConfig<UpdatementConfig<DataType>>().TimePoints[Content + 1] < currentTime)
Content++; Content++;
if (Content + 1 > CompiledEntries.Count) if (Content + 1 > GetConfig<UpdatementConfig<DataType>>().TimePoints.Length)
return; return;
UpdateEntry(Content, GetPercentValue()); UpdateEntry(Content, GetPercentValue());
break; break;
@@ -259,21 +229,22 @@ namespace Demo.Game
public DataType Evaluate(float time) public DataType Evaluate(float time)
{ {
if (CompiledEntries.Count == 0) if (GetConfig<UpdatementConfig<DataType>>().TimePoints.Length == 0)
return default; return default;
if (CompiledEntries.Count == 1) if (GetConfig<UpdatementConfig<DataType>>().TimePoints.Length == 1)
return CompiledEntries.Positions[0]; return GetConfig<UpdatementConfig<DataType>>().Positions[0];
if (time < CompiledEntries.TimePoints[0]) if (time < GetConfig<UpdatementConfig<DataType>>().TimePoints[0])
return CompiledEntries.Positions[0]; return GetConfig<UpdatementConfig<DataType>>().Positions[0];
for (int i = 1; i < CompiledEntries.Count; i++) for (int i = 1; i < GetConfig<UpdatementConfig<DataType>>().TimePoints.Length; i++)
{ {
if (CompiledEntries.TimePoints[i - 1] <= time && CompiledEntries.TimePoints[i] > time) if (GetConfig<UpdatementConfig<DataType>>().TimePoints[i - 1] <= time && GetConfig<UpdatementConfig<DataType>>().TimePoints[i] > time)
{ {
return Lerp(CompiledEntries.Positions[i - 1], CompiledEntries.Positions[i], return Lerp(GetConfig<UpdatementConfig<DataType>>().Positions[i - 1], GetConfig<UpdatementConfig<DataType>>().Positions[i],
(time - CompiledEntries.TimePoints[i - 1]) / (CompiledEntries.TimePoints[i] - CompiledEntries.TimePoints[i - 1])); (time - GetConfig<UpdatementConfig<DataType>>().TimePoints[i - 1]) /
(GetConfig<UpdatementConfig<DataType>>().TimePoints[i] - GetConfig<UpdatementConfig<DataType>>().TimePoints[i - 1]));
} }
} }
return CompiledEntries.Positions[^1]; return GetConfig<UpdatementConfig<DataType>>().Positions[^1];
} }
[Content] public GameObject UpdateTarget; [Content] public GameObject UpdateTarget;
@@ -293,15 +264,20 @@ namespace Demo.Game
/// <param name="item">实例在父类中控制</param> /// <param name="item">实例在父类中控制</param>
protected override void SetupTimelineItem(TimelineItem item) protected override void SetupTimelineItem(TimelineItem item)
{ {
if (CompiledEntries.Count == 0) if (GetConfig<UpdatementConfig<DataType>>().TimePoints.Length == 0)
return; return;
item.SetupDuration(new(CompiledEntries.TimePoints[0], CompiledEntries.TimePoints[^1]), GetTimelineItemColor()); item.SetupDuration(new(GetConfig<UpdatementConfig<DataType>>().TimePoints[0], GetConfig<UpdatementConfig<DataType>>().TimePoints[^1]), GetTimelineItemColor());
} }
private void OnDestroy() private void OnDestroy()
{ {
CompiledEntries.Dispose(); if (GetConfig<UpdatementConfig<DataType>>().TimePoints.IsCreated)
GetConfig<UpdatementConfig<DataType>>().TimePoints.Dispose();
if (GetConfig<UpdatementConfig<DataType>>().Positions.IsCreated)
GetConfig<UpdatementConfig<DataType>>().Positions.Dispose();
if (GetConfig<UpdatementConfig<DataType>>().EaseCurveTypes.IsCreated)
GetConfig<UpdatementConfig<DataType>>().EaseCurveTypes.Dispose();
} }
} }
} }

View File

@@ -1,7 +1,6 @@
using Convention; using Convention;
using Demo.Game.Attr; using Demo.Game.Attr;
using System.Collections; using Demo.Game.ConfigType;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game
@@ -9,6 +8,10 @@ namespace Demo.Game
[Scriptable] [Scriptable]
public class LookAtAnchor : Updatement<int> public class LookAtAnchor : Updatement<int>
{ {
protected override ScriptLoadableConfig MakeConfig()
{
return new UpdatementIntConfig();
}
public static LookAtAnchor Make() public static LookAtAnchor Make()
{ {
return new GameObject().AddComponent<LookAtAnchor>(); return new GameObject().AddComponent<LookAtAnchor>();

View File

@@ -1,10 +1,10 @@
using Convention; using Convention;
using Demo.Game.Attr; using Demo.Game.Attr;
using Demo.Game.ConfigType;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering.LookDev;
namespace Demo.Game namespace Demo.Game
{ {
@@ -36,6 +36,10 @@ namespace Demo.Game
[Scriptable] [Scriptable]
public class MaterialUpdatement : Updatement<int>, IAssetBundleLoader public class MaterialUpdatement : Updatement<int>, IAssetBundleLoader
{ {
protected override ScriptLoadableConfig MakeConfig()
{
return new MaterialUpdatementConfig();
}
public static MaterialUpdatement Make() public static MaterialUpdatement Make()
{ {
return new GameObject().AddComponent<MaterialUpdatement>(); return new GameObject().AddComponent<MaterialUpdatement>();

View File

@@ -1,7 +1,8 @@
using Convention;
using Demo.Game.ConfigType;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Convention;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game
@@ -28,6 +29,10 @@ namespace Demo.Game
public abstract class BaseOnMaterialUpdatement : Updatement<float> public abstract class BaseOnMaterialUpdatement : Updatement<float>
{ {
protected override ConfigType.ScriptLoadableConfig MakeConfig()
{
return new BaseOnMaterialUpdatementConfig();
}
public abstract string TargetFieldName { get; } public abstract string TargetFieldName { get; }
protected override float Lerp(float begin, float end, float t) protected override float Lerp(float begin, float end, float t)

View File

@@ -1,16 +1,17 @@
using System; using Convention;
using Demo.Game.ConfigType;
using Dreamteck.Splines;
using System.Collections; using System.Collections;
using System.IO; using System.IO;
using Convention;
using Dreamteck.Splines;
using Unity.Collections; using Unity.Collections;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering;
namespace Demo.Game namespace Demo.Game
{ {
namespace ConfigType namespace ConfigType
{ {
public class BasicSplineRendererConfig : UpdatementVec2Config public class BasicSplineRendererConfig : UpdatementConfig<SplineClipDuration>
{ {
public int MySplineCore; public int MySplineCore;
public string LinesAssetBundlePath; public string LinesAssetBundlePath;
@@ -31,11 +32,38 @@ namespace Demo.Game
BinarySerializeUtility.WriteString(writer, MyDefaultMaterial); BinarySerializeUtility.WriteString(writer, MyDefaultMaterial);
base.Serialize(writer); base.Serialize(writer);
} }
protected override void DeserializePositions(BinaryReader reader, ref NativeArray<SplineClipDuration> positions)
{
NativeArray<Vector2> temp = new(0, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
int e = BinarySerializeUtility.DeserializeNativeArray(reader, ref temp);
positions.ResizeArray(e);
for (int i = 0; i < e; i++)
{
positions[i] = new(temp[i].x, temp[i].y);
}
temp.Dispose();
}
protected override void SerializePositions(BinaryWriter writer, in NativeArray<SplineClipDuration> positions)
{
NativeArray<Vector2> temp = new(positions.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
for (int i = 0, e=positions.Length; i < e; i++)
{
temp[i] = new(positions[i].ClipFrom, positions[i].ClipTo);
}
BinarySerializeUtility.SerializeNativeArray(writer, temp);
temp.Dispose();
}
} }
} }
public abstract class BasicSplineRenderer : Updatement<SplineClipDuration>, IAssetBundleLoader, IDependOnSplineCore public abstract class BasicSplineRenderer : Updatement<SplineClipDuration>, IAssetBundleLoader, IDependOnSplineCore
{ {
protected override ConfigType.ScriptLoadableConfig MakeConfig()
{
return new BasicSplineRendererConfig();
}
/// <summary> /// <summary>
/// 加载并绑定到新样条线 /// 加载并绑定到新样条线
/// </summary> /// </summary>

View File

@@ -1,5 +1,6 @@
using Convention; using Convention;
using Demo.Game.Attr; using Demo.Game.Attr;
using Demo.Game.ConfigType;
using Dreamteck.Splines; using Dreamteck.Splines;
using System; using System;
using System.Collections; using System.Collections;
@@ -36,6 +37,10 @@ namespace Demo.Game
[Scriptable] [Scriptable]
public class SplineTubeRenderer : BasicSplineRenderer<TubeGenerator> public class SplineTubeRenderer : BasicSplineRenderer<TubeGenerator>
{ {
protected override ScriptLoadableConfig MakeConfig()
{
return new SplineTubeRendererConfig();
}
public static SplineTubeRenderer Make() public static SplineTubeRenderer Make()
{ {
return new GameObject().AddComponent<SplineTubeRenderer>(); return new GameObject().AddComponent<SplineTubeRenderer>();

View File

@@ -76,14 +76,6 @@ namespace Demo.Game
public bool IsClose = false; public bool IsClose = false;
public SplineComputer MySplineComputer => m_MySplineComputer; public SplineComputer MySplineComputer => m_MySplineComputer;
//{
// get
// {
// if (m_MySplineComputer == null)
// m_MySplineComputer = this.GetComponent<SplineComputer>();
// return m_MySplineComputer;
// }
//}
/// <summary> /// <summary>
/// <see cref="SplineCore"/>需要在子<see cref="SplineNode"/>都添加后再应用脚本才能使得节点生效 /// <see cref="SplineCore"/>需要在子<see cref="SplineNode"/>都添加后再应用脚本才能使得节点生效

View File

@@ -75,6 +75,7 @@ namespace Demo.Game
[Convention.RScript.Variable.Attr.Method] [Convention.RScript.Variable.Attr.Method]
public void SetNodeSize(float size) public void SetNodeSize(float size)
{ {
SetLocalScaling(size, size, size);
NodeSize = size; NodeSize = size;
} }

View File

@@ -1,14 +1,15 @@
using Convention;
using Demo.Game.ConfigType;
using System; using System;
using System.Collections; using System.Collections;
using System.IO; using System.IO;
using Convention;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game
{ {
namespace ConfigType namespace ConfigType
{ {
public class BasicSplineJustFollowConfig : ScriptLoadableConfig public class BasicSplineJustFollowConfig : UpdatementFloatConfig
{ {
public int MySplineCore; public int MySplineCore;
public override void Deserialize(BinaryReader reader) public override void Deserialize(BinaryReader reader)
@@ -27,6 +28,10 @@ namespace Demo.Game
public abstract class BasicSplineJustFollow : Updatement<float>, IDependOnSplineCore public abstract class BasicSplineJustFollow : Updatement<float>, IDependOnSplineCore
{ {
protected override ConfigType.ScriptLoadableConfig MakeConfig()
{
return new BasicSplineJustFollowConfig();
}
/// <summary> /// <summary>
/// 加载并绑定到新样条线 /// 加载并绑定到新样条线
/// </summary> /// </summary>

View File

@@ -1,8 +1,4 @@
using Convention;
using Convention.WindowsUI.Variant;
using Demo.Game.Attr; using Demo.Game.Attr;
using Dreamteck.Splines;
using System.Collections;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game

View File

@@ -1,9 +1,4 @@
using Convention;
using Convention.WindowsUI.Variant;
using Demo.Game.Attr; using Demo.Game.Attr;
using Dreamteck.Splines;
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game

View File

@@ -1,7 +1,4 @@
using Convention;
using Demo.Game.Attr; using Demo.Game.Attr;
using System;
using System.Collections;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game

View File

@@ -1,9 +1,6 @@
using Convention; using Convention;
using Convention.WindowsUI.Variant;
using Demo.Game.Attr; using Demo.Game.Attr;
using System; using Demo.Game.ConfigType;
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game
@@ -11,6 +8,10 @@ namespace Demo.Game
[Scriptable] [Scriptable]
public class TickMovement : Updatement<Vector3> public class TickMovement : Updatement<Vector3>
{ {
protected override ScriptLoadableConfig MakeConfig()
{
return new UpdatementVec3Config();
}
public static TickMovement Make() public static TickMovement Make()
{ {
return new GameObject().AddComponent<TickMovement>(); return new GameObject().AddComponent<TickMovement>();

View File

@@ -1,6 +1,6 @@
using Convention; using Convention;
using Demo.Game.Attr; using Demo.Game.Attr;
using System; using Demo.Game.ConfigType;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game
@@ -8,6 +8,10 @@ namespace Demo.Game
[Scriptable] [Scriptable]
public class TickRotation : Updatement<Vector3> public class TickRotation : Updatement<Vector3>
{ {
protected override ScriptLoadableConfig MakeConfig()
{
return new UpdatementVec3Config();
}
public static TickRotation Make() public static TickRotation Make()
{ {
return new GameObject().AddComponent<TickRotation>(); return new GameObject().AddComponent<TickRotation>();

View File

@@ -1,6 +1,6 @@
using Convention; using Convention;
using Demo.Game.Attr; using Demo.Game.Attr;
using System; using Demo.Game.ConfigType;
using UnityEngine; using UnityEngine;
namespace Demo.Game namespace Demo.Game
@@ -8,6 +8,10 @@ namespace Demo.Game
[Scriptable] [Scriptable]
public class TickScaling : Updatement<Vector3> public class TickScaling : Updatement<Vector3>
{ {
protected override ScriptLoadableConfig MakeConfig()
{
return new UpdatementVec3Config();
}
public static TickScaling Make() public static TickScaling Make()
{ {
return new GameObject().AddComponent<TickScaling>(); return new GameObject().AddComponent<TickScaling>();