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..32f28b77 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, ref int value) { - data = Animator.StringToHash(TriggerName); + value = Animator.StringToHash(TriggerName); } } } diff --git a/Assets/Samples/GameObjectWithoutEntity/BTController.cs b/Assets/Samples/GameObjectWithoutEntity/BTController.cs index 7f12af88..bd6953c4 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.ToBlob(RootNode.FindScopeValuesList())); + var blobRef = RootNode.Node.ToBuilder(RootNode.FindGlobalValuesList()).CreateManagedBlobAssetReference(); + _nodeBlobRef = new ManagedNodeBlobRef(blobRef, gameObject.GetInstanceID()); 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(); } } } 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/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/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/Samples/Runtime/Entity/IsEntityPositionInBox.cs b/Assets/Samples/Runtime/Entity/IsEntityPositionInBox.cs index bc37fe27..2a825024 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, ref Bounds value) { - data = new Bounds(Box.center + Transform.position, Box.size); + value = 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..b289dcd3 100644 --- a/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs +++ b/Assets/Samples/Runtime/InputSystem/InputActionGuidBuilder.cs @@ -1,17 +1,17 @@ using System; +using Blob; using Nuwa.Blob; -using Unity.Entities; using UnityEngine.InputSystem; namespace EntitiesBT.Extensions.InputSystem { - public class InputActionGuidBuilder : PlainDataBuilder + public class InputActionGuidBuilder : Nuwa.Blob.Builder { public InputActionReference InputAction; - public override void Build(BlobBuilder builder, ref Guid data) + protected override void BuildImpl(IBlobStream stream, ref Guid value) { - data = InputAction.action.id; + value = InputAction.action.id; } } diff --git a/Assets/Samples/Variable/VariableSample.unity b/Assets/Samples/Variable/VariableSample.unity index ee63e38a..95628e6b 100644 --- a/Assets/Samples/Variable/VariableSample.unity +++ b/Assets/Samples/Variable/VariableSample.unity @@ -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/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 8d37de69..16968654 100644 --- a/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef +++ b/Assets/Tests/Editor/EntitiesBT.Tests.Editor.asmdef @@ -11,7 +11,9 @@ "GUID:6679f77e90ec1d540ab279146d203dbb", "GUID:f49b79f7e0a9b4b63a97d15e26787406", "GUID:ce5f967ea6c735344b367065891c4afb", - "GUID:f320ee23a990e5640812e0939a441a2b" + "GUID:f320ee23a990e5640812e0939a441a2b", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469", + "GUID:6d84eb5386377416e93c122a00485b68" ], "includePlatforms": [ "Editor" @@ -21,7 +23,6 @@ "overrideReferences": true, "precompiledReferences": [ "nunit.framework.dll", - "Moq.dll", "Mono.Cecil.dll", "Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll", diff --git a/Packages/deprecated/Editor/Odin.meta b/Assets/Tests/Editor/MultipleVariant.meta similarity index 77% rename from Packages/deprecated/Editor/Odin.meta rename to Assets/Tests/Editor/MultipleVariant.meta index f726fa4f..fefdca24 100644 --- a/Packages/deprecated/Editor/Odin.meta +++ b/Assets/Tests/Editor/MultipleVariant.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 049b83c82f1e4ba418a9e5f232e7e941 +guid: 7fae54ba66263b640bcf391006c17d9b folderAsset: yes DefaultImporter: externalObjects: {} 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/Packages/samples/DEPRECATED.meta b/Assets/Tests/Editor/MultipleVariant/component-linked.prefab.meta similarity index 63% rename from Packages/samples/DEPRECATED.meta rename to Assets/Tests/Editor/MultipleVariant/component-linked.prefab.meta index 3d97acfd..6ed3799b 100644 --- a/Packages/samples/DEPRECATED.meta +++ b/Assets/Tests/Editor/MultipleVariant/component-linked.prefab.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: dedf66bbd51d4c54cb8e8ae38ffe5f33 -DefaultImporter: +guid: 15ae73273578e1d43b20d18f67097030 +PrefabImporter: externalObjects: {} userData: assetBundleName: 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/Packages/deprecated/package.json.meta b/Assets/Tests/Editor/MultipleVariant/component.prefab.meta similarity index 60% rename from Packages/deprecated/package.json.meta rename to Assets/Tests/Editor/MultipleVariant/component.prefab.meta index adce1fcb..99add571 100644 --- a/Packages/deprecated/package.json.meta +++ b/Assets/Tests/Editor/MultipleVariant/component.prefab.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 850a2d287b82f1f4daa6d36bada41de1 -PackageManifestImporter: +guid: 1540eb8a60e048e4b80c650b2da2a662 +PrefabImporter: externalObjects: {} userData: assetBundleName: 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/Packages/samples/package.json.meta b/Assets/Tests/Editor/MultipleVariant/local-linked.prefab.meta similarity index 60% rename from Packages/samples/package.json.meta rename to Assets/Tests/Editor/MultipleVariant/local-linked.prefab.meta index 17988252..112c18a9 100644 --- a/Packages/samples/package.json.meta +++ b/Assets/Tests/Editor/MultipleVariant/local-linked.prefab.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 32f693585e8cd12489578b2ceae1b5d5 -PackageManifestImporter: +guid: 225578966e943ca4aaf62c60546cc47e +PrefabImporter: externalObjects: {} userData: assetBundleName: 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/Packages/deprecated/Editor.meta b/Assets/Tests/Editor/SingleVariant.meta similarity index 77% rename from Packages/deprecated/Editor.meta rename to Assets/Tests/Editor/SingleVariant.meta index 45999419..7a7dd23d 100644 --- a/Packages/deprecated/Editor.meta +++ b/Assets/Tests/Editor/SingleVariant.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5205ed2e1a3d0ab4d9a6467d47d23c1b +guid: f79b82819b22f3f4fb8048791bd6c2f5 folderAsset: yes DefaultImporter: externalObjects: {} 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 new file mode 100644 index 00000000..a1c1c931 --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs @@ -0,0 +1,103 @@ +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("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); + 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, blob.GetInstanceID()); + } + } +} diff --git a/Packages/builder.component/Runtime/BTVirtualNode.cs.meta b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs.meta similarity index 83% rename from Packages/builder.component/Runtime/BTVirtualNode.cs.meta rename to Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs.meta index 9f76c055..89888145 100644 --- a/Packages/builder.component/Runtime/BTVirtualNode.cs.meta +++ b/Assets/Tests/Editor/SingleVariant/TestSingleVariant.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9e2d8829726a85c4dbfe5b0d3f987381 +guid: 912f472bbc804564f867117e68162d72 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Tests/Editor/SingleVariant/TestVariables.asset b/Assets/Tests/Editor/SingleVariant/TestVariables.asset new file mode 100644 index 00000000..f94591fe --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/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: 222 + FloatValue: 0 + AnotherFloatValue: 0 + k__BackingField: 0 diff --git a/Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset.meta b/Assets/Tests/Editor/SingleVariant/TestVariables.asset.meta similarity index 79% rename from Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset.meta rename to Assets/Tests/Editor/SingleVariant/TestVariables.asset.meta index cef5d117..d706ccbc 100644 --- a/Packages/deprecated/Runtime/Component/NodeCodeGenerator.asset.meta +++ b/Assets/Tests/Editor/SingleVariant/TestVariables.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7458b90d338864635ad5fa764629835e +guid: 29b05bb74db20b44d9c43d888551daa9 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Tests/Editor/SingleVariant/component.prefab b/Assets/Tests/Editor/SingleVariant/component.prefab new file mode 100644 index 00000000..0c183d1f --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/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/SingleVariant/component.prefab.meta b/Assets/Tests/Editor/SingleVariant/component.prefab.meta new file mode 100644 index 00000000..c081a30d --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/component.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 81dfd4c06c8b7fd4ba747b7415fddfd5 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleVariant/expression.prefab b/Assets/Tests/Editor/SingleVariant/expression.prefab new file mode 100644 index 00000000..22715d1a --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/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/SingleVariant/expression.prefab.meta b/Assets/Tests/Editor/SingleVariant/expression.prefab.meta new file mode 100644 index 00000000..aab5ac9a --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/expression.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2b090dbff7c65944697c10c7d6be153f +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleVariant/local.prefab b/Assets/Tests/Editor/SingleVariant/local.prefab new file mode 100644 index 00000000..f5d70ebe --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/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/SingleVariant/local.prefab.meta b/Assets/Tests/Editor/SingleVariant/local.prefab.meta new file mode 100644 index 00000000..f280be00 --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/local.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5ddb40aa53d04b24b83d43e75d2a52fa +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleVariant/node.prefab b/Assets/Tests/Editor/SingleVariant/node.prefab new file mode 100644 index 00000000..b0fd3ee5 --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/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/SingleVariant/node.prefab.meta b/Assets/Tests/Editor/SingleVariant/node.prefab.meta new file mode 100644 index 00000000..6ac73afd --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/node.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5cff0e1f08c2fab48a6e5646a7f35113 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/SingleVariant/scriptable-object.prefab b/Assets/Tests/Editor/SingleVariant/scriptable-object.prefab new file mode 100644 index 00000000..1bfce779 --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/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/SingleVariant/scriptable-object.prefab.meta b/Assets/Tests/Editor/SingleVariant/scriptable-object.prefab.meta new file mode 100644 index 00000000..c5ee811c --- /dev/null +++ b/Assets/Tests/Editor/SingleVariant/scriptable-object.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3314f0c46781f454fb8fdb037fb8988d +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Editor/TestExpression.cs b/Assets/Tests/Editor/TestExpression.cs index 50e94aa4..86dae189 100644 --- a/Assets/Tests/Editor/TestExpression.cs +++ b/Assets/Tests/Editor/TestExpression.cs @@ -1,24 +1,20 @@ 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 { - using TreeNodeBuilder = ITreeNode; - public class TestExpression { - private BlobBuilder _builder; private MockNodeBlob _nodeBlob; private MockBlackboard _bb; 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(); @@ -46,17 +42,10 @@ private struct MockBlackboard : IBlackboard [SetUp] public void SetUp() { - _builder = new BlobBuilder(Allocator.Temp); - _nodeBlob = new MockNodeBlob(); + _nodeBlob = new MockNodeBlob { RuntimeId = 123 }; _bb = new MockBlackboard(); } - [TearDown] - public void TearDown() - { - _builder.Dispose(); - } - [Test] public void should_eval_expression() { @@ -68,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(ref _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/Assets/Tests/Editor/TestNodeBlob.cs b/Assets/Tests/Editor/TestNodeBlob.cs index bc569874..85a5f8be 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,110 +14,113 @@ 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() { - 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 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.FindScopeValuesList()); + 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.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.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}); - - 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/Assets/Tests/Editor/TestVariant.cs b/Assets/Tests/Editor/TestVariant.cs index ef3fb34e..78f01fcb 100644 --- a/Assets/Tests/Editor/TestVariant.cs +++ b/Assets/Tests/Editor/TestVariant.cs @@ -1,7 +1,8 @@ using System; -using EntitiesBT.Core; +using Blob; using EntitiesBT.Variant; using NUnit.Framework; +using Nuwa.Blob; using Unity.Entities; namespace EntitiesBT.Test @@ -17,9 +18,8 @@ public void should_find_value_type_of_variant() class InvalidVariant : IVariant { - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(BlobVariantStream stream) { - throw new NotImplementedException(); } public object PreviewValue => throw new NotImplementedException(); @@ -32,4 +32,69 @@ 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); + } + + 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 = 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())); + Assert.That(blob.Value.MetaDataOffsetPtr, Is.EqualTo(4)); + 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 diff --git a/Packages/deprecated/Editor/Component.meta b/Assets/Tests/NodeBlob.meta similarity index 77% rename from Packages/deprecated/Editor/Component.meta rename to Assets/Tests/NodeBlob.meta index 3521f175..4bdd95d7 100644 --- a/Packages/deprecated/Editor/Component.meta +++ b/Assets/Tests/NodeBlob.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a811b6da7ca78bf4d823965dba1dc711 +guid: baf6127a6e52d3846afbb7582c78e3a6 folderAsset: yes DefaultImporter: externalObjects: {} 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/Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef.meta b/Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef.meta similarity index 76% rename from Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef.meta rename to Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef.meta index 583ead57..d1d8cdb4 100644 --- a/Packages/deprecated/Editor/Odin/EntitiesBT.Builder.Odin.Editor.asmdef.meta +++ b/Assets/Tests/NodeBlob/Entities.Tests.NodeBlob.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f5b81ab0b632dbb48a50fc1efe546d5a +guid: 7546d3cf84d0c3c428edf6b5823057bc AssemblyDefinitionImporter: externalObjects: {} userData: 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/Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs.meta b/Assets/Tests/NodeBlob/TestNodeBlob.cs.meta similarity index 83% rename from Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs.meta rename to Assets/Tests/NodeBlob/TestNodeBlob.cs.meta index 7cacff0c..190556e6 100644 --- a/Packages/deprecated/Editor/CodeGen/INodeCodeTemplate.cs.meta +++ b/Assets/Tests/NodeBlob/TestNodeBlob.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 916d6a86705e1ad4fa277937de201f7c +guid: e5af0afc3d39c604e810eff2d1aae7d5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Tests/Runtime/BTTestNodeA.cs b/Assets/Tests/Runtime/BTTestNodeA.cs index a56c4138..48ea2551 100644 --- a/Assets/Tests/Runtime/BTTestNodeA.cs +++ b/Assets/Tests/Runtime/BTTestNodeA.cs @@ -2,7 +2,6 @@ using EntitiesBT.Components; using EntitiesBT.Core; -using Unity.Entities; using UnityEngine; namespace EntitiesBT.Test @@ -33,7 +32,7 @@ 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 NodeA _Value => new NodeA { A = A }; } } diff --git a/Assets/Tests/Runtime/BTTestNodeB.cs b/Assets/Tests/Runtime/BTTestNodeB.cs index 032615cc..bb91334f 100644 --- a/Assets/Tests/Runtime/BTTestNodeB.cs +++ b/Assets/Tests/Runtime/BTTestNodeB.cs @@ -1,8 +1,9 @@ #if UNITY_EDITOR +using Blob; using EntitiesBT.Components; using EntitiesBT.Core; -using Unity.Entities; +using Nuwa.Blob; using UnityEngine; namespace EntitiesBT.Test @@ -36,11 +37,7 @@ public class BTTestNodeB : BTNode public int B; public int BB; - protected override void Build(ref NodeB data, BlobBuilder _, ITreeNode[] __) - { - data.B = B; - data.BB = BB; - } + 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 9ec42d76..7f8e4f53 100644 --- a/Assets/Tests/Runtime/BTTestNodeState.cs +++ b/Assets/Tests/Runtime/BTTestNodeState.cs @@ -2,7 +2,6 @@ using EntitiesBT.Components; using EntitiesBT.Core; -using Unity.Entities; using UnityEngine.Assertions; namespace EntitiesBT.Test @@ -44,13 +43,7 @@ public NodeState Tick(int index, ref TNodeBlob blob, ref public class BTTestNodeState : BTNode { public NodeState State; - - protected override void Build(ref TestNode data, BlobBuilder builder, ITreeNode[] tree) - { - data.State = State; - data.ResetTimes = 0; - data.TickTimes = 0; - } + protected override TestNode _Value => new TestNode { State = State, ResetTimes = 0, TickTimes = 0 }; } } diff --git a/Assets/Tests/Editor/BehaviorTreeTestBase.cs b/Assets/Tests/Runtime/BehaviorTreeTestBase.cs similarity index 57% rename from Assets/Tests/Editor/BehaviorTreeTestBase.cs rename to Assets/Tests/Runtime/BehaviorTreeTestBase.cs index 3346c942..afc78e3d 100644 --- a/Assets/Tests/Editor/BehaviorTreeTestBase.cs +++ b/Assets/Tests/Runtime/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.ToBlob(root.FindScopeValuesList()); - 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/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 328b7380..38231249 100644 --- a/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef +++ b/Assets/Tests/Runtime/EntitiesBT.Tests.Runtime.asmdef @@ -2,19 +2,25 @@ "name": "EntitiesBT.Tests.Runtime", "rootNamespace": "", "references": [ - "GUID:27619889b8ba8c24980f49ee34dbb44a", "GUID:c7babe7561eb244059259745ef27b866", - "GUID:d3630359ae08047918d5cd6cddd51767", "GUID:734d92eba21c94caba915361bd5ac177", - "GUID:f320ee23a990e5640812e0939a441a2b" + "GUID:f320ee23a990e5640812e0939a441a2b", + "GUID:9835e0fdeb3db2247b6bf67e4f7d0469", + "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 91% rename from Assets/Tests/Editor/TestSimpleComposites.cs rename to Assets/Tests/Runtime/TestSimpleComposites.cs index e153a7e1..083638e6 100644 --- a/Assets/Tests/Editor/TestSimpleComposites.cs +++ b/Assets/Tests/Runtime/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/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 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); diff --git a/Packages/builder.component/Runtime/BTDecorator.cs b/Packages/builder.component/Runtime/BTDecorator.cs deleted file mode 100644 index 393e2b02..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/BTDynamicNode.cs b/Packages/builder.component/Runtime/BTDynamicNode.cs index 4ad73041..c8e2acd9 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 { @@ -9,13 +9,15 @@ 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; + public override IBuilder BlobStreamBuilder => NodeData.Builder; + public override INodeDataBuilder Node => RunOnMainThread ? _mainThreadNodeBuilder : base.Node; + + private readonly DecoratorNode _mainThreadNodeBuilder; - protected override unsafe void Build(void* dataPtr, BlobBuilder blobBuilder, ITreeNode[] builders) + public BTDynamicNode() { - NodeData.Build(blobBuilder, new IntPtr(dataPtr)); + _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 93d31706..60cd368d 100644 --- a/Packages/builder.component/Runtime/BTNode.cs +++ b/Packages/builder.component/Runtime/BTNode.cs @@ -1,49 +1,51 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; +using Blob; using EntitiesBT.Core; using EntitiesBT.Entities; using EntitiesBT.Nodes; -using Unity.Collections; -using Unity.Collections.LowLevel.Unsafe; +using JetBrains.Annotations; using UnityEngine; -using Unity.Entities; namespace EntitiesBT.Components { [DisallowMultipleComponent, ExecuteInEditMode] - public abstract class BTNode : MonoBehaviour, INodeDataBuilder + public abstract class BTNode : MonoBehaviour { - 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 class Builder : INodeDataBuilder + { + [NotNull] private readonly BTNode _node; - 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 int NodeId => _node.NodeId; - public INodeDataBuilder Self => gameObject.activeSelf ? SelfImpl : null; + public int NodeIndex { get; set; } = -1; - protected virtual INodeDataBuilder SelfImpl => this; + public IBuilder BlobStreamBuilder => _node.BlobStreamBuilder; - public unsafe 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 + public IEnumerable Children => _node.Children() + .Where(child => child.IsValid) + .Select(child => child.Node) + ; + + public Builder([NotNull] BTNode node) { - blobBuilder.Dispose(); + _node = node; } } - protected virtual unsafe void Build(void* dataPtr, BlobBuilder blobBuilder, ITreeNode[] builders) {} + public BehaviorNodeType BehaviorNodeType => NodeType.GetBehaviorNodeAttribute().Type; + public int NodeId => NodeType.GetBehaviorNodeAttribute().Id; + protected virtual Type NodeType { get; } = typeof(ZeroNode); + public abstract IBuilder BlobStreamBuilder { get; } + public virtual bool IsValid => gameObject.activeInHierarchy; + public virtual INodeDataBuilder Node { get; } + + public BTNode() + { + Node = new Builder(this); + } protected virtual void Reset() => name = GetType().Name; @@ -97,7 +99,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)) Node.SaveToStream(this.FindGlobalValuesList(), file); UnityEditor.AssetDatabase.Refresh(); } #endif @@ -106,12 +108,7 @@ public void SaveToFile() 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) - { - Build(ref UnsafeUtility.AsRef(dataPtr), builder, tree); - } - - protected virtual void Build(ref T data, BlobBuilder builder, ITreeNode[] tree) {} + public override IBuilder BlobStreamBuilder => new ValueBuilder(_Value); + protected virtual T _Value => default; } } 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/BehaviorTreeSourceGameObject.cs b/Packages/builder.component/Runtime/BehaviorTreeSourceGameObject.cs index 208137c0..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; @@ -14,7 +15,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.Node.ToBlob(Root.FindGlobalValuesList()); if (!isPrefab && AutoDestroy) UnityEngine.Object.Destroy(Root.gameObject); return blob; } 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/GlobalComponentVariant.cs b/Packages/builder.component/Runtime/GlobalComponentVariant.cs index 94b3080d..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 IntPtr Allocate(ref BlobBuilder builder, 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 builder.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/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/builder.component/Runtime/NodeAsset.cs b/Packages/builder.component/Runtime/NodeAsset.cs index d520a745..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) => Builder.Build(builder, dataPtr); + public void Build([NotNull] IBlobStream stream) => Builder.Build(stream); public IBuilder FindBuilderByPath(string path) { diff --git a/Packages/builder.component/Runtime/NodeVariant.cs b/Packages/builder.component/Runtime/NodeVariant.cs index 2075a2b4..86998d67 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 IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(BlobVariantStream stream) { - return Allocate(ref builder, ref blobVariant, NodeObject, ValueFieldName); + Allocate(stream, NodeObject.Node, 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/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs b/Packages/com.quabug.entities-bt.builder.graphview/Runtime/BehaviorNodeComponent.cs index 37d46431..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,27 +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 @@ -186,30 +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 { - var nodeType = _node.BehaviorNodeDataType; - if (nodeType.IsZeroSizeStruct()) return BlobAssetReference.Null; - var blobBuilder = new BlobBuilder(Allocator.Temp, UnsafeUtility.SizeOf(nodeType)); - try - { - var dataPtr = blobBuilder.ConstructRootPtrByType(nodeType); - _node.Blob.Build(blobBuilder, new IntPtr(dataPtr)); - return blobBuilder.CreateReferenceByType(nodeType); - } - finally + [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) { - blobBuilder.Dispose(); + _component = component; } } + + public int NodeId => _node.BehaviorNodeAttribute.Id; + public Builder NodeBuilder => new Builder(this); #endregion #region Save to File @@ -220,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.FindScopeValuesList(), file); + using (var file = new FileStream(path, FileMode.OpenOrCreate)) NodeBuilder.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..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; @@ -18,7 +19,7 @@ public BlobAssetReference GetBlobAsset() { Assert.IsTrue(Root.IsPrefab()); Assert.IsNotNull(_behaviorTree); - return _behaviorTree.ToBlob(_behaviorTree.FindScopeValuesList()); + return _behaviorTree.NodeBuilder.ToBlob(_behaviorTree.FindGlobalValuesList()); } } } \ No newline at end of file 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..f8726c3e 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(BlobVariantStream stream) { // TODO: check validation - return NodeComponent.VariantNode.Allocate(ref builder, 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 6967a70f..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(ref builder, ref blobVariant); + Variant.Allocate(stream); } public bool IsPortCompatible(GraphRuntime graph, in PortId input, in PortId output) => true; 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/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/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/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/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/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/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs b/Packages/essential/Dependencies/Nuwa/Blob/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs index e430d4d6..1bd55f78 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; @@ -105,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/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..c05d0e4e 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; } } @@ -22,13 +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 unsafe void Build(BlobBuilder builder, IntPtr dataPtr) - { - Build(builder, ref UnsafeUtility.AsRef(dataPtr.ToPointer())); - } - public virtual IBuilder GetBuilder(string name) => throw new NotImplementedException(); public virtual object PreviewValue @@ -36,8 +34,6 @@ public virtual object PreviewValue get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - public abstract void Build(BlobBuilder builder, ref T data); } /// @@ -51,15 +47,15 @@ public class PlainDataBuilder : Builder where T : unmanaged { public T Value; - public override object PreviewValue + protected override void BuildImpl(IBlobStream stream, ref T value) { - get => Value; - set => Value = (T)value; + value = Value; } - public override void Build(BlobBuilder builder, ref T data) + public override object PreviewValue { - data = Value; + get => Value; + set => Value = (T)value; } } @@ -80,14 +76,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, ref T value) { - var dataPtr = new IntPtr(UnsafeUtility.AddressOf(ref data)); + var dataPosition = stream.Position; 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 +117,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, ref BlobArray value) { - 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) @@ -142,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 { @@ -153,9 +170,9 @@ public override object PreviewValue set => Value = (string)value; } - public override void Build(BlobBuilder builder, ref BlobString data) + protected override void BuildImpl(IBlobStream stream, ref BlobString data) { - builder.AllocateString(ref data, Value); + new StringBuilder(Value).Build(stream); } } @@ -167,10 +184,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 BlobPtr value) { - 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..83864d2c 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,46 @@ public abstract class DynamicBuilderFactory : IDynamicBuilderFactory where T public abstract object Create(Type dataType, FieldInfo fieldInfo); } + public abstract class DynamicBuilder : IBuilder + { + 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) + { + 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); + + 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,14 +74,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; - } - - public IBuilder GetBuilder(string name) - { - throw new NotImplementedException(); + stream.WriteValue(Value); } public class Factory : DynamicBuilderFactory where U : DynamicEnumBuilder, new() @@ -101,23 +134,26 @@ 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.Position; + 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]); } } - 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}"); @@ -154,7 +190,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,14 +204,16 @@ 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) + public override IBuilder GetBuilder(string name) { var index = int.Parse(name); return Value[index]; @@ -190,18 +228,18 @@ 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) + 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/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/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/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/Components/Utilities.cs b/Packages/essential/Runtime/Components/Utilities.cs index 47460ea4..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); } @@ -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/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/DecoratorNode.cs.meta b/Packages/essential/Runtime/Core/DecoratorNode.cs.meta new file mode 100644 index 00000000..01779eca --- /dev/null +++ b/Packages/essential/Runtime/Core/DecoratorNode.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/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/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/INodeDataBuilder.cs b/Packages/essential/Runtime/Core/INodeDataBuilder.cs index 144223ee..53b46643 100644 --- a/Packages/essential/Runtime/Core/INodeDataBuilder.cs +++ b/Packages/essential/Runtime/Core/INodeDataBuilder.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Linq; +using Blob; using JetBrains.Annotations; namespace EntitiesBT.Core @@ -7,13 +10,9 @@ namespace EntitiesBT.Core public interface INodeDataBuilder { int NodeId { get; } - BlobAssetReference Build([NotNull] ITreeNode[] builders); int NodeIndex { get; set; } - INodeDataBuilder Self { get; } + IBuilder BlobStreamBuilder { get; } IEnumerable Children { get; } - - object GetPreviewValue(string path); - void SetPreviewValue(string path, object value); } public static partial class NodeDataBuilderExtension @@ -21,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.DataBuilder) + ); + 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/Core/ManagedNodeBlobRef.cs b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs new file mode 100644 index 00000000..02f54a1f --- /dev/null +++ b/Packages/essential/Runtime/Core/ManagedNodeBlobRef.cs @@ -0,0 +1,84 @@ +using System; +using Blob; +using Nuwa.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, int runtimeId = -1) + { + BlobRef = blobRef; + RuntimeId = runtimeId; + } + + 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.Add(new 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/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/NodeBlob.cs b/Packages/essential/Runtime/Core/NodeBlob.cs new file mode 100644 index 00000000..637e736d --- /dev/null +++ b/Packages/essential/Runtime/Core/NodeBlob.cs @@ -0,0 +1,41 @@ +using JetBrains.Annotations; +using Unity.Collections.LowLevel.Unsafe; +using Blob; + +namespace EntitiesBT.Core +{ + public struct NodeBlob + { + public const int VERSION = 5; + +#region Serialized Data + public BlobArray Types; + public BlobTreeAny Nodes; + 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 RuntimeGlobalValues; +#endregion + + public int Count => Types.Length; + public int RuntimeSize => CalculateRuntimeSize(Count, RuntimeDataBlob.Length, RuntimeGlobalValues.Length); + + 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; + + [Pure] + public static int CalculateSize(int count, int dataSize, int scopeValuesSize) => + CalculateDefaultSize(count, dataSize, scopeValuesSize) + CalculateRuntimeSize(count, dataSize, scopeValuesSize); + } +} 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/Core/Utilities.cs b/Packages/essential/Runtime/Core/Utilities.cs index cd4d4b8c..fb0bb28f 100644 --- a/Packages/essential/Runtime/Core/Utilities.cs +++ b/Packages/essential/Runtime/Core/Utilities.cs @@ -5,78 +5,20 @@ 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 - { - 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) - { - Value = value; - Parent = parent; - Index = index; - } - - public TreeNode UpdateIndex(int index) - { - Index = index; - return this; - } - } - 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) - { - 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/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 new file mode 100644 index 00000000..3b2eb845 --- /dev/null +++ b/Packages/essential/Runtime/Entities/ArrayBuilderWithMemoryCopy.cs @@ -0,0 +1,23 @@ +using JetBrains.Annotations; + +namespace Blob +{ + public class ArrayBuilderWithMemoryCopy : Builder where TArray : unmanaged + { + [NotNull] private readonly IBuilder _builder; + + public ArrayBuilderWithMemoryCopy([NotNull] IBuilder builder) + { + _builder = builder; + } + + protected override unsafe void BuildImpl(IBlobStream stream, ref TArray data) + { + stream.WriteArrayMeta(_builder.PatchSize).ToPatchPosition(); + fixed (void* ptr = &stream.Buffer[_builder.PatchPosition]) + { + stream.Write((byte*)ptr, _builder.PatchSize); + } + } + } +} \ 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/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/ComponentVariant.cs b/Packages/essential/Runtime/Entities/ComponentVariant.cs index e72dd90d..38615df7 100644 --- a/Packages/essential/Runtime/Entities/ComponentVariant.cs +++ b/Packages/essential/Runtime/Entities/ComponentVariant.cs @@ -22,16 +22,16 @@ public class Any : IVariant where T : unmanaged { [VariantComponentData] public string ComponentValueName; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + 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 builder.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(); @@ -50,8 +50,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(); } diff --git a/Packages/essential/Runtime/Entities/NodeBlob.cs b/Packages/essential/Runtime/Entities/NodeBlob.cs deleted file mode 100644 index 62635d4d..00000000 --- a/Packages/essential/Runtime/Entities/NodeBlob.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using EntitiesBT.Core; -using JetBrains.Annotations; -using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; -using Unity.Mathematics; - -namespace EntitiesBT.Entities -{ - public struct NodeBlob - { - public const int VERSION = 4; - -#region Serialized Data - public BlobArray Types; - public BlobArray EndIndices; - public BlobArray Offsets; // count = count of nodes + 1 - public BlobArray DefaultDataBlob; - public BlobArray DefaultScopeValues; -#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; -#endregion - - public int Count => Types.Length; - public int RuntimeSize => CalculateRuntimeSize(Count, RuntimeDataBlob.Length, RuntimeScopeValues.Length); - - [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; - - [Pure] - 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 BlobAssetReference BlobRef; - - public NodeBlobRef(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.EndIndices[nodeIndex]; - public int GetNodeDataSize(int nodeIndex, int count = 1) - { - var currentOffset = _blob.Offsets[nodeIndex]; - var nextOffset = _blob.Offsets[math.min(nodeIndex + count, Count)]; - 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 IntPtr GetDefaultDataPtr(int nodeIndex) => - (IntPtr) _blob.DefaultDataBlob.GetUnsafePtr() + _blob.Offsets[nodeIndex]; - - 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); - - public unsafe IntPtr GetRuntimeScopeValuePtr(int offset) => - IntPtr.Add(new IntPtr(_blob.RuntimeScopeValues.GetUnsafePtr()), 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/NodeBlobExtensions.cs b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs index dacce302..8718cec9 100644 --- a/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs +++ b/Packages/essential/Runtime/Entities/NodeBlobExtensions.cs @@ -1,14 +1,11 @@ -using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Blob; 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 { @@ -17,118 +14,19 @@ public static class NodeBlobExtensions [Pure] public static BlobAssetReference ToBlob( [NotNull] this INodeDataBuilder root - , IReadOnlyList scopeValuesList - , Allocator allocator = Allocator.Persistent + , IEnumerable globalValuesList ) { - return root.Flatten(builder => builder.Children, builder => builder.Self).ToArray().ToBlob(scopeValuesList, allocator); - } - - [Pure] - public static unsafe BlobAssetReference ToBlob( - [NotNull] this ITreeNode[] nodes - , IReadOnlyList scopeValuesList - , Allocator allocator - ) - { - var dataSize = 0; - var nodeDataList = new NativeArray(nodes.Length, Allocator.Temp); - try - { - var scopeValuesSize = 0; - foreach (var values in scopeValuesList) - { - 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); - - 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 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.DefaultScopeValues, scopeValuesSize); - var scopeValuesPtr = new IntPtr(scopeValues.GetUnsafePtr()); - var scopeValuesOffset = 0; - foreach (var values in scopeValuesList) - { - var destPtr = scopeValuesPtr + scopeValuesOffset; - UnsafeUtility.MemCpy(destPtr.ToPointer(), values.ValuePtr.ToPointer(), values.Size); - scopeValuesOffset += values.Size; - } - var runtimeScopeValues = blobBuilder.Allocate(ref blob.RuntimeScopeValues, 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); - } - catch (Exception ex) - { - Debug.LogException(ex); - throw; - } - finally - { - foreach (var data in nodeDataList.Where(data => data.IsCreated)) data.Dispose(); - nodeDataList.Dispose(); - } + return root.ToBuilder(globalValuesList).CreateUnityBlobAssetReference(); } public static unsafe void SaveToStream( [NotNull] this INodeDataBuilder builder - , [NotNull] IReadOnlyList scopeValuesList + , [NotNull] IReadOnlyList scopeValuesList , [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/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 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/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/Composites/WeightRandomSelectorNode.cs b/Packages/essential/Runtime/Nodes/Composites/WeightRandomSelectorNode.cs index 7b528abd..88a5daca 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.Linq; -using EntitiesBT.Components; +using Blob; using EntitiesBT.Core; using EntitiesBT.Entities; -using Nuwa; using Nuwa.Blob; -using Unity.Entities; -using UnityEngine; namespace EntitiesBT.Nodes { @@ -44,14 +40,14 @@ public NodeState Tick(int index, ref TNodeBlob blob, ref } } - public class NormalizedWeightBuilder : PlainDataBuilder> + public class NormalizedWeightBuilder : Nuwa.Blob.Builder> { public int[] Weights; - public override void Build(BlobBuilder builder, ref BlobArray data) + protected override void BuildImpl(IBlobStream stream, ref BlobArray data) { float sum = Weights.Sum(); - builder.AllocateArray(ref data, Weights.Select(w => w / sum).ToArray()); + new Blob.ArrayBuilder(Weights.Select(w => w / sum).ToArray()).Build(stream); } } } \ No newline at end of file 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 { diff --git a/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs b/Packages/essential/Runtime/Variant/BlobVariantStream.cs similarity index 65% rename from Packages/essential/Runtime/Variant/BlobVariantBuilder.cs rename to Packages/essential/Runtime/Variant/BlobVariantStream.cs index 0cb3bb33..fbf8d8fc 100644 --- a/Packages/essential/Runtime/Variant/BlobVariantBuilder.cs +++ b/Packages/essential/Runtime/Variant/BlobVariantStream.cs @@ -1,17 +1,63 @@ using System; using System.Linq; 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.Position; + _patchPosition = stream.PatchPosition; + stream.WriteValue(new BlobVariant().VariantId); + _offsetPosition = stream.Position; + } + + public void SetVariantId(int id) + { + _stream.Position = _idPosition; + _stream.WriteValue(id); + } + + public void SetVariantValue(T value) where T : unmanaged + { + _stream.Position = _offsetPosition; + _stream.WritePatchOffset(); + _stream.Position = _patchPosition; + _stream.WriteValue(value); + } + + public void SetVariantValue(IBuilder builder) where T : unmanaged + { + _stream.Position = _offsetPosition; + _stream.WritePatchOffset(); + _stream.Position = _patchPosition; + builder.Build(_stream); + } + + public void SetVariantOffset(int offset) + { + _stream.Position = _offsetPosition; + _stream.WriteValue(offset); + } + } + [Serializable] - public class BlobVariantROBuilder : Builder + public class BlobVariantROBuilder : Nuwa.Blob.Builder { [SerializeField, HideInInspector] internal string _variantTypeName; [SerializeField, HideInInspector] internal bool IsOptional; @@ -22,9 +68,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, ref BlobVariant value) { - if (_variant != null) _variant.Allocate(ref builder, ref data); + _variant?.Allocate(new BlobVariantStream(stream)); } public class Factory : DynamicBuilderFactory @@ -45,7 +91,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 +102,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, ref BlobVariant value) { - _variant.Allocate(ref builder, ref data); + _variant.Allocate(new BlobVariantStream(stream)); } public class Factory : DynamicBuilderFactory @@ -79,7 +125,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,19 +136,21 @@ 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 unsafe void BuildImpl(IBlobStream stream, ref BlobVariantRW value) { - var metaDataPtr = _variant.Allocate(ref builder, ref data.Reader); - data.Writer.VariantId = data.Reader.VariantId; - + _variant.Allocate(new BlobVariantStream(stream)); + value.Writer.VariantId = 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.Writer.MetaDataOffsetPtr) + fixed (void* readerDataPtr = &value.Reader.MetaDataOffsetPtr) + { + value.Writer.MetaDataOffsetPtr = value.Reader.MetaDataOffsetPtr - (int)((byte*)writerDataPtr - (byte*)readerDataPtr); + } } } [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; @@ -111,16 +159,18 @@ public class BlobVariantLinkedRWBuilder : 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 unsafe void BuildImpl(IBlobStream stream, ref BlobVariantRW value) { 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); + // HACK: set position to variant of writer + stream.Position = _reader.DataPosition + sizeof(BlobVariant); + _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/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; diff --git a/Packages/essential/Runtime/Variant/IVariant.cs b/Packages/essential/Runtime/Variant/IVariant.cs index f22fc46e..669534fc 100644 --- a/Packages/essential/Runtime/Variant/IVariant.cs +++ b/Packages/essential/Runtime/Variant/IVariant.cs @@ -1,15 +1,11 @@ using System; -using EntitiesBT.Core; using JetBrains.Annotations; -using Unity.Entities; namespace EntitiesBT.Variant { public interface IVariant { - // return: pointer of meta data - IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant); - + void Allocate(BlobVariantStream stream); object PreviewValue { get; } } diff --git a/Packages/essential/Runtime/Variant/LocalVariant.cs b/Packages/essential/Runtime/Variant/LocalVariant.cs index 100dbcd0..9da5ba8b 100644 --- a/Packages/essential/Runtime/Variant/LocalVariant.cs +++ b/Packages/essential/Runtime/Variant/LocalVariant.cs @@ -1,6 +1,5 @@ using System; using EntitiesBT.Core; -using Unity.Entities; using static EntitiesBT.Core.Utilities; namespace EntitiesBT.Variant @@ -15,10 +14,10 @@ public class Any : IVariant where T : unmanaged { public T Value; - public IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(BlobVariantStream stream) { - blobVariant.VariantId = GuidHashCode(GUID); - return builder.Allocate(ref blobVariant, 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 0fc7ff52..250aa2f6 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(BlobVariantStream 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(BlobVariantStream 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..81ec8cf2 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; @@ -75,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 + // 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 { - 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); + return ref UnsafeUtility.As>(ref offsetPtr); } - public static IntPtr Allocate(this BlobBuilder builder, ref BlobVariantPtrRO blob, TValue value) where TValue : unmanaged - { - return builder.Allocate(ref blob.Value, value); - } - - public static IntPtr AllocateRO( - this IVariantReader property - , ref BlobBuilder builder - , ref BlobVariantRO blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant.Value); - - public static IntPtr AllocateWO( - this IVariantWriter property - , ref BlobBuilder builder - , ref BlobVariantWO blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant.Value); - - public static IntPtr AllocateRW( - this ISerializedVariantRW property - , ref BlobBuilder builder - , ref BlobVariantRW blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant); - - public static IntPtr Allocate( - this IVariantReader property - , ref BlobBuilder builder - , ref BlobVariantRO blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant.Value); - - public static IntPtr Allocate( - this IVariantReader property - , ref BlobBuilder builder - , ref BlobVariantPtrRO blobVariant - ) => property.Allocate(ref builder, ref blobVariant.Value); - - public static IntPtr Allocate( - this IVariantWriter property - , ref BlobBuilder builder - , ref BlobVariantWO blobVariant - ) where T : unmanaged => property.Allocate(ref builder, ref blobVariant.Value); - - public static unsafe IntPtr Allocate( - this IVariantReaderAndWriter property - , ref BlobBuilder builder - , ref BlobVariantRW blobVariant - ) where T : unmanaged - { - var metaDataPtr = property.Allocate(ref builder, ref blobVariant.Reader.Value); - 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 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(ref builder, ref UnsafeUtility.AsRef(blobVariantPtr)); - } + // 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/essential/Runtime/Variant/VariantBuilder.cs b/Packages/essential/Runtime/Variant/VariantBuilder.cs new file mode 100644 index 00000000..92ee40e9 --- /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, ref T value) + { + _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/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" } } diff --git a/Packages/manifest.json b/Packages/manifest.json index 7620a4c4..72e9673c 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -2,8 +2,8 @@ "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.vscode": "1.2.4", + "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", "com.unity.ugui": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index ae65da00..d7145d23 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,5 +1,12 @@ { "dependencies": { + "com.quabug.blob": { + "version": "1.4.0", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://package.openupm.com" + }, "com.quabug.entities-bt.builder.component": { "version": "file:builder.component", "depth": 0, @@ -40,28 +47,15 @@ "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, "source": "embedded", "dependencies": { + "com.quabug.blob": "1.4.0", "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, @@ -157,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": { @@ -166,7 +160,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 +271,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/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/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/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs b/Packages/variable.scriptable-object/Runtime/ScriptableObjectVariant.cs index 4c7aa324..8a58f718 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(BlobVariantStream stream) { - blobVariant.VariantId = GuidHashCode(GUID); - return builder.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 d3143b02..0ed14c50 100644 --- a/Packages/variant.expression/Runtime/ExpressionVariant.cs +++ b/Packages/variant.expression/Runtime/ExpressionVariant.cs @@ -1,10 +1,11 @@ using System; 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; @@ -17,10 +18,10 @@ public static class ExpressionVariant public struct Data { - public BlobString Expression; + public BlobString Expression; public int ExpressionType; public BlobArray Variants; - public BlobArray VariantNames; + public BlobArray> VariantNames; public BlobArray VariantTypes; } @@ -41,23 +42,25 @@ internal class Variant [SerializeField] internal string _expression; [SerializeField] internal Variant[] _sources; - public unsafe IntPtr Allocate(ref BlobBuilder builder, ref BlobVariant blobVariant) + public void Allocate(BlobVariantStream stream) { - blobVariant.VariantId = GuidHashCode(GUID); - ref var blobPtr = ref UnsafeUtility.As>(ref blobVariant.MetaDataOffsetPtr); - ref var data = ref builder.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); - 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); - 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; diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 339c3950..0a52d40f 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.36f1 +m_EditorVersionWithRevision: 2020.3.36f1 (71f96b79b9f0)