开始进行配置字段迁移
This commit is contained in:
@@ -34,21 +34,19 @@ namespace Demo.Game
|
||||
|
||||
namespace ConfigType
|
||||
{
|
||||
[Serializable]
|
||||
public class ScriptLoadableConfig
|
||||
{
|
||||
public int UID = -1;
|
||||
public Vector3 EnterGameLocalPosition, EnterGameEulerAngles, EnterGameLocalScaling;
|
||||
public bool IsSetObjectDisable;
|
||||
public int UpdatePerFrame;
|
||||
public int ScriptUpdateCounter;
|
||||
public string ScriptName;
|
||||
private string[] ChildTypes;
|
||||
public ScriptLoadableConfig[] childs;
|
||||
[Content] public int UID = -1;
|
||||
[Content] public Vector3 EnterGameLocalPosition = Vector3.zero, EnterGameEulerAngles = Vector3.zero, EnterGameLocalScaling = Vector3.zero;
|
||||
[Content] public bool IsSetObjectDisable = false;
|
||||
[Content] public int UpdatePerFrame = 1;
|
||||
|
||||
public readonly static Dictionary<string, Func<ScriptLoadableConfig>> ConfigGeneraters = new()
|
||||
{
|
||||
{ nameof(ScriptLoadableConfig), ()=>new ScriptLoadableConfig() },
|
||||
};
|
||||
[Setting] public string ScriptName = "";
|
||||
private string[] ChildTypes = null;
|
||||
public ScriptLoadableConfig[] childs = null;
|
||||
|
||||
[Setting] public ScriptableObject target;
|
||||
|
||||
public virtual void Deserialize(BinaryReader reader)
|
||||
{
|
||||
@@ -58,14 +56,15 @@ namespace Demo.Game
|
||||
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();
|
||||
var scriptObject = DefaultInstantiate.GetScriptableObjectInstantiate()[ChildTypes[i]].Invoke();
|
||||
scriptObject.EnableScript(target);
|
||||
childs[i] = scriptObject.Config;
|
||||
childs[i].Deserialize(reader);
|
||||
}
|
||||
}
|
||||
@@ -77,8 +76,8 @@ namespace Demo.Game
|
||||
BinarySerializeUtility.WriteVec3(writer, EnterGameLocalScaling);
|
||||
BinarySerializeUtility.WriteBool(writer, IsSetObjectDisable);
|
||||
BinarySerializeUtility.WriteInt(writer, UpdatePerFrame);
|
||||
BinarySerializeUtility.WriteInt(writer, ScriptUpdateCounter);
|
||||
BinarySerializeUtility.WriteString(writer, ScriptName);
|
||||
ChildTypes = (from child in childs select child.GetType().Name).ToArray();
|
||||
BinarySerializeUtility.SerializeArray(writer, ChildTypes);
|
||||
foreach (var child in childs)
|
||||
{
|
||||
@@ -101,13 +100,32 @@ namespace Demo.Game
|
||||
/// </summary>
|
||||
public partial class ScriptableObject
|
||||
{
|
||||
[Content, SerializeField]
|
||||
private Vector3
|
||||
EnterGameLocalPosition = Vector3.zero,
|
||||
EnterGameEulerAngles = Vector3.zero,
|
||||
EnterGameLocalScaling = Vector3.one;
|
||||
[Content, SerializeField] private bool IsSetObjectDisable = false;
|
||||
[Content] public int UpdatePerFrame = 1;
|
||||
protected virtual ConfigType.ScriptLoadableConfig MakeConfig()
|
||||
{
|
||||
return new ConfigType.ScriptLoadableConfig();
|
||||
}
|
||||
[Setting, SerializeField] private ConfigType.ScriptLoadableConfig m_Config = null;
|
||||
public ConfigType.ScriptLoadableConfig Config
|
||||
{
|
||||
// 懒加载生成Config
|
||||
get
|
||||
{
|
||||
if (m_Config == null)
|
||||
{
|
||||
m_Config = MakeConfig();
|
||||
m_Config.target = this;
|
||||
}
|
||||
return m_Config;
|
||||
}
|
||||
}
|
||||
public ConfigT GetConfig<ConfigT>() where ConfigT : ConfigType.ScriptLoadableConfig
|
||||
{
|
||||
return (ConfigT)Config;
|
||||
}
|
||||
public virtual void UpdateConfig()
|
||||
{
|
||||
Config.childs = (from child in this.Childs select child.Config).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置坐标
|
||||
@@ -118,7 +136,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetLocalPosition(float x, float y, float z)
|
||||
{
|
||||
EnterGameLocalPosition = new(x, y, z);
|
||||
Config.EnterGameLocalPosition = new(x, y, z);
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置欧拉角
|
||||
@@ -129,7 +147,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetLocalEulerAngles(float x, float y, float z)
|
||||
{
|
||||
EnterGameEulerAngles = new(x, y, z);
|
||||
Config.EnterGameEulerAngles = new(x, y, z);
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置缩放
|
||||
@@ -140,7 +158,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetLocalScaling(float x, float y, float z)
|
||||
{
|
||||
EnterGameLocalScaling = new(x, y, z);
|
||||
Config.EnterGameLocalScaling = new(x, y, z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,7 +168,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetObjectDisable()
|
||||
{
|
||||
IsSetObjectDisable = true;
|
||||
Config.IsSetObjectDisable = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,15 +179,15 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetUpdatePerFrame(int frame)
|
||||
{
|
||||
UpdatePerFrame = Mathf.Max(1, frame);
|
||||
Config.UpdatePerFrame = Mathf.Max(1, frame);
|
||||
}
|
||||
|
||||
private void ScriptableObjectDoReset()
|
||||
{
|
||||
transform.localPosition = EnterGameLocalPosition;
|
||||
transform.localEulerAngles = EnterGameEulerAngles;
|
||||
transform.localScale = EnterGameLocalScaling;
|
||||
gameObject.SetActive(IsSetObjectDisable == false);
|
||||
transform.localPosition = Config.EnterGameLocalPosition;
|
||||
transform.localEulerAngles = Config.EnterGameEulerAngles;
|
||||
transform.localScale = Config.EnterGameLocalScaling;
|
||||
gameObject.SetActive(Config.IsSetObjectDisable == false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +229,11 @@ namespace Demo.Game
|
||||
public static float OneBarTime = 60;
|
||||
|
||||
private bool isEnableScript = false;
|
||||
public string ScriptName = "";
|
||||
public string ScriptName
|
||||
{
|
||||
get => Config.ScriptName;
|
||||
set => Config.ScriptName = value;
|
||||
}
|
||||
private string s_ScriptType = null;
|
||||
public string m_ScriptType
|
||||
{
|
||||
@@ -318,7 +340,7 @@ namespace Demo.Game
|
||||
return result;
|
||||
}
|
||||
|
||||
public void EnableScript(ScriptableObject parent)
|
||||
public void EnableScript(ScriptableObject parent,int uid = -1)
|
||||
{
|
||||
if (isEnableScript)
|
||||
{
|
||||
@@ -342,7 +364,10 @@ namespace Demo.Game
|
||||
|
||||
isEnableScript = true;
|
||||
// 只有RootObject的parent会是空的
|
||||
GetRoot().PushLoadedScriptObject(this);
|
||||
if (uid < 0)
|
||||
Config.UID = GetRoot().PushLoadedScriptObject(this);
|
||||
else
|
||||
GetRoot().PushLoadedScriptObject(this, uid);
|
||||
if (parent != null)
|
||||
{
|
||||
MyHierarchyItem = parent.MyHierarchyItem.GetHierarchyItem().CreateSubPropertyItem(1)[0];
|
||||
@@ -531,7 +556,7 @@ namespace Demo.Game
|
||||
else
|
||||
{
|
||||
// UpdateTicks
|
||||
if (ScriptUpdateCounter % UpdatePerFrame == 0)
|
||||
if (ScriptUpdateCounter % Config.UpdatePerFrame == 0)
|
||||
UpdateTicks(currentTime, deltaTime, tickType);
|
||||
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
||||
}
|
||||
@@ -629,6 +654,7 @@ namespace Demo.Game
|
||||
if (this.ScriptableObjectContents.IsCreated)
|
||||
this.ScriptableObjectContents.Dispose();
|
||||
}
|
||||
UpdateConfig();
|
||||
IsScriptApply = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user