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 void ComputeHashForFile(string path, ref ulong h1, ref ulong h2) { byte[] bytes; // Read bytes from file as read-only using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { bytes = new byte[fileStream.Length]; fileStream.Read(bytes, 0, (int)fileStream.Length); } ulong hash1; ulong hash2; unsafe { fixed(byte *bytePointer = bytes) { HashUnsafeUtilities.ComputeHash128(bytePointer, (ulong)bytes.LongLength, &hash1, &hash2); } } h1 = hash1; h2 = hash2; }
static unsafe void RegisterConversionSystems() { var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.GameObjectConversion | WorldSystemFilterFlags.EntitySceneOptimizations); var nameAndVersion = new NameAndVersion[systems.Count]; for (int i = 0; i != nameAndVersion.Length; i++) { nameAndVersion[i].FullName = systems[i].FullName; var systemVersionAttribute = systems[i].GetCustomAttribute <ConverterVersionAttribute>(); if (systemVersionAttribute != null) { nameAndVersion[i].Version = systemVersionAttribute.Version; } } Array.Sort(nameAndVersion); UnityEngine.Hash128 hash = default; for (int i = 0; i != nameAndVersion.Length; i++) { var fullName = nameAndVersion[i].FullName; fixed(char *str = fullName) { HashUnsafeUtilities.ComputeHash128(str, (ulong)(sizeof(char) * fullName.Length), &hash); } int version = nameAndVersion[i].Version; HashUnsafeUtilities.ComputeHash128(&version, sizeof(int), &hash); } UnityEditor.Experimental.AssetDatabaseExperimental.RegisterCustomDependency(SystemsVersion, hash); }
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 unsafe void RegisterPlatformDependency() { var activeBuildTarget = EditorUserBuildSettings.activeBuildTarget.ToString(); UnityEngine.Hash128 hash = default; fixed(char *str = activeBuildTarget) { HashUnsafeUtilities.ComputeHash128(str, (ulong)(sizeof(char) * activeBuildTarget.Length), &hash); } AssetDatabaseCompatibility.RegisterCustomDependency(livelinkBuildTargetDependencyName, hash); }
protected override void HashCore(byte[] array, int ibStart, int cbSize) { fixed(byte *data = &array[ibStart]) fixed(byte *hash = &m_Hash[0]) { var dataSize = (ulong)cbSize; var lower = (ulong *)&hash[0]; var upper = (ulong *)&hash[8]; HashUnsafeUtilities.ComputeHash128(data, dataSize, lower, upper); } }
internal static unsafe void Initialize() { if (s_Initialized) { return; } // ensure internal UnityEngine.SpookyHash class is initialized on the main thread before it is used anywhere var hash128 = new UnityEngine.Hash128(); byte data = 0; HashUnsafeUtilities.ComputeHash128(UnsafeUtility.AddressOf(ref data), 1, &hash128); s_Initialized = true; }
public void Persist() { unsafe { fixed(SkinAttachmentPose *ptrPose = pose) fixed(SkinAttachmentItem * ptrItem = item) fixed(ulong *ptrChecksum0 = &checksum0) fixed(ulong *ptrChecksum1 = &checksum1) { HashUnsafeUtilities.ComputeHash128(ptrPose, (ulong)(sizeof(SkinAttachmentPose) * poseCount), ptrChecksum0, ptrChecksum1); HashUnsafeUtilities.ComputeHash128(ptrItem, (ulong)(sizeof(SkinAttachmentItem) * itemCount), ptrChecksum0, ptrChecksum1); Debug.LogFormat("SkinAttachmentData changed, new checksum = '{0}' ({1} poses, {2} items)", Checksum(), poseCount, itemCount); } } #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(this); UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.Undo.ClearUndo(this); #endif }
// use the native implementation from dots (not burstable) public static Hash128 Hash <T>(NativeArray <T> data) where T : struct { if (NativeArrayUtility.IsInvalidOrEmpty(data)) { return(new Hash128()); } var sizeOfT = UnsafeUtility.SizeOf <T>(); var sizeInBytes = sizeOfT * data.Length; var hash = new Hash128(); unsafe { var ptr = data.GetUnsafeReadOnlyPtr(); var resultPtr = (UnityEngine.Hash128 *)UnsafeUtility.AddressOf(ref hash); HashUnsafeUtilities.ComputeHash128(ptr, (ulong)sizeInBytes, resultPtr); } return(hash); }