更新至unity6并且更改Scriptable完成
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
using System.Collections;
|
||||
using Convention;
|
||||
using Demo.Editor.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
public class SkyUpdatement : Updatement<string>, IAssetBundleLoader
|
||||
public class SkyUpdatement : Updatement<Material>, IAssetBundleLoader
|
||||
{
|
||||
public static SkyUpdatement Make()
|
||||
{
|
||||
@@ -13,33 +12,26 @@ namespace Demo.Game
|
||||
}
|
||||
|
||||
public string SkyAssetBundlePath;
|
||||
private IEnumerator SkyAssetBundleLoading;
|
||||
public AssetBundle SkyAssetBundle;
|
||||
|
||||
protected override string Lerp(string begin, string end, float t)
|
||||
protected override Material Lerp(Material begin, Material end, float t)
|
||||
{
|
||||
return begin;
|
||||
}
|
||||
|
||||
[Content, SerializeField] private string Cache;
|
||||
[Content, SerializeField] private Material Cache;
|
||||
|
||||
protected override void UpdateData(string data)
|
||||
protected override void UpdateData(Material data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(SkyAssetBundlePath))
|
||||
return;
|
||||
if (Cache != data)
|
||||
{
|
||||
RenderSettings.skybox = SkyAssetBundle.LoadAsset<Material>(data);
|
||||
RenderSettings.skybox = data;
|
||||
Cache = data;
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
yield return base.LoadScript(script);
|
||||
yield return SkyAssetBundleLoading;
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
Cache = null;
|
||||
@@ -69,20 +61,15 @@ namespace Demo.Game
|
||||
/// <param name="time"></param>
|
||||
/// <param name="sky"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void Add(string time, string sky)
|
||||
public IEnumerator Add(float time, string sky)
|
||||
{
|
||||
ManualAddEntry(time, sky, default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定时刻切换天空
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <param name="sky"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void Add(float time, string sky)
|
||||
{
|
||||
ManualAddEntry(time, sky, default);
|
||||
var ir = SkyAssetBundle.LoadAssetAsync<Material>(sky);
|
||||
ir.completed += delegate
|
||||
{
|
||||
var mat = ir.asset as Material;
|
||||
ManualAddEntry(time, mat, default);
|
||||
};
|
||||
yield return ir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ namespace Demo.Game
|
||||
[Content, SerializeField] private Vector3 LastPosition = Vector3.zero;
|
||||
[Content, SerializeField] private Quaternion LastRotation = Quaternion.identity;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
public override void ResetEnterGameStatus()
|
||||
{
|
||||
yield return base.LoadScript(script);
|
||||
base.ResetEnterGameStatus();
|
||||
var light = GetRoot().RootGameController.GlobalLight;
|
||||
LastPosition = light.localPosition;
|
||||
LastRotation = light.localRotation;
|
||||
|
||||
@@ -19,8 +19,6 @@ namespace Demo.Game
|
||||
|
||||
[Content] private RootObject MainObject;
|
||||
|
||||
[Content] public bool IsHideTrackRender = false;
|
||||
|
||||
public string RootSourcePath { get; private set; }
|
||||
public Action<float, float> SetupSongDuration { get; private set; } = (_, _) => { };
|
||||
public Action<float> SetSongCurrentTime { get; private set; } = _ => { };
|
||||
@@ -155,7 +153,6 @@ namespace Demo.Game
|
||||
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
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Demo.Game
|
||||
{ $"{nameof(SplineMovement)}",SplineMovement.Make},
|
||||
{ $"{nameof(SplineRotation)}",SplineRotation.Make},
|
||||
{ $"{nameof(SplineScaling)}",SplineScaling.Make},
|
||||
{ $"{nameof(SplineHeadObject)}",SplineHeadObject.Make},
|
||||
{ $"{nameof(SplinePointerObject)}",SplinePointerObject.Make},
|
||||
{ $"{nameof(SplineTrackRenderer)}",SplineTrackRenderer.Make},
|
||||
{ $"{nameof(SplineTubeRenderer)}",SplineTubeRenderer.Make},
|
||||
{ $"{nameof(SplineSurfaceRenderer)}",SplineTubeRenderer.Make},
|
||||
@@ -68,155 +68,19 @@ namespace Demo.Game
|
||||
{ $"{nameof(ParticleJudgement)}",ParticleJudgement.Make},
|
||||
};
|
||||
|
||||
public static void GenerateLayerMenu(ScriptableObject so, RectTransform item, Dictionary<string, Func<ScriptableObject>> calls)
|
||||
{
|
||||
List<SharedModule.CallbackData> result = new();
|
||||
foreach (var instantiaterPair in calls)
|
||||
{
|
||||
var type = instantiaterPair.Key;
|
||||
var invoker = instantiaterPair.Value;
|
||||
|
||||
void LoadSubScriptWrapper(Vector3 _)
|
||||
{
|
||||
// 构建默认名称
|
||||
var childDirName = Path.Combine(so.SourcePath, so.ScriptName);
|
||||
var childDir = new ToolFile(childDirName);
|
||||
var childName = type;
|
||||
int childIndex = 1;
|
||||
var childFullNameWithoutExtension = childName;
|
||||
var extension = ".rscript";
|
||||
if (childDir.Exists())
|
||||
{
|
||||
childFullNameWithoutExtension = $"{childName}{(childIndex == 1 ? "" : childIndex.ToString())}";
|
||||
while (childDir | $"{childFullNameWithoutExtension}{extension}")
|
||||
{
|
||||
childIndex++;
|
||||
childFullNameWithoutExtension = $"{childName}{childIndex}";
|
||||
}
|
||||
}
|
||||
var childFullName = childFullNameWithoutExtension + extension;
|
||||
var chlidPath = Path.Combine(childDirName, childFullName);
|
||||
SharedModule.instance.SingleEditString("Generate Sub Script", chlidPath, x =>
|
||||
{
|
||||
//用户不一定使用默认名称,用真实输入重新转换
|
||||
ToolFile childFile = File.Exists(x) ? new(x) : new(Path.Combine(so.SourcePath, x));
|
||||
if (childFile.MustExistsPath())
|
||||
{
|
||||
if (so is not RootObject && so.FindWithPath(x, false) != null)
|
||||
{
|
||||
Debug.LogError($"SubScript {x} is exists", so);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
using var fs = File.AppendText(so.ScriptPath);
|
||||
var childFilePath = childFile.GetFullPath().Replace('\\', '/');
|
||||
var path2 = so.SourcePath.TrimEnd('\\', '/').Replace('\\', '/');
|
||||
if (childFilePath.StartsWith(path2))
|
||||
{
|
||||
x = childFilePath[path2.Length..].TrimStart('\\', '/');
|
||||
}
|
||||
fs.Write($"\nthis.{nameof(so.LoadSubScript)}({type}, \"{x}\");");
|
||||
// 新建时添加模板内容
|
||||
using var childFileStream = File.AppendText(childFile);
|
||||
{
|
||||
//ScriptUtility.WriteDefaultScript(childFileStream, ScriptableObject.FastScriptableObjectTypen[type]);
|
||||
childFileStream.Close();
|
||||
}
|
||||
//不刷新世界,直接加载
|
||||
so.StartCoroutine(so.DoLoadSubScriptAsync(type, childFile, targetChildSO =>
|
||||
{
|
||||
// 打开手动编辑
|
||||
try
|
||||
{
|
||||
ScriptUtility.OpenScriptFile(targetChildSO);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Cannt open {childFile}", so);
|
||||
Debug.LogException(ex, so);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"SubScript {x} is failed to generate", so);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
result.Add(new(type, LoadSubScriptWrapper));
|
||||
}
|
||||
SharedModule.instance.OpenCustomMenu(item, result.ToArray());
|
||||
}
|
||||
|
||||
public static void GetGenerateData(ScriptableObject so, RectTransform item, List<SharedModule.CallbackData> result)
|
||||
{
|
||||
result.Add(new(nameof(GameObject), _ =>
|
||||
{
|
||||
GenerateLayerMenu(so, item, GameObjectInstantiate);
|
||||
}));
|
||||
result.Add(new(nameof(DDT), _ =>
|
||||
{
|
||||
GenerateLayerMenu(so, item, DDTInstantiate);
|
||||
}));
|
||||
result.Add(new(nameof(Transform), _ =>
|
||||
{
|
||||
GenerateLayerMenu(so, item, TickUpdatementInstantiate);
|
||||
}));
|
||||
result.Add(new(nameof(Material), _ =>
|
||||
{
|
||||
GenerateLayerMenu(so, item, MaterialUpdatementInstantiate);
|
||||
}));
|
||||
result.Add(new(nameof(Spline), _ =>
|
||||
{
|
||||
GenerateLayerMenu(so, item, SplineInstantiate);
|
||||
}));
|
||||
result.Add(new("Judge & Effect", _ =>
|
||||
{
|
||||
GenerateLayerMenu(so, item, JudgementInstantiate);
|
||||
}));
|
||||
}
|
||||
|
||||
public static void OpenInstantiateMenu(this ScriptableObject self, RectTransform item)
|
||||
{
|
||||
List<SharedModule.CallbackData> result = new()
|
||||
{
|
||||
// Show Name
|
||||
new($"In {self.SourcePath}",_=>{ }),
|
||||
new($"At {self.ScriptName}",_=>{ }),
|
||||
new($"Is {self.ScriptTypename}",_=>{ }),
|
||||
new("<color=red>----------</color>",_=>{ }),
|
||||
// Load Operator
|
||||
new("Reload", _ =>
|
||||
{
|
||||
IEnumerator Foo()
|
||||
{
|
||||
var sourcePath =self.SourcePath;
|
||||
var scriptPath = self.ScriptPath;
|
||||
var scriptType =self.ScriptTypename;
|
||||
var parent = self.Parent;
|
||||
yield return self.UnloadScript();
|
||||
foreach (var child in self.Childs)
|
||||
{
|
||||
UnityEngine.Object.Destroy(child.gameObject);
|
||||
}
|
||||
self.Childs.Clear();
|
||||
self.EnableScript(sourcePath,scriptPath,scriptType,parent);
|
||||
yield return self.LoadScript(new ToolFile(self.ScriptPath).LoadAsText());
|
||||
}
|
||||
|
||||
self.GetRoot().RootGameController.StartCoroutine(Foo());
|
||||
}),
|
||||
// Open Script
|
||||
new("Open",_=>
|
||||
{
|
||||
ScriptUtility.OpenScriptFile(self);
|
||||
}),
|
||||
new("<color=red>----------</color>",_=>{ })
|
||||
new($"{self.ScriptName}",_=>{ }),
|
||||
new($"{self.GetType()}",_=>{ }),
|
||||
new($"Pos:{self.transform.position}",_=>{ }),
|
||||
new($"xPos:{self.transform.localPosition}",_=>{ }),
|
||||
new($"Angles:{self.transform.eulerAngles}",_=>{ }),
|
||||
new($"xAngles:{self.transform.localEulerAngles}",_=>{ }),
|
||||
new($"Scale:{self.transform.localScale}",_=>{ }),
|
||||
};
|
||||
GetGenerateData(self,item, result);
|
||||
SharedModule.instance.OpenCustomMenu(item, result.ToArray());
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Demo.Game
|
||||
Entries.Sort((x, y) => x.TimePoint.CompareTo(y.TimePoint));
|
||||
if (UpdateTarget == null)
|
||||
{
|
||||
UpdateTarget = transform.parent.gameObject;
|
||||
UpdateTarget = Parent.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,18 +15,30 @@ namespace Demo.Game
|
||||
InteractableIntervalThatCanScoreBest = 0
|
||||
}
|
||||
|
||||
[Content, SerializeField] private IInteraction MyInteractionModule;
|
||||
[Content, SerializeField] private IInteraction m_MyInteractionModule;
|
||||
[Content, SerializeField] private InteractiveEffectType MyInteractiveLevel = default;
|
||||
|
||||
private IInteraction MyInteractionModule
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_MyInteractionModule == null)
|
||||
m_MyInteractionModule = Parent.GetComponent<IInteraction>();
|
||||
return m_MyInteractionModule;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_MyInteractionModule = value;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void OnInit();
|
||||
public abstract void OnBegin();
|
||||
public abstract void OnEnd();
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
yield return base.LoadScript(script);
|
||||
if (MyInteractionModule == null)
|
||||
MyInteractionModule = Parent.GetComponent<IInteraction>();
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
switch (MyInteractiveLevel)
|
||||
{
|
||||
case InteractiveEffectType.VisibleDuration:
|
||||
@@ -96,7 +108,6 @@ namespace Demo.Game
|
||||
}
|
||||
break;
|
||||
}
|
||||
MyInteractionModule = null;
|
||||
yield return base.UnloadScript();
|
||||
}
|
||||
|
||||
@@ -115,9 +126,9 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="type">VisibleDuration,InteractiveDuration,InteractableScoreInterval,InteractableIntervalThatCanScoreBest</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetInteractiveEffectType(string type)
|
||||
public void SetInteractiveEffectType(InteractiveEffectType type)
|
||||
{
|
||||
MyInteractiveLevel = Enum.Parse<InteractiveEffectType>(type);
|
||||
MyInteractiveLevel = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,15 +128,6 @@ namespace Demo.Game
|
||||
|
||||
public const int JudgementLevelCount = 3;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
yield return base.LoadScript(script);
|
||||
if (BestJudgementTimePoint <= 0)
|
||||
{
|
||||
DoSetupJudgement(0);
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
yield return base.UnloadScript();
|
||||
@@ -324,9 +315,9 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="bestJudgementTimePoint">最佳判定点</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetupJudgement(string bestJudgementTimePoint)
|
||||
public void SetupJudgement(float bestJudgementTimePoint)
|
||||
{
|
||||
DoSetupJudgement(Parse(bestJudgementTimePoint));
|
||||
DoSetupJudgement(bestJudgementTimePoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -343,18 +334,18 @@ namespace Demo.Game
|
||||
/// (bestJudgementTimePoint-visibleDuration/2,bestJudgementTimePoint+visibleDuration/2)</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetupJudgementLevels(
|
||||
string bestJudgementTimePoint,
|
||||
string interactableIntervalThatCanScoreBest,
|
||||
string interactableScoreInterval,
|
||||
string interactiveDuration,
|
||||
string visibleDuration)
|
||||
float bestJudgementTimePoint,
|
||||
float interactableIntervalThatCanScoreBest,
|
||||
float interactableScoreInterval,
|
||||
float interactiveDuration,
|
||||
float visibleDuration)
|
||||
{
|
||||
DoSetupJudgementLevels(
|
||||
Parse(bestJudgementTimePoint),
|
||||
Parse(interactableIntervalThatCanScoreBest),
|
||||
Parse(interactableScoreInterval),
|
||||
Parse(interactiveDuration),
|
||||
Parse(visibleDuration));
|
||||
bestJudgementTimePoint,
|
||||
interactableIntervalThatCanScoreBest,
|
||||
interactableScoreInterval,
|
||||
interactiveDuration,
|
||||
visibleDuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -362,18 +353,18 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetVisibleDurationBegin(string value)
|
||||
public void SetVisibleDurationBegin(float value)
|
||||
{
|
||||
VisibleDuration.x = Parse(value);
|
||||
VisibleDuration.x = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置可见区间(显现但不可判定,3级判定区间)结束时间
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetVisibleDurationEnd(string value)
|
||||
public void SetVisibleDurationEnd(float value)
|
||||
{
|
||||
VisibleDuration.y = Parse(value);
|
||||
VisibleDuration.y = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -381,18 +372,18 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetInteractiveDurationBegin(string value)
|
||||
public void SetInteractiveDurationBegin(float value)
|
||||
{
|
||||
InteractiveDuration.x = Parse(value);
|
||||
InteractiveDuration.x = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置2级判定区间(可判定但错误的)结束时间
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetInteractiveDurationEnd(string value)
|
||||
public void SetInteractiveDurationEnd(float value)
|
||||
{
|
||||
InteractiveDuration.y = Parse(value);
|
||||
InteractiveDuration.y = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -400,18 +391,18 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetInteractableScoreIntervalBegin(string value)
|
||||
public void SetInteractableScoreIntervalBegin(float value)
|
||||
{
|
||||
InteractableScoreInterval.x = Parse(value);
|
||||
InteractableScoreInterval.x = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置1级判定区间(可判定的)结束时间
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetInteractableScoreIntervalEnd(string value)
|
||||
public void SetInteractableScoreIntervalEnd(float value)
|
||||
{
|
||||
InteractableScoreInterval.y = Parse(value);
|
||||
InteractableScoreInterval.y = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -419,9 +410,9 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetInteractableIntervalThatCanScoreBestBegin(string value)
|
||||
public void SetInteractableIntervalThatCanScoreBestBegin(float value)
|
||||
{
|
||||
InteractableIntervalThatCanScoreBest.x = Parse(value);
|
||||
InteractableIntervalThatCanScoreBest.x = value;
|
||||
if (BestJudgementTimePoint < 0)
|
||||
{
|
||||
BestJudgementTimePoint = Mathf.Lerp(InteractableIntervalThatCanScoreBest.x, InteractableIntervalThatCanScoreBest.y, 0.5f);
|
||||
@@ -432,9 +423,9 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetInteractableIntervalThatCanScoreBestEnd(string value)
|
||||
public void SetInteractableIntervalThatCanScoreBestEnd(float value)
|
||||
{
|
||||
InteractableIntervalThatCanScoreBest.y = Parse(value);
|
||||
InteractableIntervalThatCanScoreBest.y = value;
|
||||
if (BestJudgementTimePoint < 0)
|
||||
{
|
||||
BestJudgementTimePoint = Mathf.Lerp(InteractableIntervalThatCanScoreBest.x, InteractableIntervalThatCanScoreBest.y, 0.5f);
|
||||
|
||||
@@ -7,15 +7,26 @@ namespace Demo.Game
|
||||
public abstract class IJudgementHookObject : ScriptableObject, IHookInteraction
|
||||
{
|
||||
|
||||
[Content, SerializeField] private IInteraction MyInteractionModule;
|
||||
[Content, SerializeField] private IInteraction m_MyInteractionModule;
|
||||
private IInteraction MyInteractionModule
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_MyInteractionModule == null)
|
||||
m_MyInteractionModule = Parent.GetComponent<IInteraction>();
|
||||
return m_MyInteractionModule;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_MyInteractionModule = value;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void OnJudgement(IInteraction.JudgementLevel level);
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
yield return base.LoadScript(script);
|
||||
if (MyInteractionModule == null)
|
||||
MyInteractionModule = Parent.GetComponent<IInteraction>();
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
MyInteractionModule.JudgementEvent.AddListener(OnJudgement);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,24 @@ namespace Demo.Game
|
||||
[Content] private MeshRenderer m_MyMeshRenderer;
|
||||
[Header("LineRenderer.Material")]
|
||||
[Content] public string LinesAssetBundlePath;
|
||||
[Content] public AssetBundle LinesAssetBundle;
|
||||
[Content] public Material LineDefaultMaterial;
|
||||
|
||||
private static Material m_StaticCacheDefaultMaterial;
|
||||
protected static Material StaticCacheDefaultMaterial
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_StaticCacheDefaultMaterial == null)
|
||||
m_StaticCacheDefaultMaterial = Resources.Load<Material>("Line/Default");
|
||||
return m_StaticCacheDefaultMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
[Content] public Material MyDefaultMaterial;
|
||||
|
||||
public override void ResetEnterGameStatus()
|
||||
{
|
||||
base.ResetEnterGameStatus();
|
||||
MyMeshRenderer.material = LineDefaultMaterial;
|
||||
MyMeshRenderer.material = MyDefaultMaterial;
|
||||
}
|
||||
|
||||
public MeshFilter MyMeshFilter
|
||||
@@ -107,10 +118,9 @@ namespace Demo.Game
|
||||
MyMeshRenderer.enabled = true;
|
||||
LinesAssetBundlePath = ab;
|
||||
this.LoadAssetBundle(ab, x =>
|
||||
{
|
||||
LinesAssetBundle = x;
|
||||
LineDefaultMaterial = LinesAssetBundle.LoadAsset<Material>(material);
|
||||
});
|
||||
{
|
||||
MyDefaultMaterial = x.LoadAsset<Material>(material);
|
||||
});
|
||||
}
|
||||
|
||||
protected override SplineClipDuration Lerp(SplineClipDuration begin, SplineClipDuration end, float t)
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<SplineTrackRenderer>();
|
||||
}
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
MyLineMaterial = Resources.Load<Material>("Line/Default");
|
||||
yield return base.LoadScript(script);
|
||||
if (MyDefaultMaterial == null)
|
||||
MyDefaultMaterial = StaticCacheDefaultMaterial;
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<SplineTrackRenderer>();
|
||||
}
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
MyLineMaterial = Resources.Load<Material>("Line/Default");
|
||||
yield return base.LoadScript(script);
|
||||
if (MyDefaultMaterial == null)
|
||||
MyDefaultMaterial = StaticCacheDefaultMaterial;
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ namespace Demo.Game
|
||||
[Content] public bool IsDoubleSide = DefaultIsDoubleSide;
|
||||
[Content] public int SidesCount = DefaultSidesCount;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
MyLineMaterial = Resources.Load<Material>("Tube/Default");
|
||||
yield return base.LoadScript(script);
|
||||
if (MyDefaultMaterial == null)
|
||||
MyDefaultMaterial = Resources.Load<Material>("Tube/Default");
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
}
|
||||
|
||||
public override void SetupMeshGenerator(TubeGenerator meshGenerater)
|
||||
|
||||
@@ -16,11 +16,6 @@ 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;
|
||||
@@ -34,26 +29,19 @@ namespace Demo.Game
|
||||
/// <param name="value"></param>
|
||||
/// <param name="curveType">可取值为30种缓动曲线</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void Add(string time, string value, string curveType)
|
||||
public void Add(float time, float value, MathExtension.EaseCurveType curveType)
|
||||
{
|
||||
ManualAddEntry(time, float.Parse(value), Enum.Parse<MathExtension.EaseCurveType>(curveType));
|
||||
ManualAddEntry(time, value, curveType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如未加载则加载,然后绑定到样条线
|
||||
/// 绑定到样条线
|
||||
/// </summary>
|
||||
/// <param name="path">脚本位置</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public IEnumerator Load(string path)
|
||||
public void Load(SplineCore splineCore)
|
||||
{
|
||||
MySplineCore = FindWithPath(path, false) as SplineCore;
|
||||
if (MySplineCore == null)
|
||||
{
|
||||
yield return DoLoadSubScriptAsync(nameof(SplineCore), path, x =>
|
||||
{
|
||||
MySplineCore = x as SplineCore;
|
||||
});
|
||||
}
|
||||
MySplineCore = splineCore;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Convention;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Dreamteck.Splines;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
public class SplineHeadObject : BasicSplineJustFollow
|
||||
{
|
||||
public static SplineHeadObject Make()
|
||||
{
|
||||
return new GameObject().AddComponent<SplineHeadObject>();
|
||||
}
|
||||
|
||||
private SplineRenderer MySplineRenderer;
|
||||
|
||||
/// <summary>
|
||||
/// 设置为仅跟随,将会被动的跟随spline运动,
|
||||
/// 这在多个脚本都绑定在同一个spline计算核心上时非常有用
|
||||
/// </summary>
|
||||
[Content, SerializeField] private bool IsJustFollow = false;
|
||||
[Content, SerializeField] private double Cache = 0;
|
||||
|
||||
protected override void UpdateData(float data)
|
||||
{
|
||||
var sample = MySplineCore.MySplineComputer.Evaluate(data);
|
||||
Cache = sample.percent;
|
||||
UpdateTarget.transform.SetPositionAndRotation(sample.position, sample.rotation);
|
||||
//UpdateTarget.transform.localScale = Vector3.one * sample.size;
|
||||
}
|
||||
|
||||
private SceneGameWindow SceneStats;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
SceneStats = FindObjectOfType<SceneGameWindow>();
|
||||
yield return base.LoadScript(script);
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
if (MySplineCore == null)
|
||||
yield break;
|
||||
var splineGameObject = MySplineCore.gameObject;
|
||||
splineGameObject.GetOrAddComponent<MeshFilter>();
|
||||
var meshRenderer = splineGameObject.GetOrAddComponent<MeshRenderer>();
|
||||
meshRenderer.enabled = true;
|
||||
meshRenderer.material = Resources.Load<Material>("Line/Dash");
|
||||
MySplineRenderer = splineGameObject.AddComponent<SplineRenderer>();
|
||||
MySplineRenderer.spline = MySplineCore.MySplineComputer;
|
||||
MySplineRenderer.uvMode = MeshGenerator.UVMode.UniformClip;
|
||||
MySplineRenderer.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
{
|
||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
if (IsJustFollow == false)
|
||||
{
|
||||
if (SceneStats.IsSelectSceneCamera || tickType == TickType.Pause || tickType == TickType.Reset)
|
||||
{
|
||||
MySplineCore.gameObject.GetComponent<MeshRenderer>().enabled = true;
|
||||
MySplineCore.gameObject.GetComponent<SplineRenderer>().Rebuild();
|
||||
}
|
||||
else if (tickType == TickType.Start)
|
||||
{
|
||||
MySplineCore.gameObject.GetComponent<MeshRenderer>().enabled = false;
|
||||
}
|
||||
//不为跟随模式时,需要自己更新clip
|
||||
if (tickType == TickType.Update || tickType == TickType.Reset)
|
||||
{
|
||||
MySplineRenderer.clipFrom = Cache;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
var splineGameObject = MySplineCore.gameObject;
|
||||
Destroy(splineGameObject.GetComponent<SplineRenderer>());
|
||||
Destroy(splineGameObject.GetComponent<MeshRenderer>());
|
||||
Destroy(splineGameObject.GetComponent<MeshFilter>());
|
||||
MySplineCore = null;
|
||||
MySplineRenderer = null;
|
||||
}
|
||||
yield return base.UnloadScript();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置为仅跟随,将会被动的跟随spline运动,
|
||||
/// 这在多个脚本都绑定在同一个spline计算核心上时非常有用
|
||||
/// </summary>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void JustFollow()
|
||||
{
|
||||
IsJustFollow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,94 +13,9 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<SplineMovement>();
|
||||
}
|
||||
|
||||
private SplineRenderer MySplineRenderer;
|
||||
|
||||
/// <summary>
|
||||
/// 设置为仅跟随,将会被动的跟随spline运动,
|
||||
/// 这在多个脚本都绑定在同一个spline计算核心上时非常有用
|
||||
/// </summary>
|
||||
[Content, SerializeField] private bool IsJustFollow = false;
|
||||
[Content, SerializeField] private double Cache = 0;
|
||||
|
||||
protected override void UpdateData(float data)
|
||||
{
|
||||
Cache = MySplineCore.MySplineComputer.Evaluate(data).percent;
|
||||
UpdateTarget.transform.position = MySplineCore.MySplineComputer.EvaluatePosition(data);
|
||||
}
|
||||
|
||||
private SceneGameWindow SceneStats;
|
||||
|
||||
public override IEnumerator LoadScript(string script)
|
||||
{
|
||||
SceneStats = FindObjectOfType<SceneGameWindow>();
|
||||
yield return base.LoadScript(script);
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
if (MySplineCore == null)
|
||||
yield break;
|
||||
var splineGameObject = MySplineCore.gameObject;
|
||||
splineGameObject.GetOrAddComponent<MeshFilter>();
|
||||
var meshRenderer = splineGameObject.GetOrAddComponent<MeshRenderer>();
|
||||
meshRenderer.enabled = true;
|
||||
meshRenderer.material = Resources.Load<Material>("Line/Dash");
|
||||
MySplineRenderer = splineGameObject.AddComponent<SplineRenderer>();
|
||||
MySplineRenderer.spline = MySplineCore.MySplineComputer;
|
||||
MySplineRenderer.uvMode = MeshGenerator.UVMode.UniformClip;
|
||||
MySplineRenderer.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
{
|
||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
if (IsJustFollow == false)
|
||||
{
|
||||
if (SceneStats.IsSelectSceneCamera || tickType == TickType.Pause || tickType == TickType.Reset)
|
||||
{
|
||||
MySplineCore.gameObject.GetComponent<MeshRenderer>().enabled = true;
|
||||
MySplineCore.gameObject.GetComponent<SplineRenderer>().Rebuild();
|
||||
}
|
||||
else if (tickType == TickType.Start)
|
||||
{
|
||||
MySplineCore.gameObject.GetComponent<MeshRenderer>().enabled = false;
|
||||
}
|
||||
//不为跟随模式时,需要自己更新clip
|
||||
if (tickType == TickType.Update || tickType == TickType.Reset)
|
||||
{
|
||||
MySplineRenderer.clipFrom = Cache;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
if (GetRoot().RootGameController.IsHideTrackRender == false)
|
||||
{
|
||||
var splineGameObject = MySplineCore.gameObject;
|
||||
Destroy(splineGameObject.GetComponent<SplineRenderer>());
|
||||
Destroy(splineGameObject.GetComponent<MeshRenderer>());
|
||||
Destroy(splineGameObject.GetComponent<MeshFilter>());
|
||||
MySplineCore = null;
|
||||
MySplineRenderer = null;
|
||||
}
|
||||
yield return base.UnloadScript();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置为仅跟随,将会被动的跟随spline运动,
|
||||
/// 这在多个脚本都绑定在同一个spline计算核心上时非常有用
|
||||
/// </summary>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void JustFollow()
|
||||
{
|
||||
IsJustFollow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
Assets/Scripts/MoreSpline/Updatement/SplinePointerObject.cs
Normal file
23
Assets/Scripts/MoreSpline/Updatement/SplinePointerObject.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Convention;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Dreamteck.Splines;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
public class SplinePointerObject : BasicSplineJustFollow
|
||||
{
|
||||
public static SplinePointerObject Make()
|
||||
{
|
||||
return new GameObject().AddComponent<SplinePointerObject>();
|
||||
}
|
||||
|
||||
protected override void UpdateData(float data)
|
||||
{
|
||||
var sample = MySplineCore.MySplineComputer.Evaluate(data);
|
||||
UpdateTarget.transform.SetPositionAndRotation(sample.position, sample.rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user