脚本缓存机制已经被添加
This commit is contained in:
Submodule Assets/Convention updated: 48965decbb...8e419a3257
@@ -220,7 +220,7 @@ namespace Demo.Game
|
||||
rootGameObject.SetContent(nameof(SongOffset), SongOffset);
|
||||
rootGameObject.SetContent(nameof(IsAutoPlay), IsAutoPlay ? 1 : 0);
|
||||
rootGameObject.SetContent("SongLength", MainAudio.CurrentClip.length);
|
||||
yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText());
|
||||
yield return rootGameObject.ParseFromScriptFile2Expr(rootObject);
|
||||
static void NDFS(ScriptableObject current)
|
||||
{
|
||||
foreach (var child in current.Childs)
|
||||
|
||||
@@ -21,81 +21,6 @@ namespace Demo
|
||||
|
||||
#region ScriptableObject Inside
|
||||
|
||||
namespace PrivateType
|
||||
{
|
||||
public class EaseCurveTypeInstance
|
||||
{
|
||||
public static EaseCurveTypeInstance instance = new();
|
||||
public MathExtension.EaseCurveType Linear => MathExtension.EaseCurveType.Linear;
|
||||
public MathExtension.EaseCurveType InQuad => MathExtension.EaseCurveType.InQuad;
|
||||
public MathExtension.EaseCurveType OutQuad => MathExtension.EaseCurveType.OutQuad;
|
||||
public MathExtension.EaseCurveType InOutQuad => MathExtension.EaseCurveType.InOutQuad;
|
||||
public MathExtension.EaseCurveType InCubic => MathExtension.EaseCurveType.InCubic;
|
||||
public MathExtension.EaseCurveType OutCubic => MathExtension.EaseCurveType.OutCubic;
|
||||
public MathExtension.EaseCurveType InOutCubic => MathExtension.EaseCurveType.InOutCubic;
|
||||
public MathExtension.EaseCurveType InQuart => MathExtension.EaseCurveType.InQuart;
|
||||
public MathExtension.EaseCurveType OutQuart => MathExtension.EaseCurveType.OutQuart;
|
||||
public MathExtension.EaseCurveType InOutQuart => MathExtension.EaseCurveType.InOutQuart;
|
||||
public MathExtension.EaseCurveType InQuint => MathExtension.EaseCurveType.InQuint;
|
||||
public MathExtension.EaseCurveType OutQuint => MathExtension.EaseCurveType.OutQuint;
|
||||
public MathExtension.EaseCurveType InOutQuint => MathExtension.EaseCurveType.InOutQuint;
|
||||
public MathExtension.EaseCurveType InSine => MathExtension.EaseCurveType.InSine;
|
||||
public MathExtension.EaseCurveType OutSine => MathExtension.EaseCurveType.OutSine;
|
||||
public MathExtension.EaseCurveType InOutSine => MathExtension.EaseCurveType.InOutSine;
|
||||
public MathExtension.EaseCurveType InExpo => MathExtension.EaseCurveType.InExpo;
|
||||
public MathExtension.EaseCurveType OutExpo => MathExtension.EaseCurveType.OutExpo;
|
||||
public MathExtension.EaseCurveType InOutExpo => MathExtension.EaseCurveType.InOutExpo;
|
||||
public MathExtension.EaseCurveType InCirc => MathExtension.EaseCurveType.InCirc;
|
||||
public MathExtension.EaseCurveType OutCirc => MathExtension.EaseCurveType.OutCirc;
|
||||
public MathExtension.EaseCurveType InOutCirc => MathExtension.EaseCurveType.InOutCirc;
|
||||
public MathExtension.EaseCurveType InBounce => MathExtension.EaseCurveType.InBounce;
|
||||
public MathExtension.EaseCurveType OutBounce => MathExtension.EaseCurveType.OutBounce;
|
||||
public MathExtension.EaseCurveType InOutBounce => MathExtension.EaseCurveType.InOutBounce;
|
||||
public MathExtension.EaseCurveType InElastic => MathExtension.EaseCurveType.InElastic;
|
||||
public MathExtension.EaseCurveType OutElastic => MathExtension.EaseCurveType.OutElastic;
|
||||
public MathExtension.EaseCurveType InOutElastic => MathExtension.EaseCurveType.InOutElastic;
|
||||
public MathExtension.EaseCurveType InBack => MathExtension.EaseCurveType.InBack;
|
||||
public MathExtension.EaseCurveType OutBack => MathExtension.EaseCurveType.OutBack;
|
||||
public MathExtension.EaseCurveType InOutBack => MathExtension.EaseCurveType.InOutBack;
|
||||
public MathExtension.EaseCurveType Custom => MathExtension.EaseCurveType.Custom;
|
||||
}
|
||||
|
||||
public class SplineComputerSampleModeInstance
|
||||
{
|
||||
public static SplineComputerSampleModeInstance instance = new();
|
||||
public SplineComputer.SampleMode Default => SplineComputer.SampleMode.Default;
|
||||
public SplineComputer.SampleMode Uniform => SplineComputer.SampleMode.Uniform;
|
||||
public SplineComputer.SampleMode Optimized => SplineComputer.SampleMode.Optimized;
|
||||
}
|
||||
|
||||
public class SplineTypeInstance
|
||||
{
|
||||
public static SplineTypeInstance instance = new();
|
||||
public Spline.Type Linear => Spline.Type.Linear;
|
||||
public Spline.Type BSpline => Spline.Type.BSpline;
|
||||
public Spline.Type CatmullRom => Spline.Type.CatmullRom;
|
||||
public Spline.Type Bezier => Spline.Type.Bezier;
|
||||
}
|
||||
|
||||
public class IEffectHookObjectInstance
|
||||
{
|
||||
public static IEffectHookObjectInstance instance = new();
|
||||
public IEffectHookObject.InteractiveEffectType VisibleDuration => IEffectHookObject.InteractiveEffectType.VisibleDuration;
|
||||
public IEffectHookObject.InteractiveEffectType InteractiveDuration => IEffectHookObject.InteractiveEffectType.InteractiveDuration;
|
||||
public IEffectHookObject.InteractiveEffectType InteractableScoreInterval => IEffectHookObject.InteractiveEffectType.InteractableScoreInterval;
|
||||
public IEffectHookObject.InteractiveEffectType InteractableIntervalThatCanScoreBest => IEffectHookObject.InteractiveEffectType.InteractableIntervalThatCanScoreBest;
|
||||
}
|
||||
|
||||
public class IInteractionJudgementLevelInstance
|
||||
{
|
||||
public static IInteractionJudgementLevelInstance instance = new();
|
||||
public IInteraction.JudgementLevel Bad => IInteraction.JudgementLevel.Bad;
|
||||
public IInteraction.JudgementLevel ScoreLevel => IInteraction.JudgementLevel.ScoreLevel;
|
||||
public IInteraction.JudgementLevel None => IInteraction.JudgementLevel.None;
|
||||
public IInteraction.JudgementLevel BestLevel => IInteraction.JudgementLevel.BestLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ScriptableObject : IScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
@@ -351,7 +276,6 @@ namespace Demo
|
||||
|
||||
public PropertiesWindow.ItemEntry MyHierarchyItem;
|
||||
public static PropertiesWindow.ItemEntry AllScriptableObjectCounterHierarchyItem;
|
||||
public static PropertiesWindow.ItemEntry ScriptParseingHierarchyItem;
|
||||
|
||||
public bool EnsureEnableScript()
|
||||
{
|
||||
@@ -414,7 +338,7 @@ namespace Demo
|
||||
Childs.Add(child);
|
||||
|
||||
// Load Child Script
|
||||
ConventionUtility.StartCoroutine(child.ParseScript2Expr(file.LoadAsText()));
|
||||
ConventionUtility.StartCoroutine(child.ParseFromScriptFile2Expr(file));
|
||||
|
||||
return child;
|
||||
}
|
||||
@@ -470,79 +394,6 @@ namespace Demo
|
||||
|
||||
#endregion
|
||||
|
||||
public static class RandomTool
|
||||
{
|
||||
public static float Random(float min, float max)
|
||||
{
|
||||
return UnityEngine.Random.Range(min, max);
|
||||
}
|
||||
|
||||
public static float Random(double min, double max)
|
||||
{
|
||||
return UnityEngine.Random.Range((float)min, (float)max);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsoleTool
|
||||
{
|
||||
private GameObject gameObject;
|
||||
public ConsoleTool(GameObject gameObject)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
}
|
||||
|
||||
public void Log(object obj)
|
||||
{
|
||||
Debug.Log(obj, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly object ParseScript2ExprObjectLocker = new();
|
||||
public IEnumerator ParseScript2Expr(string script)
|
||||
{
|
||||
IsParseScript2Expr = true;
|
||||
try
|
||||
{
|
||||
RScriptEngine engine = new();
|
||||
RScriptImportClass importClass = new()
|
||||
{
|
||||
typeof(Mathf),
|
||||
typeof(RandomTool),
|
||||
};
|
||||
RScriptVariables variables = new()
|
||||
{
|
||||
{ "this", new() { data = this, type = this.GetType() } },
|
||||
{ "self", new() { data = this, type = this.GetType() } },
|
||||
{ "console", new() { data = new ConsoleTool(gameObject), type = typeof(ConsoleTool) } },
|
||||
{ nameof(MathExtension.EaseCurveType), new() { data = PrivateType.EaseCurveTypeInstance.instance, type = typeof(PrivateType.EaseCurveTypeInstance) } },
|
||||
{ $"Spline{nameof(SplineComputer.SampleMode)}",
|
||||
new() { data = PrivateType.SplineComputerSampleModeInstance.instance, type = typeof(PrivateType.SplineComputerSampleModeInstance)} },
|
||||
{ $"Spline{nameof(Spline.Type)}",
|
||||
new() { data = PrivateType.SplineTypeInstance.instance, type = typeof(PrivateType.SplineTypeInstance)} },
|
||||
{ nameof(IEffectHookObject.InteractiveEffectType),
|
||||
new() { data = PrivateType.IEffectHookObjectInstance.instance, type = typeof(PrivateType.IEffectHookObjectInstance)} },
|
||||
{ nameof(IInteraction.JudgementLevel),
|
||||
new() { data = PrivateType.IInteractionJudgementLevelInstance.instance, type = typeof(PrivateType.IInteractionJudgementLevelInstance) } }
|
||||
};
|
||||
|
||||
if (ScriptParseingHierarchyItem == null)
|
||||
{
|
||||
ScriptParseingHierarchyItem = HierarchyWindow.instance.CreateRootItemEntryWithBinders(ParseScript2ExprObjectLocker)[0];
|
||||
}
|
||||
|
||||
foreach (var ir in engine.RunAsync(script, importClass, variables).Yield())
|
||||
{
|
||||
yield return ir;
|
||||
if (engine.context.CurrentRuntimePointer < engine.context.Sentences.Length)
|
||||
ScriptParseingHierarchyItem.GetHierarchyItem().title = engine.context.CurrentSentence.ToString();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsParseScript2Expr = false;
|
||||
}
|
||||
}
|
||||
|
||||
public enum TickType
|
||||
{
|
||||
Reset,
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
using Convention;
|
||||
using Convention.RScript;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Demo.Game;
|
||||
using Demo.PrivateType;
|
||||
using Dreamteck.Splines;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Convention;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Dreamteck.Splines;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo.Game
|
||||
namespace Demo
|
||||
{
|
||||
public static class DefaultInstantiate
|
||||
namespace Game
|
||||
{
|
||||
public static Dictionary<string, Func<ScriptableObject>> GameObjectInstantiate = new()
|
||||
public static class DefaultInstantiate
|
||||
{
|
||||
public static Dictionary<string, Func<ScriptableObject>> GameObjectInstantiate = new()
|
||||
{
|
||||
{ $"{nameof(Anchor)}",Anchor.Make},
|
||||
// Camera
|
||||
{ $"{nameof(CameraObject)}",CameraObject.MakeCameraObject},
|
||||
@@ -22,30 +27,30 @@ namespace Demo.Game
|
||||
{ $"{nameof(SkyUpdatement)}",SkyUpdatement.Make},
|
||||
// Sub World
|
||||
{ $"{nameof(SubWorld)}",SubWorld.Make},
|
||||
};
|
||||
};
|
||||
|
||||
public static Dictionary<string, Func<ScriptableObject>> DDTInstantiate = new()
|
||||
{
|
||||
public static Dictionary<string, Func<ScriptableObject>> DDTInstantiate = new()
|
||||
{
|
||||
{ $"{nameof(DDT)}",DDT.Make}
|
||||
};
|
||||
};
|
||||
|
||||
public static Dictionary<string, Func<ScriptableObject>> TickUpdatementInstantiate = new ()
|
||||
{
|
||||
public static Dictionary<string, Func<ScriptableObject>> TickUpdatementInstantiate = new()
|
||||
{
|
||||
{ $"{nameof(LookAtAnchor)}",LookAtAnchor.Make},
|
||||
{ $"{nameof(TickMovement)}",TickMovement.Make},
|
||||
{ $"{nameof(TickRotation)}",TickRotation.Make},
|
||||
{ $"{nameof(TickScaling)}",TickScaling.Make},
|
||||
};
|
||||
};
|
||||
|
||||
public static Dictionary<string, Func<ScriptableObject>> MaterialUpdatementInstantiate = new()
|
||||
{
|
||||
public static Dictionary<string, Func<ScriptableObject>> MaterialUpdatementInstantiate = new()
|
||||
{
|
||||
{ $"{nameof(MaterialUpdatement)}",MaterialUpdatement.Make},
|
||||
{ $"{nameof(ColorUpdatement)}",ColorUpdatement.Make},
|
||||
{ $"{nameof(EmissionColorUpdatement)}",EmissionColorUpdatement.Make},
|
||||
};
|
||||
};
|
||||
|
||||
public static Dictionary<string, Func<ScriptableObject>> SplineInstantiate = new()
|
||||
{
|
||||
public static Dictionary<string, Func<ScriptableObject>> SplineInstantiate = new()
|
||||
{
|
||||
{ $"{nameof(SplineCore)}",SplineCore.Make},
|
||||
{ $"{nameof(SplineNode)}",SplineNode.Make},
|
||||
{ $"{nameof(SplineAnchor)}",SplineAnchor.Make},
|
||||
@@ -56,22 +61,22 @@ namespace Demo.Game
|
||||
{ $"{nameof(SplineTrackRenderer)}",SplineTrackRenderer.Make},
|
||||
{ $"{nameof(SplineTubeRenderer)}",SplineTubeRenderer.Make},
|
||||
{ $"{nameof(SplineSurfaceRenderer)}",SplineSurfaceRenderer.Make},
|
||||
};
|
||||
};
|
||||
|
||||
public static Dictionary<string, Func<ScriptableObject>> JudgementInstantiate = new()
|
||||
{
|
||||
public static Dictionary<string, Func<ScriptableObject>> JudgementInstantiate = new()
|
||||
{
|
||||
// 可判定物只能有一个种类被使用,否则会引起输入检定冲突
|
||||
{ $"{nameof(FullScreenInteraction)}",FullScreenInteraction.Make},
|
||||
// Effect
|
||||
{ $"{nameof(ParticleEffect)}",ParticleEffect.Make },
|
||||
// JudgementEffect
|
||||
{ $"{nameof(ParticleJudgement)}",ParticleJudgement.Make},
|
||||
};
|
||||
};
|
||||
|
||||
public static void OpenInstantiateMenu(this ScriptableObject self, RectTransform item)
|
||||
{
|
||||
List<SharedModule.CallbackData> result = new()
|
||||
public static void OpenInstantiateMenu(this ScriptableObject self, RectTransform item)
|
||||
{
|
||||
List<SharedModule.CallbackData> result = new()
|
||||
{
|
||||
// Show Name
|
||||
new($"{self.ScriptName}",_=>{ }),
|
||||
new($"{self.GetType()}",_=>{ }),
|
||||
@@ -80,18 +85,259 @@ namespace Demo.Game
|
||||
new($"Angles:{self.transform.eulerAngles}",_=>{ }),
|
||||
new($"xAngles:{self.transform.localEulerAngles}",_=>{ }),
|
||||
new($"Scale:{self.transform.localScale}",_=>{ }),
|
||||
};
|
||||
SharedModule.instance.OpenCustomMenu(item, result.ToArray());
|
||||
};
|
||||
SharedModule.instance.OpenCustomMenu(item, result.ToArray());
|
||||
}
|
||||
|
||||
public static Dictionary<string, Func<ScriptableObject>> GetScriptableObjectInstantiate()
|
||||
{
|
||||
return new Dictionary<string, Func<ScriptableObject>>(GameObjectInstantiate
|
||||
.Union(DDTInstantiate)
|
||||
.Union(TickUpdatementInstantiate)
|
||||
.Union(MaterialUpdatementInstantiate)
|
||||
.Union(SplineInstantiate)
|
||||
.Union(JudgementInstantiate));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace PrivateType
|
||||
{
|
||||
public class EaseCurveTypeInstance
|
||||
{
|
||||
public static EaseCurveTypeInstance instance = new();
|
||||
public MathExtension.EaseCurveType Linear => MathExtension.EaseCurveType.Linear;
|
||||
public MathExtension.EaseCurveType InQuad => MathExtension.EaseCurveType.InQuad;
|
||||
public MathExtension.EaseCurveType OutQuad => MathExtension.EaseCurveType.OutQuad;
|
||||
public MathExtension.EaseCurveType InOutQuad => MathExtension.EaseCurveType.InOutQuad;
|
||||
public MathExtension.EaseCurveType InCubic => MathExtension.EaseCurveType.InCubic;
|
||||
public MathExtension.EaseCurveType OutCubic => MathExtension.EaseCurveType.OutCubic;
|
||||
public MathExtension.EaseCurveType InOutCubic => MathExtension.EaseCurveType.InOutCubic;
|
||||
public MathExtension.EaseCurveType InQuart => MathExtension.EaseCurveType.InQuart;
|
||||
public MathExtension.EaseCurveType OutQuart => MathExtension.EaseCurveType.OutQuart;
|
||||
public MathExtension.EaseCurveType InOutQuart => MathExtension.EaseCurveType.InOutQuart;
|
||||
public MathExtension.EaseCurveType InQuint => MathExtension.EaseCurveType.InQuint;
|
||||
public MathExtension.EaseCurveType OutQuint => MathExtension.EaseCurveType.OutQuint;
|
||||
public MathExtension.EaseCurveType InOutQuint => MathExtension.EaseCurveType.InOutQuint;
|
||||
public MathExtension.EaseCurveType InSine => MathExtension.EaseCurveType.InSine;
|
||||
public MathExtension.EaseCurveType OutSine => MathExtension.EaseCurveType.OutSine;
|
||||
public MathExtension.EaseCurveType InOutSine => MathExtension.EaseCurveType.InOutSine;
|
||||
public MathExtension.EaseCurveType InExpo => MathExtension.EaseCurveType.InExpo;
|
||||
public MathExtension.EaseCurveType OutExpo => MathExtension.EaseCurveType.OutExpo;
|
||||
public MathExtension.EaseCurveType InOutExpo => MathExtension.EaseCurveType.InOutExpo;
|
||||
public MathExtension.EaseCurveType InCirc => MathExtension.EaseCurveType.InCirc;
|
||||
public MathExtension.EaseCurveType OutCirc => MathExtension.EaseCurveType.OutCirc;
|
||||
public MathExtension.EaseCurveType InOutCirc => MathExtension.EaseCurveType.InOutCirc;
|
||||
public MathExtension.EaseCurveType InBounce => MathExtension.EaseCurveType.InBounce;
|
||||
public MathExtension.EaseCurveType OutBounce => MathExtension.EaseCurveType.OutBounce;
|
||||
public MathExtension.EaseCurveType InOutBounce => MathExtension.EaseCurveType.InOutBounce;
|
||||
public MathExtension.EaseCurveType InElastic => MathExtension.EaseCurveType.InElastic;
|
||||
public MathExtension.EaseCurveType OutElastic => MathExtension.EaseCurveType.OutElastic;
|
||||
public MathExtension.EaseCurveType InOutElastic => MathExtension.EaseCurveType.InOutElastic;
|
||||
public MathExtension.EaseCurveType InBack => MathExtension.EaseCurveType.InBack;
|
||||
public MathExtension.EaseCurveType OutBack => MathExtension.EaseCurveType.OutBack;
|
||||
public MathExtension.EaseCurveType InOutBack => MathExtension.EaseCurveType.InOutBack;
|
||||
public MathExtension.EaseCurveType Custom => MathExtension.EaseCurveType.Custom;
|
||||
}
|
||||
|
||||
public static Dictionary<string, Func<ScriptableObject>> GetScriptableObjectInstantiate()
|
||||
public class SplineComputerSampleModeInstance
|
||||
{
|
||||
return new Dictionary<string, Func<ScriptableObject>>(GameObjectInstantiate
|
||||
.Union(DDTInstantiate)
|
||||
.Union(TickUpdatementInstantiate)
|
||||
.Union(MaterialUpdatementInstantiate)
|
||||
.Union(SplineInstantiate)
|
||||
.Union(JudgementInstantiate));
|
||||
public static SplineComputerSampleModeInstance instance = new();
|
||||
public SplineComputer.SampleMode Default => SplineComputer.SampleMode.Default;
|
||||
public SplineComputer.SampleMode Uniform => SplineComputer.SampleMode.Uniform;
|
||||
public SplineComputer.SampleMode Optimized => SplineComputer.SampleMode.Optimized;
|
||||
}
|
||||
|
||||
public class SplineTypeInstance
|
||||
{
|
||||
public static SplineTypeInstance instance = new();
|
||||
public Spline.Type Linear => Spline.Type.Linear;
|
||||
public Spline.Type BSpline => Spline.Type.BSpline;
|
||||
public Spline.Type CatmullRom => Spline.Type.CatmullRom;
|
||||
public Spline.Type Bezier => Spline.Type.Bezier;
|
||||
}
|
||||
|
||||
public class IEffectHookObjectInstance
|
||||
{
|
||||
public static IEffectHookObjectInstance instance = new();
|
||||
public IEffectHookObject.InteractiveEffectType VisibleDuration => IEffectHookObject.InteractiveEffectType.VisibleDuration;
|
||||
public IEffectHookObject.InteractiveEffectType InteractiveDuration => IEffectHookObject.InteractiveEffectType.InteractiveDuration;
|
||||
public IEffectHookObject.InteractiveEffectType InteractableScoreInterval => IEffectHookObject.InteractiveEffectType.InteractableScoreInterval;
|
||||
public IEffectHookObject.InteractiveEffectType InteractableIntervalThatCanScoreBest => IEffectHookObject.InteractiveEffectType.InteractableIntervalThatCanScoreBest;
|
||||
}
|
||||
|
||||
public class IInteractionJudgementLevelInstance
|
||||
{
|
||||
public static IInteractionJudgementLevelInstance instance = new();
|
||||
public IInteraction.JudgementLevel Bad => IInteraction.JudgementLevel.Bad;
|
||||
public IInteraction.JudgementLevel ScoreLevel => IInteraction.JudgementLevel.ScoreLevel;
|
||||
public IInteraction.JudgementLevel None => IInteraction.JudgementLevel.None;
|
||||
public IInteraction.JudgementLevel BestLevel => IInteraction.JudgementLevel.BestLevel;
|
||||
}
|
||||
|
||||
public static class RandomTool
|
||||
{
|
||||
public static float Random(float min, float max)
|
||||
{
|
||||
return UnityEngine.Random.Range(min, max);
|
||||
}
|
||||
|
||||
public static float Random(double min, double max)
|
||||
{
|
||||
return UnityEngine.Random.Range((float)min, (float)max);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsoleTool
|
||||
{
|
||||
private GameObject gameObject;
|
||||
public ConsoleTool(GameObject gameObject)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
}
|
||||
|
||||
public void Log(object obj)
|
||||
{
|
||||
Debug.Log(obj, gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
protected virtual bool IsImptSerialize => false;
|
||||
protected virtual void LoadFromImptCacheFile(ToolFile file)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected virtual void CreateAndLoadingImptCacheFile(ToolFile file)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public RScriptImportClass GenerateImport()
|
||||
{
|
||||
RScriptImportClass importClass = new()
|
||||
{
|
||||
typeof(Mathf),
|
||||
typeof(RandomTool),
|
||||
};
|
||||
return importClass;
|
||||
}
|
||||
|
||||
public RScriptVariables GenerateVariables()
|
||||
{
|
||||
RScriptVariables variables = new()
|
||||
{
|
||||
{ "this", new() { data = this, type = this.GetType() } },
|
||||
{ "self", new() { data = this, type = this.GetType() } },
|
||||
{ "console", new() { data = new ConsoleTool(gameObject), type = typeof(ConsoleTool) } },
|
||||
{ nameof(MathExtension.EaseCurveType), new() { data = EaseCurveTypeInstance.instance, type = typeof(EaseCurveTypeInstance) } },
|
||||
{ $"Spline{nameof(SplineComputer.SampleMode)}",
|
||||
new() { data = SplineComputerSampleModeInstance.instance, type = typeof(SplineComputerSampleModeInstance)} },
|
||||
{ $"Spline{nameof(Spline.Type)}",
|
||||
new() { data = SplineTypeInstance.instance, type = typeof(SplineTypeInstance)} },
|
||||
{ nameof(IEffectHookObject.InteractiveEffectType),
|
||||
new() { data = IEffectHookObjectInstance.instance, type = typeof(IEffectHookObjectInstance)} },
|
||||
{ nameof(IInteraction.JudgementLevel),
|
||||
new() { data = IInteractionJudgementLevelInstance.instance, type = typeof(IInteractionJudgementLevelInstance) } }
|
||||
};
|
||||
return variables;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<string, object> s_FileLocker = new();
|
||||
|
||||
public IEnumerator ParseFromScriptFile2Expr(ToolFile file)
|
||||
{
|
||||
IsParseScript2Expr = true;
|
||||
try
|
||||
{
|
||||
var hash = file.CalculateHash();
|
||||
var lastHashFile = file.GetParentDir() | ".cache" | $"{file.GetFilename(true)}.hash";
|
||||
var bin = file.GetParentDir() | ".cache" | $"{file.GetFilename(true)}.bin";
|
||||
if (IsImptSerialize)
|
||||
{
|
||||
if (lastHashFile.Exists() == false || lastHashFile.LoadAsText() != hash)
|
||||
{
|
||||
lastHashFile.MustExistsPath();
|
||||
lastHashFile.SaveAsText(hash);
|
||||
CreateAndLoadingImptCacheFile(bin);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadFromImptCacheFile(bin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RScriptEngine engine = new();
|
||||
RScriptImportClass importClass = GenerateImport();
|
||||
RScriptVariables variables = GenerateVariables();
|
||||
object locker;
|
||||
IEnumerator step = null;
|
||||
if (lastHashFile.Exists() == false || lastHashFile.LoadAsText() != hash)
|
||||
{
|
||||
lastHashFile.MustExistsPath();
|
||||
bin.MustExistsPath();
|
||||
lastHashFile.SaveAsText(hash);
|
||||
var script = file.LoadAsText();
|
||||
|
||||
var structBin = engine.Compile(script, importClass, variables);
|
||||
lock (s_FileLocker)
|
||||
{
|
||||
if (s_FileLocker.TryGetValue(file.GetFullPath(), out locker) == false)
|
||||
{
|
||||
s_FileLocker.Add(file.GetFullPath(), locker = new object());
|
||||
}
|
||||
}
|
||||
lock (locker)
|
||||
{
|
||||
bin.SaveAsBinary(RScriptSerializer.SerializeClass(structBin));
|
||||
}
|
||||
step = engine.RunAsync(script, importClass, variables);
|
||||
}
|
||||
else
|
||||
{
|
||||
RScriptContext.SerializableClass structBin;
|
||||
lock (s_FileLocker)
|
||||
{
|
||||
if (s_FileLocker.TryGetValue(file.GetFullPath(), out locker) == false)
|
||||
{
|
||||
s_FileLocker.Add(file.GetFullPath(), locker = new object());
|
||||
}
|
||||
}
|
||||
lock (locker)
|
||||
{
|
||||
structBin = RScriptSerializer.DeserializeClass(bin.LoadAsBinary());
|
||||
}
|
||||
step = engine.RunAsync(structBin, importClass, variables);
|
||||
|
||||
}
|
||||
yield return step;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsParseScript2Expr = false;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator ParseScript2Expr(string script)
|
||||
{
|
||||
IsParseScript2Expr = true;
|
||||
try
|
||||
{
|
||||
RScriptEngine engine = new();
|
||||
RScriptImportClass importClass = GenerateImport();
|
||||
RScriptVariables variables = GenerateVariables();
|
||||
|
||||
var step = engine.RunAsync(script, importClass, variables);
|
||||
yield return step;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsParseScript2Expr = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Submodule Assets/Scripts/Framework/[RScript] updated: cdf04acecf...02906f836d
Reference in New Issue
Block a user