public NativeStaticMapHead ToHead()
            {
                var head = new NativeStaticMapHead()
                {
                    TypePositions = NativeLists.ToArray(Allocator.Persistent),
                    Size          = offset
                };

                NativeLists.Dispose();
                return(head);
            }
        public static NativeStaticMap Create(ref NativeStaticMapHead head, int size)
        {
            var map = new NativeStaticMap
            {
                head     = head,
                Capacity = size,
                data     = (byte *)UnsafeUtility.Malloc(head.Size * size, 4, Allocator.Persistent),
                _idle    = new NativeQueue <int>(Allocator.Persistent)
            };

            return(map);
        }
        public static ActionStateContainer Create(GraphAsset graph, int chunkCapacity = 5)
        {
            var container = new ActionStateContainer();
            // var builder = NativeStructMap.CreateBuilder();
            var builder = NativeStaticMapHead.CreateBuilder();
            var count   = graph.RuntimeNodes.Length;

            container._containerInfo = new NativeArray <Info>(1, Allocator.Persistent);
            var info = new Info {
                NodeCount = count
            };

            container._chunks = new NativeList <ActionStateChunk>(Allocator.Persistent);
            // container.Chunks.Add(new ActionStateChunk());
            container._nodes = new NativeArray <ActionStateNode>(count * chunkCapacity, Allocator.Persistent);
            info.ChunkCount  = 0;

            var capacity = 1000;
            var statePtr = (byte *)UnsafeUtility.Malloc(capacity, 4, Allocator.Temp);

            var offset = 0;

            for (var i = 0; i < count; i++)
            {
                var inode = graph.m_Nodes[i];// as INodeAsset;
                var node  = new ActionStateNode()
                {
                    Cycle = NodeCycle.Inactive, offset = offset
                };
                container._nodes[i] = node;

                if (inode is IStatusNode nodeObject)
                {
                    var t    = nodeObject.NodeDataType();
                    var size = UnsafeUtility.SizeOf(t);
                    if (offset + size > capacity)
                    {
                        capacity = capacity * 2;
                        var ptr = (byte *)UnsafeUtility.Malloc(capacity, 4, Allocator.Temp);
                        UnsafeUtility.MemCpy(ptr, statePtr, offset);
                        UnsafeUtility.Free(ptr, Allocator.Temp);
                        statePtr = ptr;
                    }
                    nodeObject.CreateNodeDataTo(statePtr + offset);
                    offset += size;
                }
                if (inode is IAccessBlackboard accessBlackboard)
                {
                    accessBlackboard.ToBuilder(builder);
                }
            }
            container._states = (byte *)UnsafeUtility.Malloc(offset * chunkCapacity, 4, Allocator.Persistent);
            UnsafeUtility.MemCpy(container._states, statePtr, offset);
            UnsafeUtility.Free(statePtr, Allocator.Temp);

            //var array = builder.ToNativeStructMapArray(chunkCapacity, Allocator.Persistent);
            var head       = builder.ToHead();
            var blackboard = NativeStaticMap.Create(ref head, chunkCapacity);

            //container.BlackboardArray = array;
            container._blackboard = blackboard;


            info.StatesSize             = offset;
            info.NodeCount              = count;
            info.ChunkCapacity          = chunkCapacity;
            container._containerInfo[0] = info;


            return(container);
        }