static unsafe TypeDependencyCache() { //TODO: Find a better way to enforce Version 2 compatibility bool v2Enabled = (bool)typeof(AssetDatabase).GetMethod("IsV2Enabled", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null); if (!v2Enabled) { throw new System.InvalidOperationException("com.unity.entities requires Asset Pipeline Version 2. Please enable Version 2 in Project Settings / Editor / Asset Pipeline / Mode"); } // Custom dependencies are transmitted to the import worker so dont spent time on registering them if (AssetDatabaseCompatibility.IsAssetImportWorkerProcess()) { return; } using (kRegisterComponentTypes.Auto()) RegisterComponentTypes(); using (kRegisterConversionSystemVersions.Auto()) RegisterConversionSystems(); int fileFormatVersion = SerializeUtility.CurrentFileFormatVersion; UnityEngine.Hash128 fileFormatHash = default; HashUnsafeUtilities.ComputeHash128(&fileFormatVersion, sizeof(int), &fileFormatHash); AssetDatabaseCompatibility.RegisterCustomDependency("EntityBinaryFileFormatVersion", fileFormatHash); int sceneFileFormatVersion = SceneMetaDataSerializeUtility.CurrentFileFormatVersion; UnityEngine.Hash128 sceneFileFormatHash = default; HashUnsafeUtilities.ComputeHash128(&sceneFileFormatVersion, sizeof(int), &sceneFileFormatHash); AssetDatabaseCompatibility.RegisterCustomDependency("SceneMetaDataFileFormatVersion", sceneFileFormatHash); }
static unsafe void RegisterConversionSystems() { var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.GameObjectConversion | WorldSystemFilterFlags.EntitySceneOptimizations); var behaviours = TypeCache.GetTypesDerivedFrom <IConvertGameObjectToEntity>(); var nameAndVersion = new NameAndVersion[systems.Count + behaviours.Count]; int count = 0; // System versions for (int i = 0; i != systems.Count; i++) { var fullName = systems[i].FullName; if (fullName == null) { continue; } nameAndVersion[count++].Init(systems[i], fullName); } // IConvertGameObjectToEntity versions for (int i = 0; i != behaviours.Count; i++) { var fullName = behaviours[i].FullName; if (fullName == null) { continue; } nameAndVersion[count++].Init(behaviours[i], fullName); } Array.Sort(nameAndVersion, 0, count); UnityEngine.Hash128 hash = default; for (int i = 0; i != count; i++) { var fullName = nameAndVersion[i].FullName; fixed(char *str = fullName) { HashUnsafeUtilities.ComputeHash128(str, (ulong)(sizeof(char) * fullName.Length), &hash); } var userName = nameAndVersion[i].UserName; if (userName != null) { fixed(char *str = userName) { HashUnsafeUtilities.ComputeHash128(str, (ulong)(sizeof(char) * userName.Length), &hash); } } int version = nameAndVersion[i].Version; HashUnsafeUtilities.ComputeHash128(&version, sizeof(int), &hash); } AssetDatabaseCompatibility.RegisterCustomDependency(SystemsVersion, hash); }
static void RegisterComponentTypes() { TypeManager.Initialize(); AssetDatabaseCompatibility.UnregisterCustomDependencyPrefixFilter("DOTSType/"); int typeCount = TypeManager.GetTypeCount(); for (int i = 1; i < typeCount; ++i) { var typeInfo = TypeManager.GetTypeInfo(i); var hash = typeInfo.StableTypeHash; AssetDatabaseCompatibility.RegisterCustomDependency(TypeString(typeInfo.Type), new UnityEngine.Hash128(hash, hash)); } }
public static void RegisterMonoScripts() { if (AssetDatabaseCompatibility.IsAssetImportWorkerProcess() || s_Initialized) { return; } s_Initialized = true; AssetDatabaseCompatibility.UnregisterCustomDependencyPrefixFilter("UnityEngineType/"); var behaviours = TypeCache.GetTypesDerivedFrom <UnityEngine.MonoBehaviour>(); var scripts = TypeCache.GetTypesDerivedFrom <UnityEngine.ScriptableObject>(); for (int i = 0; i != behaviours.Count; i++) { var type = behaviours[i]; if (type.IsGenericType) { continue; } var hash = TypeHash.CalculateStableTypeHash(type); AssetDatabaseCompatibility.RegisterCustomDependency(TypeString(type), new UnityEngine.Hash128(hash, hash)); } for (int i = 0; i != scripts.Count; i++) { var type = scripts[i]; if (type.IsGenericType) { continue; } var hash = TypeHash.CalculateStableTypeHash(type); AssetDatabaseCompatibility.RegisterCustomDependency(TypeString(type), new UnityEngine.Hash128(hash, hash)); } }