命名空间迁移
This commit is contained in:
@@ -159,31 +159,33 @@ namespace Demo
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ScriptableObject
|
||||
namespace Game
|
||||
{
|
||||
protected virtual bool IsImptSerialize => false;
|
||||
protected virtual IEnumerator LoadFromImptCacheFile(ToolFile cacheFile)
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected virtual IEnumerator CreateAndLoadingImptCacheFile(ToolFile scriptFile, ToolFile cacheFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected virtual bool IsImptSerialize => false;
|
||||
protected virtual IEnumerator LoadFromImptCacheFile(ToolFile cacheFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected virtual IEnumerator CreateAndLoadingImptCacheFile(ToolFile scriptFile, ToolFile cacheFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly RScriptImportClass s_GenerateImport = new()
|
||||
private readonly RScriptImportClass s_GenerateImport = new()
|
||||
{
|
||||
typeof(Mathf),
|
||||
typeof(RandomTool),
|
||||
};
|
||||
public RScriptImportClass GenerateImport()
|
||||
{
|
||||
return s_GenerateImport;
|
||||
}
|
||||
public RScriptImportClass GenerateImport()
|
||||
{
|
||||
return s_GenerateImport;
|
||||
}
|
||||
|
||||
public RScriptVariables GenerateVariables(ScriptableObject self)
|
||||
{
|
||||
RScriptVariables variables = new()
|
||||
public RScriptVariables GenerateVariables(ScriptableObject self)
|
||||
{
|
||||
RScriptVariables variables = new()
|
||||
{
|
||||
{ "this", new() { data = self, type = self.GetType() } },
|
||||
{ "self", new() { data = self, type = self.GetType() } },
|
||||
@@ -198,101 +200,102 @@ namespace Demo
|
||||
{ nameof(IInteraction.JudgementLevel),
|
||||
new() { data = IInteractionJudgementLevelInstance.instance, type = typeof(IInteractionJudgementLevelInstance) } }
|
||||
};
|
||||
return variables;
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<string, object> s_FileLocker = new();
|
||||
private static readonly Dictionary<string, object> s_FileLocker = new();
|
||||
|
||||
public IEnumerator ParseFromScriptFile2Expr(ToolFile file)
|
||||
{
|
||||
IsParseScript2Expr = true;
|
||||
try
|
||||
public IEnumerator ParseFromScriptFile2Expr(ToolFile file)
|
||||
{
|
||||
var hash = file.CalculateHash();
|
||||
var lastHashFile = file.GetParentDir() | ".cache" | $"{file.GetFilename(true)}.hash";
|
||||
var bin = file.GetParentDir() | ".cache" | $"{file.GetFilename(true)}.bin";
|
||||
if (IsImptSerialize)
|
||||
IsParseScript2Expr = true;
|
||||
try
|
||||
{
|
||||
if (lastHashFile.Exists() == false || lastHashFile.LoadAsText() != hash)
|
||||
var hash = file.CalculateHash();
|
||||
var lastHashFile = file.GetParentDir() | ".cache" | $"{file.GetFilename(true)}.hash";
|
||||
var bin = file.GetParentDir() | ".cache" | $"{file.GetFilename(true)}.bin";
|
||||
if (IsImptSerialize)
|
||||
{
|
||||
lastHashFile.MustExistsPath();
|
||||
lastHashFile.SaveAsText(hash);
|
||||
yield return ConventionUtility.AvoidFakeStop(CreateAndLoadingImptCacheFile(file, bin));
|
||||
if (lastHashFile.Exists() == false || lastHashFile.LoadAsText() != hash)
|
||||
{
|
||||
lastHashFile.MustExistsPath();
|
||||
lastHashFile.SaveAsText(hash);
|
||||
yield return ConventionUtility.AvoidFakeStop(CreateAndLoadingImptCacheFile(file, bin));
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return ConventionUtility.AvoidFakeStop(LoadFromImptCacheFile(bin));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return ConventionUtility.AvoidFakeStop(LoadFromImptCacheFile(bin));
|
||||
IEnumerator step = null;
|
||||
RScriptEngine engine = new();
|
||||
RScriptImportClass importClass = GenerateImport();
|
||||
RScriptVariables variables = GenerateVariables(this);
|
||||
object locker;
|
||||
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;// ConventionUtility.AvoidFakeStop(step);
|
||||
}
|
||||
}
|
||||
else
|
||||
finally
|
||||
{
|
||||
IsParseScript2Expr = false;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator ParseScript2Expr(string script)
|
||||
{
|
||||
IsParseScript2Expr = true;
|
||||
try
|
||||
{
|
||||
IEnumerator step = null;
|
||||
RScriptEngine engine = new();
|
||||
RScriptImportClass importClass = GenerateImport();
|
||||
RScriptVariables variables = GenerateVariables(this);
|
||||
object locker;
|
||||
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;// ConventionUtility.AvoidFakeStop(step);
|
||||
var step = engine.RunAsync(script, importClass, variables);
|
||||
yield return step;//ConventionUtility.AvoidFakeStop(step);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsParseScript2Expr = false;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsParseScript2Expr = false;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator ParseScript2Expr(string script)
|
||||
{
|
||||
IsParseScript2Expr = true;
|
||||
try
|
||||
{
|
||||
RScriptEngine engine = new();
|
||||
RScriptImportClass importClass = GenerateImport();
|
||||
RScriptVariables variables = GenerateVariables(this);
|
||||
|
||||
var step = engine.RunAsync(script, importClass, variables);
|
||||
yield return step;//ConventionUtility.AvoidFakeStop(step);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsParseScript2Expr = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user