命名空间迁移
This commit is contained in:
@@ -6,7 +6,7 @@ using Cinemachine;
|
||||
#endif
|
||||
using Convention.WindowsUI.Variant;
|
||||
using UnityEngine;
|
||||
using Demo.Attr;
|
||||
using Demo.Game.Attr;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Convention;
|
||||
using Demo.Attr;
|
||||
using Demo.Game.Attr;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,6 +10,26 @@ using UnityEngine.Rendering;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
namespace ConfigType
|
||||
{
|
||||
public class DDTConfig : ScriptLoadableConfig
|
||||
{
|
||||
public NativeArray<float> Datas = new(128, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
|
||||
|
||||
public override void Deserialize(BinaryReader reader)
|
||||
{
|
||||
BinarySerializeUtility.DeserializeNativeArray(reader, ref Datas);
|
||||
base.Deserialize(reader);
|
||||
}
|
||||
|
||||
public override void Serialize(BinaryWriter writer)
|
||||
{
|
||||
BinarySerializeUtility.SerializeNativeArray(writer, Datas);
|
||||
base.Serialize(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Scriptable]
|
||||
public class DDT : ScriptableObject
|
||||
{
|
||||
@@ -48,7 +68,7 @@ namespace Demo.Game
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Demo.Editor
|
||||
{
|
||||
foreach (var type in asm.GetTypes())
|
||||
{
|
||||
if (typeof(ScriptableObject).IsAssignableFrom(type) && type.IsAbstract == false)
|
||||
if (typeof(Demo.Game.ScriptableObject).IsAssignableFrom(type) && type.IsAbstract == false)
|
||||
{
|
||||
result.Add(type.Name, type);
|
||||
}
|
||||
@@ -391,7 +391,7 @@ namespace Demo.Editor
|
||||
{
|
||||
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(type, () => generater(), null, filename).Register();
|
||||
}
|
||||
else if (typeof(ScriptableObject).IsAssignableFrom(type))
|
||||
else if (typeof(Demo.Game.ScriptableObject).IsAssignableFrom(type))
|
||||
{
|
||||
new Convention.RScript.Variable.CStyle.CScriptRScriptVariableGenerater(type, null, null, filename).Register();
|
||||
}
|
||||
|
||||
@@ -205,6 +205,7 @@ namespace Demo.Game
|
||||
rootGameObject.transform.SetParent(transform);
|
||||
rootGameObject.ScriptName = rootObject.GetName(true);
|
||||
rootGameObject.audioSystem = MainAudio;
|
||||
rootGameObject.LoadedScriptSet.Add(rootObject);
|
||||
rootGameObject.EnableScript(content.RootSourceDir, this);
|
||||
rootGameObject.SetContent(nameof(SongOffset), SongOffset);
|
||||
rootGameObject.SetContent(nameof(IsAutoPlay), IsAutoPlay ? 1 : 0);
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Demo.Game
|
||||
[Content] public GameController RootGameController;
|
||||
|
||||
public string SourcePath;
|
||||
public HashSet<string> LoadedScriptSet = new();
|
||||
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Convention;
|
||||
using Convention.RScript;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Demo.Attr;
|
||||
using Demo.Game.Attr;
|
||||
using Demo.Game;
|
||||
using Dreamteck.Splines;
|
||||
using System;
|
||||
@@ -15,7 +15,7 @@ using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Demo
|
||||
namespace Demo.Game
|
||||
{
|
||||
public interface IScriptableObject
|
||||
{
|
||||
@@ -38,52 +38,55 @@ namespace Demo
|
||||
}
|
||||
}
|
||||
|
||||
public class ScriptLoadableConfig
|
||||
namespace ConfigType
|
||||
{
|
||||
public Vector3 EnterGameLocalPosition, EnterGameEulerAngles, EnterGameLocalScaling;
|
||||
public bool IsSetObjectDisable;
|
||||
public int UpdatePerFrame;
|
||||
public int ScriptUpdateCounter;
|
||||
public string ScriptName;
|
||||
private string[] ChildTypes;
|
||||
public ScriptLoadableConfig[] childs;
|
||||
|
||||
public readonly static Dictionary<string, Func<ScriptLoadableConfig>> ConfigGeneraters = new()
|
||||
public class ScriptLoadableConfig
|
||||
{
|
||||
{ nameof(ScriptLoadableConfig), ()=>new ScriptLoadableConfig() },
|
||||
};
|
||||
public Vector3 EnterGameLocalPosition, EnterGameEulerAngles, EnterGameLocalScaling;
|
||||
public bool IsSetObjectDisable;
|
||||
public int UpdatePerFrame;
|
||||
public int ScriptUpdateCounter;
|
||||
public string ScriptName;
|
||||
private string[] ChildTypes;
|
||||
public ScriptLoadableConfig[] childs;
|
||||
|
||||
public virtual void Deserialize(BinaryReader reader)
|
||||
{
|
||||
EnterGameLocalPosition = BinarySerializeUtility.ReadVec3(reader);
|
||||
EnterGameEulerAngles = BinarySerializeUtility.ReadVec3(reader);
|
||||
EnterGameLocalScaling = BinarySerializeUtility.ReadVec3(reader);
|
||||
IsSetObjectDisable = BinarySerializeUtility.ReadBool(reader);
|
||||
UpdatePerFrame = BinarySerializeUtility.ReadInt(reader);
|
||||
ScriptUpdateCounter = BinarySerializeUtility.ReadInt(reader);
|
||||
ScriptName = BinarySerializeUtility.ReadString(reader);
|
||||
ChildTypes = BinarySerializeUtility.DeserializeStringArray(reader);
|
||||
int childCount = ChildTypes.Length;
|
||||
childs = new ScriptLoadableConfig[childCount];
|
||||
for (int i = 0; i < childCount; i++)
|
||||
public readonly static Dictionary<string, Func<ScriptLoadableConfig>> ConfigGeneraters = new()
|
||||
{
|
||||
childs[i] = ConfigGeneraters[ChildTypes[i]].Invoke();
|
||||
childs[i].Deserialize(reader);
|
||||
{ nameof(ScriptLoadableConfig), ()=>new ScriptLoadableConfig() },
|
||||
};
|
||||
|
||||
public virtual void Deserialize(BinaryReader reader)
|
||||
{
|
||||
EnterGameLocalPosition = BinarySerializeUtility.ReadVec3(reader);
|
||||
EnterGameEulerAngles = BinarySerializeUtility.ReadVec3(reader);
|
||||
EnterGameLocalScaling = BinarySerializeUtility.ReadVec3(reader);
|
||||
IsSetObjectDisable = BinarySerializeUtility.ReadBool(reader);
|
||||
UpdatePerFrame = BinarySerializeUtility.ReadInt(reader);
|
||||
ScriptUpdateCounter = BinarySerializeUtility.ReadInt(reader);
|
||||
ScriptName = BinarySerializeUtility.ReadString(reader);
|
||||
ChildTypes = BinarySerializeUtility.DeserializeStringArray(reader);
|
||||
int childCount = ChildTypes.Length;
|
||||
childs = new ScriptLoadableConfig[childCount];
|
||||
for (int i = 0; i < childCount; i++)
|
||||
{
|
||||
childs[i] = ConfigGeneraters[ChildTypes[i]].Invoke();
|
||||
childs[i].Deserialize(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual void Serialize(BinaryWriter writer)
|
||||
{
|
||||
BinarySerializeUtility.WriteVec3(writer, EnterGameLocalPosition);
|
||||
BinarySerializeUtility.WriteVec3(writer, EnterGameEulerAngles);
|
||||
BinarySerializeUtility.WriteVec3(writer, EnterGameLocalScaling);
|
||||
BinarySerializeUtility.WriteBool(writer, IsSetObjectDisable);
|
||||
BinarySerializeUtility.WriteInt(writer, UpdatePerFrame);
|
||||
BinarySerializeUtility.WriteInt(writer, ScriptUpdateCounter);
|
||||
BinarySerializeUtility.WriteString(writer, ScriptName);
|
||||
BinarySerializeUtility.SerializeArray(writer, ChildTypes);
|
||||
foreach (var child in childs)
|
||||
public virtual void Serialize(BinaryWriter writer)
|
||||
{
|
||||
child.Serialize(writer);
|
||||
BinarySerializeUtility.WriteVec3(writer, EnterGameLocalPosition);
|
||||
BinarySerializeUtility.WriteVec3(writer, EnterGameEulerAngles);
|
||||
BinarySerializeUtility.WriteVec3(writer, EnterGameLocalScaling);
|
||||
BinarySerializeUtility.WriteBool(writer, IsSetObjectDisable);
|
||||
BinarySerializeUtility.WriteInt(writer, UpdatePerFrame);
|
||||
BinarySerializeUtility.WriteInt(writer, ScriptUpdateCounter);
|
||||
BinarySerializeUtility.WriteString(writer, ScriptName);
|
||||
BinarySerializeUtility.SerializeArray(writer, ChildTypes);
|
||||
foreach (var child in childs)
|
||||
{
|
||||
child.Serialize(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,6 +415,7 @@ namespace Demo
|
||||
// 获取文件
|
||||
var file = new ToolFile(GetRoot().SourcePath);
|
||||
file = file | path;
|
||||
GetRoot().LoadedScriptSet.Add(file);
|
||||
// 找不到脚本
|
||||
if (file.Exists() == false)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Convention;
|
||||
using Demo.Attr;
|
||||
using Demo.Game.Attr;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -8,6 +8,27 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
namespace ConfigType
|
||||
{
|
||||
// SubWorld 配置
|
||||
public class SubWorldConfig : ScriptLoadableConfig
|
||||
{
|
||||
public string project;
|
||||
|
||||
public override void Deserialize(BinaryReader reader)
|
||||
{
|
||||
project = BinarySerializeUtility.ReadString(reader);
|
||||
base.Deserialize(reader);
|
||||
}
|
||||
|
||||
public override void Serialize(BinaryWriter writer)
|
||||
{
|
||||
BinarySerializeUtility.WriteString(writer, project);
|
||||
base.Serialize(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Scriptable]
|
||||
public class SubWorld : ScriptableObject
|
||||
{
|
||||
@@ -25,7 +46,7 @@ namespace Demo.Game
|
||||
var ir = SceneManager.LoadSceneAsync(Editor.EditorController.SceneName, LoadSceneMode.Additive);
|
||||
ir.completed += x =>
|
||||
{
|
||||
SubWorldGameController = (from controller in FindObjectsOfType<GameController>()
|
||||
SubWorldGameController = (from controller in FindObjectsByType<GameController>(FindObjectsSortMode.None)
|
||||
where controller.RootSourcePath == project
|
||||
select controller).First();
|
||||
ConventionUtility.StartCoroutine(SubWorldGameController.GameInitBySubWorld(GetRoot().InputCatch));
|
||||
@@ -48,4 +69,4 @@ namespace Demo.Game
|
||||
this.project = project;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user