推进同化RScript
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Demo.Game
|
||||
public interface IDependOnSplineCore : IScriptableObject
|
||||
{
|
||||
SplineCore MySplineCore { get; set; }
|
||||
IEnumerator LoadSpline(string path);
|
||||
void LoadSpline(string path);
|
||||
}
|
||||
|
||||
public static class DependOnSplineCoreUtility
|
||||
@@ -38,19 +38,13 @@ namespace Demo.Game
|
||||
/// 加载并绑定到新样条线
|
||||
/// </summary>
|
||||
/// <param name="path">对象相对路径,若对象不存在则作为脚本相对路径加载</param>
|
||||
public static IEnumerator LoadSplineTool(this IDependOnSplineCore self, string path)
|
||||
public static SplineCore LoadSplineTool(this IDependOnSplineCore self, string path)
|
||||
{
|
||||
var spline = self.SharedInterfaceScriptObject.FindWithPath(path, false);
|
||||
if (spline == null)
|
||||
yield return self.SharedInterfaceScriptObject.DoLoadSubScriptAsync(nameof(SplineCore), path, x => spline = x);
|
||||
if (spline is SplineCore sc)
|
||||
{
|
||||
self.MySplineCore = sc;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"{path} is not a SplineCore", self.SharedInterfaceScriptObject);
|
||||
}
|
||||
spline = self.SharedInterfaceScriptObject.NewSubScript(nameof(SplineCore), new ToolFile(path).GetFilename(true), path);
|
||||
self.MySplineCore = (SplineCore)spline;
|
||||
return self.MySplineCore;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,18 +55,31 @@ namespace Demo.Game
|
||||
return new GameObject("", typeof(SplineComputer)).AddComponent<SplineCore>();
|
||||
}
|
||||
|
||||
[Content] public SplineComputer MySplineComputer;
|
||||
[Content] private SplineComputer m_MySplineComputer;
|
||||
[Content] public int NodeContent = 0;
|
||||
[Content] public List<SplineNode> MySplineNodes = new();
|
||||
[Content] public readonly List<SplineNode> MySplineNodes = new();
|
||||
[Content] public SplineComputer.SampleMode MySampleMode = default;
|
||||
[Content] public Spline.Type MyType = default;
|
||||
|
||||
public bool IsClose = false;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
public SplineComputer MySplineComputer
|
||||
{
|
||||
get
|
||||
{
|
||||
if(m_MySplineComputer==null)
|
||||
m_MySplineComputer= GetComponent<SplineComputer>();
|
||||
return m_MySplineComputer;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="SplineCore"/>需要在子<see cref="SplineNode"/>都添加后再应用脚本才能使得节点生效
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
MySplineComputer = GetComponent<SplineComputer>();
|
||||
yield return base.LoadScript(script);
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
NodeContent = 0;
|
||||
MySplineComputer.SetPoints(new SplinePoint[MySplineNodes.Count]);
|
||||
foreach (SplineNode node in MySplineNodes)
|
||||
@@ -86,13 +93,12 @@ namespace Demo.Game
|
||||
MySplineComputer.Break();
|
||||
MySplineComputer.sampleMode = MySampleMode;
|
||||
MySplineComputer.type = MyType;
|
||||
yield return null;
|
||||
MySplineComputer.Rebuild();
|
||||
}
|
||||
|
||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
{
|
||||
if (tickType == TickType.Start || tickType == TickType.Reset)
|
||||
if (tickType != TickType.Update)
|
||||
MySplineComputer.Rebuild();
|
||||
}
|
||||
|
||||
@@ -109,9 +115,9 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="mode">CatmullRom, BSpline, Bezier, Linear </param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetType(string mode)
|
||||
public void SetType(Spline.Type mode)
|
||||
{
|
||||
MyType = Enum.Parse<Spline.Type>(mode);
|
||||
MyType = mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -119,9 +125,9 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="mode">Default, Uniform, Optimized</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetSampleMode(string mode)
|
||||
public void SetSampleMode(SplineComputer.SampleMode mode)
|
||||
{
|
||||
MySampleMode = Enum.Parse<SplineComputer.SampleMode>(mode);
|
||||
MySampleMode = mode;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,47 +141,13 @@ namespace Demo.Game
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载并加入新节点
|
||||
/// 加入节点或者添加节点组件后加入节点
|
||||
/// </summary>
|
||||
/// <param name="path">脚本位置</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public IEnumerator LoadNode(string path)
|
||||
{
|
||||
yield return DoLoadSubScriptAsync(nameof(SplineNode), path, node =>
|
||||
{
|
||||
if (node is SplineNode _node)
|
||||
{
|
||||
MySplineNodes.Add(_node);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"{path} is not {nameof(SplineNode)}", this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加入节点脚本对象
|
||||
/// </summary>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void AddNode(ScriptableObject node)
|
||||
public void LoadNode(ScriptableObject node)
|
||||
{
|
||||
MySplineNodes.Add(node.GetOrAddComponent<SplineNode>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加入已加载的节点,如果目标脚本不是SplineNode,
|
||||
/// 那么为其添加SplineNode组件
|
||||
/// </summary>
|
||||
/// <param name="path">脚本位置</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void AddNode(string path)
|
||||
{
|
||||
var node = FindWithPath(path);
|
||||
if (node != null)
|
||||
{
|
||||
AddNode(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user