From fccfaf1527c7d917eacca26310613884ff5a770b Mon Sep 17 00:00:00 2001 From: Quan Yuan Date: Sat, 2 Apr 2022 12:52:50 +0800 Subject: [PATCH 01/28] replace `Unity.Entities.BlobBuilder` by `com.quabug.BLOB` --- Assets/Samples/Animator/AnimatorSample.asmdef | 3 +- Assets/Samples/Animator/SetAnimatorTrigger.cs | 9 +-- Assets/Tests/Editor/TestExpression.cs | 2 +- Assets/Tests/Editor/TestVariant.cs | 2 +- .../Runtime/GlobalComponentVariant.cs | 4 +- .../builder.component/Runtime/NodeVariant.cs | 4 +- .../Runtime/BehaviorNodeComponent.cs | 7 +- .../EntitiesBT.Builder.GraphView.asmdef | 3 +- .../Runtime/GraphNodeVariant.cs | 5 +- .../Runtime/VariantNode.cs | 2 +- .../BuilderDrawer/BlobDataBuilderDrawer.cs | 1 - .../Nuwa/Blob/Editor/Nuwa.Blob.Editor.asmdef | 5 +- .../Nuwa/Blob/Runtime/BlobBuilderArray.cs | 70 ------------------- .../Blob/Runtime/BlobBuilderArray.cs.meta | 3 - .../Nuwa/Blob/Runtime/Builder/BlobAsset.cs | 12 ++-- .../Nuwa/Blob/Runtime/Builder/Builders.cs | 61 ++++++++++------ .../Blob/Runtime/Builder/DynamicBuilders.cs | 65 ++++++++++++----- .../Nuwa/Blob/Runtime/Nuwa.Blob.asmdef | 3 +- .../Dependencies/Nuwa/Blob/Runtime/Utility.cs | 32 --------- .../Runtime/Entities/ComponentVariant.cs | 5 +- .../Runtime/EntitiesBT.Runtime.asmdef | 3 +- .../Composites/WeightRandomSelectorNode.cs | 11 ++- .../Runtime/Variant/BlobVariantBuilder.cs | 22 +++--- .../essential/Runtime/Variant/IVariant.cs | 5 +- .../essential/Runtime/Variant/LocalVariant.cs | 7 +- .../Runtime/Variant/SerializedVariant.cs | 9 +-- .../essential/Runtime/Variant/Utilities.cs | 41 ++++++----- .../Runtime/ScriptableObjectVariant.cs | 5 +- .../Runtime/ExpressionVariant.cs | 16 ++--- 29 files changed, 185 insertions(+), 232 deletions(-) delete mode 100644 Packages/essential/Dependencies/Nuwa/Blob/Runtime/BlobBuilderArray.cs delete mode 100644 Packages/essential/Dependencies/Nuwa/Blob/Runtime/BlobBuilderArray.cs.meta diff --git a/Assets/Samples/Animator/AnimatorSample.asmdef b/Assets/Samples/Animator/AnimatorSample.asmdef index a6657cfb..d7b7fb76 100644 --- a/Assets/Samples/Animator/AnimatorSample.asmdef +++ b/Assets/Samples/Animator/AnimatorSample.asmdef @@ -6,7 +6,8 @@ "GUID:d3630359ae08047918d5cd6cddd51767", "GUID:734d92eba21c94caba915361bd5ac177", "GUID:4285913d8daed4d6fb1061c793376ad4", - "GUID:6d84eb5386377416e93c122a00485b68" + "GUID:6d84eb5386377416e93c122a00485b68", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Samples/Animator/SetAnimatorTrigger.cs b/Assets/Samples/Animator/SetAnimatorTrigger.cs index 7950f570..5c5eb76d 100644 --- a/Assets/Samples/Animator/SetAnimatorTrigger.cs +++ b/Assets/Samples/Animator/SetAnimatorTrigger.cs @@ -1,4 +1,5 @@ -using EntitiesBT.Core; +using Blob; +using EntitiesBT.Core; using Nuwa.Blob; using Unity.Entities; using UnityEngine; @@ -20,13 +21,13 @@ public NodeState Tick(int index, ref TNodeBlob blob, ref } } - public class AnimatorTriggerNameBuilder : Builder + public class AnimatorTriggerNameBuilder : Nuwa.Blob.Builder { public string TriggerName; - public override void Build(BlobBuilder builder, ref int data) + protected override void BuildImpl(IBlobStream stream) { - data = Animator.StringToHash(TriggerName); + stream.WriteValue(Animator.StringToHash(TriggerName)); } } } diff --git a/Assets/Tests/Editor/TestExpression.cs b/Assets/Tests/Editor/TestExpression.cs index 50e94aa4..31105726 100644 --- a/Assets/Tests/Editor/TestExpression.cs +++ b/Assets/Tests/Editor/TestExpression.cs @@ -69,7 +69,7 @@ public void should_eval_expression() }; ref var buildVariant = ref _builder.ConstructRoot(); - expression.Allocate(ref _builder, ref buildVariant); + expression.Allocate(_builder, ref buildVariant); using var variant = _builder.CreateBlobAssetReference(Allocator.Temp); var result = BlobVariantExtension.Read(ref variant.Value, 0, ref _nodeBlob, ref _bb); Assert.That(result, Is.EqualTo((4.1f + 5) * 2 + 10)); diff --git a/Assets/Tests/Editor/TestVariant.cs b/Assets/Tests/Editor/TestVariant.cs index ef3fb34e..0f51fd8d 100644 --- a/Assets/Tests/Editor/TestVariant.cs +++ b/Assets/Tests/Editor/TestVariant.cs @@ -17,7 +17,7 @@ public void should_find_value_type_of_variant() class InvalidVariant : IVariant { - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream, ref BlobVariant blobVariant) { throw new NotImplementedException(); } diff --git a/Packages/builder.component/Runtime/GlobalComponentVariant.cs b/Packages/builder.component/Runtime/GlobalComponentVariant.cs index 94b3080d..c0021741 100644 --- a/Packages/builder.component/Runtime/GlobalComponentVariant.cs +++ b/Packages/builder.component/Runtime/GlobalComponentVariant.cs @@ -27,7 +27,7 @@ public class Any : IVariant where T : unmanaged protected Type _declaringType => Value?.BlobType; protected Type _fieldType => typeof(T); - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream, ref BlobVariant blobVariant) { if (Value == null || Value.BlobType == null) throw new ArgumentException(); blobVariant.VariantId = GuidHashCode(GUID); @@ -38,7 +38,7 @@ public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) throw new ArgumentException(); } var valueOffset = Value.Offset + Marshal.OffsetOf(Value.BlobType, ValueFieldName).ToInt32(); - return builder.Allocate(ref blobVariant, valueOffset); + return stream.Allocate(ref blobVariant, valueOffset); } public object PreviewValue => Value?.GetPreviewValue(ValueFieldName); diff --git a/Packages/builder.component/Runtime/NodeVariant.cs b/Packages/builder.component/Runtime/NodeVariant.cs index 2075a2b4..8568721a 100644 --- a/Packages/builder.component/Runtime/NodeVariant.cs +++ b/Packages/builder.component/Runtime/NodeVariant.cs @@ -33,9 +33,9 @@ public class Any : IVariant where T : unmanaged public BTNode NodeObject; [VariantNodeObject(nameof(NodeObject))] public string ValueFieldName; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream, ref BlobVariant blobVariant) { - return Allocate(ref builder, ref blobVariant, NodeObject, ValueFieldName); + return Allocate(ref stream, ref blobVariant, NodeObject, ValueFieldName); } public object PreviewValue => null; diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs index 37d46431..0038b236 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using Blob; using EntitiesBT.Components; using EntitiesBT.Core; using EntitiesBT.Entities; @@ -197,11 +198,11 @@ public unsafe BlobAssetReference Build(Core.ITreeNode[] builde { var nodeType = _node.BehaviorNodeDataType; if (nodeType.IsZeroSizeStruct()) return BlobAssetReference.Null; - var blobBuilder = new BlobBuilder(Allocator.Temp, UnsafeUtility.SizeOf(nodeType)); + var blobBuilder = new BlobMemoryStream(UnsafeUtility.SizeOf(nodeType)); try { - var dataPtr = blobBuilder.ConstructRootPtrByType(nodeType); - _node.Blob.Build(blobBuilder, new IntPtr(dataPtr)); + _node.Blob.Build(blobBuilder); + blobBuilder.WritePatchOffset() return blobBuilder.CreateReferenceByType(nodeType); } finally diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/EntitiesBT.Builder.GraphView.asmdef b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/EntitiesBT.Builder.GraphView.asmdef index fe03c8d9..5fdfbad9 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/EntitiesBT.Builder.GraphView.asmdef +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/EntitiesBT.Builder.GraphView.asmdef @@ -11,7 +11,8 @@ "GUID:5f47a5f08ea7f45f98654b3647509a17", "GUID:756d163a75d2d4509b594fdc3b57f09d", "GUID:234ce02035d06804fbc60711c8529437", - "GUID:90dda6e850594c7aa3588314ff000ed5" + "GUID:90dda6e850594c7aa3588314ff000ed5", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/GraphNodeVariant.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/GraphNodeVariant.cs index 74d7c816..f23015bb 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/GraphNodeVariant.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/GraphNodeVariant.cs @@ -1,4 +1,5 @@ using System; +using Blob; using EntitiesBT.Variant; using Nuwa; using Unity.Entities; @@ -17,10 +18,10 @@ public class Any : IVariant [ReadOnly, UnityDrawProperty] public VariantNodeComponent NodeComponent; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream) { // TODO: check validation - return NodeComponent.VariantNode.Allocate(ref builder, ref blobVariant); + return NodeComponent.VariantNode.Allocate(ref stream, ref blobVariant); } public object PreviewValue => NodeComponent == null ? null : NodeComponent.VariantNode.PreviewValue; diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/VariantNode.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/VariantNode.cs index 6967a70f..d13c6c58 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/VariantNode.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/VariantNode.cs @@ -34,7 +34,7 @@ public abstract class VariantNode : GraphNode, INode> public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) { - return Variant.Allocate(ref builder, ref blobVariant); + return Variant.Allocate(builder); } public bool IsPortCompatible(GraphRuntime graph, in PortId input, in PortId output) => true; diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs b/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs index e430d4d6..a91bd171 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs @@ -2,7 +2,6 @@ using System.Reflection; using Nuwa.Editor; using UnityEditor; -using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Editor/Nuwa.Blob.Editor.asmdef b/Packages/essential/Dependencies/Nuwa/Blob/Editor/Nuwa.Blob.Editor.asmdef index 646d1d1e..333fef11 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Editor/Nuwa.Blob.Editor.asmdef +++ b/Packages/essential/Dependencies/Nuwa/Blob/Editor/Nuwa.Blob.Editor.asmdef @@ -4,13 +4,14 @@ "references": [ "GUID:234ce02035d06804fbc60711c8529437", "GUID:6d84eb5386377416e93c122a00485b68", - "GUID:abe4851e67df59644865a60dae54a845" + "GUID:abe4851e67df59644865a60dae54a845", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [ "Editor" ], "excludePlatforms": [], - "allowUnsafeCode": false, + "allowUnsafeCode": true, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/BlobBuilderArray.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/BlobBuilderArray.cs deleted file mode 100644 index fb8f4d7d..00000000 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/BlobBuilderArray.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Diagnostics; -using Unity.Assertions; -using Unity.Collections.LowLevel.Unsafe; -using Nuwa.Blob; - -namespace Unity.Entities -{ - /// - /// Used by the methods to reference the arrays within a blob asset. - /// - /// Use this reference to initialize the data of a newly created . - public struct BlobBuilderArray - { - private IntPtr m_data; - private int m_length; - private Type m_elementType; - - /// - /// For internal, , use only. - /// - public BlobBuilderArray(IntPtr data, int length, Type elementType) - { - m_data = data; - m_length = length; - m_elementType = elementType; - } - - [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")] - private void CheckIndexOutOfRange(int index) - { - if (0 > index || index >= m_length) - throw new IndexOutOfRangeException($"Index {index} is out of range of '{m_length}' Length."); - } - - /// - /// Array index accessor for the elements in the array. - /// - /// The sequential index of an array item. - /// Thrown when index is less than zero or greater than the length of the array (minus one). - public IntPtr this[int index] - { - get - { - CheckIndexOutOfRange(index); - return Utility.ArrayElementAsPtr(m_data, index, UnsafeUtility.SizeOf(m_elementType)); - } - } - - public unsafe void SetElementAt(int index, in T value) where T : unmanaged - { - Assert.AreEqual(m_elementType, typeof(T)); - UnsafeUtility.AsRef(this[index].ToPointer()) = value; - } - - /// - /// Reports the number of elements in the array. - /// - public int Length => m_length; - - /// - /// Provides a pointer to the data stored in the array. - /// - /// You can only call this function in an [unsafe context]. - /// [unsafe context]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/unsafe-code - /// - /// A pointer to the first element in the array. - public IntPtr GetUnsafePtr() => m_data; - } -} diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/BlobBuilderArray.cs.meta b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/BlobBuilderArray.cs.meta deleted file mode 100644 index 053475d8..00000000 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/BlobBuilderArray.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6d775e0a5b6543cfa965ee9a0fa1127b -timeCreated: 1629800012 \ No newline at end of file diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/BlobAsset.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/BlobAsset.cs index 71b2c454..1d714642 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/BlobAsset.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/BlobAsset.cs @@ -1,5 +1,7 @@ using System; +using System.IO; using System.Linq; +using Blob; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -31,12 +33,12 @@ public IBuilder FindBuilderByPath(string path) return pathList.Aggregate(Builder, (builder, name) => builder.GetBuilder(name)); } - private unsafe BlobAssetReference Create() + private BlobAssetReference Create() { - using var builder = new BlobBuilder(Allocator.Temp); - ref var root = ref builder.ConstructRoot(); - Builder.Build(builder, new IntPtr(UnsafeUtility.AddressOf(ref root))); - return builder.CreateBlobAssetReference(Allocator.Persistent); + using var stream = new BlobMemoryStream(); + Builder.Build(stream); + stream.Length = (int)Utilities.Align((int)stream.Length); + return BlobAssetReference.Create(stream.ToArray()); } public void Dispose() diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs index 9ba33f6f..c77a907d 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs @@ -2,16 +2,19 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Text; +using Blob; using JetBrains.Annotations; using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; using UnityEngine; +using UnityEngine.Assertions; namespace Nuwa.Blob { - public interface IBuilder + using BlobString = BlobString; + + public interface IBuilder : global::Blob.IBuilder { - void Build(BlobBuilder builder, IntPtr dataPtr); IBuilder GetBuilder([NotNull] string name); object PreviewValue { get; set; } } @@ -24,11 +27,17 @@ public interface IObjectBuilder public abstract class Builder : IBuilder where T : unmanaged { - public unsafe void Build(BlobBuilder builder, IntPtr dataPtr) + public int Position { get; private set; } + + public void Build(IBlobStream stream) { - Build(builder, ref UnsafeUtility.AsRef(dataPtr.ToPointer())); + Position = stream.DataPosition; + stream.EnsureDataSize(); + BuildImpl(stream); } + protected abstract void BuildImpl([NotNull] IBlobStream stream); + public virtual IBuilder GetBuilder(string name) => throw new NotImplementedException(); public virtual object PreviewValue @@ -36,8 +45,6 @@ public virtual object PreviewValue get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - public abstract void Build(BlobBuilder builder, ref T data); } /// @@ -51,15 +58,15 @@ public class PlainDataBuilder : Builder where T : unmanaged { public T Value; - public override object PreviewValue + protected override void BuildImpl(IBlobStream stream) { - get => Value; - set => Value = (T)value; + stream.WriteValue(ref Value); } - public override void Build(BlobBuilder builder, ref T data) + public override object PreviewValue { - data = Value; + get => Value; + set => Value = (T)value; } } @@ -80,14 +87,15 @@ public BlobDataBuilder() BuilderUtility.SetBlobDataType(typeof(T), ref Builders, ref FieldNames); } - public override unsafe void Build(BlobBuilder builder, ref T data) + protected override void BuildImpl(IBlobStream stream) { - var dataPtr = new IntPtr(UnsafeUtility.AddressOf(ref data)); + var dataPosition = stream.DataPosition; var fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (var i = 0; i < Builders.Length; i++) { + Assert.AreEqual(FieldNames[i], fields[i].Name); var offset = UnsafeUtility.GetFieldOffset(fields[i]); - Builders[i].Build(builder, dataPtr + offset); + stream.ToPosition(dataPosition + offset).WriteValue(Builders[i]); } } @@ -120,10 +128,13 @@ public class ArrayBuilder : Builder> where T : unmanaged { [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Value; - public override void Build(BlobBuilder builder, ref BlobArray data) + protected override unsafe void BuildImpl(IBlobStream stream) { - var arrayBuilder = builder.Allocate(ref data, Value.Length); - for (var i = 0; i < Value.Length; i++) ((Builder)Value[i]).Build(builder, ref arrayBuilder[i]); + stream.WritePatchOffset() + .WriteValue(Value.Length) + .ToPatchPosition() + .WriteArray(Value, sizeof(T), Utilities.AlignOf()) + ; } public override IBuilder GetBuilder(string name) @@ -153,9 +164,14 @@ public override object PreviewValue set => Value = (string)value; } - public override void Build(BlobBuilder builder, ref BlobString data) + protected override void BuildImpl(IBlobStream stream) { - builder.AllocateString(ref data, Value); + var stringBytes = Encoding.UTF8.GetBytes(Value); + stream.WritePatchOffset() + .WriteValue(stringBytes.Length) + .ToPatchPosition() + .WriteArray(stringBytes) + ; } } @@ -167,10 +183,9 @@ public class PtrBuilder : Builder> where T : unmanaged { [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder Value; - public override unsafe void Build(BlobBuilder builder, ref BlobPtr data) + protected override void BuildImpl(IBlobStream stream) { - ref var value = ref builder.Allocate(ref data); - Value.Build(builder, new IntPtr(UnsafeUtility.AddressOf(ref value))); + stream.WritePatchOffset().ToPatchPosition().WriteValue(Value); } public override IBuilder GetBuilder(string name) diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs index 14fe95b5..c85cbaae 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs @@ -1,10 +1,13 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; +using Blob; +using JetBrains.Annotations; using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; using UnityEngine; +using UnityEngine.Assertions; namespace Nuwa.Blob { @@ -24,11 +27,36 @@ public abstract class DynamicBuilderFactory : IDynamicBuilderFactory where T public abstract object Create(Type dataType, FieldInfo fieldInfo); } + public abstract class DynamicBuilder : IBuilder + { + public int Position { get; private set; } + protected abstract Type _Type { get; } + + public void Build(IBlobStream stream) + { + Position = stream.DataPosition; + // TODO: fetch alignment by type? + stream.EnsureDataSize(UnsafeUtility.SizeOf(_Type), 4); + BuildImpl(stream); + } + + protected abstract void BuildImpl([NotNull] IBlobStream stream); + + public virtual IBuilder GetBuilder(string name) => throw new NotImplementedException(); + + public virtual object PreviewValue + { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } + } + [Serializable] - public class DynamicEnumBuilder : IBuilder where T : unmanaged + public class DynamicEnumBuilder : DynamicBuilder where T : unmanaged { public string EnumTypeName; public T Value; + protected override Type _Type => typeof(T); public object PreviewValue { @@ -36,9 +64,9 @@ public object PreviewValue set => Value = (T)value; } - public unsafe void Build(BlobBuilder builder, IntPtr dataPtr) + protected override void BuildImpl(IBlobStream stream) { - UnsafeUtility.AsRef(dataPtr.ToPointer()) = Value; + stream.WriteValue(Value); } public IBuilder GetBuilder(string name) @@ -101,19 +129,22 @@ public class Factory : Factory {} } [Serializable] - public class DynamicBlobDataBuilder : IBuilder, IObjectBuilder + public class DynamicBlobDataBuilder : DynamicBuilder, IObjectBuilder { public string BlobDataType; public string[] FieldNames; [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Builders; + protected override Type _Type => Type.GetType(BlobDataType); - public void Build(BlobBuilder builder, IntPtr dataPtr) + protected override void BuildImpl(IBlobStream stream) { - var fields = Type.GetType(BlobDataType).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + var position = stream.DataPosition; + var fields = _Type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (var i = 0; i < Builders.Length; i++) { + Assert.AreEqual(FieldNames[i], fields[i].Name); var offset = UnsafeUtility.GetFieldOffset(fields[i]); - Builders[i].Build(builder, dataPtr + offset); + stream.ToPosition(position + offset).WriteValue(Builders[i]); } } @@ -154,7 +185,7 @@ public override object Create(Type dataType, FieldInfo fieldInfo) } [Serializable] - public class DynamicArrayBuilder : IBuilder + public class DynamicArrayBuilder : DynamicBuilder { public string ArrayElementType; [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Value; @@ -168,11 +199,13 @@ public object PreviewValue } } - public void Build(BlobBuilder builder, IntPtr dataPtr) + protected override Type _Type => typeof(BlobArray<>).MakeGenericType(Type.GetType(ArrayElementType)); + + protected override void BuildImpl(IBlobStream stream) { var elementType = Type.GetType(ArrayElementType); - var arrayBuilder = builder.AllocateDynamicArray(elementType, dataPtr, Value.Length); - for (var i = 0; i < Value.Length; i++) Value[i].Build(builder, arrayBuilder[i]); + var elementSize = UnsafeUtility.SizeOf(elementType); + stream.WritePatchOffset().WriteValue(Value.Length).ToPatchPosition().WriteArray(Value, elementSize, 4); } public IBuilder GetBuilder(string name) @@ -190,15 +223,15 @@ public class Factory : DynamicBuilderFactory } [Serializable] - public class DynamicPtrBuilder : IBuilder + public class DynamicPtrBuilder : DynamicBuilder { public string DataType; [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder Value; + protected override Type _Type => typeof(BlobArray<>).MakeGenericType(Type.GetType(DataType)); - public void Build(BlobBuilder builder, IntPtr dataPtr) + protected override void BuildImpl(IBlobStream stream) { - var blobPtr = builder.AllocateDynamicPtr(Type.GetType(DataType), dataPtr); - Value.Build(builder, blobPtr); + stream.WritePatchOffset().WriteValue(Value); } public IBuilder GetBuilder(string name) diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Nuwa.Blob.asmdef b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Nuwa.Blob.asmdef index 98efbedf..8150d542 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Nuwa.Blob.asmdef +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Nuwa.Blob.asmdef @@ -6,7 +6,8 @@ "GUID:d8b63aba1907145bea998dd612889d6b", "GUID:39174d49d2befe84d9c54bf8b8d32755", "GUID:cf3547b97f3ec664f9eca740d393c07c", - "GUID:abe4851e67df59644865a60dae54a845" + "GUID:abe4851e67df59644865a60dae54a845", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Utility.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Utility.cs index d468416f..e54a2fd0 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Utility.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Utility.cs @@ -1,44 +1,12 @@ using System; using System.Linq; -using System.Reflection; using System.Text.RegularExpressions; using JetBrains.Annotations; -using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; namespace Nuwa.Blob { public static class Utility { - public static IntPtr ArrayElementAsPtr(IntPtr arrayDataPtr, long index, long size) => new IntPtr(arrayDataPtr.ToInt64() + index * size); - - // TODO: hack into `BlobBuilder` to make some dynamic (non-generic) methods to avoid using reflection. - public static BlobBuilderArray AllocateDynamicArray(this BlobBuilder builder, Type elementType, IntPtr arrayPtr, int length) - { - var func = typeof(Utility).GetMethod(nameof(AllocateDynamicArray), BindingFlags.Static | BindingFlags.NonPublic); - return (BlobBuilderArray) func.MakeGenericMethod(elementType).Invoke(null, new object[] {builder, arrayPtr, length}); - } - - private static unsafe BlobBuilderArray AllocateDynamicArray(BlobBuilder builder, IntPtr arrayPtr, int length) where T : unmanaged - { - ref var data = ref UnsafeUtility.AsRef>(arrayPtr.ToPointer()); - var arrayBuilder = builder.Allocate(ref data, length); - return new BlobBuilderArray(new IntPtr(arrayBuilder.GetUnsafePtr()), length, typeof(T)); - } - - public static IntPtr AllocateDynamicPtr(this BlobBuilder builder, Type dataType, IntPtr dataPtr) - { - var func = typeof(Utility).GetMethod(nameof(AllocateDynamicPtr), BindingFlags.Static | BindingFlags.NonPublic); - return (IntPtr) func.MakeGenericMethod(dataType).Invoke(null, new object[] {builder, dataPtr}); - } - - private static unsafe IntPtr AllocateDynamicPtr(BlobBuilder builder, IntPtr dataPtr) where T : unmanaged - { - ref var data = ref UnsafeUtility.AsRef>(dataPtr.ToPointer()); - ref var blobPtr = ref builder.Allocate(ref data); - return new IntPtr(UnsafeUtility.AddressOf(ref blobPtr)); - } - public static string ToReadableFullName([NotNull] this Type type) { return type.IsGenericType ? Regex.Replace(type.ToString(), @"(\w+)`\d+\[(.*)\]", "$1<$2>") : type.ToString(); diff --git a/Packages/essential/Runtime/Entities/ComponentVariant.cs b/Packages/essential/Runtime/Entities/ComponentVariant.cs index e72dd90d..b63f4f5b 100644 --- a/Packages/essential/Runtime/Entities/ComponentVariant.cs +++ b/Packages/essential/Runtime/Entities/ComponentVariant.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Blob; using EntitiesBT.Core; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -22,7 +23,7 @@ public class Any : IVariant where T : unmanaged { [VariantComponentData] public string ComponentValueName; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream) { blobVariant.VariantId = GuidHashCode(GUID); var data = GetTypeHashAndFieldOffset(ComponentValueName); @@ -31,7 +32,7 @@ public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) Debug.LogError($"{nameof(ComponentVariant)}({ComponentValueName}) is not valid, fallback to ConstantValue"); throw new ArgumentException(); } - return builder.Allocate(ref blobVariant, new DynamicComponentData{StableHash = data.Hash, Offset = data.Offset}); + return stream.Allocate(ref blobVariant, new DynamicComponentData{StableHash = data.Hash, Offset = data.Offset}); } public object PreviewValue => throw new NotImplementedException(); diff --git a/Packages/essential/Runtime/EntitiesBT.Runtime.asmdef b/Packages/essential/Runtime/EntitiesBT.Runtime.asmdef index 258c8d46..975ea732 100644 --- a/Packages/essential/Runtime/EntitiesBT.Runtime.asmdef +++ b/Packages/essential/Runtime/EntitiesBT.Runtime.asmdef @@ -8,7 +8,8 @@ "GUID:d8b63aba1907145bea998dd612889d6b", "GUID:8819f35a0fc84499b990e90a4ca1911f", "GUID:abe4851e67df59644865a60dae54a845", - "GUID:6d84eb5386377416e93c122a00485b68" + "GUID:6d84eb5386377416e93c122a00485b68", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs index 7b528abd..305d9bd6 100644 --- a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs @@ -1,12 +1,8 @@ -using System.Collections.Generic; +using System.IO; using System.Linq; -using EntitiesBT.Components; using EntitiesBT.Core; using EntitiesBT.Entities; -using Nuwa; using Nuwa.Blob; -using Unity.Entities; -using UnityEngine; namespace EntitiesBT.Nodes { @@ -48,10 +44,13 @@ public class NormalizedWeightBuilder : PlainDataBuilder> { public int[] Weights; - public override void Build(BlobBuilder builder, ref BlobArray data) + protected override void BuildImpl(BlobBuilder builder) { float sum = Weights.Sum(); builder.AllocateArray(ref data, Weights.Select(w => w / sum).ToArray()); + + builder.WriteValue(ref Value); + return patchPosition; } } } \ No newline at end of file diff --git a/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs b/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs index 0cb3bb33..700ec068 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using Blob; using EntitiesBT.Core; using Nuwa; using Nuwa.Blob; @@ -11,7 +12,7 @@ namespace EntitiesBT.Variant { [Serializable] - public class BlobVariantROBuilder : Builder + public class BlobVariantROBuilder : Nuwa.Blob.Builder { [SerializeField, HideInInspector] internal string _variantTypeName; [SerializeField, HideInInspector] internal bool IsOptional; @@ -22,9 +23,9 @@ public class BlobVariantROBuilder : Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - public override void Build(BlobBuilder builder, ref BlobVariant data) + protected override void BuildImpl(IBlobStream stream) { - if (_variant != null) _variant.Allocate(ref builder, ref data); + _variant?.Allocate(stream); } public class Factory : DynamicBuilderFactory @@ -45,7 +46,7 @@ public override object Create(Type dataType, FieldInfo fieldInfo) } [Serializable] - public class BlobVariantWOBuilder : Builder + public class BlobVariantWOBuilder : Nuwa.Blob.Builder { [SerializeField, HideInInspector] internal string _variantTypeName; [SerializeField, HideInInspector] internal bool IsOptional; @@ -56,9 +57,9 @@ public class BlobVariantWOBuilder : Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - public override void Build(BlobBuilder builder, ref BlobVariant data) + protected override void BuildImpl(IBlobStream stream) { - _variant.Allocate(ref builder, ref data); + _variant.Allocate(stream); } public class Factory : DynamicBuilderFactory @@ -79,7 +80,7 @@ public override object Create(Type dataType, FieldInfo fieldInfo) } [Serializable] - public class BlobVariantRWBuilder : Builder + public class BlobVariantRWBuilder : Nuwa.Blob.Builder { [SerializeField, HideInInspector] internal string _variantTypeName; [SerializeField, HideInInspector] internal bool IsOptional; @@ -90,9 +91,10 @@ public class BlobVariantRWBuilder : Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - public override unsafe void Build(BlobBuilder builder, ref BlobVariantRW data) + protected override void BuildImpl(IBlobStream stream) { - var metaDataPtr = _variant.Allocate(ref builder, ref data.Reader); + var position = stream.DataPosition; + _variant.Allocate(stream); data.Writer.VariantId = data.Reader.VariantId; // HACK: set meta data of writer as same as reader's @@ -102,7 +104,7 @@ public override unsafe void Build(BlobBuilder builder, ref BlobVariantRW data) } [Serializable] - public class BlobVariantLinkedRWBuilder : Builder + public class BlobVariantLinkedRWBuilder : Nuwa.Blob.Builder { [SerializeField] private bool _isLinked = true; [HideIf(nameof(_isLinked)), SerializeField, UnboxSingleProperty, UnityDrawProperty] private BlobVariantROBuilder _reader; diff --git a/Packages/essential/Runtime/Variant/IVariant.cs b/Packages/essential/Runtime/Variant/IVariant.cs index f22fc46e..479cc319 100644 --- a/Packages/essential/Runtime/Variant/IVariant.cs +++ b/Packages/essential/Runtime/Variant/IVariant.cs @@ -1,4 +1,5 @@ using System; +using Blob; using EntitiesBT.Core; using JetBrains.Annotations; using Unity.Entities; @@ -7,9 +8,7 @@ namespace EntitiesBT.Variant { public interface IVariant { - // return: pointer of meta data - IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant); - + void Allocate(IBlobStream stream); object PreviewValue { get; } } diff --git a/Packages/essential/Runtime/Variant/LocalVariant.cs b/Packages/essential/Runtime/Variant/LocalVariant.cs index 100dbcd0..512d52b4 100644 --- a/Packages/essential/Runtime/Variant/LocalVariant.cs +++ b/Packages/essential/Runtime/Variant/LocalVariant.cs @@ -1,6 +1,6 @@ using System; +using Blob; using EntitiesBT.Core; -using Unity.Entities; using static EntitiesBT.Core.Utilities; namespace EntitiesBT.Variant @@ -15,10 +15,9 @@ public class Any : IVariant where T : unmanaged { public T Value; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream) { - blobVariant.VariantId = GuidHashCode(GUID); - return builder.Allocate(ref blobVariant, Value); + stream.WriteValue(GuidHashCode(GUID)).WritePatchOffset().ToPatchPosition().WriteValue(Value); } public object PreviewValue => Value; diff --git a/Packages/essential/Runtime/Variant/SerializedVariant.cs b/Packages/essential/Runtime/Variant/SerializedVariant.cs index 0fc7ff52..4c4903bb 100644 --- a/Packages/essential/Runtime/Variant/SerializedVariant.cs +++ b/Packages/essential/Runtime/Variant/SerializedVariant.cs @@ -1,4 +1,5 @@ using System; +using Blob; using Nuwa; using EntitiesBT.Core; using Nuwa.Blob; @@ -43,9 +44,9 @@ public class SerializedVariantRO : IVariantReader where T : unmanaged private object _reader; public IVariantReader Reader => (IVariantReader)_reader; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream) { - return Reader.Allocate(ref builder, ref blobVariant); + Reader.Allocate(stream); } public object PreviewValue => Reader.PreviewValue; @@ -61,9 +62,9 @@ public class SerializedVariantWO : IVariantWriter where T : unmanaged private object _writer; public IVariantWriter Writer => (IVariantWriter)_writer; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream) { - return Writer.Allocate(ref builder, ref blobVariant); + Writer.Allocate(stream); } public object PreviewValue => Writer.PreviewValue; diff --git a/Packages/essential/Runtime/Variant/Utilities.cs b/Packages/essential/Runtime/Variant/Utilities.cs index cf2fd113..bff7c5e1 100644 --- a/Packages/essential/Runtime/Variant/Utilities.cs +++ b/Packages/essential/Runtime/Variant/Utilities.cs @@ -2,9 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Runtime.InteropServices; +using Blob; using EntitiesBT.Core; -using JetBrains.Annotations; using Unity.Assertions; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -89,49 +88,49 @@ public static IntPtr Allocate(this BlobBuilder builder, ref BlobVariantP return builder.Allocate(ref blob.Value, value); } - public static IntPtr AllocateRO( + public static void AllocateRO( this IVariantReader property - , ref BlobBuilder builder + , IBlobStream builder , ref BlobVariantRO blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant.Value); + ) where T : unmanaged => property.Allocate(builder); - public static IntPtr AllocateWO( + public static void AllocateWO( this IVariantWriter property - , ref BlobBuilder builder + , IBlobStream builder , ref BlobVariantWO blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant.Value); + ) where T : unmanaged => property.Allocate(builder); - public static IntPtr AllocateRW( + public static void AllocateRW( this ISerializedVariantRW property - , ref BlobBuilder builder + , IBlobStream builder , ref BlobVariantRW blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant); + ) where T : unmanaged => property.Allocate(builder, ref blobVariant); - public static IntPtr Allocate( + public static void Allocate( this IVariantReader property - , ref BlobBuilder builder + , IBlobStream builder , ref BlobVariantRO blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant.Value); + ) where T : unmanaged => property.Allocate(builder); public static IntPtr Allocate( this IVariantReader property , ref BlobBuilder builder , ref BlobVariantPtrRO blobVariant - ) => property.Allocate(ref builder, ref blobVariant.Value); + ) => property.Allocate(builder); public static IntPtr Allocate( this IVariantWriter property , ref BlobBuilder builder , ref BlobVariantWO blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant.Value); + ) where T : unmanaged => property.Allocate(builder); public static unsafe IntPtr Allocate( this IVariantReaderAndWriter property - , ref BlobBuilder builder + , IBlobStream builder , ref BlobVariantRW blobVariant ) where T : unmanaged { - var metaDataPtr = property.Allocate(ref builder, ref blobVariant.Reader.Value); + property.Allocate(builder); blobVariant.Writer.Value.VariantId = blobVariant.Reader.Value.VariantId; // HACK: set meta data of writer as same as reader's ref var writerMetaPtr = ref ToBlobPtr(ref blobVariant.Writer.Value.MetaDataOffsetPtr); @@ -150,9 +149,9 @@ this ISerializedVariantRW property return property.Reader.Allocate(ref builder, ref blobVariant.Reader); } - internal static ref BlobPtr ToBlobPtr(ref int offsetPtr) where T : unmanaged + internal static ref Unity.Entities.BlobPtr ToBlobPtr(ref int offsetPtr) where T : unmanaged { - return ref UnsafeUtility.As>(ref offsetPtr); + return ref UnsafeUtility.As>(ref offsetPtr); } public static unsafe void Allocate( @@ -161,7 +160,7 @@ this IVariantReader variant , void* blobVariantPtr ) where T : unmanaged { - variant.Allocate(ref builder, ref UnsafeUtility.AsRef(blobVariantPtr)); + variant.Allocate(builder); } public static MethodInfo GetVariantMethodInfo(Type type, string name) diff --git a/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs b/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs index 4c7aa324..3de9c248 100644 --- a/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs +++ b/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using Blob; using EntitiesBT.Core; using Unity.Entities; using UnityEngine; @@ -31,10 +32,10 @@ public class Reader : IVariantReader where T : unmanaged [VariantScriptableObjectValue(nameof(ScriptableObject))] public string ScriptableObjectValueName; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(IBlobStream stream) { blobVariant.VariantId = GuidHashCode(GUID); - return builder.Allocate(ref blobVariant, (T) PreviewValue); + return stream.Allocate(ref blobVariant, (T) PreviewValue); } public object PreviewValue diff --git a/Packages/variant.expression/Runtime/ExpressionVariant.cs b/Packages/variant.expression/Runtime/ExpressionVariant.cs index d3143b02..2668ee19 100644 --- a/Packages/variant.expression/Runtime/ExpressionVariant.cs +++ b/Packages/variant.expression/Runtime/ExpressionVariant.cs @@ -41,20 +41,20 @@ internal class Variant [SerializeField] internal string _expression; [SerializeField] internal Variant[] _sources; - public unsafe IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public unsafe void Allocate(IBlobStream stream, ref BlobVariant blobVariant) { blobVariant.VariantId = GuidHashCode(GUID); ref var blobPtr = ref UnsafeUtility.As>(ref blobVariant.MetaDataOffsetPtr); - ref var data = ref builder.Allocate(ref blobPtr); + ref var data = ref stream.Allocate(ref blobPtr); data.ExpressionType = VariantValueTypeRegistry.GetIdByType(typeof(T)); - builder.AllocateString(ref data.Expression, _expression); - var variants = builder.Allocate(ref data.Variants, _sources.Length); - var names = builder.Allocate(ref data.VariantNames, _sources.Length); - var types = builder.Allocate(ref data.VariantTypes, _sources.Length); + stream.AllocateString(ref data.Expression, _expression); + var variants = stream.Allocate(ref data.Variants, _sources.Length); + var names = stream.Allocate(ref data.VariantNames, _sources.Length); + var types = stream.Allocate(ref data.VariantTypes, _sources.Length); for (var i = 0; i < _sources.Length; i++) { - _sources[i].Value.Allocate(ref builder, ref variants[i]); - builder.AllocateString(ref names[i], _sources[i].Name); + _sources[i].Value.Allocate(ref stream, ref variants[i]); + stream.AllocateString(ref names[i], _sources[i].Name); types[i] = VariantValueTypeRegistry.GetIdByType(_sources[i].Value.FindValueType()); } return new IntPtr(UnsafeUtility.AddressOf(ref data)); From 5ff3d01e5d29d021b16a04716fc63150131591d9 Mon Sep 17 00:00:00 2001 From: Quan Yuan Date: Mon, 4 Apr 2022 18:17:30 +0800 Subject: [PATCH 02/28] blob variant stream --- .../Samples/Runtime/EntitiesBT.Sample.asmdef | 3 +- .../Runtime/Entity/IsEntityPositionInBox.cs | 7 +- .../Editor/EntitiesBT.Tests.Editor.asmdef | 3 +- Assets/Tests/Editor/TestExpression.cs | 2 +- Assets/Tests/Editor/TestVariant.cs | 5 +- .../Runtime/EntitiesBT.Tests.Runtime.asmdef | 3 +- .../Runtime/GlobalComponentVariant.cs | 8 +- .../builder.component/Runtime/NodeAsset.cs | 2 +- .../Runtime/BehaviorNodeComponent.cs | 27 +-- .../Runtime/GraphNodeVariant.cs | 4 +- .../Runtime/VariantNode.cs | 4 +- .../Runtime/Entities/ComponentVariant.cs | 6 +- .../Composites/WeightRandomSelectorNode.cs | 11 +- ...VariantBuilder.cs => BlobVariantStream.cs} | 63 ++++++- ...lder.cs.meta => BlobVariantStream.cs.meta} | 0 .../essential/Runtime/Variant/IVariant.cs | 5 +- .../essential/Runtime/Variant/LocalVariant.cs | 6 +- .../Runtime/Variant/SerializedVariant.cs | 4 +- .../essential/Runtime/Variant/Utilities.cs | 164 +++++++++--------- .../Runtime/ScriptableObjectVariant.cs | 6 +- .../EntitiesBT.Variant.Expression.asmdef | 3 +- .../Runtime/ExpressionVariant.cs | 49 ++++-- 22 files changed, 220 insertions(+), 165 deletions(-) rename Packages/essential/Runtime/Variant/{BlobVariantBuilder.cs => BlobVariantStream.cs} (77%) rename Packages/essential/Runtime/Variant/{BlobVariantBuilder.cs.meta => BlobVariantStream.cs.meta} (100%) diff --git a/Assets/Samples/Runtime/EntitiesBT.Sample.asmdef b/Assets/Samples/Runtime/EntitiesBT.Sample.asmdef index 0befd788..7832526e 100644 --- a/Assets/Samples/Runtime/EntitiesBT.Sample.asmdef +++ b/Assets/Samples/Runtime/EntitiesBT.Sample.asmdef @@ -10,7 +10,8 @@ "GUID:d8b63aba1907145bea998dd612889d6b", "GUID:abe4851e67df59644865a60dae54a845", "GUID:f320ee23a990e5640812e0939a441a2b", - "GUID:6d84eb5386377416e93c122a00485b68" + "GUID:6d84eb5386377416e93c122a00485b68", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs index bc37fe27..12afc44b 100644 --- a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs +++ b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs @@ -1,4 +1,5 @@ using System; +using Blob; using EntitiesBT.Core; using Nuwa.Blob; using Unity.Entities; @@ -23,14 +24,14 @@ public NodeState Tick(int index, ref TNodeBlob blob, ref } [DefaultBuilder] - public class ColliderBoundsBuilder : Builder + public class ColliderBoundsBuilder : Nuwa.Blob.Builder { public Transform Transform; public BoxCollider Box; - public override void Build(BlobBuilder builder, ref Bounds data) + protected override void BuildImpl(IBlobStream stream) { - data = new Bounds(Box.center + Transform.position, Box.size); + stream.WriteValue(new Bounds(Box.center + Transform.position, Box.size)); } } } diff --git a/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef b/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef index 8d37de69..56b0348e 100644 --- a/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef +++ b/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef @@ -11,7 +11,8 @@ "GUID:6679f77e90ec1d540ab279146d203dbb", "GUID:f49b79f7e0a9b4b63a97d15e26787406", "GUID:ce5f967ea6c735344b367065891c4afb", - "GUID:f320ee23a990e5640812e0939a441a2b" + "GUID:f320ee23a990e5640812e0939a441a2b", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [ "Editor" diff --git a/Assets/Tests/Editor/TestExpression.cs b/Assets/Tests/Editor/TestExpression.cs index 31105726..eb2f67cd 100644 --- a/Assets/Tests/Editor/TestExpression.cs +++ b/Assets/Tests/Editor/TestExpression.cs @@ -69,7 +69,7 @@ public void should_eval_expression() }; ref var buildVariant = ref _builder.ConstructRoot(); - expression.Allocate(_builder, ref buildVariant); + // expression.Allocate(_builder, ref buildVariant); using var variant = _builder.CreateBlobAssetReference(Allocator.Temp); var result = BlobVariantExtension.Read(ref variant.Value, 0, ref _nodeBlob, ref _bb); Assert.That(result, Is.EqualTo((4.1f + 5) * 2 + 10)); diff --git a/Assets/Tests/Editor/TestVariant.cs b/Assets/Tests/Editor/TestVariant.cs index 0f51fd8d..f824f8d7 100644 --- a/Assets/Tests/Editor/TestVariant.cs +++ b/Assets/Tests/Editor/TestVariant.cs @@ -1,8 +1,6 @@ using System; -using EntitiesBT.Core; using EntitiesBT.Variant; using NUnit.Framework; -using Unity.Entities; namespace EntitiesBT.Test { @@ -17,9 +15,8 @@ public void should_find_value_type_of_variant() class InvalidVariant : IVariant { - public void Allocate(IBlobStream stream, ref BlobVariant blobVariant) + public void Allocate(BlobVariantStream stream) { - throw new NotImplementedException(); } public object PreviewValue => throw new NotImplementedException(); diff --git a/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef b/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef index 328b7380..55da58c1 100644 --- a/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef +++ b/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef @@ -6,7 +6,8 @@ "GUID:c7babe7561eb244059259745ef27b866", "GUID:d3630359ae08047918d5cd6cddd51767", "GUID:734d92eba21c94caba915361bd5ac177", - "GUID:f320ee23a990e5640812e0939a441a2b" + "GUID:f320ee23a990e5640812e0939a441a2b", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/builder.component/Runtime/GlobalComponentVariant.cs b/Packages/builder.component/Runtime/GlobalComponentVariant.cs index c0021741..8f84ae38 100644 --- a/Packages/builder.component/Runtime/GlobalComponentVariant.cs +++ b/Packages/builder.component/Runtime/GlobalComponentVariant.cs @@ -27,18 +27,18 @@ public class Any : IVariant where T : unmanaged protected Type _declaringType => Value?.BlobType; protected Type _fieldType => typeof(T); - public void Allocate(IBlobStream stream, ref BlobVariant blobVariant) + public void Allocate(BlobVariantStream stream) { if (Value == null || Value.BlobType == null) throw new ArgumentException(); - blobVariant.VariantId = GuidHashCode(GUID); + stream.SetVariantId(GuidHashCode(GUID)); var fieldInfo = Value.BlobType.GetField(ValueFieldName, BindingFlags.Instance | BindingFlags.Public); if (fieldInfo == null || fieldInfo.FieldType != typeof(T)) { Debug.LogError($"{Value.BlobType.Name}.{ValueFieldName} is not valid", Value); throw new ArgumentException(); } - var valueOffset = Value.Offset + Marshal.OffsetOf(Value.BlobType, ValueFieldName).ToInt32(); - return stream.Allocate(ref blobVariant, valueOffset); + var valueOffset = Value.Offset + UnsafeUtility.GetFieldOffset(fieldInfo); + stream.SetVariantOffset(valueOffset); } public object PreviewValue => Value?.GetPreviewValue(ValueFieldName); diff --git a/Packages/builder.component/Runtime/NodeAsset.cs b/Packages/builder.component/Runtime/NodeAsset.cs index d520a745..fd326b4f 100644 --- a/Packages/builder.component/Runtime/NodeAsset.cs +++ b/Packages/builder.component/Runtime/NodeAsset.cs @@ -17,7 +17,7 @@ public class NodeAsset public DynamicBlobDataBuilder Builder; - public void Build(BlobBuilder builder, IntPtr dataPtr) => Builder.Build(builder, dataPtr); + public void Build(BlobBuilder builder, IntPtr dataPtr) => throw new NotImplementedException();//Builder.Build(builder, dataPtr); public IBuilder FindBuilderByPath(string path) { diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs index 0038b236..8e322933 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs @@ -196,19 +196,20 @@ private SerializedProperty GetSerializedNodeBuilder(SerializedObject nodeObject) public void SetPreviewValue(string path, object value) => throw new NotSupportedException(); public unsafe BlobAssetReference Build(Core.ITreeNode[] builders) { - var nodeType = _node.BehaviorNodeDataType; - if (nodeType.IsZeroSizeStruct()) return BlobAssetReference.Null; - var blobBuilder = new BlobMemoryStream(UnsafeUtility.SizeOf(nodeType)); - try - { - _node.Blob.Build(blobBuilder); - blobBuilder.WritePatchOffset() - return blobBuilder.CreateReferenceByType(nodeType); - } - finally - { - blobBuilder.Dispose(); - } + throw new NotImplementedException(); + // var nodeType = _node.BehaviorNodeDataType; + // if (nodeType.IsZeroSizeStruct()) return BlobAssetReference.Null; + // var blobBuilder = new BlobMemoryStream(UnsafeUtility.SizeOf(nodeType)); + // try + // { + // _node.Blob.Build(blobBuilder); + // blobBuilder.WritePatchOffset() + // return blobBuilder.CreateReferenceByType(nodeType); + // } + // finally + // { + // blobBuilder.Dispose(); + // } } #endregion diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/GraphNodeVariant.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/GraphNodeVariant.cs index f23015bb..f8726c3e 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/GraphNodeVariant.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/GraphNodeVariant.cs @@ -18,10 +18,10 @@ public class Any : IVariant [ReadOnly, UnityDrawProperty] public VariantNodeComponent NodeComponent; - public void Allocate(IBlobStream stream) + public void Allocate(BlobVariantStream stream) { // TODO: check validation - return NodeComponent.VariantNode.Allocate(ref stream, ref blobVariant); + NodeComponent.VariantNode.Allocate(stream); } public object PreviewValue => NodeComponent == null ? null : NodeComponent.VariantNode.PreviewValue; diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/VariantNode.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/VariantNode.cs index d13c6c58..9885f316 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/VariantNode.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/VariantNode.cs @@ -32,9 +32,9 @@ public abstract class VariantNode : GraphNode, INode> public string BaseTypeName => BaseType.AssemblyQualifiedName; public string AccessName => GetVariantAccessName(DefaultVariantType); - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(BlobVariantStream stream) { - return Variant.Allocate(builder); + Variant.Allocate(stream); } public bool IsPortCompatible(GraphRuntime graph, in PortId input, in PortId output) => true; diff --git a/Packages/essential/Runtime/Entities/ComponentVariant.cs b/Packages/essential/Runtime/Entities/ComponentVariant.cs index b63f4f5b..74e72757 100644 --- a/Packages/essential/Runtime/Entities/ComponentVariant.cs +++ b/Packages/essential/Runtime/Entities/ComponentVariant.cs @@ -23,16 +23,16 @@ public class Any : IVariant where T : unmanaged { [VariantComponentData] public string ComponentValueName; - public void Allocate(IBlobStream stream) + public void Allocate(BlobVariantStream stream) { - blobVariant.VariantId = GuidHashCode(GUID); + stream.SetVariantId(GuidHashCode(GUID)); var data = GetTypeHashAndFieldOffset(ComponentValueName); if (data.Type != typeof(T) || data.Hash == 0) { Debug.LogError($"{nameof(ComponentVariant)}({ComponentValueName}) is not valid, fallback to ConstantValue"); throw new ArgumentException(); } - return stream.Allocate(ref blobVariant, new DynamicComponentData{StableHash = data.Hash, Offset = data.Offset}); + stream.SetVariantValue(new DynamicComponentData { StableHash = data.Hash, Offset = data.Offset }); } public object PreviewValue => throw new NotImplementedException(); diff --git a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs index 305d9bd6..3bae4819 100644 --- a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs @@ -1,5 +1,5 @@ -using System.IO; using System.Linq; +using Blob; using EntitiesBT.Core; using EntitiesBT.Entities; using Nuwa.Blob; @@ -44,13 +44,12 @@ public class NormalizedWeightBuilder : PlainDataBuilder> { public int[] Weights; - protected override void BuildImpl(BlobBuilder builder) + protected override void BuildImpl(IBlobStream stream) { float sum = Weights.Sum(); - builder.AllocateArray(ref data, Weights.Select(w => w / sum).ToArray()); - - builder.WriteValue(ref Value); - return patchPosition; + // new ArrayBuilder(Weights.Select(w => w / sum).ToArray()); + // builder.AllocateArray(ref data, Weights.Select(w => w / sum).ToArray()); + // builder.WriteValue(ref Value); } } } \ No newline at end of file diff --git a/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs b/Packages/essential/Runtime/Variant/BlobVariantStream.cs similarity index 77% rename from Packages/essential/Runtime/Variant/BlobVariantBuilder.cs rename to Packages/essential/Runtime/Variant/BlobVariantStream.cs index 700ec068..9f78b541 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantStream.cs @@ -3,14 +3,60 @@ using System.Reflection; using Blob; using EntitiesBT.Core; +using JetBrains.Annotations; using Nuwa; using Nuwa.Blob; using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; using UnityEngine; namespace EntitiesBT.Variant { + public class BlobVariantStream + { + [NotNull] private readonly IBlobStream _stream; + private readonly int _idPosition; + private readonly int _offsetPosition; + private readonly int _patchPosition; + + public BlobVariantStream([NotNull] IBlobStream stream) + { + _stream = stream; + stream.EnsureDataSize(); + _idPosition = stream.DataPosition; + _patchPosition = stream.PatchPosition; + stream.WriteValue(new BlobVariant().VariantId); + _offsetPosition = stream.DataPosition; + } + + public void SetVariantId(int id) + { + _stream.DataPosition = _idPosition; + _stream.WriteValue(id); + } + + public void SetVariantValue(T value) where T : unmanaged + { + _stream.DataPosition = _offsetPosition; + _stream.WritePatchOffset(); + _stream.DataPosition = _patchPosition; + _stream.WriteValue(value); + } + + public void SetVariantValue(IBuilder builder) where T : unmanaged + { + _stream.DataPosition = _offsetPosition; + _stream.WritePatchOffset(); + _stream.DataPosition = _patchPosition; + builder.Build(_stream); + } + + public void SetVariantOffset(int offset) + { + _stream.DataPosition = _offsetPosition; + _stream.WriteValue(offset); + } + } + [Serializable] public class BlobVariantROBuilder : Nuwa.Blob.Builder { @@ -25,7 +71,7 @@ public class BlobVariantROBuilder : Nuwa.Blob.Builder protected override void BuildImpl(IBlobStream stream) { - _variant?.Allocate(stream); + _variant?.Allocate(new BlobVariantStream(stream)); } public class Factory : DynamicBuilderFactory @@ -59,7 +105,7 @@ public class BlobVariantWOBuilder : Nuwa.Blob.Builder protected override void BuildImpl(IBlobStream stream) { - _variant.Allocate(stream); + _variant.Allocate(new BlobVariantStream(stream)); } public class Factory : DynamicBuilderFactory @@ -93,8 +139,7 @@ public class BlobVariantRWBuilder : Nuwa.Blob.Builder protected override void BuildImpl(IBlobStream stream) { - var position = stream.DataPosition; - _variant.Allocate(stream); + _variant.Allocate(new BlobVariantStream(stream)); data.Writer.VariantId = data.Reader.VariantId; // HACK: set meta data of writer as same as reader's @@ -113,16 +158,16 @@ public class BlobVariantLinkedRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _isLinked ? _readerAndWriter.PreviewValue : _reader.PreviewValue; set => throw new NotImplementedException(); } - public override void Build(BlobBuilder builder, ref BlobVariantRW data) + protected override void BuildImpl(IBlobStream stream) { if (_isLinked) { - _readerAndWriter.Build(builder, ref data); + _readerAndWriter.Build(stream); } else { - _reader.Build(builder, ref data.Reader); - _writer.Build(builder, ref data.Writer); + _reader.Build(stream); + _writer.Build(stream); } } diff --git a/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs.meta b/Packages/essential/Runtime/Variant/BlobVariantStream.cs.meta similarity index 100% rename from Packages/essential/Runtime/Variant/BlobVariantBuilder.cs.meta rename to Packages/essential/Runtime/Variant/BlobVariantStream.cs.meta diff --git a/Packages/essential/Runtime/Variant/IVariant.cs b/Packages/essential/Runtime/Variant/IVariant.cs index 479cc319..669534fc 100644 --- a/Packages/essential/Runtime/Variant/IVariant.cs +++ b/Packages/essential/Runtime/Variant/IVariant.cs @@ -1,14 +1,11 @@ using System; -using Blob; -using EntitiesBT.Core; using JetBrains.Annotations; -using Unity.Entities; namespace EntitiesBT.Variant { public interface IVariant { - void Allocate(IBlobStream stream); + void Allocate(BlobVariantStream stream); object PreviewValue { get; } } diff --git a/Packages/essential/Runtime/Variant/LocalVariant.cs b/Packages/essential/Runtime/Variant/LocalVariant.cs index 512d52b4..9da5ba8b 100644 --- a/Packages/essential/Runtime/Variant/LocalVariant.cs +++ b/Packages/essential/Runtime/Variant/LocalVariant.cs @@ -1,5 +1,4 @@ using System; -using Blob; using EntitiesBT.Core; using static EntitiesBT.Core.Utilities; @@ -15,9 +14,10 @@ public class Any : IVariant where T : unmanaged { public T Value; - public void Allocate(IBlobStream stream) + public void Allocate(BlobVariantStream stream) { - stream.WriteValue(GuidHashCode(GUID)).WritePatchOffset().ToPatchPosition().WriteValue(Value); + stream.SetVariantId(GuidHashCode(GUID)); + stream.SetVariantValue(Value); } public object PreviewValue => Value; diff --git a/Packages/essential/Runtime/Variant/SerializedVariant.cs b/Packages/essential/Runtime/Variant/SerializedVariant.cs index 4c4903bb..250aa2f6 100644 --- a/Packages/essential/Runtime/Variant/SerializedVariant.cs +++ b/Packages/essential/Runtime/Variant/SerializedVariant.cs @@ -44,7 +44,7 @@ public class SerializedVariantRO : IVariantReader where T : unmanaged private object _reader; public IVariantReader Reader => (IVariantReader)_reader; - public void Allocate(IBlobStream stream) + public void Allocate(BlobVariantStream stream) { Reader.Allocate(stream); } @@ -62,7 +62,7 @@ public class SerializedVariantWO : IVariantWriter where T : unmanaged private object _writer; public IVariantWriter Writer => (IVariantWriter)_writer; - public void Allocate(IBlobStream stream) + public void Allocate(BlobVariantStream stream) { Writer.Allocate(stream); } diff --git a/Packages/essential/Runtime/Variant/Utilities.cs b/Packages/essential/Runtime/Variant/Utilities.cs index bff7c5e1..81ec8cf2 100644 --- a/Packages/essential/Runtime/Variant/Utilities.cs +++ b/Packages/essential/Runtime/Variant/Utilities.cs @@ -74,94 +74,94 @@ public static IEnumerable GetComponentFields(Type valueType) return _VALUE_TYPE_LOOKUP.Value[valueType]; } - public static unsafe IntPtr Allocate(this BlobBuilder builder, ref BlobVariant blob, TValue value) where TValue : unmanaged - { - ref var blobPtr = ref ToBlobPtr(ref blob.MetaDataOffsetPtr); - ref var blobValue = ref builder.Allocate(ref blobPtr); - blobValue = value; - var ptr = UnsafeUtility.AddressOf(ref blobValue); - return new IntPtr(ptr); - } - - public static IntPtr Allocate(this BlobBuilder builder, ref BlobVariantPtrRO blob, TValue value) where TValue : unmanaged - { - return builder.Allocate(ref blob.Value, value); - } - - public static void AllocateRO( - this IVariantReader property - , IBlobStream builder - , ref BlobVariantRO blobVariant - ) where T : unmanaged => property.Allocate(builder); - - public static void AllocateWO( - this IVariantWriter property - , IBlobStream builder - , ref BlobVariantWO blobVariant - ) where T : unmanaged => property.Allocate(builder); - - public static void AllocateRW( - this ISerializedVariantRW property - , IBlobStream builder - , ref BlobVariantRW blobVariant - ) where T : unmanaged => property.Allocate(builder, ref blobVariant); - - public static void Allocate( - this IVariantReader property - , IBlobStream builder - , ref BlobVariantRO blobVariant - ) where T : unmanaged => property.Allocate(builder); - - public static IntPtr Allocate( - this IVariantReader property - , ref BlobBuilder builder - , ref BlobVariantPtrRO blobVariant - ) => property.Allocate(builder); - - public static IntPtr Allocate( - this IVariantWriter property - , ref BlobBuilder builder - , ref BlobVariantWO blobVariant - ) where T : unmanaged => property.Allocate(builder); - - public static unsafe IntPtr Allocate( - this IVariantReaderAndWriter property - , IBlobStream builder - , ref BlobVariantRW blobVariant - ) where T : unmanaged - { - property.Allocate(builder); - blobVariant.Writer.Value.VariantId = blobVariant.Reader.Value.VariantId; - // HACK: set meta data of writer as same as reader's - ref var writerMetaPtr = ref ToBlobPtr(ref blobVariant.Writer.Value.MetaDataOffsetPtr); - builder.SetPointer(ref writerMetaPtr, ref UnsafeUtility.AsRef(metaDataPtr.ToPointer())); - return metaDataPtr; - } - - public static IntPtr Allocate( - this ISerializedVariantRW property - , ref BlobBuilder builder - , ref BlobVariantRW blobVariant - ) where T : unmanaged - { - if (property.IsLinked) return property.ReaderAndWriter.Allocate(ref builder, ref blobVariant); - property.Writer.Allocate(ref builder, ref blobVariant.Writer); - return property.Reader.Allocate(ref builder, ref blobVariant.Reader); - } + // public static unsafe IntPtr Allocate(this BlobBuilder builder, ref BlobVariant blob, TValue value) where TValue : unmanaged + // { + // ref var blobPtr = ref ToBlobPtr(ref blob.MetaDataOffsetPtr); + // ref var blobValue = ref builder.Allocate(ref blobPtr); + // blobValue = value; + // var ptr = UnsafeUtility.AddressOf(ref blobValue); + // return new IntPtr(ptr); + // } + // + // public static IntPtr Allocate(this BlobBuilder builder, ref BlobVariantPtrRO blob, TValue value) where TValue : unmanaged + // { + // return builder.Allocate(ref blob.Value, value); + // } + // + // public static void AllocateRO( + // this IVariantReader property + // , IBlobStream builder + // , ref BlobVariantRO blobVariant + // ) where T : unmanaged => property.Allocate(builder); + // + // public static void AllocateWO( + // this IVariantWriter property + // , IBlobStream builder + // , ref BlobVariantWO blobVariant + // ) where T : unmanaged => property.Allocate(builder); + // + // public static void AllocateRW( + // this ISerializedVariantRW property + // , IBlobStream builder + // , ref BlobVariantRW blobVariant + // ) where T : unmanaged => property.Allocate(builder, ref blobVariant); + // + // public static void Allocate( + // this IVariantReader property + // , IBlobStream builder + // , ref BlobVariantRO blobVariant + // ) where T : unmanaged => property.Allocate(builder); + // + // public static IntPtr Allocate( + // this IVariantReader property + // , ref BlobBuilder builder + // , ref BlobVariantPtrRO blobVariant + // ) => property.Allocate(builder); + // + // public static IntPtr Allocate( + // this IVariantWriter property + // , ref BlobBuilder builder + // , ref BlobVariantWO blobVariant + // ) where T : unmanaged => property.Allocate(builder); + // + // public static unsafe IntPtr Allocate( + // this IVariantReaderAndWriter property + // , IBlobStream builder + // , ref BlobVariantRW blobVariant + // ) where T : unmanaged + // { + // property.Allocate(builder); + // blobVariant.Writer.Value.VariantId = blobVariant.Reader.Value.VariantId; + // // HACK: set meta data of writer as same as reader's + // ref var writerMetaPtr = ref ToBlobPtr(ref blobVariant.Writer.Value.MetaDataOffsetPtr); + // builder.SetPointer(ref writerMetaPtr, ref UnsafeUtility.AsRef(metaDataPtr.ToPointer())); + // return metaDataPtr; + // } + // + // public static IntPtr Allocate( + // this ISerializedVariantRW property + // , ref BlobBuilder builder + // , ref BlobVariantRW blobVariant + // ) where T : unmanaged + // { + // if (property.IsLinked) return property.ReaderAndWriter.Allocate(ref builder, ref blobVariant); + // property.Writer.Allocate(ref builder, ref blobVariant.Writer); + // return property.Reader.Allocate(ref builder, ref blobVariant.Reader); + // } internal static ref Unity.Entities.BlobPtr ToBlobPtr(ref int offsetPtr) where T : unmanaged { return ref UnsafeUtility.As>(ref offsetPtr); } - public static unsafe void Allocate( - this IVariantReader variant - , ref BlobBuilder builder - , void* blobVariantPtr - ) where T : unmanaged - { - variant.Allocate(builder); - } + // public static unsafe void Allocate( + // this IVariantReader variant + // , ref BlobBuilder builder + // , void* blobVariantPtr + // ) where T : unmanaged + // { + // variant.Allocate(builder); + // } public static MethodInfo GetVariantMethodInfo(Type type, string name) { diff --git a/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs b/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs index 3de9c248..8a58f718 100644 --- a/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs +++ b/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs @@ -32,10 +32,10 @@ public class Reader : IVariantReader where T : unmanaged [VariantScriptableObjectValue(nameof(ScriptableObject))] public string ScriptableObjectValueName; - public void Allocate(IBlobStream stream) + public void Allocate(BlobVariantStream stream) { - blobVariant.VariantId = GuidHashCode(GUID); - return stream.Allocate(ref blobVariant, (T) PreviewValue); + stream.SetVariantId(GuidHashCode(GUID)); + stream.SetVariantValue((T)PreviewValue); } public object PreviewValue diff --git a/Packages/variant.expression/Runtime/EntitiesBT.Variant.Expression.asmdef b/Packages/variant.expression/Runtime/EntitiesBT.Variant.Expression.asmdef index 5f182036..36b25a8c 100644 --- a/Packages/variant.expression/Runtime/EntitiesBT.Variant.Expression.asmdef +++ b/Packages/variant.expression/Runtime/EntitiesBT.Variant.Expression.asmdef @@ -5,7 +5,8 @@ "GUID:c7babe7561eb244059259745ef27b866", "GUID:d8b63aba1907145bea998dd612889d6b", "GUID:734d92eba21c94caba915361bd5ac177", - "GUID:abe4851e67df59644865a60dae54a845" + "GUID:abe4851e67df59644865a60dae54a845", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/variant.expression/Runtime/ExpressionVariant.cs b/Packages/variant.expression/Runtime/ExpressionVariant.cs index 2668ee19..9cf4835a 100644 --- a/Packages/variant.expression/Runtime/ExpressionVariant.cs +++ b/Packages/variant.expression/Runtime/ExpressionVariant.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Concurrent; +using System.Linq; using System.Runtime.InteropServices; +using Blob; using EntitiesBT.Core; using Nuwa; using Unity.Collections.LowLevel.Unsafe; @@ -19,9 +21,9 @@ public struct Data { public BlobString Expression; public int ExpressionType; - public BlobArray Variants; - public BlobArray VariantNames; - public BlobArray VariantTypes; + public Unity.Entities.BlobArray Variants; + public Unity.Entities.BlobArray VariantNames; + public Unity.Entities.BlobArray VariantTypes; } private static readonly ConcurrentDictionary _expressionParameters = new ConcurrentDictionary(); @@ -41,23 +43,32 @@ internal class Variant [SerializeField] internal string _expression; [SerializeField] internal Variant[] _sources; - public unsafe void Allocate(IBlobStream stream, ref BlobVariant blobVariant) + public unsafe void Allocate(BlobVariantStream stream) { - blobVariant.VariantId = GuidHashCode(GUID); - ref var blobPtr = ref UnsafeUtility.As>(ref blobVariant.MetaDataOffsetPtr); - ref var data = ref stream.Allocate(ref blobPtr); - data.ExpressionType = VariantValueTypeRegistry.GetIdByType(typeof(T)); - stream.AllocateString(ref data.Expression, _expression); - var variants = stream.Allocate(ref data.Variants, _sources.Length); - var names = stream.Allocate(ref data.VariantNames, _sources.Length); - var types = stream.Allocate(ref data.VariantTypes, _sources.Length); - for (var i = 0; i < _sources.Length; i++) - { - _sources[i].Value.Allocate(ref stream, ref variants[i]); - stream.AllocateString(ref names[i], _sources[i].Name); - types[i] = VariantValueTypeRegistry.GetIdByType(_sources[i].Value.FindValueType()); - } - return new IntPtr(UnsafeUtility.AddressOf(ref data)); + throw new NotImplementedException(); + // stream.SetVariantId(GuidHashCode(GUID)); + // // ref var blobPtr = ref UnsafeUtility.As>(ref blobVariant.MetaDataOffsetPtr); + // var dataBuilder = new StructBuilder(); + // dataBuilder.SetValue(ref dataBuilder.Value.ExpressionType, VariantValueTypeRegistry.GetIdByType(typeof(T))); + // dataBuilder.SetString(ref dataBuilder.Value.Expression, _expression); + // dataBuilder.SetArray( + // ref dataBuilder.Value.Variants, + // _sources.Select(source => source.Value.Allocate()) + // ); + // dataBuilder.SetArray( + // ref dataBuilder.Value.VariantNames, + // _sources.Select(source => new UnityBlobStringBuilder(source.Name)) + // ); + // var variants = stream.Allocate(ref data.Variants, _sources.Length); + // var names = stream.Allocate(ref data.VariantNames, _sources.Length); + // var types = stream.Allocate(ref data.VariantTypes, _sources.Length); + // for (var i = 0; i < _sources.Length; i++) + // { + // _sources[i].Value.Allocate(ref stream, ref variants[i]); + // stream.AllocateString(ref names[i], _sources[i].Name); + // types[i] = VariantValueTypeRegistry.GetIdByType(_sources[i].Value.FindValueType()); + // } + // return new IntPtr(UnsafeUtility.AddressOf(ref data)); } public object PreviewValue => null; From 8a56a0e80255f6951dfdd31cb1fcfe991ccdb310 Mon Sep 17 00:00:00 2001 From: Quan Yuan Date: Thu, 7 Apr 2022 21:08:47 +0800 Subject: [PATCH 03/28] fix variants --- Assets/Samples/Animator/SetAnimatorTrigger.cs | 2 +- .../Runtime/Entity/IsEntityPositionInBox.cs | 2 +- .../EntitiesBT.Extensions.InputSystem.asmdef | 3 +- .../InputSystem/InputActionGuidBuilder.cs | 6 ++-- .../Runtime/EntitiesBT.Component.asmdef | 3 +- .../builder.component/Runtime/NodeVariant.cs | 31 +++++++++++-------- .../Nuwa/Blob/Runtime/Builder/Builders.cs | 17 +++++----- .../Composites/WeightRandomSelectorNode.cs | 2 +- .../Runtime/Variant/BlobVariantStream.cs | 19 +++++++----- Packages/samples/DEPRECATED | 1 - Packages/samples/DEPRECATED.meta | 7 ----- Packages/samples/package.json | 8 ----- Packages/samples/package.json.meta | 7 ----- 13 files changed, 48 insertions(+), 60 deletions(-) delete mode 100644 Packages/samples/DEPRECATED delete mode 100644 Packages/samples/DEPRECATED.meta delete mode 100644 Packages/samples/package.json delete mode 100644 Packages/samples/package.json.meta diff --git a/Assets/Samples/Animator/SetAnimatorTrigger.cs b/Assets/Samples/Animator/SetAnimatorTrigger.cs index 5c5eb76d..ed5aeb48 100644 --- a/Assets/Samples/Animator/SetAnimatorTrigger.cs +++ b/Assets/Samples/Animator/SetAnimatorTrigger.cs @@ -25,7 +25,7 @@ public class AnimatorTriggerNameBuilder : Nuwa.Blob.Builder { public string TriggerName; - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { stream.WriteValue(Animator.StringToHash(TriggerName)); } diff --git a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs index 12afc44b..26404d1e 100644 --- a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs +++ b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs @@ -29,7 +29,7 @@ public class ColliderBoundsBuilder : Nuwa.Blob.Builder public Transform Transform; public BoxCollider Box; - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { stream.WriteValue(new Bounds(Box.center + Transform.position, Box.size)); } diff --git a/Assets/Samples/Runtime/InputSystem/EntitiesBT.Extensions.InputSystem.asmdef b/Assets/Samples/Runtime/InputSystem/EntitiesBT.Extensions.InputSystem.asmdef index 80dfdff3..64cd9e9b 100644 --- a/Assets/Samples/Runtime/InputSystem/EntitiesBT.Extensions.InputSystem.asmdef +++ b/Assets/Samples/Runtime/InputSystem/EntitiesBT.Extensions.InputSystem.asmdef @@ -11,7 +11,8 @@ "GUID:4285913d8daed4d6fb1061c793376ad4", "GUID:abe4851e67df59644865a60dae54a845", "GUID:f320ee23a990e5640812e0939a441a2b", - "GUID:6d84eb5386377416e93c122a00485b68" + "GUID:6d84eb5386377416e93c122a00485b68", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs index 76d92499..c2245178 100644 --- a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs +++ b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs @@ -1,6 +1,6 @@ using System; +using Blob; using Nuwa.Blob; -using Unity.Entities; using UnityEngine.InputSystem; namespace EntitiesBT.Extensions.InputSystem @@ -9,9 +9,9 @@ public class InputActionGuidBuilder : PlainDataBuilder { public InputActionReference InputAction; - public override void Build(BlobBuilder builder, ref Guid data) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { - data = InputAction.action.id; + value.Value = InputAction.action.id; } } diff --git a/Packages/builder.component/Runtime/EntitiesBT.Component.asmdef b/Packages/builder.component/Runtime/EntitiesBT.Component.asmdef index 44bdf865..0ef916bc 100644 --- a/Packages/builder.component/Runtime/EntitiesBT.Component.asmdef +++ b/Packages/builder.component/Runtime/EntitiesBT.Component.asmdef @@ -6,7 +6,8 @@ "GUID:6d84eb5386377416e93c122a00485b68", "GUID:c7babe7561eb244059259745ef27b866", "GUID:734d92eba21c94caba915361bd5ac177", - "GUID:8819f35a0fc84499b990e90a4ca1911f" + "GUID:8819f35a0fc84499b990e90a4ca1911f", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/builder.component/Runtime/NodeVariant.cs b/Packages/builder.component/Runtime/NodeVariant.cs index 8568721a..bd51271c 100644 --- a/Packages/builder.component/Runtime/NodeVariant.cs +++ b/Packages/builder.component/Runtime/NodeVariant.cs @@ -1,10 +1,8 @@ using System; using System.Reflection; -using System.Runtime.InteropServices; using EntitiesBT.Components; using EntitiesBT.Core; using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; using UnityEngine; using static EntitiesBT.Core.Utilities; @@ -33,9 +31,9 @@ public class Any : IVariant where T : unmanaged public BTNode NodeObject; [VariantNodeObject(nameof(NodeObject))] public string ValueFieldName; - public void Allocate(IBlobStream stream, ref BlobVariant blobVariant) + public void Allocate(BlobVariantStream stream) { - return Allocate(ref stream, ref blobVariant, NodeObject, ValueFieldName); + Allocate(stream, NodeObject, ValueFieldName); } public object PreviewValue => null; @@ -129,9 +127,8 @@ private static IntPtr GetVariantPtr(ref BlobVariant blobVariant, ref return IntPtr.Add(ptr, data.Offset); } - public static IntPtr Allocate( - ref BlobBuilder builder - , ref BlobVariant blobVariant + public static void Allocate( + BlobVariantStream stream , INodeDataBuilder nodeObject , string valueFieldName ) where T : unmanaged @@ -145,7 +142,10 @@ ref BlobBuilder builder var nodeType = VirtualMachine.GetNodeType(nodeObject.NodeId); if (string.IsNullOrEmpty(valueFieldName) && nodeType == typeof(T)) - return builder.Allocate(ref blobVariant, new DynamicNodeRefData{ Index = index, Offset = 0}); + { + stream.SetVariantValue(new DynamicNodeRefData { Index = index, Offset = 0 }); + return; + } var fieldInfo = nodeType.GetField(valueFieldName, BindingFlags.Instance | BindingFlags.Public); if (fieldInfo == null) @@ -157,11 +157,11 @@ ref BlobBuilder builder var fieldType = fieldInfo.FieldType; if (fieldType == typeof(T)) { - blobVariant.VariantId = GuidHashCode(ID_RUNTIME_NODE); + stream.SetVariantId(GuidHashCode(ID_RUNTIME_NODE)); } else if (fieldType == typeof(BlobVariantRO) || fieldType == typeof(BlobVariantRW)) { - blobVariant.VariantId = GuidHashCode(ID_RUNTIME_NODE_VARIANT); + stream.SetVariantId(GuidHashCode(ID_RUNTIME_NODE_VARIANT)); } else { @@ -169,10 +169,15 @@ ref BlobBuilder builder throw new ArgumentException(); } - var fieldOffset = Marshal.OffsetOf(nodeType, valueFieldName).ToInt32(); + var fieldOffset = UnsafeUtility.GetFieldOffset(fieldInfo); if (fieldType == typeof(BlobVariantRW)) - fieldOffset += Marshal.OffsetOf(typeof(BlobVariantRW) , nameof(BlobVariantRW.Reader)).ToInt32(); - return builder.Allocate(ref blobVariant, new DynamicNodeRefData{ Index = index, Offset = fieldOffset}); + { + var fi = typeof(BlobVariantRW).GetField(nameof(BlobVariantRW.Reader), + BindingFlags.Instance | BindingFlags.Public) + ; + fieldOffset += UnsafeUtility.GetFieldOffset(fi); + } + stream.SetVariantValue(new DynamicNodeRefData{ Index = index, Offset = fieldOffset}); } } } diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs index c77a907d..9aa6e151 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs @@ -33,10 +33,11 @@ public void Build(IBlobStream stream) { Position = stream.DataPosition; stream.EnsureDataSize(); - BuildImpl(stream); + var value = new UnsafeBlobStreamValue(stream, Position); + BuildImpl(stream, value); } - protected abstract void BuildImpl([NotNull] IBlobStream stream); + protected abstract void BuildImpl([NotNull] IBlobStream stream, UnsafeBlobStreamValue value); public virtual IBuilder GetBuilder(string name) => throw new NotImplementedException(); @@ -58,9 +59,9 @@ public class PlainDataBuilder : Builder where T : unmanaged { public T Value; - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { - stream.WriteValue(ref Value); + value.Value = Value; } public override object PreviewValue @@ -87,7 +88,7 @@ public BlobDataBuilder() BuilderUtility.SetBlobDataType(typeof(T), ref Builders, ref FieldNames); } - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { var dataPosition = stream.DataPosition; var fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); @@ -128,7 +129,7 @@ public class ArrayBuilder : Builder> where T : unmanaged { [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Value; - protected override unsafe void BuildImpl(IBlobStream stream) + protected override unsafe void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue> value) { stream.WritePatchOffset() .WriteValue(Value.Length) @@ -164,7 +165,7 @@ public override object PreviewValue set => Value = (string)value; } - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { var stringBytes = Encoding.UTF8.GetBytes(Value); stream.WritePatchOffset() @@ -183,7 +184,7 @@ public class PtrBuilder : Builder> where T : unmanaged { [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder Value; - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue> value) { stream.WritePatchOffset().ToPatchPosition().WriteValue(Value); } diff --git a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs index 3bae4819..4b021a69 100644 --- a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs @@ -44,7 +44,7 @@ public class NormalizedWeightBuilder : PlainDataBuilder> { public int[] Weights; - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue> value) { float sum = Weights.Sum(); // new ArrayBuilder(Weights.Select(w => w / sum).ToArray()); diff --git a/Packages/essential/Runtime/Variant/BlobVariantStream.cs b/Packages/essential/Runtime/Variant/BlobVariantStream.cs index 9f78b541..8d5f9226 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantStream.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantStream.cs @@ -69,7 +69,7 @@ public class BlobVariantROBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { _variant?.Allocate(new BlobVariantStream(stream)); } @@ -103,7 +103,7 @@ public class BlobVariantWOBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { _variant.Allocate(new BlobVariantStream(stream)); } @@ -137,14 +137,17 @@ public class BlobVariantRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream) + protected override unsafe void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { _variant.Allocate(new BlobVariantStream(stream)); - data.Writer.VariantId = data.Reader.VariantId; - + value.Value.Writer.VariantId = value.Value.Reader.VariantId; // HACK: set meta data of writer as same as reader's - ref var writerMetaPtr = ref Utilities.ToBlobPtr(ref data.Writer.MetaDataOffsetPtr); - builder.SetPointer(ref writerMetaPtr, ref UnsafeUtility.AsRef(metaDataPtr.ToPointer())); + fixed (void* writerDataPtr = &value.Value.Writer.MetaDataOffsetPtr) + fixed (void* readerDataPtr = &value.Value.Reader.MetaDataOffsetPtr) + { + value.Value.Writer.MetaDataOffsetPtr = + value.Value.Reader.MetaDataOffsetPtr + (int)((long)writerDataPtr - (long)readerDataPtr); + } } } @@ -158,7 +161,7 @@ public class BlobVariantLinkedRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _isLinked ? _readerAndWriter.PreviewValue : _reader.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { if (_isLinked) { diff --git a/Packages/samples/DEPRECATED b/Packages/samples/DEPRECATED deleted file mode 100644 index aa087ba5..00000000 --- a/Packages/samples/DEPRECATED +++ /dev/null @@ -1 +0,0 @@ -move to Assets \ No newline at end of file diff --git a/Packages/samples/DEPRECATED.meta b/Packages/samples/DEPRECATED.meta deleted file mode 100644 index 3d97acfd..00000000 --- a/Packages/samples/DEPRECATED.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: dedf66bbd51d4c54cb8e8ae38ffe5f33 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/samples/package.json b/Packages/samples/package.json deleted file mode 100644 index 225e68f4..00000000 --- a/Packages/samples/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "com.quabug.entities-bt.samples", - "description": "Behavior Tree for Unity Entities - Samples", - "version": "1.4.0", - "unity": "2020.2", - "displayName": "EntitiesBT - Samples", - "type": "sample" -} \ No newline at end of file diff --git a/Packages/samples/package.json.meta b/Packages/samples/package.json.meta deleted file mode 100644 index 17988252..00000000 --- a/Packages/samples/package.json.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 32f693585e8cd12489578b2ceae1b5d5 -PackageManifestImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 442d6a4bb9ac226dc3d8aa0898d1890861c39747 Mon Sep 17 00:00:00 2001 From: Quan Yuan Date: Thu, 7 Apr 2022 21:10:55 +0800 Subject: [PATCH 04/28] remove deprecated packages --- Packages/deprecated/Editor.meta | 8 -- Packages/deprecated/Editor/CodeGen.meta | 8 -- .../CodeGen/EntitiesBT.Editor.Ref.asmref | 3 - .../CodeGen/EntitiesBT.Editor.Ref.asmref.meta | 7 -- .../Editor/CodeGen/INodeCodeTemplate.cs | 15 ---- .../Editor/CodeGen/INodeCodeTemplate.cs.meta | 11 --- .../CodeGen/INodeDataFieldCodeGenerator.cs | 30 ------- .../INodeDataFieldCodeGenerator.cs.meta | 11 --- .../deprecated/Editor/CodeGen/ITypeGroup.cs | 30 ------- .../Editor/CodeGen/ITypeGroup.cs.meta | 11 --- .../Editor/CodeGen/ITypeValidator.cs | 34 -------- .../Editor/CodeGen/ITypeValidator.cs.meta | 11 --- .../Editor/CodeGen/NodeCodeGenerator.cs | 67 --------------- .../Editor/CodeGen/NodeCodeGenerator.cs.meta | 11 --- .../deprecated/Editor/CodeGen/Utilities.cs | 71 ---------------- .../Editor/CodeGen/Utilities.cs.meta | 3 - Packages/deprecated/Editor/Component.meta | 8 -- .../Component/ComponentFieldCodeGenerator.cs | 81 ------------------- .../ComponentFieldCodeGenerator.cs.meta | 3 - .../EntitiesBT.Components.Editor.Ref.asmref | 3 - ...titiesBT.Components.Editor.Ref.asmref.meta | 7 -- .../Component/NodeComponentTemplateCode.cs | 43 ---------- .../NodeComponentTemplateCode.cs.meta | 3 - Packages/deprecated/Editor/Odin.meta | 8 -- .../BlobVariantFieldCodeGeneratorForOdin.cs | 72 ----------------- ...obVariantFieldCodeGeneratorForOdin.cs.meta | 11 --- .../EntitiesBT.Builder.Odin.Editor.asmdef | 25 ------ ...EntitiesBT.Builder.Odin.Editor.asmdef.meta | 7 -- .../Odin/OdinNodeComponentTemplateCode.cs | 43 ---------- .../OdinNodeComponentTemplateCode.cs.meta | 11 --- Packages/deprecated/Runtime.meta | 8 -- Packages/deprecated/Runtime/Component.meta | 8 -- .../Runtime/Component/BTDelayTimer.cs | 22 ----- .../Runtime/Component/BTDelayTimer.cs.meta | 11 --- .../Runtime/Component/BTErrorRerunOnce.cs | 21 ----- .../Component/BTErrorRerunOnce.cs.meta | 11 --- .../deprecated/Runtime/Component/BTFailed.cs | 22 ----- .../Runtime/Component/BTFailed.cs.meta | 11 --- .../Runtime/Component/BTHasComponent.cs | 22 ----- .../Runtime/Component/BTHasComponent.cs.meta | 11 --- .../Runtime/Component/BTModifyPriority.cs | 45 ----------- .../Component/BTModifyPriority.cs.meta | 11 --- .../Runtime/Component/BTParallel.cs | 22 ----- .../Runtime/Component/BTParallel.cs.meta | 11 --- .../Runtime/Component/BTPrioritySelector.cs | 30 ------- .../Component/BTPrioritySelector.cs.meta | 11 --- .../Runtime/Component/BTRandomSelector.cs | 22 ----- .../Component/BTRandomSelector.cs.meta | 11 --- .../Component/BTRecursiveResetState.cs | 22 ----- .../Component/BTRecursiveResetState.cs.meta | 11 --- .../deprecated/Runtime/Component/BTRepeat.cs | 75 ----------------- .../Runtime/Component/BTRepeat.cs.meta | 11 --- .../Runtime/Component/BTRepeatDuration.cs | 24 ------ .../Component/BTRepeatDuration.cs.meta | 11 --- .../Runtime/Component/BTRepeatForever.cs | 22 ----- .../Runtime/Component/BTRepeatForever.cs.meta | 11 --- .../Runtime/Component/BTRepeatTimes.cs | 24 ------ .../Runtime/Component/BTRepeatTimes.cs.meta | 11 --- .../Runtime/Component/BTResetBranch.cs | 22 ----- .../Runtime/Component/BTResetBranch.cs.meta | 11 --- .../Runtime/Component/BTRunOnMainThread.cs | 22 ----- .../Component/BTRunOnMainThread.cs.meta | 11 --- .../deprecated/Runtime/Component/BTRunning.cs | 22 ----- .../Runtime/Component/BTRunning.cs.meta | 11 --- .../Runtime/Component/BTSelector.cs | 17 ---- .../Runtime/Component/BTSelector.cs.meta | 11 --- .../Runtime/Component/BTSequence.cs | 17 ---- .../Runtime/Component/BTSequence.cs.meta | 11 --- .../Runtime/Component/BTStateMap.cs | 28 ------- .../Runtime/Component/BTStateMap.cs.meta | 11 --- .../Runtime/Component/BTStateReverse.cs | 22 ----- .../Runtime/Component/BTStateReverse.cs.meta | 11 --- .../deprecated/Runtime/Component/BTSubTree.cs | 11 --- .../Runtime/Component/BTSubTree.cs.meta | 11 --- .../deprecated/Runtime/Component/BTSuccess.cs | 22 ----- .../Runtime/Component/BTSuccess.cs.meta | 11 --- .../deprecated/Runtime/Component/BTTimer.cs | 24 ------ .../Runtime/Component/BTTimer.cs.meta | 11 --- .../Component/BTWeightRandomSelector.cs | 34 -------- .../Component/BTWeightRandomSelector.cs.meta | 11 --- .../Component/EntitiesBT.Component.Ref.asmref | 3 - .../EntitiesBT.Component.Ref.asmref.meta | 7 -- .../Runtime/Component/NodeCodeGenerator.asset | 51 ------------ .../Component/NodeCodeGenerator.asset.meta | 8 -- Packages/deprecated/Runtime/Odin.meta | 8 -- .../Odin/EntitiesBT.Builder.Odin.Ref.asmref | 3 - .../EntitiesBT.Builder.Odin.Ref.asmref.meta | 7 -- .../Runtime/Odin/NodeCodeGenerator.asset | 49 ----------- .../Runtime/Odin/NodeCodeGenerator.asset.meta | 8 -- .../deprecated/Runtime/Odin/OdinDelayTimer.cs | 26 ------ .../Runtime/Odin/OdinDelayTimer.cs.meta | 11 --- .../Runtime/Odin/OdinErrorRerunOnce.cs | 23 ------ .../Runtime/Odin/OdinErrorRerunOnce.cs.meta | 11 --- .../deprecated/Runtime/Odin/OdinFailed.cs | 23 ------ .../Runtime/Odin/OdinFailed.cs.meta | 11 --- .../Runtime/Odin/OdinHasComponent.cs | 23 ------ .../Runtime/Odin/OdinHasComponent.cs.meta | 11 --- .../Runtime/Odin/OdinModifyPriority.cs | 27 ------- .../Runtime/Odin/OdinModifyPriority.cs.meta | 11 --- .../deprecated/Runtime/Odin/OdinParallel.cs | 23 ------ .../Runtime/Odin/OdinParallel.cs.meta | 11 --- .../Runtime/Odin/OdinPrioritySelector.cs | 23 ------ .../Runtime/Odin/OdinPrioritySelector.cs.meta | 11 --- .../Runtime/Odin/OdinRandomSelector.cs | 23 ------ .../Runtime/Odin/OdinRandomSelector.cs.meta | 11 --- .../Runtime/Odin/OdinRecursiveResetState.cs | 23 ------ .../Odin/OdinRecursiveResetState.cs.meta | 11 --- .../Runtime/Odin/OdinRepeatDuration.cs | 25 ------ .../Runtime/Odin/OdinRepeatDuration.cs.meta | 11 --- .../Runtime/Odin/OdinRepeatForever.cs | 23 ------ .../Runtime/Odin/OdinRepeatForever.cs.meta | 11 --- .../Runtime/Odin/OdinRepeatTimes.cs | 25 ------ .../Runtime/Odin/OdinRepeatTimes.cs.meta | 11 --- .../Runtime/Odin/OdinResetBranch.cs | 23 ------ .../Runtime/Odin/OdinResetBranch.cs.meta | 11 --- .../Runtime/Odin/OdinRunOnMainThread.cs | 23 ------ .../Runtime/Odin/OdinRunOnMainThread.cs.meta | 11 --- .../deprecated/Runtime/Odin/OdinRunning.cs | 23 ------ .../Runtime/Odin/OdinRunning.cs.meta | 11 --- .../deprecated/Runtime/Odin/OdinSelector.cs | 23 ------ .../Runtime/Odin/OdinSelector.cs.meta | 11 --- .../deprecated/Runtime/Odin/OdinSequence.cs | 23 ------ .../Runtime/Odin/OdinSequence.cs.meta | 11 --- .../deprecated/Runtime/Odin/OdinStateMap.cs | 29 ------- .../Runtime/Odin/OdinStateMap.cs.meta | 11 --- .../Runtime/Odin/OdinStateReverse.cs | 23 ------ .../Runtime/Odin/OdinStateReverse.cs.meta | 11 --- .../deprecated/Runtime/Odin/OdinSuccess.cs | 23 ------ .../Runtime/Odin/OdinSuccess.cs.meta | 11 --- Packages/deprecated/Runtime/Odin/OdinTimer.cs | 28 ------- .../deprecated/Runtime/Odin/OdinTimer.cs.meta | 11 --- .../Runtime/Odin/OdinWeightRandomSelector.cs | 25 ------ .../Odin/OdinWeightRandomSelector.cs.meta | 11 --- Packages/deprecated/package.json | 9 --- Packages/deprecated/package.json.meta | 7 -- 135 files changed, 2482 deletions(-) delete mode 100644 Packages/deprecated/Editor.meta delete mode 100644 Packages/deprecated/Editor/CodeGen.meta delete mode 100644 Packages/deprecated/Editor/CodeGen/EntitiesBT.Editor.Ref.asmref delete mode 100644 Packages/deprecated/Editor/CodeGen/EntitiesBT.Editor.Ref.asmref.meta delete mode 100644 Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs delete mode 100644 Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs.meta delete mode 100644 Packages/deprecated/Editor/CodeGen/INodeDataFieldCodeGenerator.cs delete mode 100644 Packages/deprecated/Editor/CodeGen/INodeDataFieldCodeGenerator.cs.meta delete mode 100644 Packages/deprecated/Editor/CodeGen/ITypeGroup.cs delete mode 100644 Packages/deprecated/Editor/CodeGen/ITypeGroup.cs.meta delete mode 100644 Packages/deprecated/Editor/CodeGen/ITypeValidator.cs delete mode 100644 Packages/deprecated/Editor/CodeGen/ITypeValidator.cs.meta delete mode 100644 Packages/deprecated/Editor/CodeGen/NodeCodeGenerator.cs delete mode 100644 Packages/deprecated/Editor/CodeGen/NodeCodeGenerator.cs.meta delete mode 100644 Packages/deprecated/Editor/CodeGen/Utilities.cs delete mode 100644 Packages/deprecated/Editor/CodeGen/Utilities.cs.meta delete mode 100644 Packages/deprecated/Editor/Component.meta delete mode 100644 Packages/deprecated/Editor/Component/ComponentFieldCodeGenerator.cs delete mode 100644 Packages/deprecated/Editor/Component/ComponentFieldCodeGenerator.cs.meta delete mode 100644 Packages/deprecated/Editor/Component/EntitiesBT.Components.Editor.Ref.asmref delete mode 100644 Packages/deprecated/Editor/Component/EntitiesBT.Components.Editor.Ref.asmref.meta delete mode 100644 Packages/deprecated/Editor/Component/NodeComponentTemplateCode.cs delete mode 100644 Packages/deprecated/Editor/Component/NodeComponentTemplateCode.cs.meta delete mode 100644 Packages/deprecated/Editor/Odin.meta delete mode 100644 Packages/deprecated/Editor/Odin/BlobVariantFieldCodeGeneratorForOdin.cs delete mode 100644 Packages/deprecated/Editor/Odin/BlobVariantFieldCodeGeneratorForOdin.cs.meta delete mode 100644 Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef delete mode 100644 Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef.meta delete mode 100644 Packages/deprecated/Editor/Odin/OdinNodeComponentTemplateCode.cs delete mode 100644 Packages/deprecated/Editor/Odin/OdinNodeComponentTemplateCode.cs.meta delete mode 100644 Packages/deprecated/Runtime.meta delete mode 100644 Packages/deprecated/Runtime/Component.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTDelayTimer.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTDelayTimer.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTErrorRerunOnce.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTErrorRerunOnce.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTFailed.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTFailed.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTHasComponent.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTHasComponent.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTModifyPriority.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTModifyPriority.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTParallel.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTParallel.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTPrioritySelector.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTPrioritySelector.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTRandomSelector.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTRandomSelector.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTRecursiveResetState.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTRecursiveResetState.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTRepeat.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTRepeat.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTRepeatDuration.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTRepeatDuration.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTRepeatForever.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTRepeatForever.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTRepeatTimes.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTRepeatTimes.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTResetBranch.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTResetBranch.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTRunOnMainThread.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTRunOnMainThread.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTRunning.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTRunning.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTSelector.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTSelector.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTSequence.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTSequence.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTStateMap.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTStateMap.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTStateReverse.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTStateReverse.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTSubTree.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTSubTree.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTSuccess.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTSuccess.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTTimer.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTTimer.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/BTWeightRandomSelector.cs delete mode 100644 Packages/deprecated/Runtime/Component/BTWeightRandomSelector.cs.meta delete mode 100644 Packages/deprecated/Runtime/Component/EntitiesBT.Component.Ref.asmref delete mode 100644 Packages/deprecated/Runtime/Component/EntitiesBT.Component.Ref.asmref.meta delete mode 100644 Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset delete mode 100644 Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset.meta delete mode 100644 Packages/deprecated/Runtime/Odin.meta delete mode 100644 Packages/deprecated/Runtime/Odin/EntitiesBT.Builder.Odin.Ref.asmref delete mode 100644 Packages/deprecated/Runtime/Odin/EntitiesBT.Builder.Odin.Ref.asmref.meta delete mode 100644 Packages/deprecated/Runtime/Odin/NodeCodeGenerator.asset delete mode 100644 Packages/deprecated/Runtime/Odin/NodeCodeGenerator.asset.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinDelayTimer.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinDelayTimer.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinErrorRerunOnce.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinErrorRerunOnce.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinFailed.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinFailed.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinHasComponent.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinHasComponent.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinModifyPriority.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinModifyPriority.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinParallel.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinParallel.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinPrioritySelector.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinPrioritySelector.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRandomSelector.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRandomSelector.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRecursiveResetState.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRecursiveResetState.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRepeatDuration.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRepeatDuration.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRepeatForever.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRepeatForever.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRepeatTimes.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRepeatTimes.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinResetBranch.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinResetBranch.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRunOnMainThread.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRunOnMainThread.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRunning.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinRunning.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinSelector.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinSelector.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinSequence.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinSequence.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinStateMap.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinStateMap.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinStateReverse.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinStateReverse.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinSuccess.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinSuccess.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinTimer.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinTimer.cs.meta delete mode 100644 Packages/deprecated/Runtime/Odin/OdinWeightRandomSelector.cs delete mode 100644 Packages/deprecated/Runtime/Odin/OdinWeightRandomSelector.cs.meta delete mode 100644 Packages/deprecated/package.json delete mode 100644 Packages/deprecated/package.json.meta diff --git a/Packages/deprecated/Editor.meta b/Packages/deprecated/Editor.meta deleted file mode 100644 index 45999419..00000000 --- a/Packages/deprecated/Editor.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5205ed2e1a3d0ab4d9a6467d47d23c1b -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/CodeGen.meta b/Packages/deprecated/Editor/CodeGen.meta deleted file mode 100644 index 32af76c7..00000000 --- a/Packages/deprecated/Editor/CodeGen.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d97d60611960c6343a85c240b561ce50 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/CodeGen/EntitiesBT.Editor.Ref.asmref b/Packages/deprecated/Editor/CodeGen/EntitiesBT.Editor.Ref.asmref deleted file mode 100644 index 04db2487..00000000 --- a/Packages/deprecated/Editor/CodeGen/EntitiesBT.Editor.Ref.asmref +++ /dev/null @@ -1,3 +0,0 @@ -{ - "reference": "GUID:f49b79f7e0a9b4b63a97d15e26787406" -} \ No newline at end of file diff --git a/Packages/deprecated/Editor/CodeGen/EntitiesBT.Editor.Ref.asmref.meta b/Packages/deprecated/Editor/CodeGen/EntitiesBT.Editor.Ref.asmref.meta deleted file mode 100644 index 31ae19f9..00000000 --- a/Packages/deprecated/Editor/CodeGen/EntitiesBT.Editor.Ref.asmref.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 0c210c9747de24443a300b85b097482d -AssemblyDefinitionReferenceImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs b/Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs deleted file mode 100644 index de882a5d..00000000 --- a/Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace EntitiesBT.Editor -{ - public interface INodeCodeTemplate - { - string Header { get; } - string Generate( - Type nodeType - , IEnumerable fieldGenerators - , string classNameOverride = "" - ); - } -} diff --git a/Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs.meta b/Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs.meta deleted file mode 100644 index 7cacff0c..00000000 --- a/Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 916d6a86705e1ad4fa277937de201f7c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/CodeGen/INodeDataFieldCodeGenerator.cs b/Packages/deprecated/Editor/CodeGen/INodeDataFieldCodeGenerator.cs deleted file mode 100644 index f654eaeb..00000000 --- a/Packages/deprecated/Editor/CodeGen/INodeDataFieldCodeGenerator.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Reflection; - -namespace EntitiesBT.Editor -{ - public interface INodeDataFieldCodeGenerator - { - bool ShouldGenerate(FieldInfo fi); - string GenerateField(FieldInfo fi); - string GenerateBuild(FieldInfo fi); - } - - public class DefaultNodeDataFieldCodeGenerator : INodeDataFieldCodeGenerator - { - public bool ShouldGenerate(FieldInfo fi) - { - return true; - } - - public string GenerateField(FieldInfo fi) - { - return $"public {fi.FieldType.FullName.ToCodeName()} {fi.Name};"; - } - - public string GenerateBuild(FieldInfo fi) - { - return $"data.{fi.Name} = {fi.Name};"; - } - } - -} diff --git a/Packages/deprecated/Editor/CodeGen/INodeDataFieldCodeGenerator.cs.meta b/Packages/deprecated/Editor/CodeGen/INodeDataFieldCodeGenerator.cs.meta deleted file mode 100644 index d4bda6b9..00000000 --- a/Packages/deprecated/Editor/CodeGen/INodeDataFieldCodeGenerator.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 66d6ef13df32d3b45b0e99ca0a72b8c4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/CodeGen/ITypeGroup.cs b/Packages/deprecated/Editor/CodeGen/ITypeGroup.cs deleted file mode 100644 index aaf85ea4..00000000 --- a/Packages/deprecated/Editor/CodeGen/ITypeGroup.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using UnityEditorInternal; - -namespace EntitiesBT.Editor -{ - public interface ITypeGroup - { - IEnumerable Types { get; } - } - - [Serializable] - public class TypeGroupAssemblies : ITypeGroup - { - public AssemblyDefinitionAsset[] Assemblies; - - public IEnumerable Types - { - get - { - var assemblyNames = Assemblies.Select(asm => asm.Deserialize().name); - return Core.Utilities.ALL_ASSEMBLIES.Value - .Where(assembly => assemblyNames.Contains(assembly.GetName().Name)) - .SelectMany(assembly => assembly.GetTypes()) - ; - } - } - } -} diff --git a/Packages/deprecated/Editor/CodeGen/ITypeGroup.cs.meta b/Packages/deprecated/Editor/CodeGen/ITypeGroup.cs.meta deleted file mode 100644 index 9f2f6c75..00000000 --- a/Packages/deprecated/Editor/CodeGen/ITypeGroup.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 11869a34acf2cd04784f9b8ad46dbe05 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/CodeGen/ITypeValidator.cs b/Packages/deprecated/Editor/CodeGen/ITypeValidator.cs deleted file mode 100644 index 05f4a405..00000000 --- a/Packages/deprecated/Editor/CodeGen/ITypeValidator.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using EntitiesBT.Variant; - -namespace EntitiesBT.Editor -{ - public interface ITypeValidator - { - bool Verify(Type value); - } - - [Serializable] - public class TypeValidatorWithFullName : ITypeValidator - { - public string[] TypeFullNames = {}; - - public bool Verify(Type type) - { - return TypeFullNames.Contains(type.FullName); - } - } - - public class TypeValidatorWithoutBlobVariant : ITypeValidator - { - public bool Verify(Type node) - { - var fields = node.GetFields(BindingFlags.Public | BindingFlags.Instance); - return !fields.Select(fi => fi.FieldType) - .Any(type => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(BlobVariantRO<>)) - ; - } - } -} diff --git a/Packages/deprecated/Editor/CodeGen/ITypeValidator.cs.meta b/Packages/deprecated/Editor/CodeGen/ITypeValidator.cs.meta deleted file mode 100644 index 87a0be9a..00000000 --- a/Packages/deprecated/Editor/CodeGen/ITypeValidator.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fe889dfa6b9764c44b5b5b074782cad9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/CodeGen/NodeCodeGenerator.cs b/Packages/deprecated/Editor/CodeGen/NodeCodeGenerator.cs deleted file mode 100644 index 996541a8..00000000 --- a/Packages/deprecated/Editor/CodeGen/NodeCodeGenerator.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using Nuwa; -using EntitiesBT.Core; -using Unity.Assertions; -using UnityEditor; -using UnityEngine; - -#if ODIN_INSPECTOR -using DrawWithUnityAttribute = Sirenix.OdinInspector.DrawWithUnityAttribute; -#else -using DrawWithUnityAttribute = EntitiesBT.Core.DrawWithUnityAttribute; -#endif - -namespace EntitiesBT.Editor -{ - [CreateAssetMenu(fileName = "NodeCodeGenerator", menuName = "EntitiesBT/NodeCodeGenerator")] - public class NodeCodeGenerator : ScriptableObject - { - [SerializeReference, SerializeReferenceDrawer, DrawWithUnity] - private INodeCodeTemplate _codeTemplate; - - [SerializeField] - private string _outputDirectory = "Node"; - - [SerializeField] - private string _classRenameRegex = @"(\w+)(?:Node)/$1"; - - [SerializeReference, SerializeReferenceDrawer, DrawWithUnity] - private ITypeGroup[] _includedNodes = { new TypeGroupAssemblies() }; - - [SerializeReference, SerializeReferenceDrawer, DrawWithUnity] - private ITypeValidator[] _excludedNodes = { new TypeValidatorWithFullName() }; - - [SerializeReference, SerializeReferenceDrawer, DrawWithUnity] - private INodeDataFieldCodeGenerator[] _fieldCodeGenerators = { new DefaultNodeDataFieldCodeGenerator() }; - - [ContextMenu("Generate")] - public void GenerateComponents() - { - Assert.IsNotNull(_codeTemplate); - - var currentDirectory = Path.GetDirectoryName(AssetDatabase.GetAssetPath(this)); - var scriptDirectory = $"{currentDirectory}/{_outputDirectory}"; - var regexList = _classRenameRegex.Split('/'); - var classNameRegex = new Regex(regexList.Length > 0 ? regexList[0] : @"(*)"); - var replaceName = regexList.Length > 1 ? regexList[1] : "$1"; - - foreach (var nodeType in _includedNodes.SelectMany(include => include.Types) - .Where(type => typeof(INodeData).IsAssignableFrom(type) && type.IsValueType) - .Where(type => !_excludedNodes.Any(check => check.Verify(type))) - ) - { - var className = classNameRegex.Replace(nodeType.Name, replaceName); - var filepath = $"{scriptDirectory}/{className}.cs"; - if (!Directory.Exists(scriptDirectory)) Directory.CreateDirectory(scriptDirectory); - if (!File.Exists(filepath) || File.ReadLines(filepath).FirstOrDefault() == _codeTemplate.Header) - { - var script = _codeTemplate.Generate(nodeType, _fieldCodeGenerators, className); - using (var writer = new StreamWriter(filepath)) writer.Write(script); - } - } - AssetDatabase.Refresh(); - } - } -} diff --git a/Packages/deprecated/Editor/CodeGen/NodeCodeGenerator.cs.meta b/Packages/deprecated/Editor/CodeGen/NodeCodeGenerator.cs.meta deleted file mode 100644 index d0c17b45..00000000 --- a/Packages/deprecated/Editor/CodeGen/NodeCodeGenerator.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8f484a7ced5fe034d988cd932b0d4807 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/CodeGen/Utilities.cs b/Packages/deprecated/Editor/CodeGen/Utilities.cs deleted file mode 100644 index ee0e8fcd..00000000 --- a/Packages/deprecated/Editor/CodeGen/Utilities.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Nuwa.Editor; -using JetBrains.Annotations; -using UnityEditor; -using UnityEditorInternal; -using UnityEngine; - -namespace EntitiesBT.Editor -{ - public static class Utilities - { - // private static MethodInfo _PROPERTY_VERIFY_METHOD; - // private static MethodInfo _PROPERTY_SET_VALUE_METHOD; - - // static Utilities() - // { - // const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; - // _PROPERTY_VERIFY_METHOD = typeof(SerializedProperty).GetMethod(nameof(Verify), flags); - // _PROPERTY_SET_VALUE_METHOD = typeof(SerializedProperty).GetMethod(nameof(SetManagedReferenceValueInternal), flags); - // } - - // private static IDictionary _variableSubclasses = new Dictionary(); - // - // public static Type[] GetVariableSubclasses(this Type variableType) - // { - // if (!_variableSubclasses.TryGetValue(variableType, out var subclasses)) - // { - // subclasses = - // ( - // from type in Utilities.BehaviorTreeAssemblyTypes - // where type.IsGenericType - // ? IsSubclassOfRawGeneric(variableType.GetGenericTypeDefinition(), type) - // : type.IsSubclassOf(variableType) - // select type - // ).ToArray(); - // _variableSubclasses[variableType] = subclasses; - // } - // return subclasses; - // } - // - // // https://stackoverflow.com/a/457708 - // private static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) { - // while (toCheck != null && toCheck != typeof(object)) { - // var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; - // if (generic == cur) { - // return true; - // } - // toCheck = toCheck.BaseType; - // } - // return false; - // } - - [Pure] internal static string ToCodeName(this string typeName) => - typeName.Split('`').First().Replace('+', '.') - ; - - [Pure] internal static string ToShortNameWithInnerClass(this string typeName) => - typeName.Split('`').First().Split('.').Last().Replace("+", "") - ; - - - public static Assembly ToAssembly([NotNull] this AssemblyDefinitionAsset assembly) - { - var name = assembly.Deserialize().name; - return Core.Utilities.ALL_ASSEMBLIES.Value.FirstOrDefault(assembly => assembly.GetName().Name == name); - } - } -} diff --git a/Packages/deprecated/Editor/CodeGen/Utilities.cs.meta b/Packages/deprecated/Editor/CodeGen/Utilities.cs.meta deleted file mode 100644 index 4a4891c7..00000000 --- a/Packages/deprecated/Editor/CodeGen/Utilities.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8a72a8450e744526bed16ff1347f29ab -timeCreated: 1583138087 \ No newline at end of file diff --git a/Packages/deprecated/Editor/Component.meta b/Packages/deprecated/Editor/Component.meta deleted file mode 100644 index 3521f175..00000000 --- a/Packages/deprecated/Editor/Component.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a811b6da7ca78bf4d823965dba1dc711 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/Component/ComponentFieldCodeGenerator.cs b/Packages/deprecated/Editor/Component/ComponentFieldCodeGenerator.cs deleted file mode 100644 index 259af21e..00000000 --- a/Packages/deprecated/Editor/Component/ComponentFieldCodeGenerator.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using EntitiesBT.Core; -using EntitiesBT.Variant; -using Unity.Entities; -using UnityEditor; -using UnityEditorInternal; - -namespace EntitiesBT.Editor -{ - public class BlobArrayFieldCodeGenerator : INodeDataFieldCodeGenerator - { - public bool ShouldGenerate(FieldInfo fi) - { - return fi.FieldType.IsGenericType && fi.FieldType.GetGenericTypeDefinition() == typeof(BlobArray<>); - } - - public string GenerateField(FieldInfo fi) - { - return $"public {fi.FieldType.GenericTypeArguments[0].FullName}[] {fi.Name};"; - } - - public string GenerateBuild(FieldInfo fi) - { - return $"builder.AllocateArray(ref data.{fi.Name}, {fi.Name});"; - } - } - - public class BlobStringFieldCodeGenerator : INodeDataFieldCodeGenerator - { - public bool ShouldGenerate(FieldInfo fi) - { - return fi.FieldType == typeof(BlobString); - } - - public string GenerateField(FieldInfo fi) - { - return $"public string {fi.Name};"; - } - - public string GenerateBuild(FieldInfo fi) - { - return $"builder.AllocateString(ref data.{fi.Name}, {fi.Name});"; - } - } - - public class BlobVariantFieldCodeGenerator : INodeDataFieldCodeGenerator - { - public string VariantInterfaceNamespace = "EntitiesBT.Variant"; - - public bool ShouldGenerate(FieldInfo fi) - { - if (!fi.FieldType.IsGenericType) return false; - var variantType = fi.FieldType.GetGenericTypeDefinition(); - if (variantType == typeof(BlobVariantRO<>)) return true; - if (variantType == typeof(BlobVariantWO<>)) return true; - if (variantType == typeof(BlobVariantRW<>)) return true; - return false; - } - - public string GenerateField(FieldInfo fi) - { - var valueType = fi.FieldType.GetGenericArguments()[0]; - var variantType = fi.FieldType.GetGenericTypeDefinition(); - if (variantType == typeof(BlobVariantRW<>)) - return $"public {VariantInterfaceNamespace}.SerializedVariantRW<{valueType.FullName}> {fi.Name};"; - if (variantType == typeof(BlobVariantRO<>)) - return $"public {VariantInterfaceNamespace}.SerializedVariantRO<{valueType.FullName}> {fi.Name};"; - return $"public {VariantInterfaceNamespace}.SerializedVariantWO<{valueType.FullName}> {fi.Name};"; - } - - public string GenerateBuild(FieldInfo fi) - { - return $"{fi.Name}.Allocate(ref builder, ref data.{fi.Name}, Self, tree);"; - } - } -} diff --git a/Packages/deprecated/Editor/Component/ComponentFieldCodeGenerator.cs.meta b/Packages/deprecated/Editor/Component/ComponentFieldCodeGenerator.cs.meta deleted file mode 100644 index e260d5d7..00000000 --- a/Packages/deprecated/Editor/Component/ComponentFieldCodeGenerator.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7a69c6ee10b048a2bccedf3d4f94ffcd -timeCreated: 1595835974 \ No newline at end of file diff --git a/Packages/deprecated/Editor/Component/EntitiesBT.Components.Editor.Ref.asmref b/Packages/deprecated/Editor/Component/EntitiesBT.Components.Editor.Ref.asmref deleted file mode 100644 index 1af3411d..00000000 --- a/Packages/deprecated/Editor/Component/EntitiesBT.Components.Editor.Ref.asmref +++ /dev/null @@ -1,3 +0,0 @@ -{ - "reference": "GUID:dbd08b21b2d774f759596d88415755b0" -} \ No newline at end of file diff --git a/Packages/deprecated/Editor/Component/EntitiesBT.Components.Editor.Ref.asmref.meta b/Packages/deprecated/Editor/Component/EntitiesBT.Components.Editor.Ref.asmref.meta deleted file mode 100644 index 381f25ee..00000000 --- a/Packages/deprecated/Editor/Component/EntitiesBT.Components.Editor.Ref.asmref.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: ec0ff711cb5d83341a61ec9ff3bf2238 -AssemblyDefinitionReferenceImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/Component/NodeComponentTemplateCode.cs b/Packages/deprecated/Editor/Component/NodeComponentTemplateCode.cs deleted file mode 100644 index a276227e..00000000 --- a/Packages/deprecated/Editor/Component/NodeComponentTemplateCode.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace EntitiesBT.Editor -{ - internal class NodeComponentTemplate : INodeCodeTemplate - { - public string Header => "// automatically generate from `NodeComponentTemplateCode.cs`"; - public string Generate(Type nodeType, IEnumerable fieldGenerators, string classNameOverride = "") - { - var fields = nodeType.GetFields(BindingFlags.Public | BindingFlags.Instance); - var fieldStrings = fields.Select(fi => fieldGenerators.First(gen => gen.ShouldGenerate(fi)).GenerateField(fi)); - var buildStrings = fields.Select(fi => fieldGenerators.First(gen => gen.ShouldGenerate(fi)).GenerateBuild(fi)); - var className = string.IsNullOrEmpty(classNameOverride) ? nodeType.Name : classNameOverride; - return $@"{Header} -using EntitiesBT.Core; -using Nuwa; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{{ - [Obsolete(""Use BTDynamicNode"")] - public class {className} : BTNode<{nodeType.FullName}> - {{ - [Header(""obsolete: use BTDynamicNode"")] - private int _; - - {string.Join(Environment.NewLine + " ", fieldStrings)} - protected override void Build(ref {nodeType.FullName} data, BlobBuilder builder, ITreeNode[] tree) - {{ - {string.Join(Environment.NewLine + " ", buildStrings)} - }} - }} -}} -"; - } - } -} diff --git a/Packages/deprecated/Editor/Component/NodeComponentTemplateCode.cs.meta b/Packages/deprecated/Editor/Component/NodeComponentTemplateCode.cs.meta deleted file mode 100644 index 71811860..00000000 --- a/Packages/deprecated/Editor/Component/NodeComponentTemplateCode.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a7369ad53c4b44eeb9dbe4f696a20903 -timeCreated: 1595811715 \ No newline at end of file diff --git a/Packages/deprecated/Editor/Odin.meta b/Packages/deprecated/Editor/Odin.meta deleted file mode 100644 index f726fa4f..00000000 --- a/Packages/deprecated/Editor/Odin.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 049b83c82f1e4ba418a9e5f232e7e941 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/Odin/BlobVariantFieldCodeGeneratorForOdin.cs b/Packages/deprecated/Editor/Odin/BlobVariantFieldCodeGeneratorForOdin.cs deleted file mode 100644 index 74aa97f6..00000000 --- a/Packages/deprecated/Editor/Odin/BlobVariantFieldCodeGeneratorForOdin.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using EntitiesBT.Components.Odin; -using EntitiesBT.Core; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; -using Sirenix.Serialization; - -namespace EntitiesBT.Editor -{ - public class BlobVariantFieldCodeGeneratorForOdin : INodeDataFieldCodeGenerator - { - public bool ShouldGenerate(FieldInfo fi) - { - if (!fi.FieldType.IsGenericType) return false; - var variantType = fi.FieldType.GetGenericTypeDefinition(); - if (variantType == typeof(BlobVariantReader<>)) return true; - if (variantType == typeof(BlobVariantWriter<>)) return true; - if (variantType == typeof(BlobVariantReaderAndWriter<>)) return true; - return false; - } - - public string GenerateField(FieldInfo fi) - { - var variantType = fi.FieldType.GetGenericTypeDefinition(); - var valueType = fi.FieldType.GetGenericArguments()[0]; - var attributes = new List - { - nameof(OdinSerializeAttribute) - , nameof(NonSerializedAttribute) - , nameof(HideReferenceObjectPickerAttribute) - }; - Type serializedVariantType = null; - if (variantType == typeof(BlobVariantReaderAndWriter<>)) - { - serializedVariantType = typeof(OdinSerializedVariantReaderAndWriter<>); - } - else if (variantType == typeof(BlobVariantReader<>)) - { - attributes.Add(nameof(HideLabelAttribute)); - serializedVariantType = typeof(OdinSerializedVariantReader<>); - } - else if (variantType == typeof(BlobVariantWriter<>)) - { - attributes.Add(nameof(HideLabelAttribute)); - serializedVariantType = typeof(OdinSerializedVariantWriter<>); - } - else - { - throw new NotImplementedException($"Invalid type of variant {variantType}"); - } - // remove `1 from generic name - var serializedVariantName = serializedVariantType.Name.Substring(0, serializedVariantType.Name.Length - 2); - var serializedVariantNamespace = serializedVariantType.Namespace; - var serializedVariantTypeFullname = $"{serializedVariantNamespace}.{serializedVariantName}<{valueType.FullName}>"; - - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine($"[{string.Join(", ", attributes)}]"); - stringBuilder.AppendLine($" public {serializedVariantTypeFullname} {fi.Name}"); - stringBuilder.AppendLine($" = new {serializedVariantTypeFullname}();"); - return stringBuilder.ToString(); - } - - public string GenerateBuild(FieldInfo fi) - { - return $"{fi.Name}.Allocate(ref builder, ref data.{fi.Name}, Self, tree);"; - } - } -} \ No newline at end of file diff --git a/Packages/deprecated/Editor/Odin/BlobVariantFieldCodeGeneratorForOdin.cs.meta b/Packages/deprecated/Editor/Odin/BlobVariantFieldCodeGeneratorForOdin.cs.meta deleted file mode 100644 index b0cb00d2..00000000 --- a/Packages/deprecated/Editor/Odin/BlobVariantFieldCodeGeneratorForOdin.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e4d48d2c0a944eae9779ae4ef3c399ab -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef b/Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef deleted file mode 100644 index d7221597..00000000 --- a/Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "EntitiesBT.Builder.Odin.Editor", - "rootNamespace": "EntitiesBT.Editor", - "references": [ - "EntitiesBT.Editor", - "EntitiesBT.Runtime", - "EntitiesBT.Builder.Odin" - ], - "includePlatforms": [ - "Editor" - ], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": true, - "precompiledReferences": [ - "Sirenix.Serialization.dll", - "Sirenix.OdinInspector.Attributes.dll" - ], - "autoReferenced": false, - "defineConstraints": [ - "ODIN_INSPECTOR" - ], - "versionDefines": [], - "noEngineReferences": false -} \ No newline at end of file diff --git a/Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef.meta b/Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef.meta deleted file mode 100644 index 583ead57..00000000 --- a/Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: f5b81ab0b632dbb48a50fc1efe546d5a -AssemblyDefinitionImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Editor/Odin/OdinNodeComponentTemplateCode.cs b/Packages/deprecated/Editor/Odin/OdinNodeComponentTemplateCode.cs deleted file mode 100644 index 613c4d1c..00000000 --- a/Packages/deprecated/Editor/Odin/OdinNodeComponentTemplateCode.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace EntitiesBT.Editor -{ - internal class OdinNodeComponentTemplate : INodeCodeTemplate - { - public string Header => "// automatically generate from `OdinNodeComponentTemplate.cs`"; - public string Generate(Type nodeType, IEnumerable fieldGenerators, string classNameOverride = "") - { - var fields = nodeType.GetFields(BindingFlags.Public | BindingFlags.Instance); - var fieldStrings = fields.Select(fi => fieldGenerators.First(gen => gen.ShouldGenerate(fi)).GenerateField(fi)); - var buildStrings = fields.Select(fi => fieldGenerators.First(gen => gen.ShouldGenerate(fi)).GenerateBuild(fi)); - var className = string.IsNullOrEmpty(classNameOverride) ? nodeType.Name : classNameOverride; - return $@"{Header} -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{{ - public class {className} : OdinNode<{nodeType.FullName}> - {{ - {string.Join(Environment.NewLine + " ", fieldStrings)} - protected override void Build(ref {nodeType.FullName} data, BlobBuilder builder, ITreeNode[] tree) - {{ - {string.Join(Environment.NewLine + " ", buildStrings)} - }} - }} -}} - -#endif -"; - } - } -} diff --git a/Packages/deprecated/Editor/Odin/OdinNodeComponentTemplateCode.cs.meta b/Packages/deprecated/Editor/Odin/OdinNodeComponentTemplateCode.cs.meta deleted file mode 100644 index 44304648..00000000 --- a/Packages/deprecated/Editor/Odin/OdinNodeComponentTemplateCode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b61b23ea76aae3c4e9738410194f9e26 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime.meta b/Packages/deprecated/Runtime.meta deleted file mode 100644 index 1d3b1335..00000000 --- a/Packages/deprecated/Runtime.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: bdb41dcb64389aa4cbfa501713033069 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component.meta b/Packages/deprecated/Runtime/Component.meta deleted file mode 100644 index 1e236439..00000000 --- a/Packages/deprecated/Runtime/Component.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d067fba8821f02f4a874596cda51f14d -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTDelayTimer.cs b/Packages/deprecated/Runtime/Component/BTDelayTimer.cs deleted file mode 100644 index 2553ee6c..00000000 --- a/Packages/deprecated/Runtime/Component/BTDelayTimer.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTDelayTimer : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - public EntitiesBT.Variant.SerializedVariantRW TimerSeconds; - protected override void Build(ref EntitiesBT.Nodes.DelayTimerNode data, BlobBuilder builder, ITreeNode[] tree) - { - TimerSeconds.Allocate(ref builder, ref data.TimerSeconds); - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTDelayTimer.cs.meta b/Packages/deprecated/Runtime/Component/BTDelayTimer.cs.meta deleted file mode 100644 index 35c0f20e..00000000 --- a/Packages/deprecated/Runtime/Component/BTDelayTimer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: db493cf6cb9347a880404576b970ea05 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTErrorRerunOnce.cs b/Packages/deprecated/Runtime/Component/BTErrorRerunOnce.cs deleted file mode 100644 index dc900219..00000000 --- a/Packages/deprecated/Runtime/Component/BTErrorRerunOnce.cs +++ /dev/null @@ -1,21 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTErrorRerunOnce : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.ErrorRerunOnceNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTErrorRerunOnce.cs.meta b/Packages/deprecated/Runtime/Component/BTErrorRerunOnce.cs.meta deleted file mode 100644 index fe172a1c..00000000 --- a/Packages/deprecated/Runtime/Component/BTErrorRerunOnce.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d960cb25c4bec48cd9cae73c0fefd394 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTFailed.cs b/Packages/deprecated/Runtime/Component/BTFailed.cs deleted file mode 100644 index 781da93b..00000000 --- a/Packages/deprecated/Runtime/Component/BTFailed.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTFailed : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.FailedNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTFailed.cs.meta b/Packages/deprecated/Runtime/Component/BTFailed.cs.meta deleted file mode 100644 index 31c95297..00000000 --- a/Packages/deprecated/Runtime/Component/BTFailed.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0282593c01e3542cc937ce2212d67b2d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTHasComponent.cs b/Packages/deprecated/Runtime/Component/BTHasComponent.cs deleted file mode 100644 index 309fff36..00000000 --- a/Packages/deprecated/Runtime/Component/BTHasComponent.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTHasComponent : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - public System.UInt64 StableTypeHash; - protected override void Build(ref EntitiesBT.Nodes.HasComponentNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.StableTypeHash = StableTypeHash; - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTHasComponent.cs.meta b/Packages/deprecated/Runtime/Component/BTHasComponent.cs.meta deleted file mode 100644 index 3ef7860a..00000000 --- a/Packages/deprecated/Runtime/Component/BTHasComponent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 715ba81be9ab7924d809025d4481f443 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTModifyPriority.cs b/Packages/deprecated/Runtime/Component/BTModifyPriority.cs deleted file mode 100644 index ab73dea1..00000000 --- a/Packages/deprecated/Runtime/Component/BTModifyPriority.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using EntitiesBT.Core; -using EntitiesBT.Nodes; -using Unity.Entities; -using UnityEngine; - -namespace EntitiesBT.Components -{ - public class BTModifyPriority : BTNode - { - [SerializeField] private BTPrioritySelector _prioritySelector = default; - [SerializeField] private int _weightIndex = default; - [SerializeField] private int _addWeight = default; - - protected override void Reset() - { - base.Reset(); - _prioritySelector = GetComponentInParent(); - } - - protected override void Build(ref ModifyPriorityNode data, BlobBuilder _, ITreeNode[] builders) - { - var prioritySelectorIndex = Array.FindIndex(builders, b => b.Value == (INodeDataBuilder)_prioritySelector); - data.PrioritySelectorIndex = prioritySelectorIndex; - data.WeightIndex = _weightIndex; - data.AddWeight = _addWeight; - } - - protected override void OnValidate() - { - base.OnValidate(); - if (_prioritySelector == null) - { - Debug.LogWarning("Refer to invalid `PrioritySelector`", gameObject); - return; - } - - if (_weightIndex < 0 || _weightIndex >= _prioritySelector.Weights.Length) - { - Debug.LogWarning($"WeightIndex {_weightIndex} out of range [0, {_prioritySelector.Weights.Length})", gameObject); - _weightIndex = 0; - } - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTModifyPriority.cs.meta b/Packages/deprecated/Runtime/Component/BTModifyPriority.cs.meta deleted file mode 100644 index b6af8405..00000000 --- a/Packages/deprecated/Runtime/Component/BTModifyPriority.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: acaf14927b227da4dae23044914d3eeb -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTParallel.cs b/Packages/deprecated/Runtime/Component/BTParallel.cs deleted file mode 100644 index c5e21070..00000000 --- a/Packages/deprecated/Runtime/Component/BTParallel.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTParallel : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.ParallelNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTParallel.cs.meta b/Packages/deprecated/Runtime/Component/BTParallel.cs.meta deleted file mode 100644 index 0b291ffe..00000000 --- a/Packages/deprecated/Runtime/Component/BTParallel.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e281aaf7af1642679f42a1e3f343efb8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTPrioritySelector.cs b/Packages/deprecated/Runtime/Component/BTPrioritySelector.cs deleted file mode 100644 index 1e08917a..00000000 --- a/Packages/deprecated/Runtime/Component/BTPrioritySelector.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Linq; -using EntitiesBT.Core; -using EntitiesBT.Nodes; -using Unity.Entities; - -namespace EntitiesBT.Components -{ - public class BTPrioritySelector : BTNode - { - public int[] Weights; - - protected override void Build(ref PrioritySelectorNode data, BlobBuilder blobBuilder, ITreeNode[] builders) - { - blobBuilder.AllocateArray(ref data.Weights, Weights); - } - - protected override void Update() - { - base.Update(); - Array.Resize(ref Weights, Children.Count()); - } - - protected override void OnValidate() - { - base.OnValidate(); - Array.Resize(ref Weights, Children.Count()); - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTPrioritySelector.cs.meta b/Packages/deprecated/Runtime/Component/BTPrioritySelector.cs.meta deleted file mode 100644 index 5dce0974..00000000 --- a/Packages/deprecated/Runtime/Component/BTPrioritySelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 12cee77c0eaadfc4fa9ce67ef3e6b4db -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTRandomSelector.cs b/Packages/deprecated/Runtime/Component/BTRandomSelector.cs deleted file mode 100644 index ab2c25d8..00000000 --- a/Packages/deprecated/Runtime/Component/BTRandomSelector.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTRandomSelector : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.RandomSelectorNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTRandomSelector.cs.meta b/Packages/deprecated/Runtime/Component/BTRandomSelector.cs.meta deleted file mode 100644 index f57a0b89..00000000 --- a/Packages/deprecated/Runtime/Component/BTRandomSelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5272564ffd5f4fa49d7adbee0b831b09 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTRecursiveResetState.cs b/Packages/deprecated/Runtime/Component/BTRecursiveResetState.cs deleted file mode 100644 index 009ebd0c..00000000 --- a/Packages/deprecated/Runtime/Component/BTRecursiveResetState.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTRecursiveResetState : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.RecursiveResetStateNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTRecursiveResetState.cs.meta b/Packages/deprecated/Runtime/Component/BTRecursiveResetState.cs.meta deleted file mode 100644 index 01c37d4a..00000000 --- a/Packages/deprecated/Runtime/Component/BTRecursiveResetState.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 97fa6b77895174345804cbe5d568c1c7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTRepeat.cs b/Packages/deprecated/Runtime/Component/BTRepeat.cs deleted file mode 100644 index 071921cc..00000000 --- a/Packages/deprecated/Runtime/Component/BTRepeat.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Reflection; -using EntitiesBT.Core; -using EntitiesBT.Entities; -using EntitiesBT.Nodes; -using Unity.Collections; -using Unity.Entities; -using UnityEngine; - -namespace EntitiesBT.Components -{ - public class BTRepeat : BTNode - { - enum RepeatType - { - Forever, - Times, - Duration - } - - [SerializeField] private RepeatType Type = RepeatType.Forever; - public NodeState BreakStates; - [Header("for `Times` repeater")] - public int RepeatTimes; - [Header("for `Duration` repeater")] - public float RepeatDurationInSeconds; - - protected override Type NodeType - { - get - { - switch (Type) - { - case RepeatType.Forever: - return typeof(RepeatForeverNode); - case RepeatType.Times: - return typeof(RepeatTimesNode); - case RepeatType.Duration: - return typeof(RepeatDurationNode); - default: - throw new ArgumentOutOfRangeException(); - } - } - } - - protected override unsafe void Build(void* dataPtr, BlobBuilder blobBuilder, ITreeNode[] builders) - { - switch (Type) - { - case RepeatType.Forever: - { - var ptr = (RepeatForeverNode*) dataPtr; - ptr->BreakStates = BreakStates; - return; - } - case RepeatType.Times: - { - var ptr = (RepeatTimesNode*) dataPtr; - ptr->TickTimes = RepeatTimes; - ptr->BreakStates = BreakStates; - return; - } - case RepeatType.Duration: - { - var ptr = (RepeatDurationNode*) dataPtr; - ptr->CountdownSeconds = RepeatDurationInSeconds; - ptr->BreakStates = BreakStates; - break; - } - default: - throw new ArgumentOutOfRangeException(); - } - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTRepeat.cs.meta b/Packages/deprecated/Runtime/Component/BTRepeat.cs.meta deleted file mode 100644 index cf8e21e2..00000000 --- a/Packages/deprecated/Runtime/Component/BTRepeat.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ee11e4e29d666294692c71df1029cecb -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTRepeatDuration.cs b/Packages/deprecated/Runtime/Component/BTRepeatDuration.cs deleted file mode 100644 index 9f4009e3..00000000 --- a/Packages/deprecated/Runtime/Component/BTRepeatDuration.cs +++ /dev/null @@ -1,24 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTRepeatDuration : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - public System.Single CountdownSeconds; - public EntitiesBT.Core.NodeState BreakStates; - protected override void Build(ref EntitiesBT.Nodes.RepeatDurationNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.CountdownSeconds = CountdownSeconds; - data.BreakStates = BreakStates; - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTRepeatDuration.cs.meta b/Packages/deprecated/Runtime/Component/BTRepeatDuration.cs.meta deleted file mode 100644 index 2bf176e8..00000000 --- a/Packages/deprecated/Runtime/Component/BTRepeatDuration.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 09331df2c8db54a5eb8ab7028171111d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTRepeatForever.cs b/Packages/deprecated/Runtime/Component/BTRepeatForever.cs deleted file mode 100644 index 1e4e675d..00000000 --- a/Packages/deprecated/Runtime/Component/BTRepeatForever.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTRepeatForever : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - public EntitiesBT.Core.NodeState BreakStates; - protected override void Build(ref EntitiesBT.Nodes.RepeatForeverNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.BreakStates = BreakStates; - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTRepeatForever.cs.meta b/Packages/deprecated/Runtime/Component/BTRepeatForever.cs.meta deleted file mode 100644 index 8f834ae3..00000000 --- a/Packages/deprecated/Runtime/Component/BTRepeatForever.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 572e0652e18e94419852be1ebb44924b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTRepeatTimes.cs b/Packages/deprecated/Runtime/Component/BTRepeatTimes.cs deleted file mode 100644 index b8b221dd..00000000 --- a/Packages/deprecated/Runtime/Component/BTRepeatTimes.cs +++ /dev/null @@ -1,24 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTRepeatTimes : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - public System.Int32 TickTimes; - public EntitiesBT.Core.NodeState BreakStates; - protected override void Build(ref EntitiesBT.Nodes.RepeatTimesNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.TickTimes = TickTimes; - data.BreakStates = BreakStates; - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTRepeatTimes.cs.meta b/Packages/deprecated/Runtime/Component/BTRepeatTimes.cs.meta deleted file mode 100644 index 4cfd5ac3..00000000 --- a/Packages/deprecated/Runtime/Component/BTRepeatTimes.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a556627f645e54a759ee78c7c189f52a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTResetBranch.cs b/Packages/deprecated/Runtime/Component/BTResetBranch.cs deleted file mode 100644 index 3a584671..00000000 --- a/Packages/deprecated/Runtime/Component/BTResetBranch.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTResetBranch : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.ResetBranchNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTResetBranch.cs.meta b/Packages/deprecated/Runtime/Component/BTResetBranch.cs.meta deleted file mode 100644 index f40f3ada..00000000 --- a/Packages/deprecated/Runtime/Component/BTResetBranch.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4b064020ef94d42f7a435b00df208449 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTRunOnMainThread.cs b/Packages/deprecated/Runtime/Component/BTRunOnMainThread.cs deleted file mode 100644 index 96a7dc30..00000000 --- a/Packages/deprecated/Runtime/Component/BTRunOnMainThread.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTRunOnMainThread : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.RunOnMainThreadNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTRunOnMainThread.cs.meta b/Packages/deprecated/Runtime/Component/BTRunOnMainThread.cs.meta deleted file mode 100644 index 42c11bdf..00000000 --- a/Packages/deprecated/Runtime/Component/BTRunOnMainThread.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cee7e893446548509f3f237b539f1f36 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTRunning.cs b/Packages/deprecated/Runtime/Component/BTRunning.cs deleted file mode 100644 index 2ea0319d..00000000 --- a/Packages/deprecated/Runtime/Component/BTRunning.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTRunning : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.RunningNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTRunning.cs.meta b/Packages/deprecated/Runtime/Component/BTRunning.cs.meta deleted file mode 100644 index c740f948..00000000 --- a/Packages/deprecated/Runtime/Component/BTRunning.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5bfd4cbb4eaab460fb0578d818955adf -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTSelector.cs b/Packages/deprecated/Runtime/Component/BTSelector.cs deleted file mode 100644 index 420c1595..00000000 --- a/Packages/deprecated/Runtime/Component/BTSelector.cs +++ /dev/null @@ -1,17 +0,0 @@ -using EntitiesBT.Core; -using EntitiesBT.Nodes; -using UnityEngine; - -namespace EntitiesBT.Components -{ - public class BTSelector : BTNode - { - [Tooltip("Enable this will re-evaluate node state from first child instead of skip to running node directly.")] - [SerializeField] private bool _recursiveResetStatesBeforeTick = default; - - protected override INodeDataBuilder SelfImpl => _recursiveResetStatesBeforeTick - ? new BTVirtualDecorator(this) - : base.SelfImpl - ; - } -} diff --git a/Packages/deprecated/Runtime/Component/BTSelector.cs.meta b/Packages/deprecated/Runtime/Component/BTSelector.cs.meta deleted file mode 100644 index d63adcba..00000000 --- a/Packages/deprecated/Runtime/Component/BTSelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0f4058acfffc80c468822dc2b251ce64 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTSequence.cs b/Packages/deprecated/Runtime/Component/BTSequence.cs deleted file mode 100644 index 20e30240..00000000 --- a/Packages/deprecated/Runtime/Component/BTSequence.cs +++ /dev/null @@ -1,17 +0,0 @@ -using EntitiesBT.Core; -using EntitiesBT.Nodes; -using UnityEngine; - -namespace EntitiesBT.Components -{ - public class BTSequence : BTNode - { - [Tooltip("Enable this will re-evaluate node state from first child until running node instead of skip to running node directly.")] - [SerializeField] private bool _recursiveResetStatesBeforeTick = default; - - protected override INodeDataBuilder SelfImpl => _recursiveResetStatesBeforeTick - ? new BTVirtualDecorator(this) - : base.SelfImpl - ; - } -} diff --git a/Packages/deprecated/Runtime/Component/BTSequence.cs.meta b/Packages/deprecated/Runtime/Component/BTSequence.cs.meta deleted file mode 100644 index aac3806f..00000000 --- a/Packages/deprecated/Runtime/Component/BTSequence.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5d7f1d512dac6cf419021d68b8bb6630 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTStateMap.cs b/Packages/deprecated/Runtime/Component/BTStateMap.cs deleted file mode 100644 index 6c12b4a0..00000000 --- a/Packages/deprecated/Runtime/Component/BTStateMap.cs +++ /dev/null @@ -1,28 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTStateMap : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - public EntitiesBT.Core.NodeState MapSuccess; - public EntitiesBT.Core.NodeState MapFailure; - public EntitiesBT.Core.NodeState MapRunning; - public EntitiesBT.Core.NodeState MapError; - protected override void Build(ref EntitiesBT.Nodes.StateMapNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.MapSuccess = MapSuccess; - data.MapFailure = MapFailure; - data.MapRunning = MapRunning; - data.MapError = MapError; - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTStateMap.cs.meta b/Packages/deprecated/Runtime/Component/BTStateMap.cs.meta deleted file mode 100644 index 9f0e1b07..00000000 --- a/Packages/deprecated/Runtime/Component/BTStateMap.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 21715d7691c944cce82362a3916438aa -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTStateReverse.cs b/Packages/deprecated/Runtime/Component/BTStateReverse.cs deleted file mode 100644 index 6a496b30..00000000 --- a/Packages/deprecated/Runtime/Component/BTStateReverse.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTStateReverse : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.StateReverseNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTStateReverse.cs.meta b/Packages/deprecated/Runtime/Component/BTStateReverse.cs.meta deleted file mode 100644 index bd931edb..00000000 --- a/Packages/deprecated/Runtime/Component/BTStateReverse.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e37f820464d254d349634a12839a353a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTSubTree.cs b/Packages/deprecated/Runtime/Component/BTSubTree.cs deleted file mode 100644 index 8ed44bc2..00000000 --- a/Packages/deprecated/Runtime/Component/BTSubTree.cs +++ /dev/null @@ -1,11 +0,0 @@ -using EntitiesBT.Core; -using UnityEngine; - -namespace EntitiesBT.Components -{ - public class BTSubTree : BTNode, INodeDataBuilder - { - [SerializeField] private BTNode _tree = default; - protected override INodeDataBuilder SelfImpl => _tree; - } -} diff --git a/Packages/deprecated/Runtime/Component/BTSubTree.cs.meta b/Packages/deprecated/Runtime/Component/BTSubTree.cs.meta deleted file mode 100644 index 1801391a..00000000 --- a/Packages/deprecated/Runtime/Component/BTSubTree.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6eb80f4860c3f0e46873ee9380aa4f22 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTSuccess.cs b/Packages/deprecated/Runtime/Component/BTSuccess.cs deleted file mode 100644 index 0876b393..00000000 --- a/Packages/deprecated/Runtime/Component/BTSuccess.cs +++ /dev/null @@ -1,22 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTSuccess : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - - protected override void Build(ref EntitiesBT.Nodes.SuccessNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTSuccess.cs.meta b/Packages/deprecated/Runtime/Component/BTSuccess.cs.meta deleted file mode 100644 index 308690df..00000000 --- a/Packages/deprecated/Runtime/Component/BTSuccess.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9bb84658d943e4951b56133335351ce3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTTimer.cs b/Packages/deprecated/Runtime/Component/BTTimer.cs deleted file mode 100644 index ca258400..00000000 --- a/Packages/deprecated/Runtime/Component/BTTimer.cs +++ /dev/null @@ -1,24 +0,0 @@ -// automatically generate from `NodeComponentTemplateCode.cs` -using EntitiesBT.Core; -using Unity.Entities; -using static EntitiesBT.Variant.Utilities; -using UnityEngine; -using System; - -namespace EntitiesBT.Components -{ - [Obsolete("Use BTDynamicNode")] - public class BTTimer : BTNode - { - [Header("obsolete: use BTDynamicNode")] - private int _; - - public EntitiesBT.Variant.SerializedVariantRW CountdownSeconds; - public EntitiesBT.Core.NodeState BreakReturnState; - protected override void Build(ref EntitiesBT.Nodes.TimerNode data, BlobBuilder builder, ITreeNode[] tree) - { - CountdownSeconds.Allocate(ref builder, ref data.CountdownSeconds); - data.BreakReturnState = BreakReturnState; - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTTimer.cs.meta b/Packages/deprecated/Runtime/Component/BTTimer.cs.meta deleted file mode 100644 index 7f6021dc..00000000 --- a/Packages/deprecated/Runtime/Component/BTTimer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e7278b7460714ee38d430757bc239563 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/BTWeightRandomSelector.cs b/Packages/deprecated/Runtime/Component/BTWeightRandomSelector.cs deleted file mode 100644 index aed915f4..00000000 --- a/Packages/deprecated/Runtime/Component/BTWeightRandomSelector.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Linq; -using EntitiesBT.Core; -using EntitiesBT.Nodes; -using Unity.Entities; -using UnityEngine; - -namespace EntitiesBT.Components -{ - public class BTWeightRandomSelector : BTNode - { - [SerializeField] private float[] _weights; - - protected override void Build(ref WeightRandomSelectorNode data, BlobBuilder builder, ITreeNode[] __) - { - var sum = _weights.Sum(); - builder.AllocateArray(ref data.NormalizedWeights, _weights.Select(w => w / sum).ToArray()); - } - - protected override void Update() - { - base.Update(); - Array.Resize(ref _weights, Children.Count()); - } - - protected override void OnValidate() - { - base.OnValidate(); - Array.Resize(ref _weights, Children.Count()); - for (var i = 0; i < _weights.Length; i++) - if (_weights[i] < 0) _weights[i] = 0; - } - } -} diff --git a/Packages/deprecated/Runtime/Component/BTWeightRandomSelector.cs.meta b/Packages/deprecated/Runtime/Component/BTWeightRandomSelector.cs.meta deleted file mode 100644 index bd16745b..00000000 --- a/Packages/deprecated/Runtime/Component/BTWeightRandomSelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9df682de3f2aca14bbe7e32a7b61953f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/EntitiesBT.Component.Ref.asmref b/Packages/deprecated/Runtime/Component/EntitiesBT.Component.Ref.asmref deleted file mode 100644 index 287e9da9..00000000 --- a/Packages/deprecated/Runtime/Component/EntitiesBT.Component.Ref.asmref +++ /dev/null @@ -1,3 +0,0 @@ -{ - "reference": "GUID:f320ee23a990e5640812e0939a441a2b" -} \ No newline at end of file diff --git a/Packages/deprecated/Runtime/Component/EntitiesBT.Component.Ref.asmref.meta b/Packages/deprecated/Runtime/Component/EntitiesBT.Component.Ref.asmref.meta deleted file mode 100644 index 0f0fb791..00000000 --- a/Packages/deprecated/Runtime/Component/EntitiesBT.Component.Ref.asmref.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: e124d19b124f1d74a81f34fc11f3303e -AssemblyDefinitionReferenceImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset b/Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset deleted file mode 100644 index d37526fc..00000000 --- a/Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset +++ /dev/null @@ -1,51 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 283b83d5022d46b8a345bad7768d520e, type: 3} - m_Name: NodeCodeGenerator - m_EditorClassIdentifier: - _codeTemplate: - id: 0 - _outputDirectory: Components - _classRenameRegex: (\w+)(?:Node)/BT$1 - _includedNodes: - - id: 1 - _excludedNodes: - - id: 2 - _fieldCodeGenerators: - - id: 3 - - id: 4 - - id: 5 - - id: 6 - references: - version: 1 - 00000000: - type: {class: NodeComponentTemplate, ns: EntitiesBT.Editor, asm: EntitiesBT.Components.Editor} - 00000001: - type: {class: TypeGroupAssemblies, ns: EntitiesBT.Editor, asm: EntitiesBT.Editor} - data: - Assemblies: - - {fileID: 5897886265953266890, guid: c7babe7561eb244059259745ef27b866, type: 3} - 00000002: - type: {class: TypeValidatorWithFullName, ns: EntitiesBT.Editor, asm: EntitiesBT.Editor} - data: - TypeFullNames: - - EntitiesBT.Nodes.ZeroNode - 00000003: - type: {class: BlobStringFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Components.Editor} - 00000004: - type: {class: BlobArrayFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Components.Editor} - 00000005: - type: {class: BlobVariantFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Components.Editor} - data: - VariantInterfaceNamespace: EntitiesBT.Variant - 00000006: - type: {class: DefaultNodeDataFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Editor} diff --git a/Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset.meta b/Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset.meta deleted file mode 100644 index cef5d117..00000000 --- a/Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7458b90d338864635ad5fa764629835e -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin.meta b/Packages/deprecated/Runtime/Odin.meta deleted file mode 100644 index 3f6fd14d..00000000 --- a/Packages/deprecated/Runtime/Odin.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f146f1fa42a59f645a47bc0e2310b6dc -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/EntitiesBT.Builder.Odin.Ref.asmref b/Packages/deprecated/Runtime/Odin/EntitiesBT.Builder.Odin.Ref.asmref deleted file mode 100644 index 5ffc974c..00000000 --- a/Packages/deprecated/Runtime/Odin/EntitiesBT.Builder.Odin.Ref.asmref +++ /dev/null @@ -1,3 +0,0 @@ -{ - "reference": "GUID:531c7a9266080bf4ba6b3998d6aa0137" -} \ No newline at end of file diff --git a/Packages/deprecated/Runtime/Odin/EntitiesBT.Builder.Odin.Ref.asmref.meta b/Packages/deprecated/Runtime/Odin/EntitiesBT.Builder.Odin.Ref.asmref.meta deleted file mode 100644 index 8ebcced8..00000000 --- a/Packages/deprecated/Runtime/Odin/EntitiesBT.Builder.Odin.Ref.asmref.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 3413be802f232b745b16a0dd80ffb920 -AssemblyDefinitionReferenceImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/NodeCodeGenerator.asset b/Packages/deprecated/Runtime/Odin/NodeCodeGenerator.asset deleted file mode 100644 index 479a9071..00000000 --- a/Packages/deprecated/Runtime/Odin/NodeCodeGenerator.asset +++ /dev/null @@ -1,49 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 283b83d5022d46b8a345bad7768d520e, type: 3} - m_Name: NodeCodeGenerator - m_EditorClassIdentifier: - _codeTemplate: - id: 0 - _outputDirectory: OdinComponent - _classRenameRegex: (\w+)(?:Node)/Odin$1 - _includedNodes: - - id: 1 - _excludedNodes: - - id: 2 - _fieldCodeGenerators: - - id: 3 - - id: 4 - - id: 5 - - id: 6 - references: - version: 1 - 00000000: - type: {class: OdinNodeComponentTemplate, ns: EntitiesBT.Editor, asm: EntitiesBT.Builder.Odin.Editor} - 00000001: - type: {class: TypeGroupAssemblies, ns: EntitiesBT.Editor, asm: EntitiesBT.Editor} - data: - Assemblies: - - {fileID: 5897886265953266890, guid: c7babe7561eb244059259745ef27b866, type: 3} - 00000002: - type: {class: TypeValidatorWithFullName, ns: EntitiesBT.Editor, asm: EntitiesBT.Editor} - data: - TypeFullNames: - - EntitiesBT.Nodes.ZeroNode - 00000003: - type: {class: BlobStringFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Components.Editor} - 00000004: - type: {class: BlobArrayFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Components.Editor} - 00000005: - type: {class: BlobVariantFieldCodeGeneratorForOdin, ns: EntitiesBT.Editor, asm: EntitiesBT.Builder.Odin.Editor} - 00000006: - type: {class: DefaultNodeDataFieldCodeGenerator, ns: EntitiesBT.Editor, asm: EntitiesBT.Editor} diff --git a/Packages/deprecated/Runtime/Odin/NodeCodeGenerator.asset.meta b/Packages/deprecated/Runtime/Odin/NodeCodeGenerator.asset.meta deleted file mode 100644 index 740a8071..00000000 --- a/Packages/deprecated/Runtime/Odin/NodeCodeGenerator.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 730494123bf6f8a4f8856b050340250d -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinDelayTimer.cs b/Packages/deprecated/Runtime/Odin/OdinDelayTimer.cs deleted file mode 100644 index b9396077..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinDelayTimer.cs +++ /dev/null @@ -1,26 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinDelayTimer : OdinNode - { - [OdinSerializeAttribute, NonSerializedAttribute, HideReferenceObjectPickerAttribute] - public EntitiesBT.Components.Odin.OdinSerializedVariantReaderAndWriter TimerSeconds - = new EntitiesBT.Components.Odin.OdinSerializedVariantReaderAndWriter(); - - protected override void Build(ref EntitiesBT.Nodes.DelayTimerNode data, BlobBuilder builder, ITreeNode[] tree) - { - TimerSeconds.Allocate(ref builder, ref data.TimerSeconds, Self, tree); - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinDelayTimer.cs.meta b/Packages/deprecated/Runtime/Odin/OdinDelayTimer.cs.meta deleted file mode 100644 index 83b65c03..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinDelayTimer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c00479a21ad2c5241b0b7d7df6550199 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinErrorRerunOnce.cs b/Packages/deprecated/Runtime/Odin/OdinErrorRerunOnce.cs deleted file mode 100644 index e0da7162..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinErrorRerunOnce.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinErrorRerunOnce : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.ErrorRerunOnceNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinErrorRerunOnce.cs.meta b/Packages/deprecated/Runtime/Odin/OdinErrorRerunOnce.cs.meta deleted file mode 100644 index c5870dd7..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinErrorRerunOnce.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0cf8abd382119394a8bf8ef75118d7ac -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinFailed.cs b/Packages/deprecated/Runtime/Odin/OdinFailed.cs deleted file mode 100644 index 94f6fa6e..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinFailed.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinFailed : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.FailedNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinFailed.cs.meta b/Packages/deprecated/Runtime/Odin/OdinFailed.cs.meta deleted file mode 100644 index 482e0340..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinFailed.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a7f0591d45df81e4fb35a27c8e92a63c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinHasComponent.cs b/Packages/deprecated/Runtime/Odin/OdinHasComponent.cs deleted file mode 100644 index bef1dff2..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinHasComponent.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinHasComponent : OdinNode - { - public System.UInt64 StableTypeHash; - protected override void Build(ref EntitiesBT.Nodes.HasComponentNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.StableTypeHash = StableTypeHash; - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinHasComponent.cs.meta b/Packages/deprecated/Runtime/Odin/OdinHasComponent.cs.meta deleted file mode 100644 index 755fc6b1..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinHasComponent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 22e919c509ca2e145b73bc047689e86f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinModifyPriority.cs b/Packages/deprecated/Runtime/Odin/OdinModifyPriority.cs deleted file mode 100644 index 3bfa0e92..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinModifyPriority.cs +++ /dev/null @@ -1,27 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinModifyPriority : OdinNode - { - public System.Int32 PrioritySelectorIndex; - public System.Int32 WeightIndex; - public System.Int32 AddWeight; - protected override void Build(ref EntitiesBT.Nodes.ModifyPriorityNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.PrioritySelectorIndex = PrioritySelectorIndex; - data.WeightIndex = WeightIndex; - data.AddWeight = AddWeight; - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinModifyPriority.cs.meta b/Packages/deprecated/Runtime/Odin/OdinModifyPriority.cs.meta deleted file mode 100644 index 79269f61..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinModifyPriority.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 2fb97d6bb3ea72f4dafb094d47e5ed2e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinParallel.cs b/Packages/deprecated/Runtime/Odin/OdinParallel.cs deleted file mode 100644 index 19961c3c..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinParallel.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinParallel : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.ParallelNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinParallel.cs.meta b/Packages/deprecated/Runtime/Odin/OdinParallel.cs.meta deleted file mode 100644 index cb312f81..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinParallel.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0d2953ca1bc4be14cb5d44e45ab334e0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinPrioritySelector.cs b/Packages/deprecated/Runtime/Odin/OdinPrioritySelector.cs deleted file mode 100644 index 17bb52ea..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinPrioritySelector.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinPrioritySelector : OdinNode - { - public System.Int32[] Weights; - protected override void Build(ref EntitiesBT.Nodes.PrioritySelectorNode data, BlobBuilder builder, ITreeNode[] tree) - { - builder.AllocateArray(ref data.Weights, Weights); - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinPrioritySelector.cs.meta b/Packages/deprecated/Runtime/Odin/OdinPrioritySelector.cs.meta deleted file mode 100644 index 1eaadf6e..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinPrioritySelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e41ff3217ed659845ab0f4dc4dd7b352 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinRandomSelector.cs b/Packages/deprecated/Runtime/Odin/OdinRandomSelector.cs deleted file mode 100644 index 2c5aedca..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRandomSelector.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinRandomSelector : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.RandomSelectorNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinRandomSelector.cs.meta b/Packages/deprecated/Runtime/Odin/OdinRandomSelector.cs.meta deleted file mode 100644 index 6c63708e..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRandomSelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 129f97dc31a50024c860022e1d6cb9d0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinRecursiveResetState.cs b/Packages/deprecated/Runtime/Odin/OdinRecursiveResetState.cs deleted file mode 100644 index 28755319..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRecursiveResetState.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinRecursiveResetState : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.RecursiveResetStateNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinRecursiveResetState.cs.meta b/Packages/deprecated/Runtime/Odin/OdinRecursiveResetState.cs.meta deleted file mode 100644 index 0c23486d..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRecursiveResetState.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c0c005a8ee1369a4fb2a10182ad11ff6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinRepeatDuration.cs b/Packages/deprecated/Runtime/Odin/OdinRepeatDuration.cs deleted file mode 100644 index 1d7b9ed3..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRepeatDuration.cs +++ /dev/null @@ -1,25 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinRepeatDuration : OdinNode - { - public System.Single CountdownSeconds; - public EntitiesBT.Core.NodeState BreakStates; - protected override void Build(ref EntitiesBT.Nodes.RepeatDurationNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.CountdownSeconds = CountdownSeconds; - data.BreakStates = BreakStates; - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinRepeatDuration.cs.meta b/Packages/deprecated/Runtime/Odin/OdinRepeatDuration.cs.meta deleted file mode 100644 index 173c8aa2..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRepeatDuration.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c626a747bb186c442b9dd3d52c741aa7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinRepeatForever.cs b/Packages/deprecated/Runtime/Odin/OdinRepeatForever.cs deleted file mode 100644 index 356fee5a..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRepeatForever.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinRepeatForever : OdinNode - { - public EntitiesBT.Core.NodeState BreakStates; - protected override void Build(ref EntitiesBT.Nodes.RepeatForeverNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.BreakStates = BreakStates; - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinRepeatForever.cs.meta b/Packages/deprecated/Runtime/Odin/OdinRepeatForever.cs.meta deleted file mode 100644 index f9f1b8b8..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRepeatForever.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0121466f302f913458b741940ea8074f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinRepeatTimes.cs b/Packages/deprecated/Runtime/Odin/OdinRepeatTimes.cs deleted file mode 100644 index ea2384aa..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRepeatTimes.cs +++ /dev/null @@ -1,25 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinRepeatTimes : OdinNode - { - public System.Int32 TickTimes; - public EntitiesBT.Core.NodeState BreakStates; - protected override void Build(ref EntitiesBT.Nodes.RepeatTimesNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.TickTimes = TickTimes; - data.BreakStates = BreakStates; - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinRepeatTimes.cs.meta b/Packages/deprecated/Runtime/Odin/OdinRepeatTimes.cs.meta deleted file mode 100644 index f56d16ea..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRepeatTimes.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: da2bf8a2319bbb948bbb7e05dec26afa -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinResetBranch.cs b/Packages/deprecated/Runtime/Odin/OdinResetBranch.cs deleted file mode 100644 index b6759564..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinResetBranch.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinResetBranch : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.ResetBranchNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinResetBranch.cs.meta b/Packages/deprecated/Runtime/Odin/OdinResetBranch.cs.meta deleted file mode 100644 index 2cfe6aad..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinResetBranch.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3c90e8bec93d77a4486829f5a52d2538 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinRunOnMainThread.cs b/Packages/deprecated/Runtime/Odin/OdinRunOnMainThread.cs deleted file mode 100644 index ce71a1c9..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRunOnMainThread.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinRunOnMainThread : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.RunOnMainThreadNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinRunOnMainThread.cs.meta b/Packages/deprecated/Runtime/Odin/OdinRunOnMainThread.cs.meta deleted file mode 100644 index c8b426b5..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRunOnMainThread.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: bfc43b68f8dc3344ba9829e1718bbdba -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinRunning.cs b/Packages/deprecated/Runtime/Odin/OdinRunning.cs deleted file mode 100644 index 7b0de21a..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRunning.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinRunning : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.RunningNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinRunning.cs.meta b/Packages/deprecated/Runtime/Odin/OdinRunning.cs.meta deleted file mode 100644 index f31e22f6..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinRunning.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f72982c3b9e3cfe478c863711d695e52 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinSelector.cs b/Packages/deprecated/Runtime/Odin/OdinSelector.cs deleted file mode 100644 index e2a8733e..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinSelector.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinSelector : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.SelectorNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinSelector.cs.meta b/Packages/deprecated/Runtime/Odin/OdinSelector.cs.meta deleted file mode 100644 index cc1807ec..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinSelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 15b10312a3261204282b777c0daa9cf1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinSequence.cs b/Packages/deprecated/Runtime/Odin/OdinSequence.cs deleted file mode 100644 index cb1799ce..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinSequence.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinSequence : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.SequenceNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinSequence.cs.meta b/Packages/deprecated/Runtime/Odin/OdinSequence.cs.meta deleted file mode 100644 index 0d828109..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinSequence.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 285a0dc7a5c059240a1cb4c3d029ce9b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinStateMap.cs b/Packages/deprecated/Runtime/Odin/OdinStateMap.cs deleted file mode 100644 index a535619d..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinStateMap.cs +++ /dev/null @@ -1,29 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinStateMap : OdinNode - { - public EntitiesBT.Core.NodeState MapSuccess; - public EntitiesBT.Core.NodeState MapFailure; - public EntitiesBT.Core.NodeState MapRunning; - public EntitiesBT.Core.NodeState MapError; - protected override void Build(ref EntitiesBT.Nodes.StateMapNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.MapSuccess = MapSuccess; - data.MapFailure = MapFailure; - data.MapRunning = MapRunning; - data.MapError = MapError; - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinStateMap.cs.meta b/Packages/deprecated/Runtime/Odin/OdinStateMap.cs.meta deleted file mode 100644 index ad9711d9..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinStateMap.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 293c07b2fc7b2b94ea0a5a41df7bf140 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinStateReverse.cs b/Packages/deprecated/Runtime/Odin/OdinStateReverse.cs deleted file mode 100644 index 9d5f5666..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinStateReverse.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinStateReverse : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.StateReverseNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinStateReverse.cs.meta b/Packages/deprecated/Runtime/Odin/OdinStateReverse.cs.meta deleted file mode 100644 index 2a538e0b..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinStateReverse.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0eab781228726ea4293e9e0b0271b453 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinSuccess.cs b/Packages/deprecated/Runtime/Odin/OdinSuccess.cs deleted file mode 100644 index 51504a02..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinSuccess.cs +++ /dev/null @@ -1,23 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinSuccess : OdinNode - { - - protected override void Build(ref EntitiesBT.Nodes.SuccessNode data, BlobBuilder builder, ITreeNode[] tree) - { - - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinSuccess.cs.meta b/Packages/deprecated/Runtime/Odin/OdinSuccess.cs.meta deleted file mode 100644 index 4817baf0..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinSuccess.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3cde09769b6a70a4b8cad9868320d762 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinTimer.cs b/Packages/deprecated/Runtime/Odin/OdinTimer.cs deleted file mode 100644 index 13faffed..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinTimer.cs +++ /dev/null @@ -1,28 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinTimer : OdinNode - { - [OdinSerializeAttribute, NonSerializedAttribute, HideReferenceObjectPickerAttribute] - public EntitiesBT.Components.Odin.OdinSerializedVariantReaderAndWriter CountdownSeconds - = new EntitiesBT.Components.Odin.OdinSerializedVariantReaderAndWriter(); - - public EntitiesBT.Core.NodeState BreakReturnState; - protected override void Build(ref EntitiesBT.Nodes.TimerNode data, BlobBuilder builder, ITreeNode[] tree) - { - CountdownSeconds.Allocate(ref builder, ref data.CountdownSeconds, Self, tree); - data.BreakReturnState = BreakReturnState; - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinTimer.cs.meta b/Packages/deprecated/Runtime/Odin/OdinTimer.cs.meta deleted file mode 100644 index ae7e4ddc..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinTimer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cc5824aa03705a847a8c5a95812fc4c0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/Runtime/Odin/OdinWeightRandomSelector.cs b/Packages/deprecated/Runtime/Odin/OdinWeightRandomSelector.cs deleted file mode 100644 index 42bcfe1f..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinWeightRandomSelector.cs +++ /dev/null @@ -1,25 +0,0 @@ -// automatically generate from `OdinNodeComponentTemplate.cs` -#if ODIN_INSPECTOR - -using EntitiesBT.Core; -using Unity.Entities; -using Sirenix.Serialization; -using System; -using EntitiesBT.Variant; -using Sirenix.OdinInspector; - -namespace EntitiesBT.Components.Odin -{ - public class OdinWeightRandomSelector : OdinNode - { - public System.Single Sum; - public System.Single[] Weights; - protected override void Build(ref EntitiesBT.Nodes.WeightRandomSelectorNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.Sum = Sum; - builder.AllocateArray(ref data.Weights, Weights); - } - } -} - -#endif diff --git a/Packages/deprecated/Runtime/Odin/OdinWeightRandomSelector.cs.meta b/Packages/deprecated/Runtime/Odin/OdinWeightRandomSelector.cs.meta deleted file mode 100644 index 37995743..00000000 --- a/Packages/deprecated/Runtime/Odin/OdinWeightRandomSelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cdafc11768a5e884ba5499afaa325fda -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/deprecated/package.json b/Packages/deprecated/package.json deleted file mode 100644 index 4b61332e..00000000 --- a/Packages/deprecated/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "com.quabug.entities-bt.deprecated", - "version": "1.3.0", - "unity": "2020.2", - "displayName": "EntitiesBT - Deprecated Features", - "dependencies": { - "com.quabug.entities-bt.essential": "1.3.0" - } -} \ No newline at end of file diff --git a/Packages/deprecated/package.json.meta b/Packages/deprecated/package.json.meta deleted file mode 100644 index adce1fcb..00000000 --- a/Packages/deprecated/package.json.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 850a2d287b82f1f4daa6d36bada41de1 -PackageManifestImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From ce47d6620c7ae6c767edef5fe86d89242f20f0f9 Mon Sep 17 00:00:00 2001 From: Quan Yuan Date: Thu, 7 Apr 2022 23:00:54 +0800 Subject: [PATCH 05/28] update behavior component builder --- Assets/Tests/NodeBlob.meta | 8 + .../NodeBlob/Entities.Tests.NodeBlob.asmdef | 24 +++ .../Entities.Tests.NodeBlob.asmdef.meta | 7 + Assets/Tests/NodeBlob/SequenceFailed.prefab | 142 ++++++++++++++++++ .../Tests/NodeBlob/SequenceFailed.prefab.meta | 7 + Assets/Tests/NodeBlob/TestNodeBlob.cs | 28 ++++ Assets/Tests/NodeBlob/TestNodeBlob.cs.meta | 11 ++ Assets/Tests/Runtime/BTTestNodeA.cs | 11 +- Assets/Tests/Runtime/BTTestNodeB.cs | 11 +- Assets/Tests/Runtime/BTTestNodeState.cs | 13 +- .../Runtime/BTDynamicNode.cs | 6 +- Packages/builder.component/Runtime/BTNode.cs | 34 ++--- .../builder.component/Runtime/NodeAsset.cs | 5 +- .../Blob/Runtime/Builder/DynamicBuilders.cs | 11 +- .../EntitiesExtension/BlobAssetReference.cs | 34 ++++- .../essential/Runtime/Entities/NodeBlob.cs | 10 +- .../Runtime/Entities/NodeBlobExtensions.cs | 4 +- 17 files changed, 319 insertions(+), 47 deletions(-) create mode 100644 Assets/Tests/NodeBlob.meta create mode 100644 Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef create mode 100644 Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef.meta create mode 100644 Assets/Tests/NodeBlob/SequenceFailed.prefab create mode 100644 Assets/Tests/NodeBlob/SequenceFailed.prefab.meta create mode 100644 Assets/Tests/NodeBlob/TestNodeBlob.cs create mode 100644 Assets/Tests/NodeBlob/TestNodeBlob.cs.meta diff --git a/Assets/Tests/NodeBlob.meta b/Assets/Tests/NodeBlob.meta new file mode 100644 index 00000000..4bdd95d7 --- /dev/null +++ b/Assets/Tests/NodeBlob.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: baf6127a6e52d3846afbb7582c78e3a6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef b/Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef new file mode 100644 index 00000000..7d50b5ab --- /dev/null +++ b/Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef @@ -0,0 +1,24 @@ +{ + "name": "Entities.Tests.NodeBlob", + "rootNamespace": "", + "references": [ + "UnityEngine.TestRunner", + "UnityEditor.TestRunner", + "EntitiesBT.Runtime", + "BlobBuilder", + "Nuwa.Blob" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], + "autoReferenced": false, + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef.meta b/Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef.meta new file mode 100644 index 00000000..d1d8cdb4 --- /dev/null +++ b/Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7546d3cf84d0c3c428edf6b5823057bc +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/NodeBlob/SequenceFailed.prefab b/Assets/Tests/NodeBlob/SequenceFailed.prefab new file mode 100644 index 00000000..bc0adda7 --- /dev/null +++ b/Assets/Tests/NodeBlob/SequenceFailed.prefab @@ -0,0 +1,142 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &1056764932169749602 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4601142927250453780} + m_Layer: 0 + m_Name: SequenceFailed + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4601142927250453780 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1056764932169749602} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 3386550735009188333} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1654928583389780031 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3386550735009188333} + - component: {fileID: 5418904229825080982} + m_Layer: 0 + m_Name: SequenceNode + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3386550735009188333 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1654928583389780031} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 2344647653083408199} + m_Father: {fileID: 4601142927250453780} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &5418904229825080982 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1654928583389780031} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Nodes.SequenceNode, EntitiesBT.Runtime, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Nodes.SequenceNode, EntitiesBT.Runtime, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: [] + Builders: [] + RunOnMainThread: 0 + references: + version: 1 +--- !u!1 &8048039044835892260 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2344647653083408199} + - component: {fileID: 6460210972971744074} + m_Layer: 0 + m_Name: FailedNode + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2344647653083408199 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8048039044835892260} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 3386550735009188333} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6460210972971744074 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8048039044835892260} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Nodes.FailedNode, EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Nodes.FailedNode, EntitiesBT.Runtime, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: [] + Builders: [] + RunOnMainThread: 0 + references: + version: 1 diff --git a/Assets/Tests/NodeBlob/SequenceFailed.prefab.meta b/Assets/Tests/NodeBlob/SequenceFailed.prefab.meta new file mode 100644 index 00000000..b2f64084 --- /dev/null +++ b/Assets/Tests/NodeBlob/SequenceFailed.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: fa80a9fb306ac2141b48b31bf764b0de +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/NodeBlob/TestNodeBlob.cs b/Assets/Tests/NodeBlob/TestNodeBlob.cs new file mode 100644 index 00000000..aec3b49f --- /dev/null +++ b/Assets/Tests/NodeBlob/TestNodeBlob.cs @@ -0,0 +1,28 @@ +using Blob; +using EntitiesBT.Entities; +using NUnit.Framework; +using Nuwa.Blob; +using UnityEditor; + +public class TestNodeBlob +{ + [Test] + public void should_create_node_blob() + { + // AssetDatabase. + // var builder = new DynamicBlobDataBuilder(); + // using var stream = new BlobMemoryStream(); + // new StructBuilder(); + // var blobBuilder = new BlobBuilder(Allocator.Temp, UnsafeUtility.SizeOf(NodeType)); + // try + // { + // var dataPtr = blobBuilder.ConstructRootPtrByType(NodeType); + // Build(dataPtr, blobBuilder, builders); + // return blobBuilder.CreateReferenceByType(NodeType); + // } + // finally + // { + // blobBuilder.Dispose(); + // } + } +} diff --git a/Assets/Tests/NodeBlob/TestNodeBlob.cs.meta b/Assets/Tests/NodeBlob/TestNodeBlob.cs.meta new file mode 100644 index 00000000..190556e6 --- /dev/null +++ b/Assets/Tests/NodeBlob/TestNodeBlob.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e5af0afc3d39c604e810eff2d1aae7d5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Runtime/BTTestNodeA.cs b/Assets/Tests/Runtime/BTTestNodeA.cs index a56c4138..61b9558c 100644 --- a/Assets/Tests/Runtime/BTTestNodeA.cs +++ b/Assets/Tests/Runtime/BTTestNodeA.cs @@ -1,5 +1,6 @@ #if UNITY_EDITOR +using Blob; using EntitiesBT.Components; using EntitiesBT.Core; using Unity.Entities; @@ -33,7 +34,15 @@ public NodeState Tick(int index, ref TNodeBlob blob, ref public class BTTestNodeA : BTNode { public int A; - protected override void Build(ref NodeA data, BlobBuilder _, ITreeNode[] __) => data.A = A; + + protected override void Build( + UnsafeBlobStreamValue value, + IBlobStream stream, + ITreeNode[] tree + ) + { + value.Value.A = A; + } } } diff --git a/Assets/Tests/Runtime/BTTestNodeB.cs b/Assets/Tests/Runtime/BTTestNodeB.cs index 032615cc..18883564 100644 --- a/Assets/Tests/Runtime/BTTestNodeB.cs +++ b/Assets/Tests/Runtime/BTTestNodeB.cs @@ -1,5 +1,6 @@ #if UNITY_EDITOR +using Blob; using EntitiesBT.Components; using EntitiesBT.Core; using Unity.Entities; @@ -36,10 +37,14 @@ public class BTTestNodeB : BTNode public int B; public int BB; - protected override void Build(ref NodeB data, BlobBuilder _, ITreeNode[] __) + protected override void Build( + UnsafeBlobStreamValue value, + IBlobStream stream, + ITreeNode[] tree + ) { - data.B = B; - data.BB = BB; + value.Value.B = B; + value.Value.BB = B; } } } diff --git a/Assets/Tests/Runtime/BTTestNodeState.cs b/Assets/Tests/Runtime/BTTestNodeState.cs index 9ec42d76..e6d72429 100644 --- a/Assets/Tests/Runtime/BTTestNodeState.cs +++ b/Assets/Tests/Runtime/BTTestNodeState.cs @@ -1,5 +1,6 @@ #if UNITY_EDITOR +using Blob; using EntitiesBT.Components; using EntitiesBT.Core; using Unity.Entities; @@ -45,11 +46,15 @@ public class BTTestNodeState : BTNode { public NodeState State; - protected override void Build(ref TestNode data, BlobBuilder builder, ITreeNode[] tree) + protected override void Build( + UnsafeBlobStreamValue value, + IBlobStream stream, + ITreeNode[] tree + ) { - data.State = State; - data.ResetTimes = 0; - data.TickTimes = 0; + value.Value.State = State; + value.Value.ResetTimes = 0; + value.Value.TickTimes = 0; } } } diff --git a/Packages/builder.component/Runtime/BTDynamicNode.cs b/Packages/builder.component/Runtime/BTDynamicNode.cs index 4ad73041..ae5af058 100644 --- a/Packages/builder.component/Runtime/BTDynamicNode.cs +++ b/Packages/builder.component/Runtime/BTDynamicNode.cs @@ -1,7 +1,7 @@ using System; +using Blob; using EntitiesBT.Core; using EntitiesBT.Nodes; -using Unity.Entities; namespace EntitiesBT.Components { @@ -13,9 +13,9 @@ public class BTDynamicNode : BTNode protected override Type NodeType => Type.GetType(NodeData.NodeType ?? "") ?? typeof(ZeroNode); protected override INodeDataBuilder SelfImpl => RunOnMainThread ? new BTVirtualDecorator(this) : (INodeDataBuilder) this; - protected override unsafe void Build(void* dataPtr, BlobBuilder blobBuilder, ITreeNode[] builders) + protected override void Build(IBlobStream stream, ITreeNode[] tree) { - NodeData.Build(blobBuilder, new IntPtr(dataPtr)); + NodeData.Build(stream); } } } \ No newline at end of file diff --git a/Packages/builder.component/Runtime/BTNode.cs b/Packages/builder.component/Runtime/BTNode.cs index 93d31706..bcb81a2b 100644 --- a/Packages/builder.component/Runtime/BTNode.cs +++ b/Packages/builder.component/Runtime/BTNode.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; using System.IO; +using Blob; using EntitiesBT.Core; using EntitiesBT.Entities; using EntitiesBT.Nodes; -using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using UnityEngine; -using Unity.Entities; namespace EntitiesBT.Components { @@ -27,23 +26,19 @@ public abstract class BTNode : MonoBehaviour, INodeDataBuilder protected virtual INodeDataBuilder SelfImpl => this; - public unsafe BlobAssetReference Build(ITreeNode[] builders) + public BlobAssetReference Build(ITreeNode[] builders) { - if (NodeType.IsZeroSizeStruct()) return BlobAssetReference.Null; - var blobBuilder = new BlobBuilder(Allocator.Temp, UnsafeUtility.SizeOf(NodeType)); - try - { - var dataPtr = blobBuilder.ConstructRootPtrByType(NodeType); - Build(dataPtr, blobBuilder, builders); - return blobBuilder.CreateReferenceByType(NodeType); - } - finally - { - blobBuilder.Dispose(); - } + var nodeSize = UnsafeUtility.SizeOf(NodeType); + if (nodeSize == 0) return BlobAssetReference.Null; + + using var stream = new BlobMemoryStream(nodeSize); + stream.EnsureDataSize(nodeSize, 4); + Build(stream, builders); + stream.Length = (int)Blob.Utilities.Align(stream.Length, 16); + return BlobAssetReference.Create(stream.ToArray()); } - protected virtual unsafe void Build(void* dataPtr, BlobBuilder blobBuilder, ITreeNode[] builders) {} + protected virtual void Build(IBlobStream stream, ITreeNode[] builders) {} protected virtual void Reset() => name = GetType().Name; @@ -107,11 +102,12 @@ public abstract class BTNode : BTNode where T : unmanaged, INodeData { protected override Type NodeType => typeof(T); - protected override unsafe void Build(void* dataPtr, BlobBuilder builder, ITreeNode[] tree) + protected virtual void Build(IBlobStream stream, ITreeNode[] builders) { - Build(ref UnsafeUtility.AsRef(dataPtr), builder, tree); + var value = new UnsafeBlobStreamValue(stream, stream.DataPosition); + Build(value, stream, builders); } - protected virtual void Build(ref T data, BlobBuilder builder, ITreeNode[] tree) {} + protected virtual void Build(UnsafeBlobStreamValue value, IBlobStream stream, ITreeNode[] tree) {} } } diff --git a/Packages/builder.component/Runtime/NodeAsset.cs b/Packages/builder.component/Runtime/NodeAsset.cs index fd326b4f..178428b8 100644 --- a/Packages/builder.component/Runtime/NodeAsset.cs +++ b/Packages/builder.component/Runtime/NodeAsset.cs @@ -1,10 +1,13 @@ using System; using System.Linq; using System.Reflection; +using Blob; using EntitiesBT.Core; +using JetBrains.Annotations; using Nuwa; using Nuwa.Blob; using Unity.Entities; +using IBuilder = Nuwa.Blob.IBuilder; namespace EntitiesBT.Components { @@ -17,7 +20,7 @@ public class NodeAsset public DynamicBlobDataBuilder Builder; - public void Build(BlobBuilder builder, IntPtr dataPtr) => throw new NotImplementedException();//Builder.Build(builder, dataPtr); + public void Build([NotNull] IBlobStream stream) => Builder.Build(stream); public IBuilder FindBuilderByPath(string path) { diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs index c85cbaae..c7bc8a86 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs @@ -69,11 +69,6 @@ protected override void BuildImpl(IBlobStream stream) stream.WriteValue(Value); } - public IBuilder GetBuilder(string name) - { - throw new NotImplementedException(); - } - public class Factory : DynamicBuilderFactory where U : DynamicEnumBuilder, new() { public override bool IsValid(Type dataType, FieldInfo fieldInfo) @@ -148,7 +143,7 @@ protected override void BuildImpl(IBlobStream stream) } } - public IBuilder GetBuilder(string name) + public override IBuilder GetBuilder(string name) { var index = Array.IndexOf(FieldNames, name); if (index < 0) throw new ArgumentException($"cannot find field by name {name}"); @@ -208,7 +203,7 @@ protected override void BuildImpl(IBlobStream stream) stream.WritePatchOffset().WriteValue(Value.Length).ToPatchPosition().WriteArray(Value, elementSize, 4); } - public IBuilder GetBuilder(string name) + public override IBuilder GetBuilder(string name) { var index = int.Parse(name); return Value[index]; @@ -234,7 +229,7 @@ protected override void BuildImpl(IBlobStream stream) stream.WritePatchOffset().WriteValue(Value); } - public IBuilder GetBuilder(string name) + public override IBuilder GetBuilder(string name) { if (name != "*") throw new ArgumentException("it must be * to access builder of BlobPtr"); return Value; diff --git a/Packages/essential/EntitiesExtension/BlobAssetReference.cs b/Packages/essential/EntitiesExtension/BlobAssetReference.cs index 3b749fe2..e5eb9587 100644 --- a/Packages/essential/EntitiesExtension/BlobAssetReference.cs +++ b/Packages/essential/EntitiesExtension/BlobAssetReference.cs @@ -1,5 +1,9 @@ using System; +using JetBrains.Annotations; +using Unity.Collections; +using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; +using Unity.Mathematics; namespace EntitiesBT.Core { @@ -39,7 +43,35 @@ internal static BlobAssetReference Create(BlobAssetReferenceData blobData) { return new BlobAssetReference { _data = blobData }; } - + + public static unsafe BlobAssetReference Create(void* ptr, int length) + { + byte* buffer = (byte*) Memory.Unmanaged.Allocate(sizeof(BlobAssetHeader) + length, 16, Allocator.Persistent); + UnsafeUtility.MemCpy(buffer + sizeof(BlobAssetHeader), ptr, length); + + BlobAssetHeader* header = (BlobAssetHeader*) buffer; + *header = new BlobAssetHeader(); + + header->Length = length; + header->Allocator = Allocator.Persistent; + + // @TODO use 64bit hash + header->Hash = math.hash(ptr, length); + + BlobAssetReference blobAssetReference; + blobAssetReference._data.m_Align8Union = 0; + header->ValidationPtr = blobAssetReference._data.m_Ptr = buffer + sizeof(BlobAssetHeader); + return blobAssetReference; + } + + public static unsafe BlobAssetReference Create([NotNull] byte[] data) + { + fixed (byte* ptr = &data[0]) + { + return Create(ptr, data.Length); + } + } + public static BlobAssetReference Null => new BlobAssetReference(); public static unsafe bool operator ==(BlobAssetReference lhs, BlobAssetReference rhs) diff --git a/Packages/essential/Runtime/Entities/NodeBlob.cs b/Packages/essential/Runtime/Entities/NodeBlob.cs index 62635d4d..e18dcb63 100644 --- a/Packages/essential/Runtime/Entities/NodeBlob.cs +++ b/Packages/essential/Runtime/Entities/NodeBlob.cs @@ -16,18 +16,18 @@ public struct NodeBlob public BlobArray EndIndices; public BlobArray Offsets; // count = count of nodes + 1 public BlobArray DefaultDataBlob; - public BlobArray DefaultScopeValues; + public BlobArray DefaultGlobalValues; #endregion #region NonSerialized Data (runtime only) public int RuntimeId; public BlobArray States; // states of each nodes public BlobArray RuntimeDataBlob; // initialize from `DefaultDataBlob` - public BlobArray RuntimeScopeValues; + public BlobArray RuntimeGlobalValues; #endregion public int Count => Types.Length; - public int RuntimeSize => CalculateRuntimeSize(Count, RuntimeDataBlob.Length, RuntimeScopeValues.Length); + public int RuntimeSize => CalculateRuntimeSize(Count, RuntimeDataBlob.Length, RuntimeGlobalValues.Length); [Pure] private static int CalculateDefaultSize(int count, int dataSize, int scopeValuesSize) => @@ -75,10 +75,10 @@ public unsafe IntPtr GetRuntimeDataPtr(int nodeIndex) => (IntPtr) _blob.RuntimeDataBlob.GetUnsafePtr() + _blob.Offsets[nodeIndex]; public unsafe IntPtr GetDefaultScopeValuePtr(int offset) => - IntPtr.Add(new IntPtr(_blob.DefaultScopeValues.GetUnsafePtr()), offset); + IntPtr.Add(new IntPtr(_blob.DefaultGlobalValues.GetUnsafePtr()), offset); public unsafe IntPtr GetRuntimeScopeValuePtr(int offset) => - IntPtr.Add(new IntPtr(_blob.RuntimeScopeValues.GetUnsafePtr()), offset); + IntPtr.Add(new IntPtr(_blob.RuntimeGlobalValues.GetUnsafePtr()), offset); public NodeState GetState(int nodeIndex) => _blob.States[nodeIndex]; public void SetState(int nodeIndex, NodeState state) => _blob.States[nodeIndex] = state; diff --git a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs index dacce302..02723797 100644 --- a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs +++ b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs @@ -90,7 +90,7 @@ [NotNull] this ITreeNode[] nodes } } - var scopeValues = blobBuilder.Allocate(ref blob.DefaultScopeValues, scopeValuesSize); + var scopeValues = blobBuilder.Allocate(ref blob.DefaultGlobalValues, scopeValuesSize); var scopeValuesPtr = new IntPtr(scopeValues.GetUnsafePtr()); var scopeValuesOffset = 0; foreach (var values in scopeValuesList) @@ -99,7 +99,7 @@ [NotNull] this ITreeNode[] nodes UnsafeUtility.MemCpy(destPtr.ToPointer(), values.ValuePtr.ToPointer(), values.Size); scopeValuesOffset += values.Size; } - var runtimeScopeValues = blobBuilder.Allocate(ref blob.RuntimeScopeValues, scopeValuesSize); + var runtimeScopeValues = blobBuilder.Allocate(ref blob.RuntimeGlobalValues, scopeValuesSize); UnsafeUtility.MemCpy(runtimeScopeValues.GetUnsafePtr(), scopeValues.GetUnsafePtr(), scopeValuesSize); var states = blobBuilder.Allocate(ref blob.States, nodes.Length); From 36861fe08a95f7f1579485f8a8039c9888a0690f Mon Sep 17 00:00:00 2001 From: quabug Date: Fri, 8 Apr 2022 13:53:08 +0800 Subject: [PATCH 06/28] `UnsafeBlobStreamValue` --- .../Entity/EntityMoveDynamicVelocity.cs | 26 ++++++++++++++++ .../Entity/EntityMoveDynamicVelocity.cs.meta | 3 ++ Assets/Tests/Runtime/BTTestNodeA.cs | 2 +- Assets/Tests/Runtime/BTTestNodeB.cs | 2 +- Assets/Tests/Runtime/BTTestNodeState.cs | 2 +- .../Runtime/EntitiesBT.Tests.Runtime.asmdef | 3 +- Packages/builder.component/Runtime/BTNode.cs | 1 + .../Runtime/Builder/UnsafeBlobStreamValue.cs | 30 +++++++++++++++++++ .../Builder/UnsafeBlobStreamValue.cs.meta | 3 ++ 9 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 Assets/Samples/Runtime/Entity/EntityMoveDynamicVelocity.cs create mode 100644 Assets/Samples/Runtime/Entity/EntityMoveDynamicVelocity.cs.meta create mode 100644 Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs create mode 100644 Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs.meta diff --git a/Assets/Samples/Runtime/Entity/EntityMoveDynamicVelocity.cs b/Assets/Samples/Runtime/Entity/EntityMoveDynamicVelocity.cs new file mode 100644 index 00000000..c8a49a8f --- /dev/null +++ b/Assets/Samples/Runtime/Entity/EntityMoveDynamicVelocity.cs @@ -0,0 +1,26 @@ +using System; +using EntitiesBT.Core; +using EntitiesBT.Entities; +using EntitiesBT.Variant; +using Unity.Mathematics; +using Unity.Transforms; + +namespace EntitiesBT.Sample +{ + [Serializable] + [BehaviorNode("CBCA71B5-B674-4EFA-B227-83A53CAB37EF")] + public struct EntityMoveDynamicVelocityNode : INodeData + { + public BlobVariantRW Velocity; + + public NodeState Tick(int index, ref TNodeBlob blob, ref TBlackboard bb) + where TNodeBlob : struct, INodeBlob + where TBlackboard : struct, IBlackboard + { + ref var translation = ref bb.GetDataRef(); + var deltaTime = bb.GetData(); + translation.Value += Velocity.Read(index, ref blob, ref bb) * deltaTime.Value; + return NodeState.Running; + } + } +} diff --git a/Assets/Samples/Runtime/Entity/EntityMoveDynamicVelocity.cs.meta b/Assets/Samples/Runtime/Entity/EntityMoveDynamicVelocity.cs.meta new file mode 100644 index 00000000..4eb52402 --- /dev/null +++ b/Assets/Samples/Runtime/Entity/EntityMoveDynamicVelocity.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9edc2c469a0a49bfbaa2ecfaabbf9490 +timeCreated: 1647596228 \ No newline at end of file diff --git a/Assets/Tests/Runtime/BTTestNodeA.cs b/Assets/Tests/Runtime/BTTestNodeA.cs index 61b9558c..6566e808 100644 --- a/Assets/Tests/Runtime/BTTestNodeA.cs +++ b/Assets/Tests/Runtime/BTTestNodeA.cs @@ -3,7 +3,7 @@ using Blob; using EntitiesBT.Components; using EntitiesBT.Core; -using Unity.Entities; +using Nuwa.Blob; using UnityEngine; namespace EntitiesBT.Test diff --git a/Assets/Tests/Runtime/BTTestNodeB.cs b/Assets/Tests/Runtime/BTTestNodeB.cs index 18883564..c44fc806 100644 --- a/Assets/Tests/Runtime/BTTestNodeB.cs +++ b/Assets/Tests/Runtime/BTTestNodeB.cs @@ -3,7 +3,7 @@ using Blob; using EntitiesBT.Components; using EntitiesBT.Core; -using Unity.Entities; +using Nuwa.Blob; using UnityEngine; namespace EntitiesBT.Test diff --git a/Assets/Tests/Runtime/BTTestNodeState.cs b/Assets/Tests/Runtime/BTTestNodeState.cs index e6d72429..a50cb06f 100644 --- a/Assets/Tests/Runtime/BTTestNodeState.cs +++ b/Assets/Tests/Runtime/BTTestNodeState.cs @@ -3,7 +3,7 @@ using Blob; using EntitiesBT.Components; using EntitiesBT.Core; -using Unity.Entities; +using Nuwa.Blob; using UnityEngine.Assertions; namespace EntitiesBT.Test diff --git a/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef b/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef index 55da58c1..d27ff968 100644 --- a/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef +++ b/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef @@ -7,7 +7,8 @@ "GUID:d3630359ae08047918d5cd6cddd51767", "GUID:734d92eba21c94caba915361bd5ac177", "GUID:f320ee23a990e5640812e0939a441a2b", - "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469", + "GUID:6d84eb5386377416e93c122a00485b68" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/builder.component/Runtime/BTNode.cs b/Packages/builder.component/Runtime/BTNode.cs index bcb81a2b..ebd1da6d 100644 --- a/Packages/builder.component/Runtime/BTNode.cs +++ b/Packages/builder.component/Runtime/BTNode.cs @@ -5,6 +5,7 @@ using EntitiesBT.Core; using EntitiesBT.Entities; using EntitiesBT.Nodes; +using Nuwa.Blob; using Unity.Collections.LowLevel.Unsafe; using UnityEngine; diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs new file mode 100644 index 00000000..afbea7e0 --- /dev/null +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs @@ -0,0 +1,30 @@ +using Blob; +using JetBrains.Annotations; +using UnityEngine.Assertions; + +namespace Nuwa.Blob +{ + public unsafe class UnsafeBlobStreamValue where T : unmanaged + { + private readonly IBlobStream _stream; + private readonly int _position; + + public UnsafeBlobStreamValue([NotNull] IBlobStream stream, int position) + { + _stream = stream; + _position = position; + Assert.IsTrue(position < stream.Length); + } + + public ref T Value + { + get + { + fixed (void* ptr = &_stream.Buffer[_position]) + { + return ref *(T*)ptr; + } + } + } + } +} \ No newline at end of file diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs.meta b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs.meta new file mode 100644 index 00000000..132ec029 --- /dev/null +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1d6a46fef2d54a56a4cfe544584cce56 +timeCreated: 1649396128 \ No newline at end of file From bf57eecc013a3bdb1b475a9f2d454b238533232b Mon Sep 17 00:00:00 2001 From: quabug Date: Fri, 8 Apr 2022 14:38:51 +0800 Subject: [PATCH 07/28] rename scope value to global value. --- .../Samples/GameObjectWithoutEntity/BTController.cs | 2 +- Assets/Tests/Editor/BehaviorTreeTestBase.cs | 2 +- Assets/Tests/Editor/TestNodeBlob.cs | 2 +- Packages/builder.component/Runtime/BTNode.cs | 2 +- .../Runtime/BehaviorTreeSourceGameObject.cs | 2 +- Packages/builder.component/Runtime/GlobalValues.cs | 2 +- .../Runtime/BehaviorNodeComponent.cs | 2 +- .../Runtime/BehaviorTreeSourceGraphPrefab.cs | 2 +- Packages/essential/Runtime/Components/Utilities.cs | 8 ++++---- ...ScopeValuesBuilder.cs => IGlobalValuesBuilder.cs} | 2 +- ...sBuilder.cs.meta => IGlobalValuesBuilder.cs.meta} | 0 .../essential/Runtime/Entities/NodeBlobExtensions.cs | 12 ++++++------ 12 files changed, 19 insertions(+), 19 deletions(-) rename Packages/essential/Runtime/Core/{IScopeValuesBuilder.cs => IGlobalValuesBuilder.cs} (85%) rename Packages/essential/Runtime/Core/{IScopeValuesBuilder.cs.meta => IGlobalValuesBuilder.cs.meta} (100%) diff --git a/Assets/Samples/GameObjectWithoutEntity/BTController.cs b/Assets/Samples/GameObjectWithoutEntity/BTController.cs index 7f12af88..ad73d273 100644 --- a/Assets/Samples/GameObjectWithoutEntity/BTController.cs +++ b/Assets/Samples/GameObjectWithoutEntity/BTController.cs @@ -13,7 +13,7 @@ public class BTController : MonoBehaviour private void Awake() { - _nodeBlobRef = new NodeBlobRef(RootNode.ToBlob(RootNode.FindScopeValuesList())); + _nodeBlobRef = new NodeBlobRef(RootNode.ToBlob(RootNode.FindGlobalValuesList())); Destroy(RootNode.gameObject); _bb = new GameObjectBlackboard(gameObject); VirtualMachine.Reset(ref _nodeBlobRef, ref _bb); diff --git a/Assets/Tests/Editor/BehaviorTreeTestBase.cs b/Assets/Tests/Editor/BehaviorTreeTestBase.cs index 3346c942..8e1ed9c2 100644 --- a/Assets/Tests/Editor/BehaviorTreeTestBase.cs +++ b/Assets/Tests/Editor/BehaviorTreeTestBase.cs @@ -78,7 +78,7 @@ public void Setup() protected NodeBlobRef CreateBlob(string tree) { var root = CreateBTNode(tree).GetComponent(); - var blob = root.ToBlob(root.FindScopeValuesList()); + var blob = root.ToBlob(root.FindGlobalValuesList()); return new NodeBlobRef(blob); } diff --git a/Assets/Tests/Editor/TestNodeBlob.cs b/Assets/Tests/Editor/TestNodeBlob.cs index bc569874..0b153c1a 100644 --- a/Assets/Tests/Editor/TestNodeBlob.cs +++ b/Assets/Tests/Editor/TestNodeBlob.cs @@ -102,7 +102,7 @@ public unsafe void should_generate_blob_from_nodes() { var root = CreateBTNode("!seq>yes|no|b:1,1|a:111|run"); var rootNode = root.GetComponent(); - var blobRef = rootNode.ToBlob(rootNode.FindScopeValuesList()); + var blobRef = rootNode.ToBlob(rootNode.FindGlobalValuesList()); Assert.True(blobRef.IsCreated); Assert.AreEqual(blobRef.Value.Count, 6); diff --git a/Packages/builder.component/Runtime/BTNode.cs b/Packages/builder.component/Runtime/BTNode.cs index ebd1da6d..d40b3c2b 100644 --- a/Packages/builder.component/Runtime/BTNode.cs +++ b/Packages/builder.component/Runtime/BTNode.cs @@ -93,7 +93,7 @@ public void SaveToFile() path = string.IsNullOrEmpty(path) ? Application.dataPath : Path.GetDirectoryName(path); path = UnityEditor.EditorUtility.SaveFilePanel("save path", path, name, "bytes"); if (string.IsNullOrEmpty(path)) return; - using (var file = new FileStream(path, FileMode.OpenOrCreate)) this.SaveToStream(this.FindScopeValuesList(), file); + using (var file = new FileStream(path, FileMode.OpenOrCreate)) this.SaveToStream(this.FindGlobalValuesList(), file); UnityEditor.AssetDatabase.Refresh(); } #endif diff --git a/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs b/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs index 208137c0..f2ffe2fd 100644 --- a/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs +++ b/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs @@ -14,7 +14,7 @@ public BlobAssetReference GetBlobAsset() var isPrefab = Root.gameObject.IsPrefab(); if (!isPrefab && !Root.GetComponent()) Root.gameObject.AddComponent(); - var blob = Root.ToBlob(Root.FindScopeValuesList()); + var blob = Root.ToBlob(Root.FindGlobalValuesList()); if (!isPrefab && AutoDestroy) UnityEngine.Object.Destroy(Root.gameObject); return blob; } diff --git a/Packages/builder.component/Runtime/GlobalValues.cs b/Packages/builder.component/Runtime/GlobalValues.cs index 9b68ebec..60067750 100644 --- a/Packages/builder.component/Runtime/GlobalValues.cs +++ b/Packages/builder.component/Runtime/GlobalValues.cs @@ -5,7 +5,7 @@ namespace EntitiesBT.Variant { - public abstract class GlobalValues : MonoBehaviour, IScopeValuesBuilder + public abstract class GlobalValues : MonoBehaviour, IGlobalValuesBuilder { public int Offset { get; set; } public abstract IntPtr ValuePtr { get; } diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs index 8e322933..f7308bf5 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs @@ -222,7 +222,7 @@ public void SaveToFile() { var path = EditorUtility.SaveFilePanel("save path", Application.dataPath, name, "bytes"); if (string.IsNullOrEmpty(path)) return; - using (var file = new FileStream(path, FileMode.OpenOrCreate)) this.SaveToStream(this.FindScopeValuesList(), file); + using (var file = new FileStream(path, FileMode.OpenOrCreate)) this.SaveToStream(this.FindGlobalValuesList(), file); AssetDatabase.Refresh(); } #endif diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs index 80ba5186..378f2dcd 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs @@ -18,7 +18,7 @@ public BlobAssetReference GetBlobAsset() { Assert.IsTrue(Root.IsPrefab()); Assert.IsNotNull(_behaviorTree); - return _behaviorTree.ToBlob(_behaviorTree.FindScopeValuesList()); + return _behaviorTree.ToBlob(_behaviorTree.FindGlobalValuesList()); } } } \ No newline at end of file diff --git a/Packages/essential/Runtime/Components/Utilities.cs b/Packages/essential/Runtime/Components/Utilities.cs index 47460ea4..46cf64d0 100644 --- a/Packages/essential/Runtime/Components/Utilities.cs +++ b/Packages/essential/Runtime/Components/Utilities.cs @@ -77,19 +77,19 @@ public static IEnumerable AncestorsAndSelf(this GameObject gameObjec } [Pure] - public static IReadOnlyList FindScopeValuesList(this GameObject root) + public static IReadOnlyList FindGlobalValuesList(this GameObject root) { return root.DescendantsAndSelf() - .Select(obj => obj.GetComponent()) + .Select(obj => obj.GetComponent()) .Where(scopeValues => scopeValues != null) .ToArray() ; } [Pure] - public static IReadOnlyList FindScopeValuesList(this Component root) + public static IReadOnlyList FindGlobalValuesList(this Component root) { - return root.gameObject.FindScopeValuesList(); + return root.gameObject.FindGlobalValuesList(); } } } diff --git a/Packages/essential/Runtime/Core/IScopeValuesBuilder.cs b/Packages/essential/Runtime/Core/IGlobalValuesBuilder.cs similarity index 85% rename from Packages/essential/Runtime/Core/IScopeValuesBuilder.cs rename to Packages/essential/Runtime/Core/IGlobalValuesBuilder.cs index 8549167b..90ab2ac0 100644 --- a/Packages/essential/Runtime/Core/IScopeValuesBuilder.cs +++ b/Packages/essential/Runtime/Core/IGlobalValuesBuilder.cs @@ -2,7 +2,7 @@ namespace EntitiesBT.Core { - public interface IScopeValuesBuilder + public interface IGlobalValuesBuilder { IntPtr ValuePtr { get; } int Size { get; } diff --git a/Packages/essential/Runtime/Core/IScopeValuesBuilder.cs.meta b/Packages/essential/Runtime/Core/IGlobalValuesBuilder.cs.meta similarity index 100% rename from Packages/essential/Runtime/Core/IScopeValuesBuilder.cs.meta rename to Packages/essential/Runtime/Core/IGlobalValuesBuilder.cs.meta diff --git a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs index 02723797..a97136ec 100644 --- a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs +++ b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs @@ -17,17 +17,17 @@ public static class NodeBlobExtensions [Pure] public static BlobAssetReference ToBlob( [NotNull] this INodeDataBuilder root - , IReadOnlyList scopeValuesList + , IReadOnlyList globalValuesList , Allocator allocator = Allocator.Persistent ) { - return root.Flatten(builder => builder.Children, builder => builder.Self).ToArray().ToBlob(scopeValuesList, allocator); + return root.Flatten(builder => builder.Children, builder => builder.Self).ToArray().ToBlob(globalValuesList, allocator); } [Pure] public static unsafe BlobAssetReference ToBlob( [NotNull] this ITreeNode[] nodes - , IReadOnlyList scopeValuesList + , IReadOnlyList globalValuesList , Allocator allocator ) { @@ -36,7 +36,7 @@ [NotNull] this ITreeNode[] nodes try { var scopeValuesSize = 0; - foreach (var values in scopeValuesList) + foreach (var values in globalValuesList) { values.Offset = scopeValuesSize; scopeValuesSize += values.Size; @@ -93,7 +93,7 @@ [NotNull] this ITreeNode[] nodes var scopeValues = blobBuilder.Allocate(ref blob.DefaultGlobalValues, scopeValuesSize); var scopeValuesPtr = new IntPtr(scopeValues.GetUnsafePtr()); var scopeValuesOffset = 0; - foreach (var values in scopeValuesList) + foreach (var values in globalValuesList) { var destPtr = scopeValuesPtr + scopeValuesOffset; UnsafeUtility.MemCpy(destPtr.ToPointer(), values.ValuePtr.ToPointer(), values.Size); @@ -124,7 +124,7 @@ [NotNull] this ITreeNode[] nodes public static unsafe void SaveToStream( [NotNull] this INodeDataBuilder builder - , [NotNull] IReadOnlyList scopeValuesList + , [NotNull] IReadOnlyList scopeValuesList , [NotNull] Stream stream ) { From f1b3f3ece7242093db88e1c7f0c0f70270f0e8d9 Mon Sep 17 00:00:00 2001 From: quabug Date: Thu, 14 Apr 2022 19:56:41 +0800 Subject: [PATCH 08/28] replace blob container --- Packages/essential/Runtime/Core/Utilities.cs | 31 ++++------------- .../essential/Runtime/Entities/NodeBlob.cs | 34 +++++++++---------- .../Runtime/Entities/NodeBlobExtensions.cs | 9 +++-- 3 files changed, 28 insertions(+), 46 deletions(-) diff --git a/Packages/essential/Runtime/Core/Utilities.cs b/Packages/essential/Runtime/Core/Utilities.cs index cd4d4b8c..c6441d4a 100644 --- a/Packages/essential/Runtime/Core/Utilities.cs +++ b/Packages/essential/Runtime/Core/Utilities.cs @@ -5,38 +5,21 @@ using System.Linq; using System.Reflection; using System.Threading; +using Blob; using JetBrains.Annotations; -using Unity.Entities; -using Unity.Mathematics; using UnityEngine; namespace EntitiesBT.Core { - public interface ITreeNode + public class TreeNode : ITreeNode where T : unmanaged { - T Value { get; } - ITreeNode Parent { get; } - int Index { get; } - } - - public class TreeNode : ITreeNode - { - public T Value { get; } - public ITreeNode Parent { get; } - public int Index { get; private set; } - - public TreeNode(T value, ITreeNode parent, int index = -1) + public TreeNode(T value, ITreeNode parent) { - Value = value; - Parent = parent; - Index = index; + ValueBuilder = new ValueBuilder(value); } - public TreeNode UpdateIndex(int index) - { - Index = index; - return this; - } + public IBuilder ValueBuilder { get; } + public IReadOnlyList> Children { get; } } public static class Utilities @@ -65,7 +48,7 @@ private static IEnumerable> Flatten(this T node, ChildrenFunc } [Pure] - internal static IEnumerable> Flatten(this T node, ChildrenFunc childrenFunc, SelfFunc selfFunc) + internal static IEnumerable> Flatten(this T node, ChildrenFunc childrenFunc, SelfFunc selfFunc) where T : unmanaged { return selfFunc(node).Flatten(childrenFunc, default, selfFunc).Select((treeNode, i) => (ITreeNode)treeNode.UpdateIndex(i)); } diff --git a/Packages/essential/Runtime/Entities/NodeBlob.cs b/Packages/essential/Runtime/Entities/NodeBlob.cs index e18dcb63..c60d1992 100644 --- a/Packages/essential/Runtime/Entities/NodeBlob.cs +++ b/Packages/essential/Runtime/Entities/NodeBlob.cs @@ -2,8 +2,8 @@ using EntitiesBT.Core; using JetBrains.Annotations; using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; using Unity.Mathematics; +using Blob; namespace EntitiesBT.Entities { @@ -13,9 +13,7 @@ public struct NodeBlob #region Serialized Data public BlobArray Types; - public BlobArray EndIndices; - public BlobArray Offsets; // count = count of nodes + 1 - public BlobArray DefaultDataBlob; + public BlobTreeAny Tree; public BlobArray DefaultGlobalValues; #endregion @@ -29,6 +27,8 @@ public struct NodeBlob public int Count => Types.Length; public int RuntimeSize => CalculateRuntimeSize(Count, RuntimeDataBlob.Length, RuntimeGlobalValues.Length); + public Blob.BlobTreeAny.Node this[int nodeIndex] => Tree[nodeIndex]; + [Pure] private static int CalculateDefaultSize(int count, int dataSize, int scopeValuesSize) => UnsafeUtility.SizeOf() + dataSize + scopeValuesSize + sizeof(int) * count * 3/*Types/EndIndices/Offsets*/; @@ -45,9 +45,9 @@ public static int CalculateSize(int count, int dataSize, int scopeValuesSize) => public readonly struct NodeBlobRef : INodeBlob, IEquatable { private ref NodeBlob _blob => ref BlobRef.Value; - public readonly BlobAssetReference BlobRef; + public readonly Unity.Entities.BlobAssetReference BlobRef; - public NodeBlobRef(BlobAssetReference blobRef) => BlobRef = blobRef; + public NodeBlobRef(Unity.Entities.BlobAssetReference blobRef) => BlobRef = blobRef; public int RuntimeId { @@ -57,28 +57,28 @@ public int RuntimeId public int Count => _blob.Count; public int GetTypeId(int nodeIndex) => _blob.Types[nodeIndex]; - public int GetEndIndex(int nodeIndex) => _blob.EndIndices[nodeIndex]; - public int GetNodeDataSize(int nodeIndex, int count = 1) + public int GetEndIndex(int nodeIndex) => _blob[nodeIndex].EndIndex; + public int GetNodeDataSize(int nodeIndex) => _blob[nodeIndex].Size; + public int GetNodeDataSize(int nodeIndex, int count) { - var currentOffset = _blob.Offsets[nodeIndex]; - var nextOffset = _blob.Offsets[math.min(nodeIndex + count, Count)]; + var currentOffset = _blob[nodeIndex].Offset; + var nextOffset = _blob[math.min(nodeIndex + count, Count)].Offset; return nextOffset - currentOffset; } - public unsafe void ResetStates(int index, int count = 1) => - UnsafeUtility.MemClear((byte*)_blob.States.GetUnsafePtr() + sizeof(NodeState) * index, sizeof(NodeState) * count); + public unsafe void ResetStates(int index, int count) => + UnsafeUtility.MemClear(_blob.States.UnsafePtr + index, sizeof(NodeState) * count); - public unsafe IntPtr GetDefaultDataPtr(int nodeIndex) => - (IntPtr) _blob.DefaultDataBlob.GetUnsafePtr() + _blob.Offsets[nodeIndex]; + public unsafe IntPtr GetDefaultDataPtr(int nodeIndex) => (IntPtr) _blob[nodeIndex].UnsafePtr; public unsafe IntPtr GetRuntimeDataPtr(int nodeIndex) => - (IntPtr) _blob.RuntimeDataBlob.GetUnsafePtr() + _blob.Offsets[nodeIndex]; + (IntPtr) _blob.RuntimeDataBlob.UnsafePtr + _blob[nodeIndex].Offset; public unsafe IntPtr GetDefaultScopeValuePtr(int offset) => - IntPtr.Add(new IntPtr(_blob.DefaultGlobalValues.GetUnsafePtr()), offset); + IntPtr.Add(new IntPtr(_blob.DefaultGlobalValues.UnsafePtr), offset); public unsafe IntPtr GetRuntimeScopeValuePtr(int offset) => - IntPtr.Add(new IntPtr(_blob.RuntimeGlobalValues.GetUnsafePtr()), offset); + IntPtr.Add(new IntPtr(_blob.RuntimeGlobalValues.UnsafePtr), offset); public NodeState GetState(int nodeIndex) => _blob.States[nodeIndex]; public void SetState(int nodeIndex, NodeState state) => _blob.States[nodeIndex] = state; diff --git a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs index a97136ec..aaf8e5e4 100644 --- a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs +++ b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Blob; using EntitiesBT.Core; using JetBrains.Annotations; using Unity.Collections; @@ -54,11 +55,9 @@ [NotNull] this ITreeNode[] nodes var size = NodeBlob.CalculateSize(count: nodes.Length, dataSize: dataSize, scopeValuesSize: scopeValuesSize); - using var blobBuilder = new BlobBuilder(Allocator.Temp, size); - ref var blob = ref blobBuilder.ConstructRoot(); - var types = blobBuilder.Allocate(ref blob.Types, nodes.Length); - var offsets = blobBuilder.Allocate(ref blob.Offsets, nodes.Length + 1); - var unsafeDataPtr = (byte*) blobBuilder.Allocate(ref blob.DefaultDataBlob, dataSize).GetUnsafePtr(); + var types = new int[nodes.Length]; + var offsets = new int[nodes.Length + 1]; + var binary = new byte[dataSize]; var offset = 0; for (var i = 0; i < nodes.Length; i++) { From e045e520687c415b4ac214fa3078e10dac082bf4 Mon Sep 17 00:00:00 2001 From: quabug Date: Sat, 16 Apr 2022 15:12:24 +0800 Subject: [PATCH 09/28] node data builder --- .../builder.component/Runtime/BTDecorator.cs | 46 +++++++-------- .../Runtime/BTDynamicNode.cs | 13 ++--- Packages/builder.component/Runtime/BTNode.cs | 45 +++++---------- .../Runtime/BTVirtualNode.cs | 56 ------------------- .../Runtime/BTVirtualNode.cs.meta | 11 ---- .../essential/Runtime/Components/Utilities.cs | 2 +- .../Runtime/Core/DecoratorBuilder.cs | 14 +++++ .../Runtime/Core/DecoratorBuilder.cs.meta | 3 + .../Runtime/Core/INodeDataBuilder.cs | 8 +-- .../essential/Runtime/Core/NodeDataBuilder.cs | 45 +++++++++++++++ .../Runtime/Core/NodeDataBuilder.cs.meta | 3 + Packages/manifest.json | 2 +- 12 files changed, 112 insertions(+), 136 deletions(-) delete mode 100644 Packages/builder.component/Runtime/BTVirtualNode.cs delete mode 100644 Packages/builder.component/Runtime/BTVirtualNode.cs.meta create mode 100644 Packages/essential/Runtime/Core/DecoratorBuilder.cs create mode 100644 Packages/essential/Runtime/Core/DecoratorBuilder.cs.meta create mode 100644 Packages/essential/Runtime/Core/NodeDataBuilder.cs create mode 100644 Packages/essential/Runtime/Core/NodeDataBuilder.cs.meta diff --git a/Packages/builder.component/Runtime/BTDecorator.cs b/Packages/builder.component/Runtime/BTDecorator.cs index 393e2b02..942a6c27 100644 --- a/Packages/builder.component/Runtime/BTDecorator.cs +++ b/Packages/builder.component/Runtime/BTDecorator.cs @@ -1,23 +1,23 @@ -using System.Collections.Generic; -using EntitiesBT.Core; -using EntitiesBT.Nodes; -using Unity.Assertions; -using UnityEngine; - -namespace EntitiesBT.Components -{ - public class BTDecorator : BTNode where T : unmanaged, INodeData - { - [SerializeField] private bool _shouldRerunOnceOnError = true; - - protected override void OnValidate() - { - Assert.AreEqual(BehaviorNodeType.Decorate, BehaviorNodeType); - } - - public override IEnumerable Children => _shouldRerunOnceOnError - ? new BTVirtualDecorator(base.Children).Yield() - : base.Children - ; - } -} +// using System.Collections.Generic; +// using EntitiesBT.Core; +// using EntitiesBT.Nodes; +// using Unity.Assertions; +// using UnityEngine; +// +// namespace EntitiesBT.Components +// { +// public class BTDecorator : BTNode where T : unmanaged, INodeData +// { +// [SerializeField] private bool _shouldRerunOnceOnError = true; +// +// protected override void OnValidate() +// { +// Assert.AreEqual(BehaviorNodeType.Decorate, BehaviorNodeType); +// } +// +// public override IEnumerable Children => _shouldRerunOnceOnError +// ? new BTVirtualDecorator(base.Children).Yield() +// : base.Children +// ; +// } +// } diff --git a/Packages/builder.component/Runtime/BTDynamicNode.cs b/Packages/builder.component/Runtime/BTDynamicNode.cs index ae5af058..eeb170a5 100644 --- a/Packages/builder.component/Runtime/BTDynamicNode.cs +++ b/Packages/builder.component/Runtime/BTDynamicNode.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Blob; using EntitiesBT.Core; using EntitiesBT.Nodes; @@ -9,13 +10,11 @@ public class BTDynamicNode : BTNode { public NodeAsset NodeData; public bool RunOnMainThread = false; - protected override Type NodeType => Type.GetType(NodeData.NodeType ?? "") ?? typeof(ZeroNode); - protected override INodeDataBuilder SelfImpl => RunOnMainThread ? new BTVirtualDecorator(this) : (INodeDataBuilder) this; - - protected override void Build(IBlobStream stream, ITreeNode[] tree) - { - NodeData.Build(stream); - } + public override IBuilder ValueBuilder => NodeData.Builder; + public override IReadOnlyList Children => RunOnMainThread ? + new[] { new DecoratorBuilder(new NodeDataBuilder(NodeType, ValueBuilder, base.Children)) } : + base.Children + ; } } \ No newline at end of file diff --git a/Packages/builder.component/Runtime/BTNode.cs b/Packages/builder.component/Runtime/BTNode.cs index d40b3c2b..aaa49fd6 100644 --- a/Packages/builder.component/Runtime/BTNode.cs +++ b/Packages/builder.component/Runtime/BTNode.cs @@ -1,16 +1,27 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Blob; using EntitiesBT.Core; using EntitiesBT.Entities; using EntitiesBT.Nodes; -using Nuwa.Blob; -using Unity.Collections.LowLevel.Unsafe; using UnityEngine; +using IBuilder = Blob.IBuilder; namespace EntitiesBT.Components { + public class ComponentTreeNode : ITreeNode + { + public IBuilder ValueBuilder { get; } + public IReadOnlyList Children { get; } + + public ComponentTreeNode(GameObject gameObject) + { + Children = gameObject.Children().Select(builder => builder.Node).ToArray(); + } + } + [DisallowMultipleComponent, ExecuteInEditMode] public abstract class BTNode : MonoBehaviour, INodeDataBuilder { @@ -19,27 +30,7 @@ public abstract class BTNode : MonoBehaviour, INodeDataBuilder protected virtual Type NodeType { get; } = typeof(ZeroNode); public int NodeIndex { get; set; } = 0; - public virtual IEnumerable Children => this.Children(); - public virtual object GetPreviewValue(string path) => throw new NotImplementedException(); - public virtual void SetPreviewValue(string path, object value) => throw new NotImplementedException(); - - public INodeDataBuilder Self => gameObject.activeSelf ? SelfImpl : null; - - protected virtual INodeDataBuilder SelfImpl => this; - - public BlobAssetReference Build(ITreeNode[] builders) - { - var nodeSize = UnsafeUtility.SizeOf(NodeType); - if (nodeSize == 0) return BlobAssetReference.Null; - - using var stream = new BlobMemoryStream(nodeSize); - stream.EnsureDataSize(nodeSize, 4); - Build(stream, builders); - stream.Length = (int)Blob.Utilities.Align(stream.Length, 16); - return BlobAssetReference.Create(stream.ToArray()); - } - - protected virtual void Build(IBlobStream stream, ITreeNode[] builders) {} + public ITreeNode Node { get; } protected virtual void Reset() => name = GetType().Name; @@ -102,13 +93,5 @@ public void SaveToFile() public abstract class BTNode : BTNode where T : unmanaged, INodeData { protected override Type NodeType => typeof(T); - - protected virtual void Build(IBlobStream stream, ITreeNode[] builders) - { - var value = new UnsafeBlobStreamValue(stream, stream.DataPosition); - Build(value, stream, builders); - } - - protected virtual void Build(UnsafeBlobStreamValue value, IBlobStream stream, ITreeNode[] tree) {} } } diff --git a/Packages/builder.component/Runtime/BTVirtualNode.cs b/Packages/builder.component/Runtime/BTVirtualNode.cs deleted file mode 100644 index ec3bba06..00000000 --- a/Packages/builder.component/Runtime/BTVirtualNode.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Collections.Generic; -using EntitiesBT.Core; -using Unity.Collections; -using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; - -namespace EntitiesBT.Components -{ - public abstract class BTVirtualNode : INodeDataBuilder where T : unmanaged, INodeData - { - public virtual int NodeId => typeof(T).GetBehaviorNodeAttribute().Id; - public virtual INodeDataBuilder Self => this; - public abstract IEnumerable Children { get; } - - public virtual object GetPreviewValue(string path) => throw new System.NotImplementedException(); - public virtual void SetPreviewValue(string path, object value) => throw new System.NotImplementedException(); - - public int NodeIndex { get; set; } = 0; - - public BlobAssetReference Build(ITreeNode[] builders) - { - var minSize = UnsafeUtility.SizeOf(); - if (minSize == 0) return BlobAssetReference.Null; - using (var blobBuilder = new BlobBuilder(Allocator.Temp, minSize)) - { - ref var data = ref blobBuilder.ConstructRoot(); - Build(blobBuilder, ref data, builders); - return blobBuilder.CreateReference(); - } - } - - protected virtual void Build(BlobBuilder blobBuilder, ref T data, ITreeNode[] builders) {} - } - - public class BTVirtualRealSelf : INodeDataBuilder - { - public BTVirtualRealSelf(INodeDataBuilder self) => _self = self; - private readonly INodeDataBuilder _self; - public int NodeId => _self.NodeId; - public BlobAssetReference Build(ITreeNode[] builders) => BlobAssetReference.Null; - public int NodeIndex { get; set; } = 0; - public INodeDataBuilder Self => _self; - public IEnumerable Children => _self.Children; - - public virtual object GetPreviewValue(string path) => throw new System.NotImplementedException(); - public virtual void SetPreviewValue(string path, object value) => throw new System.NotImplementedException(); - } - - public class BTVirtualDecorator : BTVirtualNode where T : unmanaged, INodeData - { - private readonly IEnumerable _children; - public BTVirtualDecorator(INodeDataBuilder child) => _children = new BTVirtualRealSelf(child).Yield(); - public BTVirtualDecorator(IEnumerable children) => _children = children; - public override IEnumerable Children => _children; - } -} diff --git a/Packages/builder.component/Runtime/BTVirtualNode.cs.meta b/Packages/builder.component/Runtime/BTVirtualNode.cs.meta deleted file mode 100644 index 9f76c055..00000000 --- a/Packages/builder.component/Runtime/BTVirtualNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9e2d8829726a85c4dbfe5b0d3f987381 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/essential/Runtime/Components/Utilities.cs b/Packages/essential/Runtime/Components/Utilities.cs index 46cf64d0..70997664 100644 --- a/Packages/essential/Runtime/Components/Utilities.cs +++ b/Packages/essential/Runtime/Components/Utilities.cs @@ -29,7 +29,7 @@ public static IEnumerable Children(this T parent) where T : Component } [Pure] - public static IEnumerable Children(this GameObject parent) where T : Component + public static IEnumerable Children(this GameObject parent) { return Children(parent).Select(child => child.GetComponent()).Where(child => child != null); } diff --git a/Packages/essential/Runtime/Core/DecoratorBuilder.cs b/Packages/essential/Runtime/Core/DecoratorBuilder.cs new file mode 100644 index 00000000..889435cd --- /dev/null +++ b/Packages/essential/Runtime/Core/DecoratorBuilder.cs @@ -0,0 +1,14 @@ +using Blob; +using UnityEngine.Assertions; + +namespace EntitiesBT.Core +{ + public class DecoratorBuilder : NodeDataBuilder where T : unmanaged, INodeData + { + public DecoratorBuilder(INodeDataBuilder child) : this(child, new ValueBuilder()) {} + public DecoratorBuilder(INodeDataBuilder child, IBuilder builder) : base(builder, child.Yield()) + { + Assert.AreEqual(BehaviorNodeType.Decorate, BehaviorNodeType); + } + } +} \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/DecoratorBuilder.cs.meta b/Packages/essential/Runtime/Core/DecoratorBuilder.cs.meta new file mode 100644 index 00000000..01779eca --- /dev/null +++ b/Packages/essential/Runtime/Core/DecoratorBuilder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cf585c30c813403c99cdecccd866260b +timeCreated: 1650021292 \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/INodeDataBuilder.cs b/Packages/essential/Runtime/Core/INodeDataBuilder.cs index 144223ee..e164051e 100644 --- a/Packages/essential/Runtime/Core/INodeDataBuilder.cs +++ b/Packages/essential/Runtime/Core/INodeDataBuilder.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Blob; using JetBrains.Annotations; namespace EntitiesBT.Core @@ -7,13 +8,8 @@ namespace EntitiesBT.Core public interface INodeDataBuilder { int NodeId { get; } - BlobAssetReference Build([NotNull] ITreeNode[] builders); int NodeIndex { get; set; } - INodeDataBuilder Self { get; } - IEnumerable Children { get; } - - object GetPreviewValue(string path); - void SetPreviewValue(string path, object value); + ITreeNode Node { get; } } public static partial class NodeDataBuilderExtension diff --git a/Packages/essential/Runtime/Core/NodeDataBuilder.cs b/Packages/essential/Runtime/Core/NodeDataBuilder.cs new file mode 100644 index 00000000..9093c43b --- /dev/null +++ b/Packages/essential/Runtime/Core/NodeDataBuilder.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Blob; +using JetBrains.Annotations; + +namespace EntitiesBT.Core +{ + public class NodeDataBuilder : INodeDataBuilder + { + public IBuilder ValueBuilder { get; } + public IReadOnlyList Children { get; } + public int NodeId => NodeType.GetBehaviorNodeAttribute().Id; + public int NodeIndex { get; set; } + public Type NodeType { get; } + public BehaviorNodeType BehaviorNodeType => NodeType.GetBehaviorNodeAttribute().Type; + public virtual INodeDataBuilder Self => this; + + public NodeDataBuilder(Type nodeType, [NotNull] IBuilder builder, [NotNull] IEnumerable children) + { + ValueBuilder = builder; + Children = children.ToArray(); + NodeType = nodeType; + } + } + + public class NodeDataBuilder : INodeDataBuilder where T : unmanaged, INodeData + { + public IBuilder ValueBuilder { get; } + public IReadOnlyList Children { get; } + public int NodeId => NodeType.GetBehaviorNodeAttribute().Id; + public int NodeIndex { get; set; } + public Type NodeType => typeof(T); + public BehaviorNodeType BehaviorNodeType => NodeType.GetBehaviorNodeAttribute().Type; + public virtual INodeDataBuilder Self => this; + + public NodeDataBuilder() : this(new ValueBuilder(), Enumerable.Empty()) {} + public NodeDataBuilder(IEnumerable children) : this(new ValueBuilder(), children) {} + public NodeDataBuilder([NotNull] IBuilder builder, [NotNull] IEnumerable children) + { + ValueBuilder = builder; + Children = children.ToArray(); + } + } +} \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/NodeDataBuilder.cs.meta b/Packages/essential/Runtime/Core/NodeDataBuilder.cs.meta new file mode 100644 index 00000000..dc0a62d9 --- /dev/null +++ b/Packages/essential/Runtime/Core/NodeDataBuilder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c804332a12ec4e52b78baccdefcd31da +timeCreated: 1650017610 \ No newline at end of file diff --git a/Packages/manifest.json b/Packages/manifest.json index 7620a4c4..4e357b9b 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -3,7 +3,7 @@ "com.unity.dots.editor": "0.11.0-preview.3", "com.unity.ide.rider": "3.0.7", "com.unity.ide.visualstudio": "2.0.14", - "com.unity.ide.vscode": "1.2.4", + "com.unity.ide.vscode": "1.2.5", "com.unity.inputsystem": "1.3.0", "com.unity.rendering.hybrid": "0.8.0-preview.19", "com.unity.ugui": "1.0.0", From 10861429a3f5565c37210faf1982eeef0aa4ff1b Mon Sep 17 00:00:00 2001 From: quabug Date: Thu, 28 Apr 2022 02:28:50 +0800 Subject: [PATCH 10/28] fix errors --- Assets/Samples/Animator/SetAnimatorTrigger.cs | 2 +- .../GameObjectWithoutEntity/BTController.cs | 2 +- .../Runtime/Entity/IsEntityPositionInBox.cs | 2 +- .../InputSystem/InputActionGuidBuilder.cs | 2 +- Assets/Tests/Editor/BehaviorTreeTestBase.cs | 2 +- Assets/Tests/Editor/TestExpression.cs | 2 - Assets/Tests/Runtime/BTTestNodeA.cs | 10 +- Assets/Tests/Runtime/BTTestNodeB.cs | 10 +- Assets/Tests/Runtime/BTTestNodeState.cs | 12 +- .../Runtime/BTDynamicNode.cs | 8 +- .../Runtime/BehaviorTreeSourceGameObject.cs | 2 +- .../builder.component/Runtime/NodeVariant.cs | 2 +- .../Runtime/BehaviorTreeSourceGraphPrefab.cs | 2 +- .../Runtime/Core/DecoratorBuilder.cs | 14 -- .../essential/Runtime/Core/DecoratorNode.cs | 34 ++++ ...rBuilder.cs.meta => DecoratorNode.cs.meta} | 0 .../Runtime/Core/INodeDataBuilder.cs | 4 +- .../essential/Runtime/Core/NodeDataBuilder.cs | 45 ------ .../Runtime/Core/NodeDataBuilder.cs.meta | 3 - Packages/essential/Runtime/Core/Utilities.cs | 41 ----- .../Entities/ArrayBuilderWithMemoryCopy.cs | 29 ++++ .../ArrayBuilderWithMemoryCopy.cs.meta | 3 + .../essential/Runtime/Entities/NodeBlob.cs | 8 +- .../Runtime/Entities/NodeBlobExtensions.cs | 149 +++++++----------- .../Runtime/Variant/BlobVariantStream.cs | 8 +- 25 files changed, 142 insertions(+), 254 deletions(-) delete mode 100644 Packages/essential/Runtime/Core/DecoratorBuilder.cs create mode 100644 Packages/essential/Runtime/Core/DecoratorNode.cs rename Packages/essential/Runtime/Core/{DecoratorBuilder.cs.meta => DecoratorNode.cs.meta} (100%) delete mode 100644 Packages/essential/Runtime/Core/NodeDataBuilder.cs delete mode 100644 Packages/essential/Runtime/Core/NodeDataBuilder.cs.meta create mode 100644 Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs create mode 100644 Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs.meta diff --git a/Assets/Samples/Animator/SetAnimatorTrigger.cs b/Assets/Samples/Animator/SetAnimatorTrigger.cs index ed5aeb48..47abe379 100644 --- a/Assets/Samples/Animator/SetAnimatorTrigger.cs +++ b/Assets/Samples/Animator/SetAnimatorTrigger.cs @@ -25,7 +25,7 @@ public class AnimatorTriggerNameBuilder : Nuwa.Blob.Builder { public string TriggerName; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) { stream.WriteValue(Animator.StringToHash(TriggerName)); } diff --git a/Assets/Samples/GameObjectWithoutEntity/BTController.cs b/Assets/Samples/GameObjectWithoutEntity/BTController.cs index ad73d273..adfffa63 100644 --- a/Assets/Samples/GameObjectWithoutEntity/BTController.cs +++ b/Assets/Samples/GameObjectWithoutEntity/BTController.cs @@ -13,7 +13,7 @@ public class BTController : MonoBehaviour private void Awake() { - _nodeBlobRef = new NodeBlobRef(RootNode.ToBlob(RootNode.FindGlobalValuesList())); + _nodeBlobRef = new NodeBlobRef(RootNode.Node.ToBlob(RootNode.FindGlobalValuesList())); Destroy(RootNode.gameObject); _bb = new GameObjectBlackboard(gameObject); VirtualMachine.Reset(ref _nodeBlobRef, ref _bb); diff --git a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs index 26404d1e..a6d45ee1 100644 --- a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs +++ b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs @@ -29,7 +29,7 @@ public class ColliderBoundsBuilder : Nuwa.Blob.Builder public Transform Transform; public BoxCollider Box; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) { stream.WriteValue(new Bounds(Box.center + Transform.position, Box.size)); } diff --git a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs index c2245178..bef68268 100644 --- a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs +++ b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs @@ -9,7 +9,7 @@ public class InputActionGuidBuilder : PlainDataBuilder { public InputActionReference InputAction; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) { value.Value = InputAction.action.id; } diff --git a/Assets/Tests/Editor/BehaviorTreeTestBase.cs b/Assets/Tests/Editor/BehaviorTreeTestBase.cs index 8e1ed9c2..c84395b6 100644 --- a/Assets/Tests/Editor/BehaviorTreeTestBase.cs +++ b/Assets/Tests/Editor/BehaviorTreeTestBase.cs @@ -78,7 +78,7 @@ public void Setup() protected NodeBlobRef CreateBlob(string tree) { var root = CreateBTNode(tree).GetComponent(); - var blob = root.ToBlob(root.FindGlobalValuesList()); + var blob = root.Node.ToBlob(root.FindGlobalValuesList()); return new NodeBlobRef(blob); } diff --git a/Assets/Tests/Editor/TestExpression.cs b/Assets/Tests/Editor/TestExpression.cs index eb2f67cd..58a35dd9 100644 --- a/Assets/Tests/Editor/TestExpression.cs +++ b/Assets/Tests/Editor/TestExpression.cs @@ -8,8 +8,6 @@ namespace EntitiesBT.Test { - using TreeNodeBuilder = ITreeNode; - public class TestExpression { private BlobBuilder _builder; diff --git a/Assets/Tests/Runtime/BTTestNodeA.cs b/Assets/Tests/Runtime/BTTestNodeA.cs index 6566e808..0e3d1de3 100644 --- a/Assets/Tests/Runtime/BTTestNodeA.cs +++ b/Assets/Tests/Runtime/BTTestNodeA.cs @@ -34,15 +34,7 @@ public NodeState Tick(int index, ref TNodeBlob blob, ref public class BTTestNodeA : BTNode { public int A; - - protected override void Build( - UnsafeBlobStreamValue value, - IBlobStream stream, - ITreeNode[] tree - ) - { - value.Value.A = A; - } + protected override NodeA _Value => new NodeA { A = A }; } } diff --git a/Assets/Tests/Runtime/BTTestNodeB.cs b/Assets/Tests/Runtime/BTTestNodeB.cs index c44fc806..bb91334f 100644 --- a/Assets/Tests/Runtime/BTTestNodeB.cs +++ b/Assets/Tests/Runtime/BTTestNodeB.cs @@ -37,15 +37,7 @@ public class BTTestNodeB : BTNode public int B; public int BB; - protected override void Build( - UnsafeBlobStreamValue value, - IBlobStream stream, - ITreeNode[] tree - ) - { - value.Value.B = B; - value.Value.BB = B; - } + protected override NodeB _Value => new NodeB { B = B, BB = BB }; } } diff --git a/Assets/Tests/Runtime/BTTestNodeState.cs b/Assets/Tests/Runtime/BTTestNodeState.cs index a50cb06f..6d095bdb 100644 --- a/Assets/Tests/Runtime/BTTestNodeState.cs +++ b/Assets/Tests/Runtime/BTTestNodeState.cs @@ -45,17 +45,7 @@ public NodeState Tick(int index, ref TNodeBlob blob, ref public class BTTestNodeState : BTNode { public NodeState State; - - protected override void Build( - UnsafeBlobStreamValue value, - IBlobStream stream, - ITreeNode[] tree - ) - { - value.Value.State = State; - value.Value.ResetTimes = 0; - value.Value.TickTimes = 0; - } + protected override TestNode _Value => new TestNode { State = State, ResetTimes = 0, TickTimes = 0 }; } } diff --git a/Packages/builder.component/Runtime/BTDynamicNode.cs b/Packages/builder.component/Runtime/BTDynamicNode.cs index eeb170a5..90f3d8bf 100644 --- a/Packages/builder.component/Runtime/BTDynamicNode.cs +++ b/Packages/builder.component/Runtime/BTDynamicNode.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Blob; using EntitiesBT.Core; using EntitiesBT.Nodes; @@ -11,10 +10,7 @@ public class BTDynamicNode : BTNode public NodeAsset NodeData; public bool RunOnMainThread = false; protected override Type NodeType => Type.GetType(NodeData.NodeType ?? "") ?? typeof(ZeroNode); - public override IBuilder ValueBuilder => NodeData.Builder; - public override IReadOnlyList Children => RunOnMainThread ? - new[] { new DecoratorBuilder(new NodeDataBuilder(NodeType, ValueBuilder, base.Children)) } : - base.Children - ; + public override IBuilder BlobStreamBuilder => NodeData.Builder; + public override INodeDataBuilder Node => RunOnMainThread ? new DecoratorNode(base.Node) : base.Node; } } \ No newline at end of file diff --git a/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs b/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs index f2ffe2fd..4a8fa0d5 100644 --- a/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs +++ b/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs @@ -14,7 +14,7 @@ public BlobAssetReference GetBlobAsset() var isPrefab = Root.gameObject.IsPrefab(); if (!isPrefab && !Root.GetComponent()) Root.gameObject.AddComponent(); - var blob = Root.ToBlob(Root.FindGlobalValuesList()); + var blob = Root.Node.ToBlob(Root.FindGlobalValuesList()); if (!isPrefab && AutoDestroy) UnityEngine.Object.Destroy(Root.gameObject); return blob; } diff --git a/Packages/builder.component/Runtime/NodeVariant.cs b/Packages/builder.component/Runtime/NodeVariant.cs index bd51271c..86998d67 100644 --- a/Packages/builder.component/Runtime/NodeVariant.cs +++ b/Packages/builder.component/Runtime/NodeVariant.cs @@ -33,7 +33,7 @@ public class Any : IVariant where T : unmanaged public void Allocate(BlobVariantStream stream) { - Allocate(stream, NodeObject, ValueFieldName); + Allocate(stream, NodeObject.Node, ValueFieldName); } public object PreviewValue => null; diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs index 378f2dcd..204483e6 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs @@ -18,7 +18,7 @@ public BlobAssetReference GetBlobAsset() { Assert.IsTrue(Root.IsPrefab()); Assert.IsNotNull(_behaviorTree); - return _behaviorTree.ToBlob(_behaviorTree.FindGlobalValuesList()); + return _behaviorTree.NodeBuilder.ToBlob(_behaviorTree.FindGlobalValuesList()); } } } \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/DecoratorBuilder.cs b/Packages/essential/Runtime/Core/DecoratorBuilder.cs deleted file mode 100644 index 889435cd..00000000 --- a/Packages/essential/Runtime/Core/DecoratorBuilder.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Blob; -using UnityEngine.Assertions; - -namespace EntitiesBT.Core -{ - public class DecoratorBuilder : NodeDataBuilder where T : unmanaged, INodeData - { - public DecoratorBuilder(INodeDataBuilder child) : this(child, new ValueBuilder()) {} - public DecoratorBuilder(INodeDataBuilder child, IBuilder builder) : base(builder, child.Yield()) - { - Assert.AreEqual(BehaviorNodeType.Decorate, BehaviorNodeType); - } - } -} \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/DecoratorNode.cs b/Packages/essential/Runtime/Core/DecoratorNode.cs new file mode 100644 index 00000000..93f4fb22 --- /dev/null +++ b/Packages/essential/Runtime/Core/DecoratorNode.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using Blob; + +namespace EntitiesBT.Core +{ + public class DecoratorNode : INodeDataBuilder + where TNode : unmanaged, INodeData + where TBuilder : IBuilder, new() + { + private readonly INodeDataBuilder _child; + public TBuilder Builder { get; } + + public int NodeId => NodeType.GetBehaviorNodeAttribute().Id; + public int NodeIndex { get; set; } + public IBuilder BlobStreamBuilder => Builder; + public IEnumerable Children => _child.Yield(); + public Type NodeType => typeof(TNode); + public BehaviorNodeType BehaviorNodeType => NodeType.GetBehaviorNodeAttribute().Type; + + public DecoratorNode(INodeDataBuilder child) : this(child, new TBuilder()) {} + public DecoratorNode(INodeDataBuilder child, TBuilder builder) + { + _child = child; + Builder = builder; + } + } + + public class DecoratorNode : DecoratorNode> where TNode : unmanaged, INodeData + { + public DecoratorNode(INodeDataBuilder child) : base(child) {} + public DecoratorNode(INodeDataBuilder child, ValueBuilder builder) : base(child, builder) {} + } +} \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/DecoratorBuilder.cs.meta b/Packages/essential/Runtime/Core/DecoratorNode.cs.meta similarity index 100% rename from Packages/essential/Runtime/Core/DecoratorBuilder.cs.meta rename to Packages/essential/Runtime/Core/DecoratorNode.cs.meta diff --git a/Packages/essential/Runtime/Core/INodeDataBuilder.cs b/Packages/essential/Runtime/Core/INodeDataBuilder.cs index e164051e..f1e9ac82 100644 --- a/Packages/essential/Runtime/Core/INodeDataBuilder.cs +++ b/Packages/essential/Runtime/Core/INodeDataBuilder.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Blob; -using JetBrains.Annotations; namespace EntitiesBT.Core { @@ -9,7 +8,8 @@ public interface INodeDataBuilder { int NodeId { get; } int NodeIndex { get; set; } - ITreeNode Node { get; } + IBuilder BlobStreamBuilder { get; } + IEnumerable Children { get; } } public static partial class NodeDataBuilderExtension diff --git a/Packages/essential/Runtime/Core/NodeDataBuilder.cs b/Packages/essential/Runtime/Core/NodeDataBuilder.cs deleted file mode 100644 index 9093c43b..00000000 --- a/Packages/essential/Runtime/Core/NodeDataBuilder.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Blob; -using JetBrains.Annotations; - -namespace EntitiesBT.Core -{ - public class NodeDataBuilder : INodeDataBuilder - { - public IBuilder ValueBuilder { get; } - public IReadOnlyList Children { get; } - public int NodeId => NodeType.GetBehaviorNodeAttribute().Id; - public int NodeIndex { get; set; } - public Type NodeType { get; } - public BehaviorNodeType BehaviorNodeType => NodeType.GetBehaviorNodeAttribute().Type; - public virtual INodeDataBuilder Self => this; - - public NodeDataBuilder(Type nodeType, [NotNull] IBuilder builder, [NotNull] IEnumerable children) - { - ValueBuilder = builder; - Children = children.ToArray(); - NodeType = nodeType; - } - } - - public class NodeDataBuilder : INodeDataBuilder where T : unmanaged, INodeData - { - public IBuilder ValueBuilder { get; } - public IReadOnlyList Children { get; } - public int NodeId => NodeType.GetBehaviorNodeAttribute().Id; - public int NodeIndex { get; set; } - public Type NodeType => typeof(T); - public BehaviorNodeType BehaviorNodeType => NodeType.GetBehaviorNodeAttribute().Type; - public virtual INodeDataBuilder Self => this; - - public NodeDataBuilder() : this(new ValueBuilder(), Enumerable.Empty()) {} - public NodeDataBuilder(IEnumerable children) : this(new ValueBuilder(), children) {} - public NodeDataBuilder([NotNull] IBuilder builder, [NotNull] IEnumerable children) - { - ValueBuilder = builder; - Children = children.ToArray(); - } - } -} \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/NodeDataBuilder.cs.meta b/Packages/essential/Runtime/Core/NodeDataBuilder.cs.meta deleted file mode 100644 index dc0a62d9..00000000 --- a/Packages/essential/Runtime/Core/NodeDataBuilder.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: c804332a12ec4e52b78baccdefcd31da -timeCreated: 1650017610 \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/Utilities.cs b/Packages/essential/Runtime/Core/Utilities.cs index c6441d4a..fb0bb28f 100644 --- a/Packages/essential/Runtime/Core/Utilities.cs +++ b/Packages/essential/Runtime/Core/Utilities.cs @@ -11,55 +11,14 @@ namespace EntitiesBT.Core { - public class TreeNode : ITreeNode where T : unmanaged - { - public TreeNode(T value, ITreeNode parent) - { - ValueBuilder = new ValueBuilder(value); - } - - public IBuilder ValueBuilder { get; } - public IReadOnlyList> Children { get; } - } - public static class Utilities { - public delegate IEnumerable ChildrenFunc(T parent); - public delegate T SelfFunc(T self); - [Pure] public static IEnumerable Yield(this T self) { yield return self; } - [Pure] - internal static IEnumerable> Flatten(this T node, ChildrenFunc childrenFunc) - { - return node.Flatten(childrenFunc, default(ITreeNode)).Select((treeNode, i) => (ITreeNode)treeNode.UpdateIndex(i)); - } - - [Pure] - private static IEnumerable> Flatten(this T node, ChildrenFunc childrenFunc, ITreeNode parent) - { - if (node == null) return Enumerable.Empty>(); - var treeNode = new TreeNode(node, parent); - return treeNode.Yield().Concat(childrenFunc(node).SelectMany(child => child.Flatten(childrenFunc, treeNode))); - } - - [Pure] - internal static IEnumerable> Flatten(this T node, ChildrenFunc childrenFunc, SelfFunc selfFunc) where T : unmanaged - { - return selfFunc(node).Flatten(childrenFunc, default, selfFunc).Select((treeNode, i) => (ITreeNode)treeNode.UpdateIndex(i)); - } - - [Pure] - private static IEnumerable> Flatten(this T node, ChildrenFunc childrenFunc, ITreeNode parent, SelfFunc selfFunc) - { - if (node == null) return Enumerable.Empty>(); - var treeNode = new TreeNode(node, parent); - return treeNode.Yield().Concat(childrenFunc(node).SelectMany(child => selfFunc(child).Flatten(childrenFunc, treeNode, selfFunc))); - } // // [Pure] // public static IEnumerable NormalizeUnsafe([NotNull] this IEnumerable weights) diff --git a/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs b/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs new file mode 100644 index 00000000..f8160c80 --- /dev/null +++ b/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs @@ -0,0 +1,29 @@ +using System; + +namespace Blob +{ + public class ArrayBuilderWithMemoryCopy : Builder + where TArray : unmanaged + where TValue : unmanaged + { + private readonly Func<(int position, int length)> _getDataFunc; + public int Alignment { get; set; } = 0; + + public ArrayBuilderWithMemoryCopy(Func<(int position, int length)> getDataFunc) + { + _getDataFunc = getDataFunc; + } + + protected override unsafe void BuildImpl(IBlobStream stream) + { + if (Alignment <= 0) Alignment = Utilities.AlignOf(); + var (position, length) = _getDataFunc(); + var size = (length + sizeof(TValue) - 1) / sizeof(TValue); + stream.EnsureDataSize().WriteArrayMeta(size).ToPatchPosition(); + fixed (void* ptr = &stream.Buffer[position]) + { + stream.Write((byte*)ptr, size, Alignment); + } + } + } +} \ No newline at end of file diff --git a/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs.meta b/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs.meta new file mode 100644 index 00000000..f4c04cb9 --- /dev/null +++ b/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fde8b403616b47a380202e12a902ca61 +timeCreated: 1650802344 \ No newline at end of file diff --git a/Packages/essential/Runtime/Entities/NodeBlob.cs b/Packages/essential/Runtime/Entities/NodeBlob.cs index c60d1992..b8561734 100644 --- a/Packages/essential/Runtime/Entities/NodeBlob.cs +++ b/Packages/essential/Runtime/Entities/NodeBlob.cs @@ -9,11 +9,11 @@ namespace EntitiesBT.Entities { public struct NodeBlob { - public const int VERSION = 4; + public const int VERSION = 5; #region Serialized Data public BlobArray Types; - public BlobTreeAny Tree; + public BlobTreeAny Nodes; public BlobArray DefaultGlobalValues; #endregion @@ -27,12 +27,12 @@ public struct NodeBlob public int Count => Types.Length; public int RuntimeSize => CalculateRuntimeSize(Count, RuntimeDataBlob.Length, RuntimeGlobalValues.Length); - public Blob.BlobTreeAny.Node this[int nodeIndex] => Tree[nodeIndex]; + public BlobTreeAny.Node this[int nodeIndex] => Nodes[nodeIndex]; [Pure] private static int CalculateDefaultSize(int count, int dataSize, int scopeValuesSize) => UnsafeUtility.SizeOf() + dataSize + scopeValuesSize + sizeof(int) * count * 3/*Types/EndIndices/Offsets*/; - + [Pure] public static int CalculateRuntimeSize(int count, int dataSize, int scopeValuesSize) => dataSize/*RuntimeDataBlob*/ + scopeValuesSize/*RuntimeScopeValues*/ + sizeof(NodeState) * count; diff --git a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs index aaf8e5e4..f8c0b51b 100644 --- a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs +++ b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -6,118 +5,76 @@ using EntitiesBT.Core; using JetBrains.Annotations; using Unity.Collections; -using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; using Unity.Entities.Serialization; -using UnityEngine; namespace EntitiesBT.Entities { public static class NodeBlobExtensions { - [Pure] - public static BlobAssetReference ToBlob( - [NotNull] this INodeDataBuilder root - , IReadOnlyList globalValuesList - , Allocator allocator = Allocator.Persistent - ) + private class TreeNode : ITreeNode { - return root.Flatten(builder => builder.Children, builder => builder.Self).ToArray().ToBlob(globalValuesList, allocator); + public IBuilder ValueBuilder { get; } + public IReadOnlyList Children { get; } + + public TreeNode(IBuilder builder, IEnumerable children) + { + ValueBuilder = builder; + Children = children.ToArray(); + } } + private static TreeNode ToTreeNode([NotNull] this INodeDataBuilder nodeBuilder) => + new TreeNode(nodeBuilder.BlobStreamBuilder, nodeBuilder.Children.Select(child => child.ToTreeNode())); + + private static IEnumerable Flatten(this INodeDataBuilder node) => + node.Yield().Concat(node.Children.SelectMany(Flatten)); + [Pure] - public static unsafe BlobAssetReference ToBlob( - [NotNull] this ITreeNode[] nodes - , IReadOnlyList globalValuesList - , Allocator allocator + public static BlobAssetReference ToBlob( + [NotNull] this INodeDataBuilder root + , IEnumerable globalValuesList ) { - var dataSize = 0; - var nodeDataList = new NativeArray(nodes.Length, Allocator.Temp); - try + var builder = new StructBuilder(); + var typeList = new List(); + foreach (var node in root.Flatten()) { - var scopeValuesSize = 0; - foreach (var values in globalValuesList) - { - values.Offset = scopeValuesSize; - scopeValuesSize += values.Size; - } - - for (var i = 0; i < nodes.Length; i++) nodes[i].Value.NodeIndex = i; - - for (var i = 0; i < nodes.Length; i++) - { - var node = nodes[i]; - var data = node.Value.Build(nodes); - nodeDataList[i] = data; - dataSize += data.Length; - } - - var size = NodeBlob.CalculateSize(count: nodes.Length, dataSize: dataSize, scopeValuesSize: scopeValuesSize); - - var types = new int[nodes.Length]; - var offsets = new int[nodes.Length + 1]; - var binary = new byte[dataSize]; - var offset = 0; - for (var i = 0; i < nodes.Length; i++) - { - var node = nodes[i]; - types[i] = node.Value.NodeId; - offsets[i] = offset; - - var nodeDataSize = nodeDataList[i].Length; - var srcPtr = nodeDataList[i].GetUnsafePtr(); - var destPtr = unsafeDataPtr + offset; - UnsafeUtility.MemCpy(destPtr, srcPtr, nodeDataSize); - - offset += nodeDataSize; - } - - offsets[nodes.Length] = offset; - - var endIndices = blobBuilder.Allocate(ref blob.EndIndices, nodes.Length); - // make sure the memory is clear to 0 (even it had been cleared on allocate) - UnsafeUtility.MemSet(endIndices.GetUnsafePtr(), 0, sizeof(int) * endIndices.Length); - for (var i = nodes.Length - 1; i >= 0; i--) - { - var endIndex = i + 1; - var node = nodes[i]; - while (node != null && endIndices[node.Index] == 0) - { - endIndices[node.Index] = endIndex; - node = node.Parent; - } - } - - var scopeValues = blobBuilder.Allocate(ref blob.DefaultGlobalValues, scopeValuesSize); - var scopeValuesPtr = new IntPtr(scopeValues.GetUnsafePtr()); - var scopeValuesOffset = 0; - foreach (var values in globalValuesList) - { - var destPtr = scopeValuesPtr + scopeValuesOffset; - UnsafeUtility.MemCpy(destPtr.ToPointer(), values.ValuePtr.ToPointer(), values.Size); - scopeValuesOffset += values.Size; - } - var runtimeScopeValues = blobBuilder.Allocate(ref blob.RuntimeGlobalValues, scopeValuesSize); - UnsafeUtility.MemCpy(runtimeScopeValues.GetUnsafePtr(), scopeValues.GetUnsafePtr(), scopeValuesSize); - - var states = blobBuilder.Allocate(ref blob.States, nodes.Length); - UnsafeUtility.MemClear(states.GetUnsafePtr(), sizeof(NodeState) * states.Length); - - var runtimeDataBlob = blobBuilder.Allocate(ref blob.RuntimeDataBlob, dataSize); - UnsafeUtility.MemCpy(runtimeDataBlob.GetUnsafePtr(), unsafeDataPtr, dataSize); - - return blobBuilder.CreateBlobAssetReference(allocator); + node.NodeIndex = typeList.Count; + typeList.Add(node.NodeId); } - catch (Exception ex) + builder.SetArray(ref builder.Value.Types, typeList); + var treeRoot = root.ToTreeNode(); + var treeBuilder = builder.SetTreeAny(ref builder.Value.Nodes, treeRoot); + + var globalValueOffset = 0; + using var globalValuesStream = new MemoryStream(); + foreach (var value in globalValuesList) { - Debug.LogException(ex); - throw; + value.Offset = globalValueOffset; + globalValueOffset += value.Size; + Write(globalValuesStream, value); } - finally + builder.SetArray(ref builder.Value.DefaultGlobalValues, globalValuesStream.ToArray()); + builder.SetArray(ref builder.Value.States, new NodeState[typeList.Count]); + builder.SetBuilder( + ref builder.Value.RuntimeDataBlob, + new ArrayBuilderWithMemoryCopy>(() => (treeBuilder.ArrayBuilder.PatchPosition, treeBuilder.ArrayBuilder.PatchSize)) { Alignment = treeBuilder.Alignment } + ); + builder.SetArray(ref builder.Value.RuntimeGlobalValues, globalValuesStream.ToArray()); + return builder.CreateUnityBlobAssetReference(); + + unsafe void Write(MemoryStream stream, IGlobalValuesBuilder value) { - foreach (var data in nodeDataList.Where(data => data.IsCreated)) data.Dispose(); - nodeDataList.Dispose(); +#if UNITY_2021_2_OR_NEWER + stream.Write(new System.ReadOnlySpan(value.ValuePtr.ToPointer(), value.Size)); +#else + for (var i = 0; i < value.Size; i++) + { + var @byte = *(byte*)(value.ValuePtr + i).ToPointer(); + stream.WriteByte(@byte); + } +#endif } } @@ -127,7 +84,7 @@ [NotNull] this INodeDataBuilder builder , [NotNull] Stream stream ) { - using var blob = builder.ToBlob(scopeValuesList, Allocator.Temp); + using var blob = builder.ToBlob(scopeValuesList); using var writer = new MemoryBinaryWriter(); writer.Write(NodeBlob.VERSION); writer.Write(blob); diff --git a/Packages/essential/Runtime/Variant/BlobVariantStream.cs b/Packages/essential/Runtime/Variant/BlobVariantStream.cs index 8d5f9226..a8c66c84 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantStream.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantStream.cs @@ -69,7 +69,7 @@ public class BlobVariantROBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) { _variant?.Allocate(new BlobVariantStream(stream)); } @@ -103,7 +103,7 @@ public class BlobVariantWOBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) { _variant.Allocate(new BlobVariantStream(stream)); } @@ -137,7 +137,7 @@ public class BlobVariantRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override unsafe void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override unsafe void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) { _variant.Allocate(new BlobVariantStream(stream)); value.Value.Writer.VariantId = value.Value.Reader.VariantId; @@ -161,7 +161,7 @@ public class BlobVariantLinkedRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _isLinked ? _readerAndWriter.PreviewValue : _reader.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) { if (_isLinked) { From 1ee12c163dcee0626996817a8cd620762606ef42 Mon Sep 17 00:00:00 2001 From: quabug Date: Thu, 28 Apr 2022 16:11:26 +0800 Subject: [PATCH 11/28] fix save to file --- Assets/Samples/Animator/SetAnimatorTrigger.cs | 2 +- .../InputSystem/InputActionGuidBuilder.cs | 2 +- Assets/Tests/Editor/TestNodeBlob.cs | 143 +++++++++--------- Assets/Tests/Editor/TestUtilities.cs | 31 ---- .../builder.component/Runtime/BTDecorator.cs | 23 --- .../Runtime/BTDecorator.cs.meta | 11 -- Packages/builder.component/Runtime/BTNode.cs | 42 +++-- .../Runtime/BehaviorNodeComponent.cs | 53 +++---- .../Runtime/Builder/UnsafeBlobStreamValue.cs | 30 ---- .../Builder/UnsafeBlobStreamValue.cs.meta | 3 - .../Composites/WeightRandomSelectorNode.cs | 4 +- .../Runtime/Variant/BlobVariantStream.cs | 8 +- Packages/packages-lock.json | 33 ++-- ProjectSettings/ProjectVersion.txt | 4 +- 14 files changed, 147 insertions(+), 242 deletions(-) delete mode 100644 Packages/builder.component/Runtime/BTDecorator.cs delete mode 100644 Packages/builder.component/Runtime/BTDecorator.cs.meta delete mode 100644 Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs delete mode 100644 Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs.meta diff --git a/Assets/Samples/Animator/SetAnimatorTrigger.cs b/Assets/Samples/Animator/SetAnimatorTrigger.cs index 47abe379..ed5aeb48 100644 --- a/Assets/Samples/Animator/SetAnimatorTrigger.cs +++ b/Assets/Samples/Animator/SetAnimatorTrigger.cs @@ -25,7 +25,7 @@ public class AnimatorTriggerNameBuilder : Nuwa.Blob.Builder { public string TriggerName; - protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { stream.WriteValue(Animator.StringToHash(TriggerName)); } diff --git a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs index bef68268..c2245178 100644 --- a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs +++ b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs @@ -9,7 +9,7 @@ public class InputActionGuidBuilder : PlainDataBuilder { public InputActionReference InputAction; - protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { value.Value = InputAction.action.id; } diff --git a/Assets/Tests/Editor/TestNodeBlob.cs b/Assets/Tests/Editor/TestNodeBlob.cs index 0b153c1a..c82bd5e9 100644 --- a/Assets/Tests/Editor/TestNodeBlob.cs +++ b/Assets/Tests/Editor/TestNodeBlob.cs @@ -1,4 +1,5 @@ using System.Linq; +using Blob; using EntitiesBT.Components; using EntitiesBT.Core; using EntitiesBT.Entities; @@ -13,67 +14,72 @@ namespace EntitiesBT.Test { public class TestNodeBlob : BehaviorTreeTestBase { - [Test] - public unsafe void should_able_to_create_and_fetch_data_from_node_blob() - { - Debug.Log($"sizeof NodeA: {sizeof(NodeA)}"); - Debug.Log($"sizeof NodeB: {sizeof(NodeB)}"); - - var size = sizeof(NodeA) + sizeof(NodeB); - using (var blobBuilder = new BlobBuilder(Allocator.Temp)) - { - ref var blob = ref blobBuilder.ConstructRoot(); - - var types = blobBuilder.Allocate(ref blob.Types, 3); - types[0] = 11; - types[1] = 22; - types[2] = 33; - - var endIndices = blobBuilder.Allocate(ref blob.EndIndices, 3); - endIndices[0] = 3; - endIndices[1] = 2; - endIndices[2] = 3; - - var offsets = blobBuilder.Allocate(ref blob.Offsets, 4); - var unsafePtr = (byte*) blobBuilder.Allocate(ref blob.DefaultDataBlob, size).GetUnsafePtr(); - var offset = 0; - offsets[0] = offset; - offsets[1] = offset; - UnsafeUtility.AsRef(unsafePtr + offset).A = 111; - offset += sizeof(NodeA); - offsets[2] = offset; - ref var local2 = ref UnsafeUtility.AsRef(unsafePtr + offset); - local2.B = 222; - local2.BB = 2222; - offset += sizeof(NodeB); - offsets[3] = offset; - var blobRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); - try - { - Assert.IsTrue(blobRef.IsCreated); - Assert.AreEqual(blobRef.Value.DefaultDataBlob.Length, size); - Assert.AreEqual(blobRef.Value.Count, 3); - - Assert.AreEqual(blobRef.Value.EndIndices[0], 3); - Assert.AreEqual(blobRef.Value.EndIndices[1], 2); - Assert.AreEqual(blobRef.Value.EndIndices[2], 3); - - Assert.AreEqual(GetDefaultData(1).A, 111); - ref var b = ref GetDefaultData(2); - Assert.AreEqual(b.B, 222); - Assert.AreEqual(b.BB, 2222); - } - finally - { - if (blobRef.IsCreated) blobRef.Dispose(); - } - - ref T GetDefaultData(int nodeIndex) where T : struct => - ref UnsafeUtility.AsRef((byte*) blobRef.Value.DefaultDataBlob.GetUnsafePtr() + blobRef.Value.Offsets[nodeIndex]); - } - - - } + // [Test] + // public unsafe void should_able_to_create_and_fetch_data_from_node_blob() + // { + // Debug.Log($"sizeof NodeA: {sizeof(NodeA)}"); + // Debug.Log($"sizeof NodeB: {sizeof(NodeB)}"); + // + // var size = sizeof(NodeA) + sizeof(NodeB); + // + // var builder = new StructBuilder(); + // builder.SetArray(ref builder.Value.Types, new[] { 11, 22, 33 }); + // builder.SetTreeAny(ref builder.Value.Nodes, ) + // + // using (var blobBuilder = new BlobBuilder(Allocator.Temp)) + // { + // ref var blob = ref blobBuilder.ConstructRoot(); + // + // var types = blobBuilder.Allocate(ref blob.Types, 3); + // types[0] = 11; + // types[1] = 22; + // types[2] = 33; + // + // var endIndices = blobBuilder.Allocate(ref blob.EndIndices, 3); + // endIndices[0] = 3; + // endIndices[1] = 2; + // endIndices[2] = 3; + // + // var offsets = blobBuilder.Allocate(ref blob.Offsets, 4); + // var unsafePtr = (byte*) blobBuilder.Allocate(ref blob.DefaultDataBlob, size).GetUnsafePtr(); + // var offset = 0; + // offsets[0] = offset; + // offsets[1] = offset; + // UnsafeUtility.AsRef(unsafePtr + offset).A = 111; + // offset += sizeof(NodeA); + // offsets[2] = offset; + // ref var local2 = ref UnsafeUtility.AsRef(unsafePtr + offset); + // local2.B = 222; + // local2.BB = 2222; + // offset += sizeof(NodeB); + // offsets[3] = offset; + // var blobRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); + // try + // { + // Assert.IsTrue(blobRef.IsCreated); + // Assert.AreEqual(blobRef.Value.DefaultDataBlob.Length, size); + // Assert.AreEqual(blobRef.Value.Count, 3); + // + // Assert.AreEqual(blobRef.Value.EndIndices[0], 3); + // Assert.AreEqual(blobRef.Value.EndIndices[1], 2); + // Assert.AreEqual(blobRef.Value.EndIndices[2], 3); + // + // Assert.AreEqual(GetDefaultData(1).A, 111); + // ref var b = ref GetDefaultData(2); + // Assert.AreEqual(b.B, 222); + // Assert.AreEqual(b.BB, 2222); + // } + // finally + // { + // if (blobRef.IsCreated) blobRef.Dispose(); + // } + // + // ref T GetDefaultData(int nodeIndex) where T : struct => + // ref UnsafeUtility.AsRef((byte*) blobRef.Value.DefaultDataBlob.GetUnsafePtr() + blobRef.Value.Offsets[nodeIndex]); + // } + // + // + // } [Test] public void should_create_behavior_tree_objects_from_single_line_of_string() @@ -98,25 +104,24 @@ public void should_create_behavior_tree_objects_from_single_line_of_string() } [Test] - public unsafe void should_generate_blob_from_nodes() + public void should_generate_blob_from_nodes() { var root = CreateBTNode("!seq>yes|no|b:1,1|a:111|run"); var rootNode = root.GetComponent(); - var blobRef = rootNode.ToBlob(rootNode.FindGlobalValuesList()); + var blobRef = rootNode.Node.ToBlob(rootNode.FindGlobalValuesList()); Assert.True(blobRef.IsCreated); Assert.AreEqual(blobRef.Value.Count, 6); var types = new[] {typeof(SequenceNode), typeof(TestNode), typeof(TestNode), typeof(NodeB), typeof(NodeA), typeof(TestNode)}; Assert.AreEqual(blobRef.Value.Types.ToArray(), types.Select(t => t.GetBehaviorNodeAttribute().Id)); - Assert.AreEqual(blobRef.Value.Offsets.ToArray(), new [] { 0, 0, 16, 32, 40, 44, 60 }); - Assert.AreEqual(blobRef.Value.EndIndices.ToArray(), new [] { 6, 2, 3, 4, 5, 6 }); - Assert.AreEqual(blobRef.Value.DefaultDataBlob.Length, 60); + Assert.AreEqual(blobRef.Value.Nodes.Data.Offsets.ToArray(), new [] { 0, 0, 16, 32, 40, 44, 60 }); + Assert.AreEqual(blobRef.Value.Nodes.EndIndices.ToArray(), new [] { 6, 2, 3, 4, 5, 6 }); + Assert.AreEqual(blobRef.Value.Nodes.DataSize, 60); Assert.AreEqual(GetDefaultData(3), new NodeB {B = 1, BB = 1}); Assert.AreEqual(GetDefaultData(4), new NodeA {A = 111}); - - ref T GetDefaultData(int nodeIndex) where T : struct => - ref UnsafeUtility.AsRef((byte*) blobRef.Value.DefaultDataBlob.GetUnsafePtr() + blobRef.Value.Offsets[nodeIndex]); + + ref T GetDefaultData(int nodeIndex) where T : unmanaged => ref blobRef.Value[nodeIndex].GetValue(); } } } diff --git a/Assets/Tests/Editor/TestUtilities.cs b/Assets/Tests/Editor/TestUtilities.cs index 69755f8d..cbc9bc06 100644 --- a/Assets/Tests/Editor/TestUtilities.cs +++ b/Assets/Tests/Editor/TestUtilities.cs @@ -108,21 +108,6 @@ public void should_get_all_children_of_parent_gameobject() } } - [Test] - public void should_get_all_descendants_of_root_gameobject() - { - for (var i = 0; i < _objectNames.Length; i++) - { - var obj = _objects[i]; - var objName = _objectNamesWithoutT[i]; - - var childrenNames = Descendants(objName).ToArray(); - var objectNames = obj.Flatten(Utilities.Children).Select(o => o.Value.name).ToArray(); - - Assert.AreEqual(objectNames, childrenNames); - } - } - [Test] public void should_get_all_children_with_certain_component_of_parent_gameobject() { @@ -137,21 +122,5 @@ public void should_get_all_children_with_certain_component_of_parent_gameobject( Assert.AreEqual(objectNames, childrenNames); } } - - [Test] - public void should_get_all_descendants_with_certain_component_of_root_gameobject() - { - for (var i = 0; i < _objectNames.Length; i++) - { - var obj = _objects[i].GetComponent(); - var objName = _objectNamesWithoutT[i]; - - var childrenNames = _objectNames[i].EndsWith("T") ? DescendantsWithT(objName).ToArray() : new string[0]; - var objectNames = obj == null ? new string[0] : obj.Flatten(Utilities.Children).Select(o => o.Value.name).ToArray(); - - Assert.AreEqual(objectNames, childrenNames); - } - } - } } diff --git a/Packages/builder.component/Runtime/BTDecorator.cs b/Packages/builder.component/Runtime/BTDecorator.cs deleted file mode 100644 index 942a6c27..00000000 --- a/Packages/builder.component/Runtime/BTDecorator.cs +++ /dev/null @@ -1,23 +0,0 @@ -// using System.Collections.Generic; -// using EntitiesBT.Core; -// using EntitiesBT.Nodes; -// using Unity.Assertions; -// using UnityEngine; -// -// namespace EntitiesBT.Components -// { -// public class BTDecorator : BTNode where T : unmanaged, INodeData -// { -// [SerializeField] private bool _shouldRerunOnceOnError = true; -// -// protected override void OnValidate() -// { -// Assert.AreEqual(BehaviorNodeType.Decorate, BehaviorNodeType); -// } -// -// public override IEnumerable Children => _shouldRerunOnceOnError -// ? new BTVirtualDecorator(base.Children).Yield() -// : base.Children -// ; -// } -// } diff --git a/Packages/builder.component/Runtime/BTDecorator.cs.meta b/Packages/builder.component/Runtime/BTDecorator.cs.meta deleted file mode 100644 index 774a013a..00000000 --- a/Packages/builder.component/Runtime/BTDecorator.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b2bfd270d6fe9b945b766d53be360a2c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/builder.component/Runtime/BTNode.cs b/Packages/builder.component/Runtime/BTNode.cs index aaa49fd6..ca5e2ec4 100644 --- a/Packages/builder.component/Runtime/BTNode.cs +++ b/Packages/builder.component/Runtime/BTNode.cs @@ -6,31 +6,41 @@ using EntitiesBT.Core; using EntitiesBT.Entities; using EntitiesBT.Nodes; +using JetBrains.Annotations; using UnityEngine; -using IBuilder = Blob.IBuilder; namespace EntitiesBT.Components { - public class ComponentTreeNode : ITreeNode + [DisallowMultipleComponent, ExecuteInEditMode] + public abstract class BTNode : MonoBehaviour { - public IBuilder ValueBuilder { get; } - public IReadOnlyList Children { get; } - - public ComponentTreeNode(GameObject gameObject) + public class Builder : INodeDataBuilder { - Children = gameObject.Children().Select(builder => builder.Node).ToArray(); + [NotNull] private readonly BTNode _node; + + public int NodeId => _node.NodeId; + + public int NodeIndex { get; set; } = -1; + + public IBuilder BlobStreamBuilder => _node.BlobStreamBuilder; + + public IEnumerable Children => _node.Children() + .Where(child => child.IsValid) + .Select(child => child.Node) + ; + + public Builder([NotNull] BTNode node) + { + _node = node; + } } - } - [DisallowMultipleComponent, ExecuteInEditMode] - public abstract class BTNode : MonoBehaviour, INodeDataBuilder - { public BehaviorNodeType BehaviorNodeType => NodeType.GetBehaviorNodeAttribute().Type; public int NodeId => NodeType.GetBehaviorNodeAttribute().Id; protected virtual Type NodeType { get; } = typeof(ZeroNode); - public int NodeIndex { get; set; } = 0; - - public ITreeNode Node { get; } + public abstract IBuilder BlobStreamBuilder { get; } + public virtual bool IsValid => gameObject.activeInHierarchy; + public virtual INodeDataBuilder Node => new Builder(this); protected virtual void Reset() => name = GetType().Name; @@ -84,7 +94,7 @@ public void SaveToFile() path = string.IsNullOrEmpty(path) ? Application.dataPath : Path.GetDirectoryName(path); path = UnityEditor.EditorUtility.SaveFilePanel("save path", path, name, "bytes"); if (string.IsNullOrEmpty(path)) return; - using (var file = new FileStream(path, FileMode.OpenOrCreate)) this.SaveToStream(this.FindGlobalValuesList(), file); + using (var file = new FileStream(path, FileMode.OpenOrCreate)) Node.SaveToStream(this.FindGlobalValuesList(), file); UnityEditor.AssetDatabase.Refresh(); } #endif @@ -93,5 +103,7 @@ public void SaveToFile() public abstract class BTNode : BTNode where T : unmanaged, INodeData { protected override Type NodeType => typeof(T); + public override IBuilder BlobStreamBuilder => new ValueBuilder(_Value); + protected virtual T _Value => default; } } diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs index f7308bf5..b21aff3c 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs @@ -1,28 +1,26 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Blob; using EntitiesBT.Components; using EntitiesBT.Core; using EntitiesBT.Entities; using GraphExt; +using JetBrains.Annotations; using Nuwa; -using Unity.Collections; -using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; using UnityEngine; #if UNITY_EDITOR using GraphExt.Editor; using UnityEditor; using EntitiesBT.Editor; -using UnityEditor.Experimental.SceneManagement; #endif namespace EntitiesBT { [ExecuteAlways] - public class BehaviorNodeComponent : GraphNodeComponent, ITreeNodeComponent, INodeDataBuilder + public class BehaviorNodeComponent : GraphNodeComponent, ITreeNodeComponent { #region GraphNode public override Vector2 Position @@ -187,31 +185,30 @@ private SerializedProperty GetSerializedNodeBuilder(SerializedObject nodeObject) #endregion #region NodeDataBuilder - - public int NodeId => _node.BehaviorNodeAttribute.Id; - public int NodeIndex { get; set; } - public INodeDataBuilder Self => this; - public IEnumerable Children => Components.Utilities.Children(this); - public object GetPreviewValue(string path) => throw new NotSupportedException(); - public void SetPreviewValue(string path, object value) => throw new NotSupportedException(); - public unsafe BlobAssetReference Build(Core.ITreeNode[] builders) + public class Builder : INodeDataBuilder { - throw new NotImplementedException(); - // var nodeType = _node.BehaviorNodeDataType; - // if (nodeType.IsZeroSizeStruct()) return BlobAssetReference.Null; - // var blobBuilder = new BlobMemoryStream(UnsafeUtility.SizeOf(nodeType)); - // try - // { - // _node.Blob.Build(blobBuilder); - // blobBuilder.WritePatchOffset() - // return blobBuilder.CreateReferenceByType(nodeType); - // } - // finally - // { - // blobBuilder.Dispose(); - // } + [NotNull] private readonly BehaviorNodeComponent _component; + + public int NodeId => _component.NodeId; + + public int NodeIndex { get; set; } = -1; + + public IBuilder BlobStreamBuilder => _component._node.Blob; + + public IEnumerable Children => _component.Children() + .Where(child => child.gameObject.activeInHierarchy) + .Select(child => child.NodeBuilder) + ; + + public Builder([NotNull] BehaviorNodeComponent component) + { + _component = component; + } } + + public int NodeId => _node.BehaviorNodeAttribute.Id; + public Builder NodeBuilder => new Builder(this); #endregion #region Save to File @@ -222,7 +219,7 @@ public void SaveToFile() { var path = EditorUtility.SaveFilePanel("save path", Application.dataPath, name, "bytes"); if (string.IsNullOrEmpty(path)) return; - using (var file = new FileStream(path, FileMode.OpenOrCreate)) this.SaveToStream(this.FindGlobalValuesList(), file); + using (var file = new FileStream(path, FileMode.OpenOrCreate)) NodeBuilder.SaveToStream(this.FindGlobalValuesList(), file); AssetDatabase.Refresh(); } #endif diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs deleted file mode 100644 index afbea7e0..00000000 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Blob; -using JetBrains.Annotations; -using UnityEngine.Assertions; - -namespace Nuwa.Blob -{ - public unsafe class UnsafeBlobStreamValue where T : unmanaged - { - private readonly IBlobStream _stream; - private readonly int _position; - - public UnsafeBlobStreamValue([NotNull] IBlobStream stream, int position) - { - _stream = stream; - _position = position; - Assert.IsTrue(position < stream.Length); - } - - public ref T Value - { - get - { - fixed (void* ptr = &_stream.Buffer[_position]) - { - return ref *(T*)ptr; - } - } - } - } -} \ No newline at end of file diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs.meta b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs.meta deleted file mode 100644 index 132ec029..00000000 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/UnsafeBlobStreamValue.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1d6a46fef2d54a56a4cfe544584cce56 -timeCreated: 1649396128 \ No newline at end of file diff --git a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs index 4b021a69..c2001894 100644 --- a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs @@ -47,9 +47,7 @@ public class NormalizedWeightBuilder : PlainDataBuilder> protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue> value) { float sum = Weights.Sum(); - // new ArrayBuilder(Weights.Select(w => w / sum).ToArray()); - // builder.AllocateArray(ref data, Weights.Select(w => w / sum).ToArray()); - // builder.WriteValue(ref Value); + new Blob.ArrayBuilder(Weights.Select(w => w / sum).ToArray()).Build(stream); } } } \ No newline at end of file diff --git a/Packages/essential/Runtime/Variant/BlobVariantStream.cs b/Packages/essential/Runtime/Variant/BlobVariantStream.cs index a8c66c84..8d5f9226 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantStream.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantStream.cs @@ -69,7 +69,7 @@ public class BlobVariantROBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { _variant?.Allocate(new BlobVariantStream(stream)); } @@ -103,7 +103,7 @@ public class BlobVariantWOBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { _variant.Allocate(new BlobVariantStream(stream)); } @@ -137,7 +137,7 @@ public class BlobVariantRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override unsafe void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) + protected override unsafe void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { _variant.Allocate(new BlobVariantStream(stream)); value.Value.Writer.VariantId = value.Value.Reader.VariantId; @@ -161,7 +161,7 @@ public class BlobVariantLinkedRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _isLinked ? _readerAndWriter.PreviewValue : _reader.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { if (_isLinked) { diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index ae65da00..40a06efa 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,5 +1,11 @@ { "dependencies": { + "com.quabug.blob": { + "version": "file:com.quabug.blob", + "depth": 0, + "source": "embedded", + "dependencies": {} + }, "com.quabug.entities-bt.builder.component": { "version": "file:builder.component", "depth": 0, @@ -40,14 +46,6 @@ "com.quabug.entities-bt.essential": "1.4.0" } }, - "com.quabug.entities-bt.deprecated": { - "version": "file:deprecated", - "depth": 0, - "source": "embedded", - "dependencies": { - "com.quabug.entities-bt.essential": "1.3.0" - } - }, "com.quabug.entities-bt.essential": { "version": "file:essential", "depth": 0, @@ -56,12 +54,6 @@ "com.unity.entities": "0.14.0-preview.19" } }, - "com.quabug.entities-bt.samples": { - "version": "file:samples", - "depth": 0, - "source": "embedded", - "dependencies": {} - }, "com.quabug.entities-bt.variable.scriptable-object": { "version": "file:variable.scriptable-object", "depth": 0, @@ -79,13 +71,12 @@ } }, "com.quabug.graph-ext": { - "version": "1.9.5", - "depth": 1, - "source": "registry", + "version": "file:com.quabug.graph-ext", + "depth": 0, + "source": "embedded", "dependencies": { "com.unity.modules.uielements": "1.0.0" - }, - "url": "https://package.openupm.com" + } }, "com.unity.burst": { "version": "1.3.7", @@ -166,7 +157,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.vscode": { - "version": "1.2.4", + "version": "1.2.5", "depth": 0, "source": "registry", "dependencies": {}, @@ -277,7 +268,7 @@ "url": "https://packages.unity.com" }, "com.unity.test-framework": { - "version": "1.1.29", + "version": "1.1.31", "depth": 1, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 339c3950..02057f26 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2020.3.29f1 -m_EditorVersionWithRevision: 2020.3.29f1 (2ff179115da0) +m_EditorVersion: 2020.3.33f1 +m_EditorVersionWithRevision: 2020.3.33f1 (915a7af8b0d5) From 9f150e753df69d8101e818a3b2f63ad965c8b08c Mon Sep 17 00:00:00 2001 From: quabug Date: Thu, 28 Apr 2022 16:13:12 +0800 Subject: [PATCH 12/28] fix error --- Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs index a6d45ee1..26404d1e 100644 --- a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs +++ b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs @@ -29,7 +29,7 @@ public class ColliderBoundsBuilder : Nuwa.Blob.Builder public Transform Transform; public BoxCollider Box; - protected override void BuildImpl(IBlobStream stream, Nuwa.Blob.UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) { stream.WriteValue(new Bounds(Box.center + Transform.position, Box.size)); } From 494addc5981a59afda5f67a3bb937e5f81a33d5d Mon Sep 17 00:00:00 2001 From: quabug Date: Thu, 28 Apr 2022 22:03:24 +0800 Subject: [PATCH 13/28] fix test of expression variant --- Assets/Tests/Editor/TestExpression.cs | 25 +++++---- .../Runtime/Variant/BlobVariantStream.cs | 1 - .../Runtime/Variant/VariantBuilder.cs | 21 ++++++++ .../Runtime/Variant/VariantBuilder.cs.meta | 3 ++ .../Runtime/ExpressionVariant.cs | 54 ++++++++----------- 5 files changed, 59 insertions(+), 45 deletions(-) create mode 100644 Packages/essential/Runtime/Variant/VariantBuilder.cs create mode 100644 Packages/essential/Runtime/Variant/VariantBuilder.cs.meta diff --git a/Assets/Tests/Editor/TestExpression.cs b/Assets/Tests/Editor/TestExpression.cs index 58a35dd9..d3ad5a4f 100644 --- a/Assets/Tests/Editor/TestExpression.cs +++ b/Assets/Tests/Editor/TestExpression.cs @@ -1,16 +1,14 @@ using System; +using Blob; using EntitiesBT.Core; using EntitiesBT.Variant; using EntitiesBT.Variant.Expression; using NUnit.Framework; -using Unity.Collections; -using Unity.Entities; namespace EntitiesBT.Test { public class TestExpression { - private BlobBuilder _builder; private MockNodeBlob _nodeBlob; private MockBlackboard _bb; @@ -44,17 +42,10 @@ private struct MockBlackboard : IBlackboard [SetUp] public void SetUp() { - _builder = new BlobBuilder(Allocator.Temp); _nodeBlob = new MockNodeBlob(); _bb = new MockBlackboard(); } - [TearDown] - public void TearDown() - { - _builder.Dispose(); - } - [Test] public void should_eval_expression() { @@ -66,9 +57,17 @@ public void should_eval_expression() new ExpressionVariant.Reader.Variant {Value = new LocalVariant.Reader {Value = 5}, Name = "y"}, }; - ref var buildVariant = ref _builder.ConstructRoot(); - // expression.Allocate(_builder, ref buildVariant); - using var variant = _builder.CreateBlobAssetReference(Allocator.Temp); + var builder = new VariantBuilder(expression); + using var variant = builder.CreateManagedBlobAssetReference(); + ref var expressionData = ref variant.Value.As(); + Assert.That(expressionData.Expression.ToString(), Is.EqualTo(expression._expression)); + Assert.That(expressionData.ExpressionType, Is.EqualTo(VariantValueTypeRegistry.GetIdByType(typeof(float)))); + for (var i = 0; i < expression._sources.Length; i++) + { + var source = expression._sources[i]; + Assert.That(expressionData.VariantNames[i].ToString(), Is.EqualTo(source.Name)); + Assert.That(expressionData.VariantTypes[i], Is.EqualTo(VariantValueTypeRegistry.GetIdByType(source.Value.FindValueType()))); + } var result = BlobVariantExtension.Read(ref variant.Value, 0, ref _nodeBlob, ref _bb); Assert.That(result, Is.EqualTo((4.1f + 5) * 2 + 10)); } diff --git a/Packages/essential/Runtime/Variant/BlobVariantStream.cs b/Packages/essential/Runtime/Variant/BlobVariantStream.cs index 8d5f9226..d28617ec 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantStream.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantStream.cs @@ -6,7 +6,6 @@ using JetBrains.Annotations; using Nuwa; using Nuwa.Blob; -using Unity.Collections.LowLevel.Unsafe; using UnityEngine; namespace EntitiesBT.Variant diff --git a/Packages/essential/Runtime/Variant/VariantBuilder.cs b/Packages/essential/Runtime/Variant/VariantBuilder.cs new file mode 100644 index 00000000..a90b738d --- /dev/null +++ b/Packages/essential/Runtime/Variant/VariantBuilder.cs @@ -0,0 +1,21 @@ +using System; +using Blob; + +namespace EntitiesBT.Variant +{ + public class VariantBuilder : Builder where T : unmanaged + { + static unsafe VariantBuilder() + { + if (sizeof(T) != sizeof(BlobVariant)) throw new ArgumentException($"invalid generic type {typeof(T)}"); + } + + private readonly IVariant _variant; + public VariantBuilder(IVariant variant) => _variant = variant; + + protected override void BuildImpl(IBlobStream stream) + { + _variant.Allocate(new BlobVariantStream(stream)); + } + } +} \ No newline at end of file diff --git a/Packages/essential/Runtime/Variant/VariantBuilder.cs.meta b/Packages/essential/Runtime/Variant/VariantBuilder.cs.meta new file mode 100644 index 00000000..210fa46d --- /dev/null +++ b/Packages/essential/Runtime/Variant/VariantBuilder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 03809271c3cf47edba5b9cdb84ac1df2 +timeCreated: 1651148846 \ No newline at end of file diff --git a/Packages/variant.expression/Runtime/ExpressionVariant.cs b/Packages/variant.expression/Runtime/ExpressionVariant.cs index 9cf4835a..0ed14c50 100644 --- a/Packages/variant.expression/Runtime/ExpressionVariant.cs +++ b/Packages/variant.expression/Runtime/ExpressionVariant.cs @@ -2,11 +2,10 @@ using System.Collections.Concurrent; using System.Linq; using System.Runtime.InteropServices; +using System.Text; using Blob; using EntitiesBT.Core; using Nuwa; -using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; using UnityEngine; using static EntitiesBT.Core.Utilities; @@ -19,11 +18,11 @@ public static class ExpressionVariant public struct Data { - public BlobString Expression; + public BlobString Expression; public int ExpressionType; - public Unity.Entities.BlobArray Variants; - public Unity.Entities.BlobArray VariantNames; - public Unity.Entities.BlobArray VariantTypes; + public BlobArray Variants; + public BlobArray> VariantNames; + public BlobArray VariantTypes; } private static readonly ConcurrentDictionary _expressionParameters = new ConcurrentDictionary(); @@ -43,32 +42,25 @@ internal class Variant [SerializeField] internal string _expression; [SerializeField] internal Variant[] _sources; - public unsafe void Allocate(BlobVariantStream stream) + public void Allocate(BlobVariantStream stream) { - throw new NotImplementedException(); - // stream.SetVariantId(GuidHashCode(GUID)); - // // ref var blobPtr = ref UnsafeUtility.As>(ref blobVariant.MetaDataOffsetPtr); - // var dataBuilder = new StructBuilder(); - // dataBuilder.SetValue(ref dataBuilder.Value.ExpressionType, VariantValueTypeRegistry.GetIdByType(typeof(T))); - // dataBuilder.SetString(ref dataBuilder.Value.Expression, _expression); - // dataBuilder.SetArray( - // ref dataBuilder.Value.Variants, - // _sources.Select(source => source.Value.Allocate()) - // ); - // dataBuilder.SetArray( - // ref dataBuilder.Value.VariantNames, - // _sources.Select(source => new UnityBlobStringBuilder(source.Name)) - // ); - // var variants = stream.Allocate(ref data.Variants, _sources.Length); - // var names = stream.Allocate(ref data.VariantNames, _sources.Length); - // var types = stream.Allocate(ref data.VariantTypes, _sources.Length); - // for (var i = 0; i < _sources.Length; i++) - // { - // _sources[i].Value.Allocate(ref stream, ref variants[i]); - // stream.AllocateString(ref names[i], _sources[i].Name); - // types[i] = VariantValueTypeRegistry.GetIdByType(_sources[i].Value.FindValueType()); - // } - // return new IntPtr(UnsafeUtility.AddressOf(ref data)); + stream.SetVariantId(GuidHashCode(GUID)); + var dataBuilder = new StructBuilder(); + dataBuilder.SetString(ref dataBuilder.Value.Expression, _expression); + dataBuilder.SetValue(ref dataBuilder.Value.ExpressionType, VariantValueTypeRegistry.GetIdByType(typeof(T))); + dataBuilder.SetArray( + ref dataBuilder.Value.Variants, + _sources.Select(source => new VariantBuilder(source.Value)) + ); + dataBuilder.SetArray( + ref dataBuilder.Value.VariantNames, + _sources.Select(source => new StringBuilder(source.Name)) + ); + dataBuilder.SetArray( + ref dataBuilder.Value.VariantTypes, + _sources.Select(source => VariantValueTypeRegistry.GetIdByType(source.Value.FindValueType())) + ); + stream.SetVariantValue(dataBuilder); } public object PreviewValue => null; From 0bab649c7ef0d89557be2b51ed250cc7976091d2 Mon Sep 17 00:00:00 2001 From: quabug Date: Thu, 28 Apr 2022 23:15:42 +0800 Subject: [PATCH 14/28] move NodeBlob to Core --- .../Runtime/BehaviorTreeSourceGameObject.cs | 1 + .../Runtime/BehaviorTreeSourceGraphPrefab.cs | 1 + .../Components/BehaviorTreeSourceTextAsset.cs | 2 +- .../Runtime/Components/IBehaviorTreeSource.cs | 6 +- .../Runtime/Core/INodeDataBuilder.cs | 68 +++++++++++++++++++ .../Runtime/{Entities => Core}/NodeBlob.cs | 3 +- .../{Entities => Core}/NodeBlob.cs.meta | 0 .../Entities/BehaviorTreeComponents.cs | 1 + .../Entities/BehaviorTreeLifeCycleSystem.cs | 1 + .../Runtime/Entities/NodeBlobExtensions.cs | 60 +--------------- .../Runtime/Variant/BlobVariantViewer.cs | 1 + 11 files changed, 77 insertions(+), 67 deletions(-) rename Packages/essential/Runtime/{Entities => Core}/NodeBlob.cs (98%) rename Packages/essential/Runtime/{Entities => Core}/NodeBlob.cs.meta (100%) diff --git a/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs b/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs index 4a8fa0d5..4f536f9e 100644 --- a/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs +++ b/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs @@ -1,4 +1,5 @@ using System; +using EntitiesBT.Core; using EntitiesBT.Entities; using Unity.Entities; diff --git a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs index 204483e6..8bf45ced 100644 --- a/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs +++ b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorTreeSourceGraphPrefab.cs @@ -1,5 +1,6 @@ using System; using EntitiesBT.Components; +using EntitiesBT.Core; using EntitiesBT.Entities; using Nuwa; using Unity.Entities; diff --git a/Packages/essential/Runtime/Components/BehaviorTreeSourceTextAsset.cs b/Packages/essential/Runtime/Components/BehaviorTreeSourceTextAsset.cs index bcc18ffd..f048c44a 100644 --- a/Packages/essential/Runtime/Components/BehaviorTreeSourceTextAsset.cs +++ b/Packages/essential/Runtime/Components/BehaviorTreeSourceTextAsset.cs @@ -1,5 +1,5 @@ using System; -using EntitiesBT.Entities; +using EntitiesBT.Core; using Unity.Entities; using UnityEngine; diff --git a/Packages/essential/Runtime/Components/IBehaviorTreeSource.cs b/Packages/essential/Runtime/Components/IBehaviorTreeSource.cs index f9020ac0..59788328 100644 --- a/Packages/essential/Runtime/Components/IBehaviorTreeSource.cs +++ b/Packages/essential/Runtime/Components/IBehaviorTreeSource.cs @@ -1,9 +1,5 @@ -using System; -using System.Threading.Tasks; -using EntitiesBT.Entities; +using EntitiesBT.Core; using Unity.Entities; -using UnityEngine; -using Object = UnityEngine.Object; namespace EntitiesBT.Components { diff --git a/Packages/essential/Runtime/Core/INodeDataBuilder.cs b/Packages/essential/Runtime/Core/INodeDataBuilder.cs index f1e9ac82..29ba7aaf 100644 --- a/Packages/essential/Runtime/Core/INodeDataBuilder.cs +++ b/Packages/essential/Runtime/Core/INodeDataBuilder.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using Blob; +using JetBrains.Annotations; namespace EntitiesBT.Core { @@ -17,5 +20,70 @@ public static partial class NodeDataBuilderExtension public static Type GetNodeType(this INodeDataBuilder builder) => MetaNodeRegister.NODES[builder.NodeId].Type; public static BehaviorNodeAttribute GetBehaviorNodeAttribute(this INodeDataBuilder builder) => GetNodeType(builder).GetBehaviorNodeAttribute(); public static BehaviorNodeType GetBehaviorNodeType(this INodeDataBuilder builder) => GetBehaviorNodeAttribute(builder).Type; + + public static IBuilder ToBuilder( + this INodeDataBuilder root + , IEnumerable globalValuesList + ) + { + var builder = new StructBuilder(); + var typeList = new List(); + foreach (var node in root.Flatten()) + { + node.NodeIndex = typeList.Count; + typeList.Add(node.NodeId); + } + builder.SetArray(ref builder.Value.Types, typeList); + var treeRoot = root.ToTreeNode(); + var treeBuilder = builder.SetTreeAny(ref builder.Value.Nodes, treeRoot); + + var globalValueOffset = 0; + using var globalValuesStream = new MemoryStream(); + foreach (var value in globalValuesList) + { + value.Offset = globalValueOffset; + globalValueOffset += value.Size; + Write(globalValuesStream, value); + } + builder.SetArray(ref builder.Value.DefaultGlobalValues, globalValuesStream.ToArray()); + builder.SetArray(ref builder.Value.States, new NodeState[typeList.Count]); + builder.SetBuilder( + ref builder.Value.RuntimeDataBlob, + new ArrayBuilderWithMemoryCopy>(() => (treeBuilder.ArrayBuilder.PatchPosition, treeBuilder.ArrayBuilder.PatchSize)) { Alignment = treeBuilder.Alignment } + ); + builder.SetArray(ref builder.Value.RuntimeGlobalValues, globalValuesStream.ToArray()); + return builder; + + unsafe void Write(MemoryStream stream, IGlobalValuesBuilder value) + { +#if UNITY_2021_2_OR_NEWER + stream.Write(new System.ReadOnlySpan(value.ValuePtr.ToPointer(), value.Size)); +#else + for (var i = 0; i < value.Size; i++) + { + var @byte = *(byte*)(value.ValuePtr + i).ToPointer(); + stream.WriteByte(@byte); + } +#endif + } + } + + private class TreeNode : ITreeNode + { + public IBuilder ValueBuilder { get; } + public IReadOnlyList Children { get; } + + public TreeNode(IBuilder builder, IEnumerable children) + { + ValueBuilder = builder; + Children = children.ToArray(); + } + } + + private static TreeNode ToTreeNode([NotNull] this INodeDataBuilder nodeBuilder) => + new TreeNode(nodeBuilder.BlobStreamBuilder, nodeBuilder.Children.Select(child => child.ToTreeNode())); + + private static IEnumerable Flatten(this INodeDataBuilder node) => + node.Yield().Concat(node.Children.SelectMany(Flatten)); } } diff --git a/Packages/essential/Runtime/Entities/NodeBlob.cs b/Packages/essential/Runtime/Core/NodeBlob.cs similarity index 98% rename from Packages/essential/Runtime/Entities/NodeBlob.cs rename to Packages/essential/Runtime/Core/NodeBlob.cs index b8561734..9196ed7f 100644 --- a/Packages/essential/Runtime/Entities/NodeBlob.cs +++ b/Packages/essential/Runtime/Core/NodeBlob.cs @@ -1,11 +1,10 @@ using System; -using EntitiesBT.Core; using JetBrains.Annotations; using Unity.Collections.LowLevel.Unsafe; using Unity.Mathematics; using Blob; -namespace EntitiesBT.Entities +namespace EntitiesBT.Core { public struct NodeBlob { diff --git a/Packages/essential/Runtime/Entities/NodeBlob.cs.meta b/Packages/essential/Runtime/Core/NodeBlob.cs.meta similarity index 100% rename from Packages/essential/Runtime/Entities/NodeBlob.cs.meta rename to Packages/essential/Runtime/Core/NodeBlob.cs.meta diff --git a/Packages/essential/Runtime/Entities/BehaviorTreeComponents.cs b/Packages/essential/Runtime/Entities/BehaviorTreeComponents.cs index 06ac60d3..1c40460b 100644 --- a/Packages/essential/Runtime/Entities/BehaviorTreeComponents.cs +++ b/Packages/essential/Runtime/Entities/BehaviorTreeComponents.cs @@ -2,6 +2,7 @@ using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; using Unity.Jobs; +using EntitiesBT.Core; namespace EntitiesBT.Entities { diff --git a/Packages/essential/Runtime/Entities/BehaviorTreeLifeCycleSystem.cs b/Packages/essential/Runtime/Entities/BehaviorTreeLifeCycleSystem.cs index 23ab43df..a0b32572 100644 --- a/Packages/essential/Runtime/Entities/BehaviorTreeLifeCycleSystem.cs +++ b/Packages/essential/Runtime/Entities/BehaviorTreeLifeCycleSystem.cs @@ -1,4 +1,5 @@ using System.Reflection; +using EntitiesBT.Core; using Unity.Entities; namespace EntitiesBT.Entities diff --git a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs index f8c0b51b..8718cec9 100644 --- a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs +++ b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs @@ -4,7 +4,6 @@ using Blob; using EntitiesBT.Core; using JetBrains.Annotations; -using Unity.Collections; using Unity.Entities; using Unity.Entities.Serialization; @@ -12,70 +11,13 @@ namespace EntitiesBT.Entities { public static class NodeBlobExtensions { - private class TreeNode : ITreeNode - { - public IBuilder ValueBuilder { get; } - public IReadOnlyList Children { get; } - - public TreeNode(IBuilder builder, IEnumerable children) - { - ValueBuilder = builder; - Children = children.ToArray(); - } - } - - private static TreeNode ToTreeNode([NotNull] this INodeDataBuilder nodeBuilder) => - new TreeNode(nodeBuilder.BlobStreamBuilder, nodeBuilder.Children.Select(child => child.ToTreeNode())); - - private static IEnumerable Flatten(this INodeDataBuilder node) => - node.Yield().Concat(node.Children.SelectMany(Flatten)); - [Pure] public static BlobAssetReference ToBlob( [NotNull] this INodeDataBuilder root , IEnumerable globalValuesList ) { - var builder = new StructBuilder(); - var typeList = new List(); - foreach (var node in root.Flatten()) - { - node.NodeIndex = typeList.Count; - typeList.Add(node.NodeId); - } - builder.SetArray(ref builder.Value.Types, typeList); - var treeRoot = root.ToTreeNode(); - var treeBuilder = builder.SetTreeAny(ref builder.Value.Nodes, treeRoot); - - var globalValueOffset = 0; - using var globalValuesStream = new MemoryStream(); - foreach (var value in globalValuesList) - { - value.Offset = globalValueOffset; - globalValueOffset += value.Size; - Write(globalValuesStream, value); - } - builder.SetArray(ref builder.Value.DefaultGlobalValues, globalValuesStream.ToArray()); - builder.SetArray(ref builder.Value.States, new NodeState[typeList.Count]); - builder.SetBuilder( - ref builder.Value.RuntimeDataBlob, - new ArrayBuilderWithMemoryCopy>(() => (treeBuilder.ArrayBuilder.PatchPosition, treeBuilder.ArrayBuilder.PatchSize)) { Alignment = treeBuilder.Alignment } - ); - builder.SetArray(ref builder.Value.RuntimeGlobalValues, globalValuesStream.ToArray()); - return builder.CreateUnityBlobAssetReference(); - - unsafe void Write(MemoryStream stream, IGlobalValuesBuilder value) - { -#if UNITY_2021_2_OR_NEWER - stream.Write(new System.ReadOnlySpan(value.ValuePtr.ToPointer(), value.Size)); -#else - for (var i = 0; i < value.Size; i++) - { - var @byte = *(byte*)(value.ValuePtr + i).ToPointer(); - stream.WriteByte(@byte); - } -#endif - } + return root.ToBuilder(globalValuesList).CreateUnityBlobAssetReference(); } public static unsafe void SaveToStream( diff --git a/Packages/essential/Runtime/Variant/BlobVariantViewer.cs b/Packages/essential/Runtime/Variant/BlobVariantViewer.cs index 35bff0d6..5192cf75 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantViewer.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantViewer.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.InteropServices; +using EntitiesBT.Core; using EntitiesBT.Entities; using Nuwa.Blob; using Unity.Collections.LowLevel.Unsafe; From a90ceba31d552ca04719d485ff2712a80e528ba3 Mon Sep 17 00:00:00 2001 From: quabug Date: Fri, 29 Apr 2022 01:09:16 +0800 Subject: [PATCH 15/28] set size of empty nodes to zero explicitly --- Packages/essential/Runtime/Nodes/Actions/FailedNode.cs | 2 ++ Packages/essential/Runtime/Nodes/Actions/RunningNode.cs | 2 ++ Packages/essential/Runtime/Nodes/Actions/SuccessNode.cs | 2 ++ Packages/essential/Runtime/Nodes/Composites/ParallelNode.cs | 2 ++ .../essential/Runtime/Nodes/Composites/RandomSelectorNode.cs | 2 ++ Packages/essential/Runtime/Nodes/Composites/SelectorNode.cs | 2 ++ Packages/essential/Runtime/Nodes/Composites/SequenceNode.cs | 2 ++ .../essential/Runtime/Nodes/Decorators/ErrorRerunOnceNode.cs | 2 ++ .../Runtime/Nodes/Decorators/RecursiveResetStateNode.cs | 2 ++ Packages/essential/Runtime/Nodes/Decorators/ResetBranchNode.cs | 2 ++ .../essential/Runtime/Nodes/Decorators/RunOnMainThreadNode.cs | 2 ++ Packages/essential/Runtime/Nodes/Decorators/StateReverseNode.cs | 2 ++ 12 files changed, 24 insertions(+) diff --git a/Packages/essential/Runtime/Nodes/Actions/FailedNode.cs b/Packages/essential/Runtime/Nodes/Actions/FailedNode.cs index 00610b77..ce884757 100644 --- a/Packages/essential/Runtime/Nodes/Actions/FailedNode.cs +++ b/Packages/essential/Runtime/Nodes/Actions/FailedNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("AC5CB763-5F7A-4301-9670-D4E38A5557CB")] public struct FailedNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Actions/RunningNode.cs b/Packages/essential/Runtime/Nodes/Actions/RunningNode.cs index 9f475088..ce59cc86 100644 --- a/Packages/essential/Runtime/Nodes/Actions/RunningNode.cs +++ b/Packages/essential/Runtime/Nodes/Actions/RunningNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("F17339E0-D401-451B-864B-007AD44E05A3")] public struct RunningNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Actions/SuccessNode.cs b/Packages/essential/Runtime/Nodes/Actions/SuccessNode.cs index 02e9a548..99852617 100644 --- a/Packages/essential/Runtime/Nodes/Actions/SuccessNode.cs +++ b/Packages/essential/Runtime/Nodes/Actions/SuccessNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("A2E43D78-8993-4D0A-9CD0-70A98AAF9E8A")] public struct SuccessNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Composites/ParallelNode.cs b/Packages/essential/Runtime/Nodes/Composites/ParallelNode.cs index 0d6bc462..41a7781e 100644 --- a/Packages/essential/Runtime/Nodes/Composites/ParallelNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/ParallelNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("A316D182-7D8C-4075-A46D-FEE08CAEEEAF", BehaviorNodeType.Composite)] public struct ParallelNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Composites/RandomSelectorNode.cs b/Packages/essential/Runtime/Nodes/Composites/RandomSelectorNode.cs index d1891810..ad8b19fa 100644 --- a/Packages/essential/Runtime/Nodes/Composites/RandomSelectorNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/RandomSelectorNode.cs @@ -1,8 +1,10 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; using EntitiesBT.Entities; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("BA0106CA-618F-409A-903A-973B89F1470A", BehaviorNodeType.Composite)] public struct RandomSelectorNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Composites/SelectorNode.cs b/Packages/essential/Runtime/Nodes/Composites/SelectorNode.cs index d6dcdd19..932fe31a 100644 --- a/Packages/essential/Runtime/Nodes/Composites/SelectorNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/SelectorNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("BD4C1D8F-BA8E-4D74-9039-7D1E6010B058", BehaviorNodeType.Composite)] public struct SelectorNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Composites/SequenceNode.cs b/Packages/essential/Runtime/Nodes/Composites/SequenceNode.cs index c502f441..e8f1d837 100644 --- a/Packages/essential/Runtime/Nodes/Composites/SequenceNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/SequenceNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("8A3B18AE-C5E9-4F34-BCB7-BD645C5017A5", BehaviorNodeType.Composite)] public struct SequenceNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Decorators/ErrorRerunOnceNode.cs b/Packages/essential/Runtime/Nodes/Decorators/ErrorRerunOnceNode.cs index 8e81d77b..2c95fd95 100644 --- a/Packages/essential/Runtime/Nodes/Decorators/ErrorRerunOnceNode.cs +++ b/Packages/essential/Runtime/Nodes/Decorators/ErrorRerunOnceNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("B1C31393-4041-47E6-98CA-2F5E3BE4E1BD", BehaviorNodeType.Decorate)] public struct ErrorRerunOnceNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Decorators/RecursiveResetStateNode.cs b/Packages/essential/Runtime/Nodes/Decorators/RecursiveResetStateNode.cs index 5625e6ab..d18e4d07 100644 --- a/Packages/essential/Runtime/Nodes/Decorators/RecursiveResetStateNode.cs +++ b/Packages/essential/Runtime/Nodes/Decorators/RecursiveResetStateNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("7656C8CB-EBC9-4C82-A374-511D4CB4D7FA", BehaviorNodeType.Decorate)] public struct RecursiveResetStateNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Decorators/ResetBranchNode.cs b/Packages/essential/Runtime/Nodes/Decorators/ResetBranchNode.cs index 54177607..704450f4 100644 --- a/Packages/essential/Runtime/Nodes/Decorators/ResetBranchNode.cs +++ b/Packages/essential/Runtime/Nodes/Decorators/ResetBranchNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("3F494113-5404-49D6-ABCC-8BB285B730F8", BehaviorNodeType.Decorate)] public struct ResetBranchNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Decorators/RunOnMainThreadNode.cs b/Packages/essential/Runtime/Nodes/Decorators/RunOnMainThreadNode.cs index 0fe521d3..30a7d4de 100644 --- a/Packages/essential/Runtime/Nodes/Decorators/RunOnMainThreadNode.cs +++ b/Packages/essential/Runtime/Nodes/Decorators/RunOnMainThreadNode.cs @@ -1,8 +1,10 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; using EntitiesBT.Entities; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("64E0DAFB-20E2-4DF4-910E-ADFA831DB8A9", BehaviorNodeType.Decorate)] public struct RunOnMainThreadNode : INodeData { diff --git a/Packages/essential/Runtime/Nodes/Decorators/StateReverseNode.cs b/Packages/essential/Runtime/Nodes/Decorators/StateReverseNode.cs index a2df0be2..379cbe70 100644 --- a/Packages/essential/Runtime/Nodes/Decorators/StateReverseNode.cs +++ b/Packages/essential/Runtime/Nodes/Decorators/StateReverseNode.cs @@ -1,7 +1,9 @@ +using System.Runtime.InteropServices; using EntitiesBT.Core; namespace EntitiesBT.Nodes { + [StructLayout(LayoutKind.Explicit)] [BehaviorNode("E99D019A-78E4-49B1-AE0D-6A1D0101E080", BehaviorNodeType.Decorate)] public struct StateReverseNode : INodeData { From 5b6871c51343dd696e47d49bff4b8665c1cbe784 Mon Sep 17 00:00:00 2001 From: quabug Date: Fri, 29 Apr 2022 01:10:52 +0800 Subject: [PATCH 16/28] remove dependency of Unity.Entities from tests --- Assets/Tests/Editor/BehaviorTreeTestBase.cs | 84 ++++++++++--------- Assets/Tests/Editor/TestNodeBlob.cs | 33 ++++---- Assets/Tests/Editor/TestSimpleComposites.cs | 23 ++--- Assets/Tests/Runtime/BTTestNodeA.cs | 2 - Assets/Tests/Runtime/BTTestNodeState.cs | 2 - Packages/essential/Runtime/Core/INodeBlob.cs | 6 +- .../Runtime/Core/ManagedNodeBlobRef.cs | 79 +++++++++++++++++ .../Runtime/Core/ManagedNodeBlobRef.cs.meta | 3 + Packages/essential/Runtime/Core/NodeBlob.cs | 69 --------------- .../essential/Runtime/Entities/NodeBlobRef.cs | 74 ++++++++++++++++ .../Runtime/Entities/NodeBlobRef.cs.meta | 3 + 11 files changed, 234 insertions(+), 144 deletions(-) create mode 100644 Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs create mode 100644 Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs.meta create mode 100644 Packages/essential/Runtime/Entities/NodeBlobRef.cs create mode 100644 Packages/essential/Runtime/Entities/NodeBlobRef.cs.meta diff --git a/Assets/Tests/Editor/BehaviorTreeTestBase.cs b/Assets/Tests/Editor/BehaviorTreeTestBase.cs index c84395b6..afc78e3d 100644 --- a/Assets/Tests/Editor/BehaviorTreeTestBase.cs +++ b/Assets/Tests/Editor/BehaviorTreeTestBase.cs @@ -2,26 +2,40 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using EntitiesBT.Components; +using Blob; using EntitiesBT.Core; -using EntitiesBT.Entities; using EntitiesBT.Nodes; using NUnit.Framework; -using UnityEngine; namespace EntitiesBT.Test { public class BehaviorTreeTestBase { - class Sequence : BTNode {} - class Selector : BTNode {} - class Parallel : BTNode {} + public abstract class NodeDataBuilder : INodeDataBuilder + { + public abstract Type NodeType { get; } + public abstract int NodeId { get; } + public int NodeIndex { get; set; } + public abstract IBuilder BlobStreamBuilder { get; } + public IEnumerable Children => ChildrenList; + public readonly List ChildrenList = new List(); + } + + public class NodeDataBuilder : NodeDataBuilder where T : unmanaged, INodeData + { + public override Type NodeType => typeof(T); + public override int NodeId => typeof(T).GetBehaviorNodeAttribute().Id; + public override IBuilder BlobStreamBuilder => new ValueBuilder(Value); + public T Value { get; } + public NodeDataBuilder() : this(default) {} + public NodeDataBuilder(T value) => Value = value; + } - private readonly Dictionary> _nodeCreators = new Dictionary> + private readonly Dictionary> _nodeCreators = new Dictionary> { - { "seq", Create } - , { "sel", Create } - , { "par", Create } + { "seq", _ => new NodeDataBuilder() } + , { "sel", _ => new NodeDataBuilder() } + , { "par", _ => new NodeDataBuilder() } , { "yes", CreateTestNode(NodeState.Success) } , { "no", CreateTestNode(NodeState.Failure) } , { "run", CreateTestNode(NodeState.Running) } @@ -75,44 +89,32 @@ public void Setup() _blackboard = new Blackboard(); } - protected NodeBlobRef CreateBlob(string tree) + protected ManagedNodeBlobRef CreateBlob(string tree) { - var root = CreateBTNode(tree).GetComponent(); - var blob = root.Node.ToBlob(root.FindGlobalValuesList()); - return new NodeBlobRef(blob); + var root = CreateRootBuilder(tree); + var blob = root.ToBuilder(Enumerable.Empty()).CreateManagedBlobAssetReference(); + return new ManagedNodeBlobRef(blob); } - private static BTNode CreateA(string @params) + private static NodeDataBuilder CreateA(string @params) { - var nodeA = Create(); - nodeA.A = int.Parse(@params); - return nodeA; + return new NodeDataBuilder(new NodeA { A = int.Parse(@params) }); } - private static BTNode CreateB(string @params) + private static NodeDataBuilder CreateB(string @params) { - var nodeB = Create(); var paramArray = @params.Split(','); - nodeB.B = int.Parse(paramArray[0].Trim()); - nodeB.BB = int.Parse(paramArray[1].Trim()); - return nodeB; - } - - private static Func CreateTestNode(NodeState state) - { - return @params => + var node = new NodeB { - var testNodeState = Create(); - testNodeState.State = state; - return testNodeState; + B = int.Parse(paramArray[0].Trim()), + BB = int.Parse(paramArray[1].Trim()) }; + return new NodeDataBuilder(node); } - private static T Create(string @params = "") where T : BTNode + private static Func CreateTestNode(NodeState state) { - var obj = new GameObject(typeof(T).Name); - var comp = obj.AddComponent(); - return comp; + return @params => new NodeDataBuilder(new TestNode { State = state } ); } // sample 1: "!seq>yes|no|run|a:10"; @@ -124,14 +126,14 @@ private static T Create(string @params = "") where T : BTNode // a:10 // b:1,2 // "; - protected GameObject CreateBTNode(string branch) + protected NodeDataBuilder CreateRootBuilder(string branch) { if (branch.First() == '!') return ParseSingleLine(branch.Substring(1)); using (var reader = new StringReader(branch)) return ParseMultiLines(reader); - GameObject ParseMultiLines(StringReader reader) + NodeDataBuilder ParseMultiLines(StringReader reader) { throw new NotImplementedException(); // var splits = branch.Split('>'); @@ -145,7 +147,7 @@ GameObject ParseMultiLines(StringReader reader) // return parent; } - GameObject ParseSingleLine(string branchString) + NodeDataBuilder ParseSingleLine(string branchString) { var splits = branchString.Split('>'); Assert.AreEqual(splits.Length, 2); @@ -153,17 +155,17 @@ GameObject ParseSingleLine(string branchString) foreach (var nodeString in splits[1].Split('|')) { var child = Create(nodeString.Trim()); - child.transform.SetParent(parent.transform, false); + parent.ChildrenList.Add(child); } return parent; } - GameObject Create(string nodeString) + NodeDataBuilder Create(string nodeString) { var nameParamsArray = nodeString.Split(':'); var name = nameParamsArray[0].Trim(); var @params = nameParamsArray.Length >= 2 ? nameParamsArray[1].Trim() : ""; - return _nodeCreators[name](@params).gameObject; + return _nodeCreators[name](@params); } } } diff --git a/Assets/Tests/Editor/TestNodeBlob.cs b/Assets/Tests/Editor/TestNodeBlob.cs index c82bd5e9..85a5f8be 100644 --- a/Assets/Tests/Editor/TestNodeBlob.cs +++ b/Assets/Tests/Editor/TestNodeBlob.cs @@ -84,39 +84,38 @@ public class TestNodeBlob : BehaviorTreeTestBase [Test] public void should_create_behavior_tree_objects_from_single_line_of_string() { - var root = CreateBTNode("!seq>yes|yes|b:1,1|a:111"); - Assert.AreEqual(root.name, "Sequence"); - Assert.AreEqual(root.transform.childCount, 4); + var root = CreateRootBuilder("!seq>yes|yes|b:1,1|a:111"); + Assert.AreEqual(root.NodeType, typeof(SequenceNode)); + Assert.AreEqual(root.ChildrenList.Count, 4); - var children = root.Children().ToArray(); + var children = root.ChildrenList; - Assert.AreEqual(children[0].name, "BTTestNodeState"); - Assert.AreEqual(children[0].transform.childCount, 0); + Assert.AreEqual(children[0].NodeType, typeof(TestNode)); + Assert.AreEqual(children[0].ChildrenList.Count, 0); - Assert.AreEqual(children[1].name, "BTTestNodeState"); - Assert.AreEqual(children[1].transform.childCount, 0); + Assert.AreEqual(children[1].NodeType, typeof(TestNode)); + Assert.AreEqual(children[1].ChildrenList.Count, 0); - Assert.AreEqual(children[2].name, "BTTestNodeB"); - Assert.AreEqual(children[2].transform.childCount, 0); + Assert.AreEqual(children[2].NodeType, typeof(NodeB)); + Assert.AreEqual(children[2].ChildrenList.Count, 0); - Assert.AreEqual(children[3].name, "BTTestNodeA"); - Assert.AreEqual(children[3].transform.childCount, 0); + Assert.AreEqual(children[3].NodeType, typeof(NodeA)); + Assert.AreEqual(children[3].ChildrenList.Count, 0); } [Test] public void should_generate_blob_from_nodes() { - var root = CreateBTNode("!seq>yes|no|b:1,1|a:111|run"); - var rootNode = root.GetComponent(); - var blobRef = rootNode.Node.ToBlob(rootNode.FindGlobalValuesList()); + var root = CreateRootBuilder("!seq>yes|no|b:1,1|a:111|run"); + using var blobRef = root.ToBuilder(Enumerable.Empty()).CreateManagedBlobAssetReference(); - Assert.True(blobRef.IsCreated); + Assert.True(blobRef.Length > 0); Assert.AreEqual(blobRef.Value.Count, 6); var types = new[] {typeof(SequenceNode), typeof(TestNode), typeof(TestNode), typeof(NodeB), typeof(NodeA), typeof(TestNode)}; Assert.AreEqual(blobRef.Value.Types.ToArray(), types.Select(t => t.GetBehaviorNodeAttribute().Id)); - Assert.AreEqual(blobRef.Value.Nodes.Data.Offsets.ToArray(), new [] { 0, 0, 16, 32, 40, 44, 60 }); Assert.AreEqual(blobRef.Value.Nodes.EndIndices.ToArray(), new [] { 6, 2, 3, 4, 5, 6 }); + Assert.AreEqual(blobRef.Value.Nodes.Data.Offsets.ToArray(), new [] { 0, 0, 16, 32, 40, 44, 60 }); Assert.AreEqual(blobRef.Value.Nodes.DataSize, 60); Assert.AreEqual(GetDefaultData(3), new NodeB {B = 1, BB = 1}); Assert.AreEqual(GetDefaultData(4), new NodeA {A = 111}); diff --git a/Assets/Tests/Editor/TestSimpleComposites.cs b/Assets/Tests/Editor/TestSimpleComposites.cs index e153a7e1..083638e6 100644 --- a/Assets/Tests/Editor/TestSimpleComposites.cs +++ b/Assets/Tests/Editor/TestSimpleComposites.cs @@ -1,6 +1,5 @@ using System.Linq; using EntitiesBT.Core; -using EntitiesBT.Entities; using NUnit.Framework; namespace EntitiesBT.Test @@ -11,7 +10,7 @@ public class TestSimpleComposites : BehaviorTreeTestBase public void should_run_sequence_until_reach_failure_node() { var blobRef = CreateBlob("!seq>yes|yes|yes|no|yes"); - var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); + var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); VirtualMachine.Reset(ref blobRef, ref _blackboard); Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Failure); @@ -30,7 +29,7 @@ public void should_run_sequence_until_reach_failure_node() public void should_run_select_until_reach_success_node() { var blobRef = CreateBlob("!sel>no|no|no|yes|no"); - var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); + var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); VirtualMachine.Reset(ref blobRef, ref _blackboard); Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Success); @@ -48,7 +47,7 @@ public void should_run_select_until_reach_success_node() public void should_run_all_children_of_parallel() { var blobRef = CreateBlob("!par>yes|no|yes|yes|no"); - var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); + var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); VirtualMachine.Reset(ref blobRef, ref _blackboard); Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Failure); @@ -60,13 +59,15 @@ public void should_run_all_children_of_parallel() Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Failure); Assert.AreEqual(nodes.Select(n => n.ResetTimes), new [] { 2, 2, 2, 2, 2 }); Assert.AreEqual(nodes.Select(n => n.TickTimes), new [] { 2, 2, 2, 2, 2 }); + + blobRef.Dispose(); } [Test] public void should_stay_on_running_node_for_select() { var blobRef = CreateBlob("!sel>no|run|no|no|no"); - var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); + var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); VirtualMachine.Reset(ref blobRef, ref _blackboard); Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Running); @@ -77,7 +78,7 @@ public void should_stay_on_running_node_for_select() Assert.AreEqual(nodes.Select(n => n.ResetTimes), new [] { 1, 1, 1, 1, 1 }); Assert.AreEqual(nodes.Select(n => n.TickTimes), new [] { 1, 2, 0, 0, 0 }); - blobRef.GetNodeData(2).State = NodeState.Failure; + blobRef.GetNodeData(2).State = NodeState.Failure; Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Failure); Assert.AreEqual(nodes.Select(n => n.ResetTimes), new [] { 1, 1, 1, 1, 1 }); Assert.AreEqual(nodes.Select(n => n.TickTimes), new [] { 1, 3, 1, 1, 1 }); @@ -93,7 +94,7 @@ public void should_stay_on_running_node_for_select() public void should_stay_on_running_node_for_sequence() { var blobRef = CreateBlob("!seq>yes|run|yes|yes|yes"); - var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); + var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); VirtualMachine.Reset(ref blobRef, ref _blackboard); Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Running); @@ -104,7 +105,7 @@ public void should_stay_on_running_node_for_sequence() Assert.AreEqual(nodes.Select(n => n.ResetTimes), new [] { 1, 1, 1, 1, 1 }); Assert.AreEqual(nodes.Select(n => n.TickTimes), new [] { 1, 2, 0, 0, 0 }); - blobRef.GetNodeData(2).State = NodeState.Success; + blobRef.GetNodeData(2).State = NodeState.Success; Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Success); Assert.AreEqual(nodes.Select(n => n.ResetTimes), new [] { 1, 1, 1, 1, 1 }); Assert.AreEqual(nodes.Select(n => n.TickTimes), new [] { 1, 3, 1, 1, 1 }); @@ -120,19 +121,19 @@ public void should_stay_on_running_node_for_sequence() public void should_stay_on_running_node_for_parallel() { var blobRef = CreateBlob("!par>no|run|yes|run|no"); - var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); + var nodes = Enumerable.Range(1, 5).Select(i => blobRef.GetNodeData(i)); VirtualMachine.Reset(ref blobRef, ref _blackboard); Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Running); Assert.AreEqual(nodes.Select(n => n.ResetTimes), new [] { 1, 1, 1, 1, 1 }); Assert.AreEqual(nodes.Select(n => n.TickTimes), new [] { 1, 1, 1, 1, 1 }); - blobRef.GetNodeData(2).State = NodeState.Success; + blobRef.GetNodeData(2).State = NodeState.Success; Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Running); Assert.AreEqual(nodes.Select(n => n.ResetTimes), new [] { 1, 1, 1, 1, 1 }); Assert.AreEqual(nodes.Select(n => n.TickTimes), new [] { 1, 2, 1, 2, 1 }); - blobRef.GetNodeData(4).State = NodeState.Failure; + blobRef.GetNodeData(4).State = NodeState.Failure; Assert.AreEqual(VirtualMachine.Tick(ref blobRef, ref _blackboard), NodeState.Failure); Assert.AreEqual(nodes.Select(n => n.ResetTimes), new [] { 1, 1, 1, 1, 1 }); Assert.AreEqual(nodes.Select(n => n.TickTimes), new [] { 1, 2, 1, 3, 1 }); diff --git a/Assets/Tests/Runtime/BTTestNodeA.cs b/Assets/Tests/Runtime/BTTestNodeA.cs index 0e3d1de3..48ea2551 100644 --- a/Assets/Tests/Runtime/BTTestNodeA.cs +++ b/Assets/Tests/Runtime/BTTestNodeA.cs @@ -1,9 +1,7 @@ #if UNITY_EDITOR -using Blob; using EntitiesBT.Components; using EntitiesBT.Core; -using Nuwa.Blob; using UnityEngine; namespace EntitiesBT.Test diff --git a/Assets/Tests/Runtime/BTTestNodeState.cs b/Assets/Tests/Runtime/BTTestNodeState.cs index 6d095bdb..7f8e4f53 100644 --- a/Assets/Tests/Runtime/BTTestNodeState.cs +++ b/Assets/Tests/Runtime/BTTestNodeState.cs @@ -1,9 +1,7 @@ #if UNITY_EDITOR -using Blob; using EntitiesBT.Components; using EntitiesBT.Core; -using Nuwa.Blob; using UnityEngine.Assertions; namespace EntitiesBT.Test diff --git a/Packages/essential/Runtime/Core/INodeBlob.cs b/Packages/essential/Runtime/Core/INodeBlob.cs index 21f9dae0..65b8edd3 100644 --- a/Packages/essential/Runtime/Core/INodeBlob.cs +++ b/Packages/essential/Runtime/Core/INodeBlob.cs @@ -62,14 +62,16 @@ public static unsafe void ResetRuntimeData(this ref TNodeBlob blob, i } [Pure] - public static unsafe ref T GetNodeData(this ref TNodeBlob blob, int index) where T : struct + public static unsafe ref T GetNodeData(this ref TNodeBlob blob, int index) + where T : struct where TNodeBlob : struct, INodeBlob { return ref UnsafeUtility.AsRef((void*)blob.GetRuntimeDataPtr(index)); } [Pure] - public static unsafe ref T GetNodeDefaultData(this ref TNodeBlob blob, int index) where T : struct + public static unsafe ref T GetNodeDefaultData(this ref TNodeBlob blob, int index) + where T : struct where TNodeBlob : struct, INodeBlob { return ref UnsafeUtility.AsRef((void*)blob.GetDefaultDataPtr(index)); diff --git a/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs new file mode 100644 index 00000000..3bb6426d --- /dev/null +++ b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs @@ -0,0 +1,79 @@ +using System; +using Blob; +using Unity.Collections.LowLevel.Unsafe; +using Unity.Mathematics; + +namespace EntitiesBT.Core +{ + public readonly struct ManagedNodeBlobRef : INodeBlob, IEquatable, IDisposable + { + private ref NodeBlob _blob => ref BlobRef.Value; + public readonly ManagedBlobAssetReference BlobRef; + + public ManagedNodeBlobRef(ManagedBlobAssetReference blobRef) => BlobRef = blobRef; + + public int RuntimeId + { + get => _blob.RuntimeId; + set => _blob.RuntimeId = value; + } + + public int Count => _blob.Count; + public int GetTypeId(int nodeIndex) => _blob.Types[nodeIndex]; + public int GetEndIndex(int nodeIndex) => _blob[nodeIndex].EndIndex; + public int GetNodeDataSize(int nodeIndex) => _blob[nodeIndex].Size; + public int GetNodeDataSize(int nodeIndex, int count) + { + var currentOffset = _blob[nodeIndex].Offset; + var nextOffset = _blob[math.min(nodeIndex + count, Count)].Offset; + return nextOffset - currentOffset; + } + + public unsafe void ResetStates(int index, int count) => + UnsafeUtility.MemClear(_blob.States.UnsafePtr + index, sizeof(NodeState) * count); + + public unsafe IntPtr GetDefaultDataPtr(int nodeIndex) => (IntPtr) _blob[nodeIndex].UnsafePtr; + + public unsafe IntPtr GetRuntimeDataPtr(int nodeIndex) => + (IntPtr) _blob.RuntimeDataBlob.UnsafePtr + _blob[nodeIndex].Offset; + + public unsafe IntPtr GetDefaultScopeValuePtr(int offset) => + IntPtr.Add(new IntPtr(_blob.DefaultGlobalValues.UnsafePtr), offset); + + public unsafe IntPtr GetRuntimeScopeValuePtr(int offset) => + IntPtr.Add(new IntPtr(_blob.RuntimeGlobalValues.UnsafePtr), offset); + + public NodeState GetState(int nodeIndex) => _blob.States[nodeIndex]; + public void SetState(int nodeIndex, NodeState state) => _blob.States[nodeIndex] = state; + + public bool Equals(ManagedNodeBlobRef other) + { + return BlobRef.Equals(other.BlobRef); + } + + public override bool Equals(object obj) + { + return obj is ManagedNodeBlobRef other && Equals(other); + } + + public override int GetHashCode() + { + return BlobRef.GetHashCode(); + } + + public static bool operator==(ManagedNodeBlobRef lhs, ManagedNodeBlobRef rhs) + { + return lhs.BlobRef == rhs.BlobRef; + } + + public static bool operator !=(ManagedNodeBlobRef lhs, ManagedNodeBlobRef rhs) + { + return !(lhs == rhs); + } + + public void Dispose() + { + BlobRef?.Dispose(); + } + } +} diff --git a/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs.meta b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs.meta new file mode 100644 index 00000000..822a9f96 --- /dev/null +++ b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2fe5457da66e425193ebf7fde7e7be94 +timeCreated: 1651161661 \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/NodeBlob.cs b/Packages/essential/Runtime/Core/NodeBlob.cs index 9196ed7f..637e736d 100644 --- a/Packages/essential/Runtime/Core/NodeBlob.cs +++ b/Packages/essential/Runtime/Core/NodeBlob.cs @@ -1,7 +1,5 @@ -using System; using JetBrains.Annotations; using Unity.Collections.LowLevel.Unsafe; -using Unity.Mathematics; using Blob; namespace EntitiesBT.Core @@ -40,71 +38,4 @@ public static int CalculateRuntimeSize(int count, int dataSize, int scopeValuesS public static int CalculateSize(int count, int dataSize, int scopeValuesSize) => CalculateDefaultSize(count, dataSize, scopeValuesSize) + CalculateRuntimeSize(count, dataSize, scopeValuesSize); } - - public readonly struct NodeBlobRef : INodeBlob, IEquatable - { - private ref NodeBlob _blob => ref BlobRef.Value; - public readonly Unity.Entities.BlobAssetReference BlobRef; - - public NodeBlobRef(Unity.Entities.BlobAssetReference blobRef) => BlobRef = blobRef; - - public int RuntimeId - { - get => _blob.RuntimeId; - set => _blob.RuntimeId = value; - } - - public int Count => _blob.Count; - public int GetTypeId(int nodeIndex) => _blob.Types[nodeIndex]; - public int GetEndIndex(int nodeIndex) => _blob[nodeIndex].EndIndex; - public int GetNodeDataSize(int nodeIndex) => _blob[nodeIndex].Size; - public int GetNodeDataSize(int nodeIndex, int count) - { - var currentOffset = _blob[nodeIndex].Offset; - var nextOffset = _blob[math.min(nodeIndex + count, Count)].Offset; - return nextOffset - currentOffset; - } - - public unsafe void ResetStates(int index, int count) => - UnsafeUtility.MemClear(_blob.States.UnsafePtr + index, sizeof(NodeState) * count); - - public unsafe IntPtr GetDefaultDataPtr(int nodeIndex) => (IntPtr) _blob[nodeIndex].UnsafePtr; - - public unsafe IntPtr GetRuntimeDataPtr(int nodeIndex) => - (IntPtr) _blob.RuntimeDataBlob.UnsafePtr + _blob[nodeIndex].Offset; - - public unsafe IntPtr GetDefaultScopeValuePtr(int offset) => - IntPtr.Add(new IntPtr(_blob.DefaultGlobalValues.UnsafePtr), offset); - - public unsafe IntPtr GetRuntimeScopeValuePtr(int offset) => - IntPtr.Add(new IntPtr(_blob.RuntimeGlobalValues.UnsafePtr), offset); - - public NodeState GetState(int nodeIndex) => _blob.States[nodeIndex]; - public void SetState(int nodeIndex, NodeState state) => _blob.States[nodeIndex] = state; - - public bool Equals(NodeBlobRef other) - { - return BlobRef.Equals(other.BlobRef); - } - - public override bool Equals(object obj) - { - return obj is NodeBlobRef other && Equals(other); - } - - public override int GetHashCode() - { - return BlobRef.GetHashCode(); - } - - public static bool operator==(NodeBlobRef lhs, NodeBlobRef rhs) - { - return lhs.BlobRef == rhs.BlobRef; - } - - public static bool operator !=(NodeBlobRef lhs, NodeBlobRef rhs) - { - return !(lhs == rhs); - } - } } diff --git a/Packages/essential/Runtime/Entities/NodeBlobRef.cs b/Packages/essential/Runtime/Entities/NodeBlobRef.cs new file mode 100644 index 00000000..2ff4b3dc --- /dev/null +++ b/Packages/essential/Runtime/Entities/NodeBlobRef.cs @@ -0,0 +1,74 @@ +using System; +using EntitiesBT.Core; +using Unity.Collections.LowLevel.Unsafe; +using Unity.Mathematics; + +namespace EntitiesBT.Entities +{ + public readonly struct NodeBlobRef : INodeBlob, IEquatable + { + private ref NodeBlob _blob => ref BlobRef.Value; + public readonly Unity.Entities.BlobAssetReference BlobRef; + + public NodeBlobRef(Unity.Entities.BlobAssetReference blobRef) => BlobRef = blobRef; + + public int RuntimeId + { + get => _blob.RuntimeId; + set => _blob.RuntimeId = value; + } + + public int Count => _blob.Count; + public int GetTypeId(int nodeIndex) => _blob.Types[nodeIndex]; + public int GetEndIndex(int nodeIndex) => _blob[nodeIndex].EndIndex; + public int GetNodeDataSize(int nodeIndex) => _blob[nodeIndex].Size; + public int GetNodeDataSize(int nodeIndex, int count) + { + var currentOffset = _blob[nodeIndex].Offset; + var nextOffset = _blob[math.min(nodeIndex + count, Count)].Offset; + return nextOffset - currentOffset; + } + + public unsafe void ResetStates(int index, int count) => + UnsafeUtility.MemClear(_blob.States.UnsafePtr + index, sizeof(NodeState) * count); + + public unsafe IntPtr GetDefaultDataPtr(int nodeIndex) => (IntPtr) _blob[nodeIndex].UnsafePtr; + + public unsafe IntPtr GetRuntimeDataPtr(int nodeIndex) => + (IntPtr) _blob.RuntimeDataBlob.UnsafePtr + _blob[nodeIndex].Offset; + + public unsafe IntPtr GetDefaultScopeValuePtr(int offset) => + IntPtr.Add(new IntPtr(_blob.DefaultGlobalValues.UnsafePtr), offset); + + public unsafe IntPtr GetRuntimeScopeValuePtr(int offset) => + IntPtr.Add(new IntPtr(_blob.RuntimeGlobalValues.UnsafePtr), offset); + + public NodeState GetState(int nodeIndex) => _blob.States[nodeIndex]; + public void SetState(int nodeIndex, NodeState state) => _blob.States[nodeIndex] = state; + + public bool Equals(NodeBlobRef other) + { + return BlobRef.Equals(other.BlobRef); + } + + public override bool Equals(object obj) + { + return obj is NodeBlobRef other && Equals(other); + } + + public override int GetHashCode() + { + return BlobRef.GetHashCode(); + } + + public static bool operator==(NodeBlobRef lhs, NodeBlobRef rhs) + { + return lhs.BlobRef == rhs.BlobRef; + } + + public static bool operator !=(NodeBlobRef lhs, NodeBlobRef rhs) + { + return !(lhs == rhs); + } + } +} \ No newline at end of file diff --git a/Packages/essential/Runtime/Entities/NodeBlobRef.cs.meta b/Packages/essential/Runtime/Entities/NodeBlobRef.cs.meta new file mode 100644 index 00000000..4dca8c7b --- /dev/null +++ b/Packages/essential/Runtime/Entities/NodeBlobRef.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 92ff237175bb43499945fd9ef636f447 +timeCreated: 1651161333 \ No newline at end of file From 8e7b3284b2bbadee7713c572ce90972177259ae5 Mon Sep 17 00:00:00 2001 From: quabug Date: Fri, 29 Apr 2022 01:18:00 +0800 Subject: [PATCH 17/28] use play mode testing for tests of simple composites to avoid crash. --- .../Tests/Editor/EntitiesBT.Tests.Editor.asmdef | 1 - .../{Editor => Runtime}/BehaviorTreeTestBase.cs | 0 .../BehaviorTreeTestBase.cs.meta | 0 .../Runtime/EntitiesBT.Tests.Runtime.asmdef | 16 ++++++++++------ .../{Editor => Runtime}/TestSimpleComposites.cs | 0 .../TestSimpleComposites.cs.meta | 0 6 files changed, 10 insertions(+), 7 deletions(-) rename Assets/Tests/{Editor => Runtime}/BehaviorTreeTestBase.cs (100%) rename Assets/Tests/{Editor => Runtime}/BehaviorTreeTestBase.cs.meta (100%) rename Assets/Tests/{Editor => Runtime}/TestSimpleComposites.cs (100%) rename Assets/Tests/{Editor => Runtime}/TestSimpleComposites.cs.meta (100%) diff --git a/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef b/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef index 56b0348e..b4a708df 100644 --- a/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef +++ b/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef @@ -22,7 +22,6 @@ "overrideReferences": true, "precompiledReferences": [ "nunit.framework.dll", - "Moq.dll", "Mono.Cecil.dll", "Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll", diff --git a/Assets/Tests/Editor/BehaviorTreeTestBase.cs b/Assets/Tests/Runtime/BehaviorTreeTestBase.cs similarity index 100% rename from Assets/Tests/Editor/BehaviorTreeTestBase.cs rename to Assets/Tests/Runtime/BehaviorTreeTestBase.cs diff --git a/Assets/Tests/Editor/BehaviorTreeTestBase.cs.meta b/Assets/Tests/Runtime/BehaviorTreeTestBase.cs.meta similarity index 100% rename from Assets/Tests/Editor/BehaviorTreeTestBase.cs.meta rename to Assets/Tests/Runtime/BehaviorTreeTestBase.cs.meta diff --git a/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef b/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef index d27ff968..38231249 100644 --- a/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef +++ b/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef @@ -2,21 +2,25 @@ "name": "EntitiesBT.Tests.Runtime", "rootNamespace": "", "references": [ - "GUID:27619889b8ba8c24980f49ee34dbb44a", "GUID:c7babe7561eb244059259745ef27b866", - "GUID:d3630359ae08047918d5cd6cddd51767", "GUID:734d92eba21c94caba915361bd5ac177", "GUID:f320ee23a990e5640812e0939a441a2b", "GUID:9835e0fdeb3db2247b6bf67e4f7d0469", - "GUID:6d84eb5386377416e93c122a00485b68" + "GUID:6d84eb5386377416e93c122a00485b68", + "GUID:27619889b8ba8c24980f49ee34dbb44a", + "GUID:0acc523941302664db1f4e527237feb3" ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": true, - "overrideReferences": false, - "precompiledReferences": [], + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], "autoReferenced": false, - "defineConstraints": [], + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], "versionDefines": [], "noEngineReferences": false } \ No newline at end of file diff --git a/Assets/Tests/Editor/TestSimpleComposites.cs b/Assets/Tests/Runtime/TestSimpleComposites.cs similarity index 100% rename from Assets/Tests/Editor/TestSimpleComposites.cs rename to Assets/Tests/Runtime/TestSimpleComposites.cs diff --git a/Assets/Tests/Editor/TestSimpleComposites.cs.meta b/Assets/Tests/Runtime/TestSimpleComposites.cs.meta similarity index 100% rename from Assets/Tests/Editor/TestSimpleComposites.cs.meta rename to Assets/Tests/Runtime/TestSimpleComposites.cs.meta From 9fc51de88158a061164c333824d164cd85aa44e4 Mon Sep 17 00:00:00 2001 From: quabug Date: Fri, 29 Apr 2022 21:38:23 +0800 Subject: [PATCH 18/28] fix drawer of node variant --- .../Editor/VariantNodeObjectAttributeDrawer.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Packages/builder.component/Editor/VariantNodeObjectAttributeDrawer.cs b/Packages/builder.component/Editor/VariantNodeObjectAttributeDrawer.cs index 2213205a..ce344158 100644 --- a/Packages/builder.component/Editor/VariantNodeObjectAttributeDrawer.cs +++ b/Packages/builder.component/Editor/VariantNodeObjectAttributeDrawer.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using EntitiesBT.Components; using EntitiesBT.Core; using EntitiesBT.Variant; using Nuwa.Editor; @@ -12,7 +13,7 @@ namespace EntitiesBT.Editor [CustomPropertyDrawer(typeof(VariantNodeObjectAttribute))] public class VariantNodeObjectAttributeDrawer : PropertyDrawer { - private INodeDataBuilder _nodeObject; + private BTNode _nodeObject; private string[] _options = new string[0]; private Type _genericType; private VariantNodeObjectAttribute _attribute; @@ -23,7 +24,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten { if (_genericType == null) _genericType = this.FirstGenericTypeArgument(); if (_attribute == null) _attribute = (VariantNodeObjectAttribute)attribute; - var nodeObject = (INodeDataBuilder)property.GetSiblingFieldValue(_attribute.NodeObjectFieldName); + var nodeObject = (BTNode)property.GetSiblingFieldValue(_attribute.NodeObjectFieldName); if (!Equals(nodeObject, _nodeObject)) { var readerType = typeof(BlobVariantRO<>).MakeGenericType(_genericType); From 28ef18e13081f1e23f69de1aca10650cde898ae9 Mon Sep 17 00:00:00 2001 From: quabug Date: Fri, 29 Apr 2022 21:39:01 +0800 Subject: [PATCH 19/28] use ManagedNodeBlobRef for GameObject BT. --- Assets/Samples/GameObjectWithoutEntity/BTController.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Assets/Samples/GameObjectWithoutEntity/BTController.cs b/Assets/Samples/GameObjectWithoutEntity/BTController.cs index adfffa63..15100e69 100644 --- a/Assets/Samples/GameObjectWithoutEntity/BTController.cs +++ b/Assets/Samples/GameObjectWithoutEntity/BTController.cs @@ -1,3 +1,4 @@ +using Blob; using EntitiesBT.Core; using EntitiesBT.Components; using EntitiesBT.Entities; @@ -8,12 +9,13 @@ namespace EntitiesBT.Sample public class BTController : MonoBehaviour { public BTNode RootNode; - private NodeBlobRef _nodeBlobRef; + private ManagedNodeBlobRef _nodeBlobRef; private GameObjectBlackboard _bb; private void Awake() { - _nodeBlobRef = new NodeBlobRef(RootNode.Node.ToBlob(RootNode.FindGlobalValuesList())); + var blobRef = RootNode.Node.ToBuilder(RootNode.FindGlobalValuesList()).CreateManagedBlobAssetReference(); + _nodeBlobRef = new ManagedNodeBlobRef(blobRef); Destroy(RootNode.gameObject); _bb = new GameObjectBlackboard(gameObject); VirtualMachine.Reset(ref _nodeBlobRef, ref _bb); @@ -27,7 +29,7 @@ private void Update() private void OnDestroy() { - _nodeBlobRef.BlobRef.Dispose(); + _nodeBlobRef.Dispose(); } } } From 961db0ea7a345d4093c27ed8fe170583e7c46a22 Mon Sep 17 00:00:00 2001 From: quabug Date: Wed, 4 May 2022 22:39:30 +0800 Subject: [PATCH 20/28] fix NodeBuilder of each node. --- Assets/Samples/Variable/VariableSample.unity | 2 +- Assets/Tests/Editor/TestVariant.cs | 29 +++++++++++++++++++ .../Runtime/BTDynamicNode.cs | 9 +++++- Packages/builder.component/Runtime/BTNode.cs | 7 ++++- .../Runtime/Entities/ComponentVariant.cs | 4 +-- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Assets/Samples/Variable/VariableSample.unity b/Assets/Samples/Variable/VariableSample.unity index ee63e38a..8d36a274 100644 --- a/Assets/Samples/Variable/VariableSample.unity +++ b/Assets/Samples/Variable/VariableSample.unity @@ -221,7 +221,7 @@ MonoBehaviour: 00000000: type: {class: BehaviorTreeSourceGameObject, ns: EntitiesBT.Components, asm: EntitiesBT.Component} data: - Root: {fileID: 340380320} + Root: {fileID: 1723425238} AutoDestroy: 0 --- !u!114 &1392768647 MonoBehaviour: diff --git a/Assets/Tests/Editor/TestVariant.cs b/Assets/Tests/Editor/TestVariant.cs index f824f8d7..a6393375 100644 --- a/Assets/Tests/Editor/TestVariant.cs +++ b/Assets/Tests/Editor/TestVariant.cs @@ -1,6 +1,8 @@ using System; +using Blob; using EntitiesBT.Variant; using NUnit.Framework; +using Unity.Entities; namespace EntitiesBT.Test { @@ -29,4 +31,31 @@ public void should_get_null_as_value_type_from_invalid_variant() Assert.That(variant.FindValueType(), Is.EqualTo(null)); } } + + public class TestComponentVariant + { + private BlobMemoryStream _blobStream; + private BlobVariantStream _variantStream; + + [SetUp] + public void SetUp() + { + _blobStream = new BlobMemoryStream(); + _variantStream = new BlobVariantStream(_blobStream); + } + + [Test] + public void should_find_value_type_of_variant() + { + var variant = new ComponentVariant.ReaderAndWriter(); + var type = Type.GetType("EntitiesBT.Sample.ComponentVariableData"); + variant.ComponentValueName = $"{type.FullName}.IntValue"; + variant.Allocate(_variantStream); + var blob = new ManagedBlobAssetReference(_blobStream.ToArray()); + Assert.That(blob.Value.VariantId, Is.EqualTo(Guid.Parse(ComponentVariant.GUID).GetHashCode())); + Assert.That(blob.Value.MetaDataOffsetPtr, Is.EqualTo(4)); + ref var data = ref blob.Value.As(); + Assert.That(data.StableHash, Is.EqualTo(TypeHash.CalculateStableTypeHash(type))); + } + } } \ No newline at end of file diff --git a/Packages/builder.component/Runtime/BTDynamicNode.cs b/Packages/builder.component/Runtime/BTDynamicNode.cs index 90f3d8bf..c8e2acd9 100644 --- a/Packages/builder.component/Runtime/BTDynamicNode.cs +++ b/Packages/builder.component/Runtime/BTDynamicNode.cs @@ -11,6 +11,13 @@ public class BTDynamicNode : BTNode public bool RunOnMainThread = false; protected override Type NodeType => Type.GetType(NodeData.NodeType ?? "") ?? typeof(ZeroNode); public override IBuilder BlobStreamBuilder => NodeData.Builder; - public override INodeDataBuilder Node => RunOnMainThread ? new DecoratorNode(base.Node) : base.Node; + public override INodeDataBuilder Node => RunOnMainThread ? _mainThreadNodeBuilder : base.Node; + + private readonly DecoratorNode _mainThreadNodeBuilder; + + public BTDynamicNode() + { + _mainThreadNodeBuilder = new DecoratorNode(base.Node); + } } } \ No newline at end of file diff --git a/Packages/builder.component/Runtime/BTNode.cs b/Packages/builder.component/Runtime/BTNode.cs index ca5e2ec4..60cd368d 100644 --- a/Packages/builder.component/Runtime/BTNode.cs +++ b/Packages/builder.component/Runtime/BTNode.cs @@ -40,7 +40,12 @@ public Builder([NotNull] BTNode node) protected virtual Type NodeType { get; } = typeof(ZeroNode); public abstract IBuilder BlobStreamBuilder { get; } public virtual bool IsValid => gameObject.activeInHierarchy; - public virtual INodeDataBuilder Node => new Builder(this); + public virtual INodeDataBuilder Node { get; } + + public BTNode() + { + Node = new Builder(this); + } protected virtual void Reset() => name = GetType().Name; diff --git a/Packages/essential/Runtime/Entities/ComponentVariant.cs b/Packages/essential/Runtime/Entities/ComponentVariant.cs index 74e72757..0452caaa 100644 --- a/Packages/essential/Runtime/Entities/ComponentVariant.cs +++ b/Packages/essential/Runtime/Entities/ComponentVariant.cs @@ -51,8 +51,8 @@ public struct DynamicComponentData [AccessorMethod] private static IEnumerable GetDynamicAccess(ref BlobVariant blobVariant) { - var hash = blobVariant.As().StableHash; - var typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(hash); + ref var data = ref blobVariant.As(); + var typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(data.StableHash); return ComponentType.FromTypeIndex(typeIndex).Yield(); } From 94f269ee7bc6bc6325e7e4a6b4a299c034b5c167 Mon Sep 17 00:00:00 2001 From: quabug Date: Tue, 21 Jun 2022 16:08:13 +0800 Subject: [PATCH 21/28] fix variant test --- Assets/Tests/Editor/TestVariant.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Assets/Tests/Editor/TestVariant.cs b/Assets/Tests/Editor/TestVariant.cs index a6393375..18e1b287 100644 --- a/Assets/Tests/Editor/TestVariant.cs +++ b/Assets/Tests/Editor/TestVariant.cs @@ -44,12 +44,19 @@ public void SetUp() _variantStream = new BlobVariantStream(_blobStream); } + struct ComponentVariableData : IComponentData + { + public float FloatValue; + public int IntValue; + public long LongValue; + } + [Test] public void should_find_value_type_of_variant() { var variant = new ComponentVariant.ReaderAndWriter(); - var type = Type.GetType("EntitiesBT.Sample.ComponentVariableData"); - variant.ComponentValueName = $"{type.FullName}.IntValue"; + var type = typeof(ComponentVariableData); + variant.ComponentValueName = $"{type.FullName}.{nameof(ComponentVariableData.IntValue)}"; variant.Allocate(_variantStream); var blob = new ManagedBlobAssetReference(_blobStream.ToArray()); Assert.That(blob.Value.VariantId, Is.EqualTo(Guid.Parse(ComponentVariant.GUID).GetHashCode())); From 843aa4202450c03752e536cc66e1bef0b926bf9f Mon Sep 17 00:00:00 2001 From: quabug Date: Sun, 26 Jun 2022 20:53:00 +0800 Subject: [PATCH 22/28] test cases of single variant --- Assets/Tests/Editor/Blackboard.cs | 71 +++++++++++ Assets/Tests/Editor/Blackboard.cs.meta | 3 + .../Editor/EntitiesBT.Tests.Editor.asmdef | 3 +- Assets/Tests/Editor/SingleLocalVariant.meta | 8 ++ .../Editor/SingleLocalVariant/Local.prefab | 78 ++++++++++++ .../SingleLocalVariant/Local.prefab.meta | 7 ++ .../SingleLocalVariant/TestSingleVariant.cs | 112 ++++++++++++++++++ .../TestSingleVariant.cs.meta | 11 ++ .../SingleLocalVariant/TestVariables.asset | 18 +++ .../TestVariables.asset.meta | 8 ++ .../SingleLocalVariant/component.prefab | 78 ++++++++++++ .../SingleLocalVariant/component.prefab.meta | 7 ++ .../SingleLocalVariant/expression.prefab | 79 ++++++++++++ .../SingleLocalVariant/expression.prefab.meta | 7 ++ .../Editor/SingleLocalVariant/node.prefab | 79 ++++++++++++ .../SingleLocalVariant/node.prefab.meta | 7 ++ .../scriptable-object.prefab | 80 +++++++++++++ .../scriptable-object.prefab.meta | 7 ++ .../Runtime/Core/ManagedNodeBlobRef.cs | 3 +- .../Runtime/Entities/ComponentVariant.cs | 1 - 20 files changed, 664 insertions(+), 3 deletions(-) create mode 100644 Assets/Tests/Editor/Blackboard.cs create mode 100644 Assets/Tests/Editor/Blackboard.cs.meta create mode 100644 Assets/Tests/Editor/SingleLocalVariant.meta create mode 100644 Assets/Tests/Editor/SingleLocalVariant/Local.prefab create mode 100644 Assets/Tests/Editor/SingleLocalVariant/Local.prefab.meta create mode 100644 Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs create mode 100644 Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs.meta create mode 100644 Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset create mode 100644 Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset.meta create mode 100644 Assets/Tests/Editor/SingleLocalVariant/component.prefab create mode 100644 Assets/Tests/Editor/SingleLocalVariant/component.prefab.meta create mode 100644 Assets/Tests/Editor/SingleLocalVariant/expression.prefab create mode 100644 Assets/Tests/Editor/SingleLocalVariant/expression.prefab.meta create mode 100644 Assets/Tests/Editor/SingleLocalVariant/node.prefab create mode 100644 Assets/Tests/Editor/SingleLocalVariant/node.prefab.meta create mode 100644 Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab create mode 100644 Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab.meta diff --git a/Assets/Tests/Editor/Blackboard.cs b/Assets/Tests/Editor/Blackboard.cs new file mode 100644 index 00000000..4dcf612f --- /dev/null +++ b/Assets/Tests/Editor/Blackboard.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using EntitiesBT.Core; +using Unity.Collections.LowLevel.Unsafe; + +namespace EntitiesBT.Test +{ + public struct Blackboard : IBlackboard + { + interface IBoxedValue + { + unsafe void* ValuePtr { get; } + } + + class BoxedValue : IBoxedValue where T : struct + { + public T Value; + public unsafe void* ValuePtr => UnsafeUtility.AddressOf(ref Value); + public BoxedValue(T value) => Value = value; + } + + private Dictionary _map; + + public void SetData(T value) where T : struct + { + if (_map == null) _map = new Dictionary(); + _map[typeof(T)] = new BoxedValue(value); + } + + public void SetObject(T value) where T : class + { + if (_map == null) _map = new Dictionary(); + _map[typeof(T)] = value; + } + + public bool HasData() where T : struct + { + return HasData(typeof(T)); + } + + public T GetData() where T : struct + { + return GetDataRef(); + } + + public ref T GetDataRef() where T : struct + { + return ref ((BoxedValue)_map[typeof(T)]).Value; + } + + public bool HasData(Type type) + { + return _map != null && _map.ContainsKey(type); + } + + public unsafe IntPtr GetDataPtrRO(Type type) + { + return new IntPtr(((IBoxedValue)_map[type]).ValuePtr); + } + + public IntPtr GetDataPtrRW(Type type) + { + return GetDataPtrRO(type); + } + + public T GetObject() where T : class + { + return (T)_map[typeof(T)]; + } + } +} \ No newline at end of file diff --git a/Assets/Tests/Editor/Blackboard.cs.meta b/Assets/Tests/Editor/Blackboard.cs.meta new file mode 100644 index 00000000..f84ec80e --- /dev/null +++ b/Assets/Tests/Editor/Blackboard.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 24f9948ae72341d2b4b27a020f132b2f +timeCreated: 1656235955 \ No newline at end of file diff --git a/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef b/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef index b4a708df..16968654 100644 --- a/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef +++ b/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef @@ -12,7 +12,8 @@ "GUID:f49b79f7e0a9b4b63a97d15e26787406", "GUID:ce5f967ea6c735344b367065891c4afb", "GUID:f320ee23a990e5640812e0939a441a2b", - "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469", + "GUID:6d84eb5386377416e93c122a00485b68" ], "includePlatforms": [ "Editor" diff --git a/Assets/Tests/Editor/SingleLocalVariant.meta b/Assets/Tests/Editor/SingleLocalVariant.meta new file mode 100644 index 00000000..7a7dd23d --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f79b82819b22f3f4fb8048791bd6c2f5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleLocalVariant/Local.prefab b/Assets/Tests/Editor/SingleLocalVariant/Local.prefab new file mode 100644 index 00000000..f5d70ebe --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/Local.prefab @@ -0,0 +1,78 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &3859903811092112260 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3544524698446228412} + - component: {fileID: 4666106902992339550} + m_Layer: 0 + m_Name: local + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3544524698446228412 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3859903811092112260} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &4666106902992339550 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3859903811092112260} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - Variant + Builders: + - id: 0 + - id: 1 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 0 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 2 + 00000002: + type: {class: /Int32LocalVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + Value: 123 diff --git a/Assets/Tests/Editor/SingleLocalVariant/Local.prefab.meta b/Assets/Tests/Editor/SingleLocalVariant/Local.prefab.meta new file mode 100644 index 00000000..f280be00 --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/Local.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5ddb40aa53d04b24b83d43e75d2a52fa +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs b/Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs new file mode 100644 index 00000000..f48e70ad --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs @@ -0,0 +1,112 @@ +using System; +using System.IO; +using Blob; +using EntitiesBT.Components; +using EntitiesBT.Core; +using EntitiesBT.Variant; +using EntitiesBT.Variant.Expression; +using JetBrains.Annotations; +using NUnit.Framework; +using Unity.Entities; +using UnityEditor; +using UnityEngine; + +namespace EntitiesBT.Test +{ + public struct TestComponentVariableData : IComponentData + { + public float FloatValue; + public int IntValue; + public long LongValue; + } + + [BehaviorNode("F5451E3F-B230-4207-A11B-B5E7D728F1E0")] + public struct SingleVariantNode : INodeData + { + public int IntValue; + public BlobVariantRO Variant; + + public NodeState Tick(int index, ref TNodeBlob blob, ref TBlackboard bb) + where TNodeBlob : struct, INodeBlob + where TBlackboard : struct, IBlackboard + { + throw new NotImplementedException(); + } + } + + public class TestSingleVariant + { + private Blackboard _bb; + + [SetUp] + public void SetUp() + { + _bb = new Blackboard(); + } + + [Test] + public void should_create_correct_blob_from_local_variant() + { + CheckVariant("local", LocalVariant.GUID, 123); + } + + [Test] + public void should_create_correct_blob_from_component_variant() + { + _bb.SetData(new TestComponentVariableData { IntValue = 234 }); + CheckVariant("component", ComponentVariant.GUID, 234); + } + + [Test] + public void should_create_correct_blob_from_expression_variant() + { + CheckVariant("expression", ExpressionVariant.GUID, 123+456); + } + + [Test] + public void should_create_correct_blob_from_node_variant() + { + CheckVariant("node", NodeVariant.ID_RUNTIME_NODE, 111); + } + + [Test] + public void should_create_correct_blob_from_scriptable_object_variant() + { + CheckVariant("scriptable-object", ScriptableObjectVariant.GUID, 222); + } + + void CheckVariant(string prefabName, string variantGUID, int value) + { + var blob = LoadBlob(prefabName); + try + { + Assert.That(blob.Count, Is.EqualTo(1)); + Assert.That(blob.GetTypeId(0), Is.EqualTo(typeof(SingleVariantNode).GetBehaviorNodeAttribute().Id)); + + ref var defaultNode = ref blob.GetNodeDefaultData(0); + Assert.That(defaultNode.Variant.Value.VariantId, Is.EqualTo(Guid.Parse(variantGUID).GetHashCode())); + Assert.That(defaultNode.Variant.Value.MetaDataOffsetPtr, Is.EqualTo(4)); + Assert.That(defaultNode.Variant.Read(0, ref blob, ref _bb), Is.EqualTo(value)); + + ref var node = ref blob.GetNodeData(0); + // ref var node = ref blob.BlobRef.Value.Nodes[0].GetValue(); + Assert.That(node.Variant.Value.VariantId, Is.EqualTo(Guid.Parse(variantGUID).GetHashCode())); + Assert.That(node.Variant.Value.MetaDataOffsetPtr, Is.EqualTo(4)); + Assert.That(node.Variant.Read(0, ref blob, ref _bb), Is.EqualTo(value)); + } + finally + { + blob.Dispose(); + } + } + + private ManagedNodeBlobRef LoadBlob([NotNull] string prefabName) + { + var directory = Core.Utilities.GetCurrentDirectoryProjectRelativePath(); + var prefabPath = Path.Combine(directory, $"{prefabName}.prefab"); + var blob = AssetDatabase.LoadAssetAtPath(prefabPath).GetComponent(); + var blobRef = blob.Node.ToBuilder(blob.FindGlobalValuesList()).CreateManagedBlobAssetReference(); + return new ManagedNodeBlobRef(blobRef); + } + } +} diff --git a/Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs.meta b/Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs.meta new file mode 100644 index 00000000..89888145 --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 912f472bbc804564f867117e68162d72 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset b/Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset new file mode 100644 index 00000000..f1858bef --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bd078efebeb340edaa2b83df6eba9a83, type: 3} + m_Name: TestVariables + m_EditorClassIdentifier: + IntValue: 0 + FloatValue: 0 + AnotherFloatValue: 0 + k__BackingField: 0 diff --git a/Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset.meta b/Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset.meta new file mode 100644 index 00000000..d706ccbc --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 29b05bb74db20b44d9c43d888551daa9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleLocalVariant/component.prefab b/Assets/Tests/Editor/SingleLocalVariant/component.prefab new file mode 100644 index 00000000..0c183d1f --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/component.prefab @@ -0,0 +1,78 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &81978901338157521 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 397076660311587305} + - component: {fileID: 8391132929918455819} + m_Layer: 0 + m_Name: component + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &397076660311587305 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 81978901338157521} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &8391132929918455819 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 81978901338157521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - Variant + Builders: + - id: 0 + - id: 1 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 0 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 2 + 00000002: + type: {class: /Int32ComponentVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + ComponentValueName: EntitiesBT.Test.TestComponentVariableData.IntValue diff --git a/Assets/Tests/Editor/SingleLocalVariant/component.prefab.meta b/Assets/Tests/Editor/SingleLocalVariant/component.prefab.meta new file mode 100644 index 00000000..c081a30d --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/component.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 81dfd4c06c8b7fd4ba747b7415fddfd5 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleLocalVariant/expression.prefab b/Assets/Tests/Editor/SingleLocalVariant/expression.prefab new file mode 100644 index 00000000..22715d1a --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/expression.prefab @@ -0,0 +1,79 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &5229742286920136598 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5490532916533968814} + - component: {fileID: 4450598183092852300} + m_Layer: 0 + m_Name: expression + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5490532916533968814 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5229742286920136598} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &4450598183092852300 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5229742286920136598} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - Variant + Builders: + - id: 0 + - id: 1 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 0 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 2 + 00000002: + type: {class: /Int32ExpressionVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + _expression: 123+456 + _sources: [] diff --git a/Assets/Tests/Editor/SingleLocalVariant/expression.prefab.meta b/Assets/Tests/Editor/SingleLocalVariant/expression.prefab.meta new file mode 100644 index 00000000..aab5ac9a --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/expression.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2b090dbff7c65944697c10c7d6be153f +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleLocalVariant/node.prefab b/Assets/Tests/Editor/SingleLocalVariant/node.prefab new file mode 100644 index 00000000..b0fd3ee5 --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/node.prefab @@ -0,0 +1,79 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2046534156072362949 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1785452431825153021} + - component: {fileID: 7581469577241723423} + m_Layer: 0 + m_Name: node + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1785452431825153021 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2046534156072362949} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &7581469577241723423 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2046534156072362949} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - Variant + Builders: + - id: 0 + - id: 1 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 111 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 2 + 00000002: + type: {class: /Int32NodeVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + NodeObject: {fileID: 7581469577241723423} + ValueFieldName: IntValue diff --git a/Assets/Tests/Editor/SingleLocalVariant/node.prefab.meta b/Assets/Tests/Editor/SingleLocalVariant/node.prefab.meta new file mode 100644 index 00000000..6ac73afd --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/node.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5cff0e1f08c2fab48a6e5646a7f35113 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab b/Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab new file mode 100644 index 00000000..1bfce779 --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab @@ -0,0 +1,80 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &1660291744759977088 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1417234160006765752} + - component: {fileID: 7087257454083814746} + m_Layer: 0 + m_Name: scriptable-object + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1417234160006765752 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1660291744759977088} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &7087257454083814746 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1660291744759977088} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.SingleVariantNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - Variant + Builders: + - id: 0 + - id: 1 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 0 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 2 + 00000002: + type: {class: /Int32ScriptableObjectVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + ScriptableObject: {fileID: 11400000, guid: 29b05bb74db20b44d9c43d888551daa9, + type: 2} + ScriptableObjectValueName: IntValue diff --git a/Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab.meta b/Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab.meta new file mode 100644 index 00000000..c5ee811c --- /dev/null +++ b/Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3314f0c46781f454fb8fdb037fb8988d +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs index 3bb6426d..85ad52cf 100644 --- a/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs +++ b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs @@ -1,5 +1,6 @@ using System; using Blob; +using Nuwa.Blob; using Unity.Collections.LowLevel.Unsafe; using Unity.Mathematics; @@ -35,7 +36,7 @@ public unsafe void ResetStates(int index, int count) => public unsafe IntPtr GetDefaultDataPtr(int nodeIndex) => (IntPtr) _blob[nodeIndex].UnsafePtr; public unsafe IntPtr GetRuntimeDataPtr(int nodeIndex) => - (IntPtr) _blob.RuntimeDataBlob.UnsafePtr + _blob[nodeIndex].Offset; + IntPtr.Add(new IntPtr(_blob.RuntimeDataBlob.UnsafePtr), _blob[nodeIndex].Offset); public unsafe IntPtr GetDefaultScopeValuePtr(int offset) => IntPtr.Add(new IntPtr(_blob.DefaultGlobalValues.UnsafePtr), offset); diff --git a/Packages/essential/Runtime/Entities/ComponentVariant.cs b/Packages/essential/Runtime/Entities/ComponentVariant.cs index 0452caaa..38615df7 100644 --- a/Packages/essential/Runtime/Entities/ComponentVariant.cs +++ b/Packages/essential/Runtime/Entities/ComponentVariant.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Blob; using EntitiesBT.Core; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; From b37789e1ede432d10d39a2127a994235026e33e7 Mon Sep 17 00:00:00 2001 From: quabug Date: Sun, 26 Jun 2022 21:05:06 +0800 Subject: [PATCH 23/28] rename directory --- Assets/Tests/Editor/MultipleVariant.meta | 8 ++++++++ .../{SingleLocalVariant.meta => SingleVariant.meta} | 0 .../TestSingleVariant.cs | 0 .../TestSingleVariant.cs.meta | 0 .../TestVariables.asset | 0 .../TestVariables.asset.meta | 0 .../component.prefab | 0 .../component.prefab.meta | 0 .../expression.prefab | 0 .../expression.prefab.meta | 0 .../Local.prefab => SingleVariant/local.prefab} | 0 .../Local.prefab.meta => SingleVariant/local.prefab.meta} | 0 .../{SingleLocalVariant => SingleVariant}/node.prefab | 0 .../node.prefab.meta | 0 .../scriptable-object.prefab | 0 .../scriptable-object.prefab.meta | 0 16 files changed, 8 insertions(+) create mode 100644 Assets/Tests/Editor/MultipleVariant.meta rename Assets/Tests/Editor/{SingleLocalVariant.meta => SingleVariant.meta} (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/TestSingleVariant.cs (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/TestSingleVariant.cs.meta (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/TestVariables.asset (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/TestVariables.asset.meta (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/component.prefab (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/component.prefab.meta (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/expression.prefab (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/expression.prefab.meta (100%) rename Assets/Tests/Editor/{SingleLocalVariant/Local.prefab => SingleVariant/local.prefab} (100%) rename Assets/Tests/Editor/{SingleLocalVariant/Local.prefab.meta => SingleVariant/local.prefab.meta} (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/node.prefab (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/node.prefab.meta (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/scriptable-object.prefab (100%) rename Assets/Tests/Editor/{SingleLocalVariant => SingleVariant}/scriptable-object.prefab.meta (100%) diff --git a/Assets/Tests/Editor/MultipleVariant.meta b/Assets/Tests/Editor/MultipleVariant.meta new file mode 100644 index 00000000..fefdca24 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7fae54ba66263b640bcf391006c17d9b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleLocalVariant.meta b/Assets/Tests/Editor/SingleVariant.meta similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant.meta rename to Assets/Tests/Editor/SingleVariant.meta diff --git a/Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs rename to Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs diff --git a/Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs.meta b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs.meta similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/TestSingleVariant.cs.meta rename to Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs.meta diff --git a/Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset b/Assets/Tests/Editor/SingleVariant/TestVariables.asset similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset rename to Assets/Tests/Editor/SingleVariant/TestVariables.asset diff --git a/Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset.meta b/Assets/Tests/Editor/SingleVariant/TestVariables.asset.meta similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/TestVariables.asset.meta rename to Assets/Tests/Editor/SingleVariant/TestVariables.asset.meta diff --git a/Assets/Tests/Editor/SingleLocalVariant/component.prefab b/Assets/Tests/Editor/SingleVariant/component.prefab similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/component.prefab rename to Assets/Tests/Editor/SingleVariant/component.prefab diff --git a/Assets/Tests/Editor/SingleLocalVariant/component.prefab.meta b/Assets/Tests/Editor/SingleVariant/component.prefab.meta similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/component.prefab.meta rename to Assets/Tests/Editor/SingleVariant/component.prefab.meta diff --git a/Assets/Tests/Editor/SingleLocalVariant/expression.prefab b/Assets/Tests/Editor/SingleVariant/expression.prefab similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/expression.prefab rename to Assets/Tests/Editor/SingleVariant/expression.prefab diff --git a/Assets/Tests/Editor/SingleLocalVariant/expression.prefab.meta b/Assets/Tests/Editor/SingleVariant/expression.prefab.meta similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/expression.prefab.meta rename to Assets/Tests/Editor/SingleVariant/expression.prefab.meta diff --git a/Assets/Tests/Editor/SingleLocalVariant/Local.prefab b/Assets/Tests/Editor/SingleVariant/local.prefab similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/Local.prefab rename to Assets/Tests/Editor/SingleVariant/local.prefab diff --git a/Assets/Tests/Editor/SingleLocalVariant/Local.prefab.meta b/Assets/Tests/Editor/SingleVariant/local.prefab.meta similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/Local.prefab.meta rename to Assets/Tests/Editor/SingleVariant/local.prefab.meta diff --git a/Assets/Tests/Editor/SingleLocalVariant/node.prefab b/Assets/Tests/Editor/SingleVariant/node.prefab similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/node.prefab rename to Assets/Tests/Editor/SingleVariant/node.prefab diff --git a/Assets/Tests/Editor/SingleLocalVariant/node.prefab.meta b/Assets/Tests/Editor/SingleVariant/node.prefab.meta similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/node.prefab.meta rename to Assets/Tests/Editor/SingleVariant/node.prefab.meta diff --git a/Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab b/Assets/Tests/Editor/SingleVariant/scriptable-object.prefab similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab rename to Assets/Tests/Editor/SingleVariant/scriptable-object.prefab diff --git a/Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab.meta b/Assets/Tests/Editor/SingleVariant/scriptable-object.prefab.meta similarity index 100% rename from Assets/Tests/Editor/SingleLocalVariant/scriptable-object.prefab.meta rename to Assets/Tests/Editor/SingleVariant/scriptable-object.prefab.meta From bd5dbef05608bf4a5bd9cdf8a1cc3432ac2980f8 Mon Sep 17 00:00:00 2001 From: quabug Date: Wed, 20 Jul 2022 14:49:06 +0800 Subject: [PATCH 24/28] tests of single variant and multiple variant. --- .../GameObjectSample.unity | 76 ++++++++++- .../GameObjectWithoutEntitySample.asmdef | 3 +- .../MultipleVariant/TestMultipleVariants.cs | 125 ++++++++++++++++++ .../TestMultipleVariants.cs.meta | 3 + .../MultipleVariant/component-linked.prefab | 112 ++++++++++++++++ .../component-linked.prefab.meta | 7 + .../Editor/MultipleVariant/component.prefab | 120 +++++++++++++++++ .../MultipleVariant/component.prefab.meta | 7 + .../MultipleVariant/local-linked.prefab | 112 ++++++++++++++++ .../MultipleVariant/local-linked.prefab.meta | 7 + .../Tests/Editor/MultipleVariant/local.prefab | 120 +++++++++++++++++ .../Editor/MultipleVariant/local.prefab.meta | 7 + .../Editor/MultipleVariant/node-linked.prefab | 114 ++++++++++++++++ .../MultipleVariant/node-linked.prefab.meta | 7 + .../Tests/Editor/MultipleVariant/node.prefab | 124 +++++++++++++++++ .../Editor/MultipleVariant/node.prefab.meta | 7 + .../TestComponentVariableData.cs | 11 ++ .../TestComponentVariableData.cs.meta | 3 + .../Editor/SingleVariant/TestSingleVariant.cs | 9 -- .../Editor/SingleVariant/TestVariables.asset | 2 +- Assets/Tests/Editor/TestVariant.cs | 32 +++++ 21 files changed, 996 insertions(+), 12 deletions(-) create mode 100644 Assets/Tests/Editor/MultipleVariant/TestMultipleVariants.cs create mode 100644 Assets/Tests/Editor/MultipleVariant/TestMultipleVariants.cs.meta create mode 100644 Assets/Tests/Editor/MultipleVariant/component-linked.prefab create mode 100644 Assets/Tests/Editor/MultipleVariant/component-linked.prefab.meta create mode 100644 Assets/Tests/Editor/MultipleVariant/component.prefab create mode 100644 Assets/Tests/Editor/MultipleVariant/component.prefab.meta create mode 100644 Assets/Tests/Editor/MultipleVariant/local-linked.prefab create mode 100644 Assets/Tests/Editor/MultipleVariant/local-linked.prefab.meta create mode 100644 Assets/Tests/Editor/MultipleVariant/local.prefab create mode 100644 Assets/Tests/Editor/MultipleVariant/local.prefab.meta create mode 100644 Assets/Tests/Editor/MultipleVariant/node-linked.prefab create mode 100644 Assets/Tests/Editor/MultipleVariant/node-linked.prefab.meta create mode 100644 Assets/Tests/Editor/MultipleVariant/node.prefab create mode 100644 Assets/Tests/Editor/MultipleVariant/node.prefab.meta create mode 100644 Assets/Tests/Editor/SingleVariant/TestComponentVariableData.cs create mode 100644 Assets/Tests/Editor/SingleVariant/TestComponentVariableData.cs.meta diff --git a/Assets/Samples/GameObjectWithoutEntity/GameObjectSample.unity b/Assets/Samples/GameObjectWithoutEntity/GameObjectSample.unity index c6e0f858..17077774 100644 --- a/Assets/Samples/GameObjectWithoutEntity/GameObjectSample.unity +++ b/Assets/Samples/GameObjectWithoutEntity/GameObjectSample.unity @@ -344,18 +344,21 @@ MonoBehaviour: _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 _variant: id: 2 _writer: _variantTypeName: EntitiesBT.Variant.IVariantWriter`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 _variant: id: 2 _readerAndWriter: _variantTypeName: EntitiesBT.Variant.IVariantReaderAndWriter`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 _variant: id: 3 00000001: @@ -514,6 +517,74 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1371246634 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1371246636} + - component: {fileID: 1371246635} + m_Layer: 0 + m_Name: RepeatTimesNode + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1371246635 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1371246634} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Nodes.RepeatTimesNode, EntitiesBT.Runtime, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Nodes.RepeatTimesNode, EntitiesBT.Runtime, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: + - TickTimes + - BreakStates + Builders: + - id: 0 + - id: 1 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 99 + 00000001: + type: {class: DynamicIntEnumBuilder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + EnumTypeName: EntitiesBT.Core.NodeState, EntitiesBT.Runtime, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Value: 0 +--- !u!4 &1371246636 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1371246634} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1406639141 GameObject: m_ObjectHideFlags: 0 @@ -664,7 +735,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cd51157a0681449e922dfe58f2e96327, type: 3} m_Name: m_EditorClassIdentifier: - RootNode: {fileID: 1406639143} + RootNode: {fileID: 1371246635} --- !u!23 &2006228428 MeshRenderer: m_ObjectHideFlags: 0 @@ -796,18 +867,21 @@ MonoBehaviour: _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 _variant: id: 2 _writer: _variantTypeName: EntitiesBT.Variant.IVariantWriter`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 _variant: id: 2 _readerAndWriter: _variantTypeName: EntitiesBT.Variant.IVariantReaderAndWriter`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 _variant: id: 3 00000001: diff --git a/Assets/Samples/GameObjectWithoutEntity/GameObjectWithoutEntitySample.asmdef b/Assets/Samples/GameObjectWithoutEntity/GameObjectWithoutEntitySample.asmdef index 7d31942c..372d5ea5 100644 --- a/Assets/Samples/GameObjectWithoutEntity/GameObjectWithoutEntitySample.asmdef +++ b/Assets/Samples/GameObjectWithoutEntity/GameObjectWithoutEntitySample.asmdef @@ -5,7 +5,8 @@ "GUID:c7babe7561eb244059259745ef27b866", "GUID:734d92eba21c94caba915361bd5ac177", "GUID:f320ee23a990e5640812e0939a441a2b", - "GUID:6d84eb5386377416e93c122a00485b68" + "GUID:6d84eb5386377416e93c122a00485b68", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Tests/Editor/MultipleVariant/TestMultipleVariants.cs b/Assets/Tests/Editor/MultipleVariant/TestMultipleVariants.cs new file mode 100644 index 00000000..bf7236a8 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/TestMultipleVariants.cs @@ -0,0 +1,125 @@ +using System; +using System.IO; +using Blob; +using EntitiesBT.Components; +using EntitiesBT.Core; +using EntitiesBT.Variant; +using EntitiesBT.Variant.Expression; +using JetBrains.Annotations; +using NUnit.Framework; +using UnityEditor; +using UnityEngine; + +namespace EntitiesBT.Test +{ + [BehaviorNode("9CE63B04-86E6-48CE-A4A0-49A03D9A11B8")] + public struct MultipleVariantsNode : INodeData + { + public int IntValue; + public BlobVariantRO ReadOnlyVariant; + public BlobVariantRW ReadWriteVariant; + + public NodeState Tick(int index, ref TNodeBlob blob, ref TBlackboard bb) + where TNodeBlob : struct, INodeBlob + where TBlackboard : struct, IBlackboard + { + throw new NotImplementedException(); + } + } + + public class TestMultipleVariant + { + private Blackboard _bb; + + [SetUp] + public void SetUp() + { + _bb = new Blackboard(); + } + + [Test] + public void should_create_correct_blob_from_local_variant_with_linked_rw() + { + CheckVariant("local-linked", LocalVariant.GUID, 123, 234); + } + + [Test] + public void should_create_correct_blob_from_component_variant_with_linked_rw() + { + _bb.SetData(new TestComponentVariableData { IntValue = 234 }); + CheckVariant("component-linked", ComponentVariant.GUID, 234); + } + + [Test] + public void should_create_correct_blob_from_node_variant_with_linked_rw() + { + CheckVariant("node-linked", NodeVariant.ID_RUNTIME_NODE, 222); + } + + [Test] + public void should_create_correct_blob_from_local_variant() + { + CheckVariant("local", LocalVariant.GUID, 123, 234); + } + + [Test] + public void should_create_correct_blob_from_component_variant() + { + _bb.SetData(new TestComponentVariableData { IntValue = 234 }); + CheckVariant("component", ComponentVariant.GUID, 234); + } + + [Test] + public void should_create_correct_blob_from_node_variant() + { + CheckVariant("node", NodeVariant.ID_RUNTIME_NODE, 222); + } + + void CheckVariant(string prefabName, string variantGUID, int readOnlyValue) + { + CheckVariant(prefabName, variantGUID, readOnlyValue, readOnlyValue); + } + + void CheckVariant(string prefabName, string variantGUID, int readOnlyValue, int readWriteValue) + { + var blob = LoadBlob(prefabName); + try + { + Assert.That(blob.Count, Is.EqualTo(1)); + Assert.That(blob.GetTypeId(0), Is.EqualTo(typeof(MultipleVariantsNode).GetBehaviorNodeAttribute().Id)); + + ref var defaultNode = ref blob.GetNodeDefaultData(0); + ref var node = ref blob.GetNodeData(0); + + Assert.That(defaultNode.ReadOnlyVariant.Value.VariantId, Is.EqualTo(Guid.Parse(variantGUID).GetHashCode())); + // Assert.That(defaultNode.ReadOnlyVariant.Value.MetaDataOffsetPtr, Is.EqualTo(20)); + Assert.That(defaultNode.ReadOnlyVariant.Read(0, ref blob, ref _bb), Is.EqualTo(readOnlyValue)); + + Assert.That(node.ReadOnlyVariant.Value.VariantId, Is.EqualTo(Guid.Parse(variantGUID).GetHashCode())); + // Assert.That(node.ReadOnlyVariant.Value.MetaDataOffsetPtr, Is.EqualTo(20)); + Assert.That(node.ReadOnlyVariant.Read(0, ref blob, ref _bb), Is.EqualTo(readOnlyValue)); + + Assert.That(defaultNode.ReadWriteVariant.Reader.Value.VariantId, Is.EqualTo(Guid.Parse(variantGUID).GetHashCode())); + // Assert.That(defaultNode.ReadWriteVariant.Reader.Value.MetaDataOffsetPtr, Is.EqualTo(16)); + Assert.That(defaultNode.ReadWriteVariant.Read(0, ref blob, ref _bb), Is.EqualTo(readWriteValue)); + + Assert.That(node.ReadWriteVariant.Reader.Value.VariantId, Is.EqualTo(Guid.Parse(variantGUID).GetHashCode())); + // Assert.That(node.ReadWriteVariant.Reader.Value.MetaDataOffsetPtr, Is.EqualTo(16)); + Assert.That(node.ReadWriteVariant.Read(0, ref blob, ref _bb), Is.EqualTo(readWriteValue)); + } + finally + { + blob.Dispose(); + } + } + + private ManagedNodeBlobRef LoadBlob([NotNull] string prefabName) + { + var directory = Core.Utilities.GetCurrentDirectoryProjectRelativePath(); + var prefabPath = Path.Combine(directory, $"{prefabName}.prefab"); + var blob = AssetDatabase.LoadAssetAtPath(prefabPath).GetComponent(); + var blobRef = blob.Node.ToBuilder(blob.FindGlobalValuesList()).CreateManagedBlobAssetReference(); + return new ManagedNodeBlobRef(blobRef); + } + } +} diff --git a/Assets/Tests/Editor/MultipleVariant/TestMultipleVariants.cs.meta b/Assets/Tests/Editor/MultipleVariant/TestMultipleVariants.cs.meta new file mode 100644 index 00000000..9f74990d --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/TestMultipleVariants.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6abb7d3b82fc4f34bf36e3368bad0f91 +timeCreated: 1656249051 \ No newline at end of file diff --git a/Assets/Tests/Editor/MultipleVariant/component-linked.prefab b/Assets/Tests/Editor/MultipleVariant/component-linked.prefab new file mode 100644 index 00000000..54050345 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/component-linked.prefab @@ -0,0 +1,112 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &7890031917118167316 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7628686858733261100} + - component: {fileID: 1742738750063753422} + m_Layer: 0 + m_Name: component-linked + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7628686858733261100 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7890031917118167316} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1742738750063753422 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7890031917118167316} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - ReadOnlyVariant + - ReadWriteVariant + Builders: + - id: 0 + - id: 1 + - id: 2 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 0 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 3 + 00000002: + type: {class: BlobVariantLinkedRWBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _isLinked: 1 + _reader: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _writer: + _variantTypeName: EntitiesBT.Variant.IVariantWriter`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _readerAndWriter: + _variantTypeName: EntitiesBT.Variant.IVariantReaderAndWriter`1[[System.Int32, + mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 5 + 00000003: + type: {class: /Int32ComponentVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + ComponentValueName: EntitiesBT.Test.TestComponentVariableData.IntValue + 00000004: + type: {class: , ns: , asm: } + 00000005: + type: {class: /Int32ComponentVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + ComponentValueName: EntitiesBT.Test.TestComponentVariableData.IntValue diff --git a/Assets/Tests/Editor/MultipleVariant/component-linked.prefab.meta b/Assets/Tests/Editor/MultipleVariant/component-linked.prefab.meta new file mode 100644 index 00000000..6ed3799b --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/component-linked.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 15ae73273578e1d43b20d18f67097030 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/MultipleVariant/component.prefab b/Assets/Tests/Editor/MultipleVariant/component.prefab new file mode 100644 index 00000000..327a220a --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/component.prefab @@ -0,0 +1,120 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &5372626118164492463 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5633698032500357271} + - component: {fileID: 4602418700512334197} + m_Layer: 0 + m_Name: component + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5633698032500357271 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5372626118164492463} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &4602418700512334197 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5372626118164492463} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - ReadOnlyVariant + - ReadWriteVariant + Builders: + - id: 0 + - id: 1 + - id: 2 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 0 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 3 + 00000002: + type: {class: BlobVariantLinkedRWBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _isLinked: 0 + _reader: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _writer: + _variantTypeName: EntitiesBT.Variant.IVariantWriter`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 5 + _readerAndWriter: + _variantTypeName: EntitiesBT.Variant.IVariantReaderAndWriter`1[[System.Int32, + mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 6 + 00000003: + type: {class: /Int32ComponentVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + ComponentValueName: EntitiesBT.Test.TestComponentVariableData.IntValue + 00000004: + type: {class: /Int32ComponentVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + ComponentValueName: EntitiesBT.Test.TestComponentVariableData.IntValue + 00000005: + type: {class: /Int32ComponentVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + ComponentValueName: EntitiesBT.Test.TestComponentVariableData.IntValue + 00000006: + type: {class: /Int32ComponentVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + ComponentValueName: EntitiesBT.Test.TestComponentVariableData.IntValue diff --git a/Assets/Tests/Editor/MultipleVariant/component.prefab.meta b/Assets/Tests/Editor/MultipleVariant/component.prefab.meta new file mode 100644 index 00000000..99add571 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/component.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1540eb8a60e048e4b80c650b2da2a662 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/MultipleVariant/local-linked.prefab b/Assets/Tests/Editor/MultipleVariant/local-linked.prefab new file mode 100644 index 00000000..0cca36c8 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/local-linked.prefab @@ -0,0 +1,112 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4949212295219883738 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4615818131263039202} + - component: {fileID: 3602694765253660416} + m_Layer: 0 + m_Name: local-linked + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4615818131263039202 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4949212295219883738} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &3602694765253660416 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4949212295219883738} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - ReadOnlyVariant + - ReadWriteVariant + Builders: + - id: 0 + - id: 1 + - id: 2 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 0 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 3 + 00000002: + type: {class: BlobVariantLinkedRWBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _isLinked: 1 + _reader: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _writer: + _variantTypeName: EntitiesBT.Variant.IVariantWriter`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _readerAndWriter: + _variantTypeName: EntitiesBT.Variant.IVariantReaderAndWriter`1[[System.Int32, + mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 5 + 00000003: + type: {class: /Int32LocalVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + Value: 123 + 00000004: + type: {class: , ns: , asm: } + 00000005: + type: {class: /Int32LocalVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + Value: 234 diff --git a/Assets/Tests/Editor/MultipleVariant/local-linked.prefab.meta b/Assets/Tests/Editor/MultipleVariant/local-linked.prefab.meta new file mode 100644 index 00000000..112c18a9 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/local-linked.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 225578966e943ca4aaf62c60546cc47e +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/MultipleVariant/local.prefab b/Assets/Tests/Editor/MultipleVariant/local.prefab new file mode 100644 index 00000000..dc73a62c --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/local.prefab @@ -0,0 +1,120 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2567794249172743731 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2811142535560658443} + - component: {fileID: 6265306231702968297} + m_Layer: 0 + m_Name: local + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2811142535560658443 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2567794249172743731} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6265306231702968297 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2567794249172743731} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - ReadOnlyVariant + - ReadWriteVariant + Builders: + - id: 0 + - id: 1 + - id: 2 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 0 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 3 + 00000002: + type: {class: BlobVariantLinkedRWBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _isLinked: 0 + _reader: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _writer: + _variantTypeName: EntitiesBT.Variant.IVariantWriter`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 5 + _readerAndWriter: + _variantTypeName: EntitiesBT.Variant.IVariantReaderAndWriter`1[[System.Int32, + mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 6 + 00000003: + type: {class: /Int32LocalVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + Value: 123 + 00000004: + type: {class: /Int32LocalVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + Value: 234 + 00000005: + type: {class: /Int32LocalVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + Value: 0 + 00000006: + type: {class: /Int32LocalVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + Value: 234 diff --git a/Assets/Tests/Editor/MultipleVariant/local.prefab.meta b/Assets/Tests/Editor/MultipleVariant/local.prefab.meta new file mode 100644 index 00000000..6e8f5720 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/local.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0ab01efdc6e08b54b8495612a35817a0 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/MultipleVariant/node-linked.prefab b/Assets/Tests/Editor/MultipleVariant/node-linked.prefab new file mode 100644 index 00000000..424abdf0 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/node-linked.prefab @@ -0,0 +1,114 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &1316022919807141005 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1649161481604730037} + - component: {fileID: 7427287143227696471} + m_Layer: 0 + m_Name: node-linked + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1649161481604730037 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1316022919807141005} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &7427287143227696471 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1316022919807141005} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - ReadOnlyVariant + - ReadWriteVariant + Builders: + - id: 0 + - id: 1 + - id: 2 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 222 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 3 + 00000002: + type: {class: BlobVariantLinkedRWBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _isLinked: 1 + _reader: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _writer: + _variantTypeName: EntitiesBT.Variant.IVariantWriter`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _readerAndWriter: + _variantTypeName: EntitiesBT.Variant.IVariantReaderAndWriter`1[[System.Int32, + mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 5 + 00000003: + type: {class: /Int32NodeVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + NodeObject: {fileID: 7427287143227696471} + ValueFieldName: IntValue + 00000004: + type: {class: , ns: , asm: } + 00000005: + type: {class: /Int32NodeVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + NodeObject: {fileID: 7427287143227696471} + ValueFieldName: IntValue diff --git a/Assets/Tests/Editor/MultipleVariant/node-linked.prefab.meta b/Assets/Tests/Editor/MultipleVariant/node-linked.prefab.meta new file mode 100644 index 00000000..03a814a9 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/node-linked.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 14c854469e0a7904fb0ad05fe1318a80 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/MultipleVariant/node.prefab b/Assets/Tests/Editor/MultipleVariant/node.prefab new file mode 100644 index 00000000..b884a8c3 --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/node.prefab @@ -0,0 +1,124 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &5453134615497358774 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5696175518361400718} + - component: {fileID: 4538811054105435244} + m_Layer: 0 + m_Name: node + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5696175518361400718 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5453134615497358774} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &4538811054105435244 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5453134615497358774} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9aa8e40e4654495e832b55e693d52966, type: 3} + m_Name: + m_EditorClassIdentifier: + NodeData: + NodeType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + Builder: + BlobDataType: EntitiesBT.Test.MultipleVariantsNode, EntitiesBT.Tests.Editor, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + FieldNames: + - IntValue + - ReadOnlyVariant + - ReadWriteVariant + Builders: + - id: 0 + - id: 1 + - id: 2 + RunOnMainThread: 0 + references: + version: 1 + 00000000: + type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} + data: + Value: 222 + 00000001: + type: {class: BlobVariantROBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], EntitiesBT.Runtime, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 3 + 00000002: + type: {class: BlobVariantLinkedRWBuilder, ns: EntitiesBT.Variant, asm: EntitiesBT.Runtime} + data: + _isLinked: 0 + _reader: + _variantTypeName: EntitiesBT.Variant.IVariantReader`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 4 + _writer: + _variantTypeName: EntitiesBT.Variant.IVariantWriter`1[[System.Int32, mscorlib, + Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 5 + _readerAndWriter: + _variantTypeName: EntitiesBT.Variant.IVariantReaderAndWriter`1[[System.Int32, + mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], + EntitiesBT.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + IsOptional: 0 + _variant: + id: 6 + 00000003: + type: {class: /Int32NodeVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + NodeObject: {fileID: 4538811054105435244} + ValueFieldName: IntValue + 00000004: + type: {class: /Int32NodeVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + NodeObject: {fileID: 4538811054105435244} + ValueFieldName: IntValue + 00000005: + type: {class: /Int32NodeVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + NodeObject: {fileID: 4538811054105435244} + ValueFieldName: IntValue + 00000006: + type: {class: /Int32NodeVariant, ns: EntitiesBT.Variant.CodeGen, + asm: Assembly-CSharp} + data: + NodeObject: {fileID: 4538811054105435244} + ValueFieldName: IntValue diff --git a/Assets/Tests/Editor/MultipleVariant/node.prefab.meta b/Assets/Tests/Editor/MultipleVariant/node.prefab.meta new file mode 100644 index 00000000..107c30ec --- /dev/null +++ b/Assets/Tests/Editor/MultipleVariant/node.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c5f35d7abfa9c3343942ad75d18609d7 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleVariant/TestComponentVariableData.cs b/Assets/Tests/Editor/SingleVariant/TestComponentVariableData.cs new file mode 100644 index 00000000..fca1ea20 --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/TestComponentVariableData.cs @@ -0,0 +1,11 @@ +using Unity.Entities; + +namespace EntitiesBT.Test +{ + public struct TestComponentVariableData : IComponentData + { + public float FloatValue; + public int IntValue; + public long LongValue; + } +} \ No newline at end of file diff --git a/Assets/Tests/Editor/SingleVariant/TestComponentVariableData.cs.meta b/Assets/Tests/Editor/SingleVariant/TestComponentVariableData.cs.meta new file mode 100644 index 00000000..c0a6d921 --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/TestComponentVariableData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 39c054fca90f4363b0e63fed45892a00 +timeCreated: 1656251281 \ No newline at end of file diff --git a/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs index f48e70ad..f63f71ef 100644 --- a/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs +++ b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs @@ -7,19 +7,11 @@ using EntitiesBT.Variant.Expression; using JetBrains.Annotations; using NUnit.Framework; -using Unity.Entities; using UnityEditor; using UnityEngine; namespace EntitiesBT.Test { - public struct TestComponentVariableData : IComponentData - { - public float FloatValue; - public int IntValue; - public long LongValue; - } - [BehaviorNode("F5451E3F-B230-4207-A11B-B5E7D728F1E0")] public struct SingleVariantNode : INodeData { @@ -89,7 +81,6 @@ void CheckVariant(string prefabName, string variantGUID, int value) Assert.That(defaultNode.Variant.Read(0, ref blob, ref _bb), Is.EqualTo(value)); ref var node = ref blob.GetNodeData(0); - // ref var node = ref blob.BlobRef.Value.Nodes[0].GetValue(); Assert.That(node.Variant.Value.VariantId, Is.EqualTo(Guid.Parse(variantGUID).GetHashCode())); Assert.That(node.Variant.Value.MetaDataOffsetPtr, Is.EqualTo(4)); Assert.That(node.Variant.Read(0, ref blob, ref _bb), Is.EqualTo(value)); diff --git a/Assets/Tests/Editor/SingleVariant/TestVariables.asset b/Assets/Tests/Editor/SingleVariant/TestVariables.asset index f1858bef..f94591fe 100644 --- a/Assets/Tests/Editor/SingleVariant/TestVariables.asset +++ b/Assets/Tests/Editor/SingleVariant/TestVariables.asset @@ -12,7 +12,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bd078efebeb340edaa2b83df6eba9a83, type: 3} m_Name: TestVariables m_EditorClassIdentifier: - IntValue: 0 + IntValue: 222 FloatValue: 0 AnotherFloatValue: 0 k__BackingField: 0 diff --git a/Assets/Tests/Editor/TestVariant.cs b/Assets/Tests/Editor/TestVariant.cs index 18e1b287..0a5f2009 100644 --- a/Assets/Tests/Editor/TestVariant.cs +++ b/Assets/Tests/Editor/TestVariant.cs @@ -2,6 +2,7 @@ using Blob; using EntitiesBT.Variant; using NUnit.Framework; +using Nuwa.Blob; using Unity.Entities; namespace EntitiesBT.Test @@ -64,5 +65,36 @@ public void should_find_value_type_of_variant() ref var data = ref blob.Value.As(); Assert.That(data.StableHash, Is.EqualTo(TypeHash.CalculateStableTypeHash(type))); } + + struct Variants + { + public BlobVariantRO IntRO; + public BlobVariantRW FloatRW; + } + + [Test] + public void should_find_value_type_of_variant_() + { + var type = typeof(ComponentVariableData); + var intRO = new ComponentVariant.Reader(); + intRO.ComponentValueName = $"{type.FullName}.{nameof(ComponentVariableData.IntValue)}"; + var floatRW = new ComponentVariant.ReaderAndWriter(); + floatRW.ComponentValueName = $"{type.FullName}.{nameof(ComponentVariableData.FloatValue)}"; + var builder = new StructBuilder(); + builder.SetBuilder(ref builder.Value.IntRO, new VariantBuilder>(intRO)); + builder.SetBuilder(ref builder.Value.FloatRW, new VariantBuilder>(floatRW)); + builder.Build(_blobStream); + var blob = new ManagedBlobAssetReference(_blobStream.ToArray()); + + Assert.That(blob.Value.IntRO.Value.VariantId, Is.EqualTo(Guid.Parse(ComponentVariant.GUID).GetHashCode())); + Assert.That(blob.Value.IntRO.Value.MetaDataOffsetPtr, Is.EqualTo(24)); + ref var intVariantData = ref blob.Value.IntRO.Value.As(); + Assert.That(intVariantData.StableHash, Is.EqualTo(TypeHash.CalculateStableTypeHash(type))); + + // Assert.That(blob.Value.FloatRW.Reader.Value.VariantId, Is.EqualTo(Guid.Parse(ComponentVariant.GUID).GetHashCode())); + // Assert.That(blob.Value.FloatRW.Value.MetaDataOffsetPtr, Is.EqualTo(16)); + // ref var intVariantData = ref blob.Value.FloatRW.Value.As(); + // Assert.That(intVariantData.StableHash, Is.EqualTo(TypeHash.CalculateStableTypeHash(type))); + } } } \ No newline at end of file From 60b87fe0ef3a48d43f7596f1bd1fb9e992975127 Mon Sep 17 00:00:00 2001 From: quabug Date: Sun, 31 Jul 2022 14:03:42 +0800 Subject: [PATCH 25/28] fix variables. --- Assets/Samples/Animator/SetAnimatorTrigger.cs | 4 +- .../Runtime/Entity/IsEntityPositionInBox.cs | 4 +- .../InputSystem/InputActionGuidBuilder.cs | 6 +-- Assets/Samples/Variable/VariableSample.unity | 22 ++++---- .../BuilderDrawer/BlobDataBuilderDrawer.cs | 7 +-- .../Nuwa/Blob/Runtime/Builder/Builders.cs | 52 +++++++++---------- .../Blob/Runtime/Builder/DynamicBuilders.cs | 20 +++++-- .../Runtime/Core/INodeDataBuilder.cs | 2 +- .../Runtime/Core/MetaNodeRegister.cs | 10 ++-- .../essential/Runtime/Core/VirtualMachine.cs | 4 +- .../Entities/ArrayBuilderWithMemoryCopy.cs | 24 ++++----- .../Composites/WeightRandomSelectorNode.cs | 4 +- .../Runtime/Variant/BlobVariantStream.cs | 35 +++++++------ .../Runtime/Variant/VariantBuilder.cs | 2 +- 14 files changed, 103 insertions(+), 93 deletions(-) diff --git a/Assets/Samples/Animator/SetAnimatorTrigger.cs b/Assets/Samples/Animator/SetAnimatorTrigger.cs index ed5aeb48..32f28b77 100644 --- a/Assets/Samples/Animator/SetAnimatorTrigger.cs +++ b/Assets/Samples/Animator/SetAnimatorTrigger.cs @@ -25,9 +25,9 @@ public class AnimatorTriggerNameBuilder : Nuwa.Blob.Builder { public string TriggerName; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, ref int value) { - stream.WriteValue(Animator.StringToHash(TriggerName)); + value = Animator.StringToHash(TriggerName); } } } diff --git a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs index 26404d1e..2a825024 100644 --- a/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs +++ b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs @@ -29,9 +29,9 @@ public class ColliderBoundsBuilder : Nuwa.Blob.Builder public Transform Transform; public BoxCollider Box; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, ref Bounds value) { - stream.WriteValue(new Bounds(Box.center + Transform.position, Box.size)); + value = new Bounds(Box.center + Transform.position, Box.size); } } } diff --git a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs index c2245178..b289dcd3 100644 --- a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs +++ b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs @@ -5,13 +5,13 @@ namespace EntitiesBT.Extensions.InputSystem { - public class InputActionGuidBuilder : PlainDataBuilder + public class InputActionGuidBuilder : Nuwa.Blob.Builder { public InputActionReference InputAction; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, ref Guid value) { - value.Value = InputAction.action.id; + value = InputAction.action.id; } } diff --git a/Assets/Samples/Variable/VariableSample.unity b/Assets/Samples/Variable/VariableSample.unity index 8d36a274..95628e6b 100644 --- a/Assets/Samples/Variable/VariableSample.unity +++ b/Assets/Samples/Variable/VariableSample.unity @@ -221,7 +221,7 @@ MonoBehaviour: 00000000: type: {class: BehaviorTreeSourceGameObject, ns: EntitiesBT.Components, asm: EntitiesBT.Component} data: - Root: {fileID: 1723425238} + Root: {fileID: 340380320} AutoDestroy: 0 --- !u!114 &1392768647 MonoBehaviour: @@ -439,15 +439,19 @@ MonoBehaviour: _variant: id: 7 00000001: - type: {class: StringBuilder, ns: Nuwa.Blob, asm: Nuwa.Blob} + type: {class: UnityStringBuilder, ns: Nuwa.Blob, asm: Nuwa.Blob} data: - Value: 233213adffda + Value: 3214jklfdajkl 00000002: - type: {class: DynamicArrayBuilder, ns: Nuwa.Blob, asm: Nuwa.Blob} + type: {class: DynamicBlobDataBuilder, ns: Nuwa.Blob, asm: Nuwa.Blob} data: - ArrayElementType: System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - Value: + BlobDataType: Unity.Entities.BlobArray`1[[System.Int32, mscorlib, Version=4.0.0.0, + Culture=neutral, PublicKeyToken=b77a5c561934e089]], Unity.Entities, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + FieldNames: + - m_OffsetPtr + - m_Length + Builders: - id: 8 - id: 9 00000003: @@ -505,11 +509,11 @@ MonoBehaviour: 00000008: type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} data: - Value: 333 + Value: 0 00000009: type: {class: Int32Builder, ns: Nuwa.Blob, asm: Nuwa.Blob} data: - Value: 444 + Value: 0 0000000A: type: {class: /Int64ComponentVariant, ns: EntitiesBT.Variant.CodeGen, asm: Assembly-CSharp} diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs b/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs index a91bd171..1bd55f78 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs @@ -104,13 +104,14 @@ private SerializedProperty FieldNames(SerializedProperty property) var blobField = blobFields[i]; var builderFactory = blobField.FindBuilderCreator(); var builder = builders[i]; - if (builder == null || builder.GetType() != builderFactory.Type || blobField.Name != fieldNames[i]) + var isSameType = builder?.GetType() == builderFactory.Type; + if (builder == null || !isSameType || blobField.Name != fieldNames[i]) { fieldNamesProperty.GetArrayElementAtIndex(i).stringValue = blobField.Name; var builderIndex = Array.IndexOf(fieldNames, blobField.Name); object newBuilder = null; - if (builderIndex >= 0) newBuilder = builders[builderIndex]; - else if (builder != null && builder.GetType() == builderFactory.Type) newBuilder = builder; + if (builderIndex >= 0 && isSameType) newBuilder = builders[builderIndex]; + else if (builder != null && isSameType) newBuilder = builder; else newBuilder = builderFactory.Create(); buildersProperty.GetArrayElementAtIndex(i).managedReferenceValue = newBuilder; property.serializedObject.ApplyModifiedPropertiesWithoutUndo(); diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs index 9aa6e151..c05d0e4e 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/Builders.cs @@ -25,20 +25,8 @@ public interface IObjectBuilder IReadOnlyList GetBuilders(); } - public abstract class Builder : IBuilder where T : unmanaged + public abstract class Builder : global::Blob.Builder, IBuilder where T : unmanaged { - public int Position { get; private set; } - - public void Build(IBlobStream stream) - { - Position = stream.DataPosition; - stream.EnsureDataSize(); - var value = new UnsafeBlobStreamValue(stream, Position); - BuildImpl(stream, value); - } - - protected abstract void BuildImpl([NotNull] IBlobStream stream, UnsafeBlobStreamValue value); - public virtual IBuilder GetBuilder(string name) => throw new NotImplementedException(); public virtual object PreviewValue @@ -59,9 +47,9 @@ public class PlainDataBuilder : Builder where T : unmanaged { public T Value; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, ref T value) { - value.Value = Value; + value = Value; } public override object PreviewValue @@ -88,9 +76,9 @@ public BlobDataBuilder() BuilderUtility.SetBlobDataType(typeof(T), ref Builders, ref FieldNames); } - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, ref T value) { - var dataPosition = stream.DataPosition; + var dataPosition = stream.Position; var fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (var i = 0; i < Builders.Length; i++) { @@ -129,7 +117,7 @@ public class ArrayBuilder : Builder> where T : unmanaged { [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Value; - protected override unsafe void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue> value) + protected override unsafe void BuildImpl(IBlobStream stream, ref BlobArray value) { stream.WritePatchOffset() .WriteValue(Value.Length) @@ -154,6 +142,23 @@ public override object PreviewValue } } + [Serializable, DefaultBuilder] + public class UnityStringBuilder : Builder + { + public string Value; + + public override object PreviewValue + { + get => Value; + set => Value = (string)value; + } + + protected override void BuildImpl(IBlobStream stream, ref Unity.Entities.BlobString data) + { + new global::Blob.UnityStringBuilder(Value).Build(stream); + } + } + [Serializable, DefaultBuilder] public class StringBuilder : Builder { @@ -165,14 +170,9 @@ public override object PreviewValue set => Value = (string)value; } - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, ref BlobString data) { - var stringBytes = Encoding.UTF8.GetBytes(Value); - stream.WritePatchOffset() - .WriteValue(stringBytes.Length) - .ToPatchPosition() - .WriteArray(stringBytes) - ; + new StringBuilder(Value).Build(stream); } } @@ -184,7 +184,7 @@ public class PtrBuilder : Builder> where T : unmanaged { [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder Value; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue> value) + protected override void BuildImpl(IBlobStream stream, ref BlobPtr value) { stream.WritePatchOffset().ToPatchPosition().WriteValue(Value); } diff --git a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs index c7bc8a86..83864d2c 100644 --- a/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs +++ b/Packages/essential/Dependencies/Nuwa/Blob/Runtime/Builder/DynamicBuilders.cs @@ -29,15 +29,25 @@ public abstract class DynamicBuilderFactory : IDynamicBuilderFactory where T public abstract class DynamicBuilder : IBuilder { - public int Position { get; private set; } + public int DataAlignment { get; set; } = 0; + public int PatchAlignment { get; set; } = 0; + + public int DataPosition { get; private set; } + public int DataSize { get; private set; } + public int PatchPosition { get; private set; } + public int PatchSize { get; private set; } + protected abstract Type _Type { get; } public void Build(IBlobStream stream) { - Position = stream.DataPosition; - // TODO: fetch alignment by type? - stream.EnsureDataSize(UnsafeUtility.SizeOf(_Type), 4); + DataPosition = stream.Position; + DataSize = UnsafeUtility.SizeOf(_Type); + stream.EnsureDataSize(DataSize, stream.GetAlignment(DataAlignment)); + PatchPosition = stream.PatchPosition; BuildImpl(stream); + if (PatchPosition != stream.PatchPosition) stream.AlignPatch(stream.GetAlignment(PatchAlignment)); + PatchSize = stream.PatchPosition - PatchPosition; } protected abstract void BuildImpl([NotNull] IBlobStream stream); @@ -133,7 +143,7 @@ public class DynamicBlobDataBuilder : DynamicBuilder, IObjectBuilder protected override void BuildImpl(IBlobStream stream) { - var position = stream.DataPosition; + var position = stream.Position; var fields = _Type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (var i = 0; i < Builders.Length; i++) { diff --git a/Packages/essential/Runtime/Core/INodeDataBuilder.cs b/Packages/essential/Runtime/Core/INodeDataBuilder.cs index 29ba7aaf..53b46643 100644 --- a/Packages/essential/Runtime/Core/INodeDataBuilder.cs +++ b/Packages/essential/Runtime/Core/INodeDataBuilder.cs @@ -49,7 +49,7 @@ this INodeDataBuilder root builder.SetArray(ref builder.Value.States, new NodeState[typeList.Count]); builder.SetBuilder( ref builder.Value.RuntimeDataBlob, - new ArrayBuilderWithMemoryCopy>(() => (treeBuilder.ArrayBuilder.PatchPosition, treeBuilder.ArrayBuilder.PatchSize)) { Alignment = treeBuilder.Alignment } + new ArrayBuilderWithMemoryCopy>(treeBuilder.ArrayBuilder.DataBuilder) ); builder.SetArray(ref builder.Value.RuntimeGlobalValues, globalValuesStream.ToArray()); return builder; diff --git a/Packages/essential/Runtime/Core/MetaNodeRegister.cs b/Packages/essential/Runtime/Core/MetaNodeRegister.cs index 0bfc75fe..b1c8a89f 100644 --- a/Packages/essential/Runtime/Core/MetaNodeRegister.cs +++ b/Packages/essential/Runtime/Core/MetaNodeRegister.cs @@ -101,25 +101,25 @@ internal static class MetaNodeRegister where TNodeBlob : struct, INodeBlob where TBlackboard : struct, IBlackboard { - internal delegate NodeState TickFunc(IntPtr ptr, int index, TNodeBlob blob, TBlackboard bb); + internal delegate NodeState TickFunc(IntPtr ptr, int index, ref TNodeBlob blob, ref TBlackboard bb); [Preserve] - private static unsafe NodeState Tick(IntPtr ptr, int index, TNodeBlob blob, TBlackboard bb) + private static unsafe NodeState Tick(IntPtr ptr, int index, ref TNodeBlob blob, ref TBlackboard bb) where TNodeData : unmanaged, INodeData { return UnsafeUtility.AsRef((void*)ptr).Tick(index, ref blob, ref bb); } - internal delegate void ResetFunc(IntPtr ptr, int index, TNodeBlob blob, TBlackboard bb); + internal delegate void ResetFunc(IntPtr ptr, int index, ref TNodeBlob blob, ref TBlackboard bb); [Preserve] - private static unsafe void Reset(IntPtr ptr, int index, TNodeBlob blob, TBlackboard bb) + private static unsafe void Reset(IntPtr ptr, int index, ref TNodeBlob blob, ref TBlackboard bb) where TNodeData : unmanaged, ICustomResetAction { UnsafeUtility.AsRef((void*)ptr).Reset(index, ref blob, ref bb); } - private static void DefaultReset(IntPtr ptr, int index, TNodeBlob blob, TBlackboard bb) {} + private static void DefaultReset(IntPtr ptr, int index, ref TNodeBlob blob, ref TBlackboard bb) {} internal class Node { diff --git a/Packages/essential/Runtime/Core/VirtualMachine.cs b/Packages/essential/Runtime/Core/VirtualMachine.cs index 60ea1e1b..9de0bdd4 100644 --- a/Packages/essential/Runtime/Core/VirtualMachine.cs +++ b/Packages/essential/Runtime/Core/VirtualMachine.cs @@ -21,7 +21,7 @@ public static NodeState Tick(int index, ref TNodeBlob bl { var typeId = blob.GetTypeId(index); var ptr = blob.GetRuntimeDataPtr(index); - var state = MetaNodeRegister.NODES[typeId].Tick.Invoke(ptr, index, blob, bb); + var state = MetaNodeRegister.NODES[typeId].Tick.Invoke(ptr, index, ref blob, ref bb); blob.SetState(index, state); return state; } @@ -36,7 +36,7 @@ public static void Reset(int fromIndex, ref TNodeBlob bl { var typeId = blob.GetTypeId(i); var ptr = blob.GetRuntimeDataPtr(i); - MetaNodeRegister.NODES[typeId].Reset.Invoke(ptr, i, blob, bb); + MetaNodeRegister.NODES[typeId].Reset.Invoke(ptr, i, ref blob, ref bb); } } diff --git a/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs b/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs index f8160c80..3b2eb845 100644 --- a/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs +++ b/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs @@ -1,28 +1,22 @@ -using System; +using JetBrains.Annotations; namespace Blob { - public class ArrayBuilderWithMemoryCopy : Builder - where TArray : unmanaged - where TValue : unmanaged + public class ArrayBuilderWithMemoryCopy : Builder where TArray : unmanaged { - private readonly Func<(int position, int length)> _getDataFunc; - public int Alignment { get; set; } = 0; + [NotNull] private readonly IBuilder _builder; - public ArrayBuilderWithMemoryCopy(Func<(int position, int length)> getDataFunc) + public ArrayBuilderWithMemoryCopy([NotNull] IBuilder builder) { - _getDataFunc = getDataFunc; + _builder = builder; } - protected override unsafe void BuildImpl(IBlobStream stream) + protected override unsafe void BuildImpl(IBlobStream stream, ref TArray data) { - if (Alignment <= 0) Alignment = Utilities.AlignOf(); - var (position, length) = _getDataFunc(); - var size = (length + sizeof(TValue) - 1) / sizeof(TValue); - stream.EnsureDataSize().WriteArrayMeta(size).ToPatchPosition(); - fixed (void* ptr = &stream.Buffer[position]) + stream.WriteArrayMeta(_builder.PatchSize).ToPatchPosition(); + fixed (void* ptr = &stream.Buffer[_builder.PatchPosition]) { - stream.Write((byte*)ptr, size, Alignment); + stream.Write((byte*)ptr, _builder.PatchSize); } } } diff --git a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs index c2001894..88a5daca 100644 --- a/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs +++ b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs @@ -40,11 +40,11 @@ public NodeState Tick(int index, ref TNodeBlob blob, ref } } - public class NormalizedWeightBuilder : PlainDataBuilder> + public class NormalizedWeightBuilder : Nuwa.Blob.Builder> { public int[] Weights; - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue> value) + protected override void BuildImpl(IBlobStream stream, ref BlobArray data) { float sum = Weights.Sum(); new Blob.ArrayBuilder(Weights.Select(w => w / sum).ToArray()).Build(stream); diff --git a/Packages/essential/Runtime/Variant/BlobVariantStream.cs b/Packages/essential/Runtime/Variant/BlobVariantStream.cs index d28617ec..d5fe9653 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantStream.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantStream.cs @@ -21,37 +21,37 @@ public BlobVariantStream([NotNull] IBlobStream stream) { _stream = stream; stream.EnsureDataSize(); - _idPosition = stream.DataPosition; + _idPosition = stream.Position; _patchPosition = stream.PatchPosition; stream.WriteValue(new BlobVariant().VariantId); - _offsetPosition = stream.DataPosition; + _offsetPosition = stream.Position; } public void SetVariantId(int id) { - _stream.DataPosition = _idPosition; + _stream.Position = _idPosition; _stream.WriteValue(id); } public void SetVariantValue(T value) where T : unmanaged { - _stream.DataPosition = _offsetPosition; + _stream.Position = _offsetPosition; _stream.WritePatchOffset(); - _stream.DataPosition = _patchPosition; + _stream.Position = _patchPosition; _stream.WriteValue(value); } public void SetVariantValue(IBuilder builder) where T : unmanaged { - _stream.DataPosition = _offsetPosition; + _stream.Position = _offsetPosition; _stream.WritePatchOffset(); - _stream.DataPosition = _patchPosition; + _stream.Position = _patchPosition; builder.Build(_stream); } public void SetVariantOffset(int offset) { - _stream.DataPosition = _offsetPosition; + _stream.Position = _offsetPosition; _stream.WriteValue(offset); } } @@ -68,7 +68,7 @@ public class BlobVariantROBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, ref BlobVariant value) { _variant?.Allocate(new BlobVariantStream(stream)); } @@ -102,7 +102,7 @@ public class BlobVariantWOBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override void BuildImpl(IBlobStream stream, ref BlobVariant value) { _variant.Allocate(new BlobVariantStream(stream)); } @@ -136,16 +136,15 @@ public class BlobVariantRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _variant.PreviewValue; set => throw new NotImplementedException(); } - protected override unsafe void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override unsafe void BuildImpl(IBlobStream stream, ref BlobVariantRW value) { _variant.Allocate(new BlobVariantStream(stream)); - value.Value.Writer.VariantId = value.Value.Reader.VariantId; + value.Writer.VariantId = value.Reader.VariantId; // HACK: set meta data of writer as same as reader's - fixed (void* writerDataPtr = &value.Value.Writer.MetaDataOffsetPtr) - fixed (void* readerDataPtr = &value.Value.Reader.MetaDataOffsetPtr) + fixed (void* writerDataPtr = &value.Writer.MetaDataOffsetPtr) + fixed (void* readerDataPtr = &value.Reader.MetaDataOffsetPtr) { - value.Value.Writer.MetaDataOffsetPtr = - value.Value.Reader.MetaDataOffsetPtr + (int)((long)writerDataPtr - (long)readerDataPtr); + value.Writer.MetaDataOffsetPtr = value.Reader.MetaDataOffsetPtr + (int)((byte*)writerDataPtr - (byte*)readerDataPtr); } } } @@ -160,7 +159,7 @@ public class BlobVariantLinkedRWBuilder : Nuwa.Blob.Builder public override object PreviewValue { get => _isLinked ? _readerAndWriter.PreviewValue : _reader.PreviewValue; set => throw new NotImplementedException(); } - protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue value) + protected override unsafe void BuildImpl(IBlobStream stream, ref BlobVariantRW value) { if (_isLinked) { @@ -169,6 +168,8 @@ protected override void BuildImpl(IBlobStream stream, UnsafeBlobStreamValue _variant = variant; - protected override void BuildImpl(IBlobStream stream) + protected override void BuildImpl(IBlobStream stream, ref T value) { _variant.Allocate(new BlobVariantStream(stream)); } From 2a16d65915248e253915847b16e41301729d109a Mon Sep 17 00:00:00 2001 From: quabug Date: Sun, 31 Jul 2022 15:56:06 +0800 Subject: [PATCH 26/28] fix runtime --- .../GameObjectWithoutEntity/BTController.cs | 2 +- .../Editor/SingleVariant/TestSingleVariant.cs | 2 +- Assets/Tests/Editor/TestExpression.cs | 4 +- Assets/Tests/Editor/TestVariant.cs | 50 +++++++++---------- .../Runtime/Core/ManagedNodeBlobRef.cs | 6 ++- .../Runtime/Variant/BlobVariantStream.cs | 2 +- 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/Assets/Samples/GameObjectWithoutEntity/BTController.cs b/Assets/Samples/GameObjectWithoutEntity/BTController.cs index 15100e69..bd6953c4 100644 --- a/Assets/Samples/GameObjectWithoutEntity/BTController.cs +++ b/Assets/Samples/GameObjectWithoutEntity/BTController.cs @@ -15,7 +15,7 @@ public class BTController : MonoBehaviour private void Awake() { var blobRef = RootNode.Node.ToBuilder(RootNode.FindGlobalValuesList()).CreateManagedBlobAssetReference(); - _nodeBlobRef = new ManagedNodeBlobRef(blobRef); + _nodeBlobRef = new ManagedNodeBlobRef(blobRef, gameObject.GetInstanceID()); Destroy(RootNode.gameObject); _bb = new GameObjectBlackboard(gameObject); VirtualMachine.Reset(ref _nodeBlobRef, ref _bb); diff --git a/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs index f63f71ef..a1c1c931 100644 --- a/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs +++ b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs @@ -97,7 +97,7 @@ private ManagedNodeBlobRef LoadBlob([NotNull] string prefabName) var prefabPath = Path.Combine(directory, $"{prefabName}.prefab"); var blob = AssetDatabase.LoadAssetAtPath(prefabPath).GetComponent(); var blobRef = blob.Node.ToBuilder(blob.FindGlobalValuesList()).CreateManagedBlobAssetReference(); - return new ManagedNodeBlobRef(blobRef); + return new ManagedNodeBlobRef(blobRef, blob.GetInstanceID()); } } } diff --git a/Assets/Tests/Editor/TestExpression.cs b/Assets/Tests/Editor/TestExpression.cs index d3ad5a4f..86dae189 100644 --- a/Assets/Tests/Editor/TestExpression.cs +++ b/Assets/Tests/Editor/TestExpression.cs @@ -14,7 +14,7 @@ public class TestExpression private struct MockNodeBlob : INodeBlob { - public int RuntimeId { get; } + public int RuntimeId { get; set; } public int Count { get; } public int GetTypeId(int nodeIndex) => throw new NotImplementedException(); public int GetEndIndex(int nodeIndex) => throw new NotImplementedException(); @@ -42,7 +42,7 @@ private struct MockBlackboard : IBlackboard [SetUp] public void SetUp() { - _nodeBlob = new MockNodeBlob(); + _nodeBlob = new MockNodeBlob { RuntimeId = 123 }; _bb = new MockBlackboard(); } diff --git a/Assets/Tests/Editor/TestVariant.cs b/Assets/Tests/Editor/TestVariant.cs index 0a5f2009..78f01fcb 100644 --- a/Assets/Tests/Editor/TestVariant.cs +++ b/Assets/Tests/Editor/TestVariant.cs @@ -71,30 +71,30 @@ struct Variants public BlobVariantRO IntRO; public BlobVariantRW FloatRW; } - - [Test] - public void should_find_value_type_of_variant_() - { - var type = typeof(ComponentVariableData); - var intRO = new ComponentVariant.Reader(); - intRO.ComponentValueName = $"{type.FullName}.{nameof(ComponentVariableData.IntValue)}"; - var floatRW = new ComponentVariant.ReaderAndWriter(); - floatRW.ComponentValueName = $"{type.FullName}.{nameof(ComponentVariableData.FloatValue)}"; - var builder = new StructBuilder(); - builder.SetBuilder(ref builder.Value.IntRO, new VariantBuilder>(intRO)); - builder.SetBuilder(ref builder.Value.FloatRW, new VariantBuilder>(floatRW)); - builder.Build(_blobStream); - var blob = new ManagedBlobAssetReference(_blobStream.ToArray()); - - Assert.That(blob.Value.IntRO.Value.VariantId, Is.EqualTo(Guid.Parse(ComponentVariant.GUID).GetHashCode())); - Assert.That(blob.Value.IntRO.Value.MetaDataOffsetPtr, Is.EqualTo(24)); - ref var intVariantData = ref blob.Value.IntRO.Value.As(); - Assert.That(intVariantData.StableHash, Is.EqualTo(TypeHash.CalculateStableTypeHash(type))); - - // Assert.That(blob.Value.FloatRW.Reader.Value.VariantId, Is.EqualTo(Guid.Parse(ComponentVariant.GUID).GetHashCode())); - // Assert.That(blob.Value.FloatRW.Value.MetaDataOffsetPtr, Is.EqualTo(16)); - // ref var intVariantData = ref blob.Value.FloatRW.Value.As(); - // Assert.That(intVariantData.StableHash, Is.EqualTo(TypeHash.CalculateStableTypeHash(type))); - } + // + // [Test] + // public void should_find_value_type_of_variant_() + // { + // var type = typeof(ComponentVariableData); + // var intRO = new ComponentVariant.Reader(); + // intRO.ComponentValueName = $"{type.FullName}.{nameof(ComponentVariableData.IntValue)}"; + // var floatRW = new ComponentVariant.ReaderAndWriter(); + // floatRW.ComponentValueName = $"{type.FullName}.{nameof(ComponentVariableData.FloatValue)}"; + // var builder = new StructBuilder(); + // builder.SetBuilder(ref builder.Value.IntRO, new VariantBuilder>(intRO)); + // builder.SetBuilder(ref builder.Value.FloatRW, new VariantBuilder>(floatRW)); + // builder.Build(_blobStream); + // var blob = new ManagedBlobAssetReference(_blobStream.ToArray()); + // + // Assert.That(blob.Value.IntRO.Value.VariantId, Is.EqualTo(Guid.Parse(ComponentVariant.GUID).GetHashCode())); + // Assert.That(blob.Value.IntRO.Value.MetaDataOffsetPtr, Is.EqualTo(24)); + // ref var intVariantData = ref blob.Value.IntRO.Value.As(); + // Assert.That(intVariantData.StableHash, Is.EqualTo(TypeHash.CalculateStableTypeHash(type))); + // + // // Assert.That(blob.Value.FloatRW.Reader.Value.VariantId, Is.EqualTo(Guid.Parse(ComponentVariant.GUID).GetHashCode())); + // // Assert.That(blob.Value.FloatRW.Value.MetaDataOffsetPtr, Is.EqualTo(16)); + // // ref var intVariantData = ref blob.Value.FloatRW.Value.As(); + // // Assert.That(intVariantData.StableHash, Is.EqualTo(TypeHash.CalculateStableTypeHash(type))); + // } } } \ No newline at end of file diff --git a/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs index 85ad52cf..02f54a1f 100644 --- a/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs +++ b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs @@ -11,7 +11,11 @@ namespace EntitiesBT.Core private ref NodeBlob _blob => ref BlobRef.Value; public readonly ManagedBlobAssetReference BlobRef; - public ManagedNodeBlobRef(ManagedBlobAssetReference blobRef) => BlobRef = blobRef; + public ManagedNodeBlobRef(ManagedBlobAssetReference blobRef, int runtimeId = -1) + { + BlobRef = blobRef; + RuntimeId = runtimeId; + } public int RuntimeId { diff --git a/Packages/essential/Runtime/Variant/BlobVariantStream.cs b/Packages/essential/Runtime/Variant/BlobVariantStream.cs index d5fe9653..fbf8d8fc 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantStream.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantStream.cs @@ -144,7 +144,7 @@ protected override unsafe void BuildImpl(IBlobStream stream, ref BlobVariantRW v fixed (void* writerDataPtr = &value.Writer.MetaDataOffsetPtr) fixed (void* readerDataPtr = &value.Reader.MetaDataOffsetPtr) { - value.Writer.MetaDataOffsetPtr = value.Reader.MetaDataOffsetPtr + (int)((byte*)writerDataPtr - (byte*)readerDataPtr); + value.Writer.MetaDataOffsetPtr = value.Reader.MetaDataOffsetPtr - (int)((byte*)writerDataPtr - (byte*)readerDataPtr); } } } From 5b64885e34f6f322dd21b056f84ab453745c10ee Mon Sep 17 00:00:00 2001 From: quabug Date: Sun, 31 Jul 2022 17:23:26 +0800 Subject: [PATCH 27/28] refer to blob package. --- Packages/essential/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/essential/package.json b/Packages/essential/package.json index c8f474fb..9e012013 100644 --- a/Packages/essential/package.json +++ b/Packages/essential/package.json @@ -5,6 +5,7 @@ "unity": "2020.2", "displayName": "EntitiesBT - Essential", "dependencies": { + "com.quabug.blob": "1.4.0", "com.unity.entities": "0.14.0-preview.19" } } From 4da22025940457e9282ca67507b83e64611710f8 Mon Sep 17 00:00:00 2001 From: quabug Date: Sun, 31 Jul 2022 17:25:26 +0800 Subject: [PATCH 28/28] update package manifest. --- Packages/manifest.json | 2 +- Packages/packages-lock.json | 21 ++++++++++++--------- ProjectSettings/ProjectVersion.txt | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Packages/manifest.json b/Packages/manifest.json index 4e357b9b..72e9673c 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -2,7 +2,7 @@ "dependencies": { "com.unity.dots.editor": "0.11.0-preview.3", "com.unity.ide.rider": "3.0.7", - "com.unity.ide.visualstudio": "2.0.14", + "com.unity.ide.visualstudio": "2.0.15", "com.unity.ide.vscode": "1.2.5", "com.unity.inputsystem": "1.3.0", "com.unity.rendering.hybrid": "0.8.0-preview.19", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 40a06efa..d7145d23 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,10 +1,11 @@ { "dependencies": { "com.quabug.blob": { - "version": "file:com.quabug.blob", - "depth": 0, - "source": "embedded", - "dependencies": {} + "version": "1.4.0", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://package.openupm.com" }, "com.quabug.entities-bt.builder.component": { "version": "file:builder.component", @@ -51,6 +52,7 @@ "depth": 0, "source": "embedded", "dependencies": { + "com.quabug.blob": "1.4.0", "com.unity.entities": "0.14.0-preview.19" } }, @@ -71,12 +73,13 @@ } }, "com.quabug.graph-ext": { - "version": "file:com.quabug.graph-ext", - "depth": 0, - "source": "embedded", + "version": "1.9.5", + "depth": 1, + "source": "registry", "dependencies": { "com.unity.modules.uielements": "1.0.0" - } + }, + "url": "https://package.openupm.com" }, "com.unity.burst": { "version": "1.3.7", @@ -148,7 +151,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.14", + "version": "2.0.15", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 02057f26..0a52d40f 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2020.3.33f1 -m_EditorVersionWithRevision: 2020.3.33f1 (915a7af8b0d5) +m_EditorVersion: 2020.3.36f1 +m_EditorVersionWithRevision: 2020.3.36f1 (71f96b79b9f0)