#pragma warning restore 618 internal Hash128 GetHash() { var h = new Hash128(); var h2 = new Hash128(); HashUtilities.ComputeHash128(ref bufferClearing, ref h); HashUtilities.ComputeHash128(ref culling, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref customRenderingSettings, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref defaultFrameSettings, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref flipYMode, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref frustum, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref invertFaceCulling, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref probeLayerMask, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref probeRangeCompressionFactor, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref renderingPathCustomFrameSettings, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref renderingPathCustomFrameSettingsOverrideMask, ref h2); HashUtilities.AppendHash(ref h2, ref h); int volumeHash = volumes.GetHashCode(); h2 = new Hash128((ulong)volumeHash, 0); HashUtilities.AppendHash(ref h2, ref h); return(h); }
/// <summary> /// Compute a hash of the settings. /// </summary> /// <returns>The computed hash.</returns> public Hash128 ComputeHash() { var h = new Hash128(); var h2 = new Hash128(); HashUtilities.ComputeHash128(ref type, ref h); HashUtilities.ComputeHash128(ref mode, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref lighting, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref proxySettings, ref h2); HashUtilities.AppendHash(ref h2, ref h); HashUtilities.ComputeHash128(ref cameraSettings, ref h2); HashUtilities.AppendHash(ref h2, ref h); if (influence != null) { h2 = influence.ComputeHash(); HashUtilities.AppendHash(ref h2, ref h); } if (proxy != null) { h2 = proxy.ComputeHash(); HashUtilities.AppendHash(ref h2, ref h); } return(h); }
internal void ImportXmlFromString(string xml, out VisualTreeAsset vta) { var h = new Hash128(); byte[] b = Encoding.UTF8.GetBytes(xml); if (b.Length > 0) { HashUtilities.ComputeHash128(b, ref h); } CreateVisualTreeAsset(out vta, h); XDocument doc; try { doc = XDocument.Parse(xml, LoadOptions.SetLineInfo); } catch (Exception e) { logger.LogError(ImportErrorType.Syntax, ImportErrorCode.InvalidXml, e, Error.Level.Fatal, null); return; } LoadXmlRoot(doc, vta); TryCreateInlineStyleSheet(vta); }
internal void ImportXmlFromString(string xml, out VisualTreeAsset vta) { vta = ScriptableObject.CreateInstance <VisualTreeAsset>(); vta.visualElementAssets = new List <VisualElementAsset>(); vta.templateAssets = new List <TemplateAsset>(); var h = new Hash128(); byte[] b = Encoding.UTF8.GetBytes(xml); HashUtilities.ComputeHash128(b, ref h); vta.contentHash = h.GetHashCode(); XDocument doc; try { doc = XDocument.Parse(xml, LoadOptions.SetLineInfo); } catch (Exception e) { logger.LogError(ImportErrorType.Syntax, ImportErrorCode.InvalidXml, e, Error.Level.Fatal, null); return; } LoadXmlRoot(doc, vta); TryCreateInlineStyleSheet(vta); }
static void ComputeProbeBakingHashes(int count, Hash128 allProbeDependencyHash, HDProbeBakingState *states) { for (int i = 0; i < count; ++i) { states[i].probeBakingHash = states[i].probeSettingsHash; HashUtilities.ComputeHash128(ref allProbeDependencyHash, ref states[i].probeBakingHash); } }
static Hash128 ComputeCustomIndexerHash(MethodInfo mi, CustomObjectIndexerAttribute attr) { var id = $"{mi.DeclaringType.FullName}.{mi.Name}.{attr.version}"; Hash128 dataHash = default; HashUtilities.ComputeHash128(System.Text.Encoding.ASCII.GetBytes(id), ref dataHash); return(dataHash); }
/// <summary> /// Returns a hash that can be used as a guid within a (non-persistent) session to refer to this UnityEngine.Object. /// </summary> public static Hash128 ComputeInstanceHash(this UnityObject @this) { if (@this is Component component) { @this = component.gameObject; } var instanceID = @this.GetInstanceID(); var hash = new UnityEngine.Hash128(); HashUtilities.ComputeHash128(ref instanceID, ref hash); return(hash); }
public void Import(UnityStyleSheet asset, string contents) { ParserStyleSheet styleSheet = m_Parser.Parse(contents); ImportParserStyleSheet(asset, styleSheet); var h = new Hash128(); byte[] b = Encoding.UTF8.GetBytes(contents); if (b.Length > 0) { HashUtilities.ComputeHash128(b, ref h); } asset.contentHash = h.GetHashCode(); }
void ImportXml(string xmlPath, out VisualTreeAsset vta) { vta = ScriptableObject.CreateInstance <VisualTreeAsset>(); vta.visualElementAssets = new List <VisualElementAsset>(); vta.templateAssets = new List <TemplateAsset>(); var h = new Hash128(); using (var stream = File.OpenRead(xmlPath)) { int readCount = 0; byte[] b = new byte[1024 * 16]; while ((readCount = stream.Read(b, 0, b.Length)) > 0) { for (int i = readCount; i < b.Length; i++) { b[i] = 0; } Hash128 blockHash = new Hash128(); HashUtilities.ComputeHash128(b, ref blockHash); HashUtilities.AppendHash(ref blockHash, ref h); } } vta.contentHash = h.GetHashCode(); XDocument doc; try { doc = XDocument.Load(xmlPath, LoadOptions.SetLineInfo); } catch (Exception e) { logger.LogError(ImportErrorType.Syntax, ImportErrorCode.InvalidXml, e, Error.Level.Fatal, null); return; } LoadXmlRoot(doc, vta); StyleSheet inlineSheet = ScriptableObject.CreateInstance <StyleSheet>(); inlineSheet.name = "inlineStyle"; m_Builder.BuildTo(inlineSheet); vta.inlineSheet = inlineSheet; }
// This seems neat, but might get cut public int GetCardHash(string name) { int result = 0; using (MemoryStream mstream = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(mstream, $"{Name}.{name}"); byte[] bytes = mstream.ToArray(); Hash128 hash = new Hash128(); HashUtilities.ComputeHash128(bytes, ref hash); result = hash.GetHashCode(); } return(result); }
public void TestHash128() { const int minBitDelta = 32; // on average, the bit delta will be 64 var result0 = new byte[128 / 8]; var result1 = HashUtilities.ComputeHash128(new byte[0]); Console.WriteLine("Hashed to: {0}", StringUtilities.ToHexString(result1)); Assert.GreaterOrEqual(GetBitDelta(result0, result1), minBitDelta); var result1B = HashUtilities.ComputeHash128(new byte[0]); Console.WriteLine("Hashed to: {0}", StringUtilities.ToHexString(result1B)); Assert.AreEqual(0, GetBitDelta(result1, result1B)); var result2 = HashUtilities.ComputeHash128(Encoding.ASCII.GetBytes("ClearCanvas.Common.Utilities.Tests")); Console.WriteLine("Hashed to: {0}", StringUtilities.ToHexString(result2)); Assert.GreaterOrEqual(GetBitDelta(result0, result2), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result1, result2), minBitDelta); var result3 = HashUtilities.ComputeHash128(Encoding.ASCII.GetBytes("ClearCanvas.Commom.Utilities.Tests")); Console.WriteLine("Hashed to: {0}", StringUtilities.ToHexString(result3)); Assert.GreaterOrEqual(GetBitDelta(result0, result3), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result1, result3), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result2, result3), minBitDelta); var result4 = HashUtilities.ComputeHash128(Encoding.ASCII.GetBytes("ClearCanvas.Common.Utilities.Tests"), 18, 10); Console.WriteLine("Hashed to: {0}", StringUtilities.ToHexString(result4)); Assert.GreaterOrEqual(GetBitDelta(result0, result4), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result1, result4), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result2, result4), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result3, result4), minBitDelta); var result5 = HashUtilities.ComputeHash128(Encoding.ASCII.GetBytes("ClearCanvas.Commom.Utilities.Tests"), 18, 10); Console.WriteLine("Hashed to: {0}", StringUtilities.ToHexString(result5)); Assert.GreaterOrEqual(GetBitDelta(result0, result5), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result1, result5), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result2, result5), minBitDelta); Assert.GreaterOrEqual(GetBitDelta(result3, result5), minBitDelta); Assert.AreEqual(0, GetBitDelta(result4, result5), minBitDelta); }
public static Hash128 CalculateTargetHash(GUID guid, BuildTarget target) { // Always calculate & return the new hash // TODO: target is not taken into account, this will be included when sbp moves into the asset pipeline var cache = new BuildCache(); var cachedInfo = CalculateTargetCachedInfo(cache.GetCacheEntry(guid, AssetBundleBuildVersion), target, null); // TODO: Script Property dependency // TODO: SBP returns recursive dependencies which is too much for Live Link, this will need to be changed when sbp moves into asset pipeline var targetHash = cachedInfo.Asset.Hash; foreach (var dependency in cachedInfo.Dependencies) { var dependencyHash = dependency.Hash; HashUtilities.ComputeHash128(ref dependencyHash, ref targetHash); } return(targetHash); }
public void Append(float[] values, int count) { if (values == null) { return; } // Pre-2020 versions of Unity don't have Hash128.Append() (can only hash strings and scalars) // For these versions, we'll hash element by element. #if UNITY_2020_1_OR_NEWER m_Hash.Append(values, 0, count); #else for (var i = 0; i < count; i++) { var tempHash = new Hash128(); HashUtilities.ComputeHash128(ref values[i], ref tempHash); HashUtilities.AppendHash(ref tempHash, ref m_Hash); } #endif }
void ImportXml(string xmlPath, out VisualTreeAsset vta) { var h = new Hash128(); using (var stream = File.OpenRead(xmlPath)) { int readCount = 0; byte[] b = new byte[1024 * 16]; while ((readCount = stream.Read(b, 0, b.Length)) > 0) { for (int i = readCount; i < b.Length; i++) { b[i] = 0; } Hash128 blockHash = new Hash128(); HashUtilities.ComputeHash128(b, ref blockHash); HashUtilities.AppendHash(ref blockHash, ref h); } } CreateVisualTreeAsset(out vta, h); XDocument doc; try { doc = XDocument.Load(xmlPath, LoadOptions.SetLineInfo); } catch (Exception e) { logger.LogError(ImportErrorType.Syntax, ImportErrorCode.InvalidXml, e, Error.Level.Fatal, null); return; } LoadXmlRoot(doc, vta); TryCreateInlineStyleSheet(vta); }