private void Initialize()
        {
            var typeIndexArray = new NativeArray <int>(_allPersistableTypeInfos.Count, Allocator.Persistent);

            _typeIndexToHandle = new NativeHashMap <int, PersistableTypeHandle>(_allPersistableTypeInfos.Count, Allocator.Persistent);
            for (int i = 0; i < _allPersistableTypeInfos.Count; i++)
            {
                PersistableTypeInfo typeInfo = _allPersistableTypeInfos[i];
                typeInfo.ValidityCheck();
                int typeIndex = TypeManager.GetTypeIndexFromStableTypeHash(typeInfo.StableTypeHash);
                typeIndexArray[i]             = typeIndex;
                _typeIndexToHandle[typeIndex] = new PersistableTypeHandle {
                    Handle = (ushort)(i + 1)
                };
            }
            _typeIndexLookup = new TypeIndexLookup()
            {
                TypeIndexArray = typeIndexArray
            };
            _initialized = true;
        }
Exemple #2
0
        private static bool CreatePersistableTypeInfoFromFullTypeName(string fullTypeName, out PersistableTypeInfo persistableTypeInfo)
        {
            foreach (var typeInfoEntry in TypeManager.AllTypes)
            {
                if (typeInfoEntry.Type != null && typeInfoEntry.Type.FullName == fullTypeName && IsSupported(typeInfoEntry, out _))
                {
                    bool isBuffer = typeInfoEntry.Category == TypeManager.TypeCategory.BufferData;
                    persistableTypeInfo = new PersistableTypeInfo()
                    {
                        FullTypeName   = fullTypeName,
                        StableTypeHash = typeInfoEntry.StableTypeHash,
                        IsBuffer       = isBuffer,
                        MaxElements    = math.max(1, isBuffer ? typeInfoEntry.BufferCapacity : 1) // Initial BufferCapacity seems like a decent default max
                    };
                    return(true);
                }
            }

            persistableTypeInfo = default;
            return(false);
        }