Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by canonner · Sep 28, 2016 at 01:24 AM · editortexture

how to get texture Image Contents Hash property.

I want to write a function that can delete the same texture in my project, even those textures content are same, but have different name, just like the texture duplicated from the other one. At the beginning, i use GetPixels() function to get pixels for texture's comparison, but the data is gigantic, then i found "Image Contents Hash" property(Byte[16]) of the texture in Debug mode, and i found even if a pixel change in a texture, this property will change too, so i want to use this property for comparison, now i can get all the textures in the project by script, but i don't know how to get this one. can anyone tell me, i am really appreciate about it. Sorry for my poor English.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image canonner · Sep 28, 2016 at 01:28 AM 0
Share

alt text

image-contents-hash.png (73.8 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Adam-Mechtley · Sep 28, 2016 at 08:36 AM

@canonner You can use SerializedProperty to get it. What you do with the bytes is up to you! For example:

 Texture tex = Selection.activeObject as Texture;
 if (tex == null)
 {
     return;
 }
 List<byte> bytes = new List<byte> (16);
 SerializedProperty sp = new SerializedObject (tex).FindProperty ("m_ImageContentsHash");
 while (sp.Next (true) && sp.propertyPath.StartsWith ("m_ImageContentsHash"))
     bytes.Add ((byte)sp.intValue);


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image canonner · Sep 28, 2016 at 10:28 AM 0
Share

WOW, i can get it now. i am really appreciate for you help. thanks a lot. God bless you !!!

avatar image MakinStuffLookGood · Oct 24, 2017 at 08:25 PM 0
Share

Note that the serialized value you're accessing here is not really a byte Array, but rather a Hash128— a struct Unity typically uses for deter$$anonymous$$ing whether Assets/AssetBundles. There are 16 bytes, each group of 4 represents a single unsigned int, and the 4 uint's make up the 128 bit hash. Here's an extension method that allows you to get the Hash128 value directly from a SerializedProperty.

 public static Hash128 GetHash128Value(this SerializedProperty property)
 {
     if (property.type != "Hash128")
     {
         throw new Exception("SerializedProperty does not represent a Hash128 struct.");
     }
 
     var bytes = new byte[4][];
 
     for (var i = 0; i < 4; i++)
     {
         bytes[i] = new byte[4];
 
         for (var j = 0; j < 4; j++)
         {
             property.Next(true);
             bytes[i][j] = (byte)property.intValue;
         }
     }
 
     var hash = new Hash128(
         BitConverter.ToUInt32(bytes[0], 0),
         BitConverter.ToUInt32(bytes[1], 0),
         BitConverter.ToUInt32(bytes[2], 0),
         BitConverter.ToUInt32(bytes[3], 0));
 
     return hash;
 }
avatar image
1

Answer by srivello · Sep 28, 2016 at 08:21 AM

Hi,

Here is a discussion that shares your proposed solution. Perhaps contacting those authors directly will help you find a solution.

Best wishes!

http://answers.unity3d.com/questions/722645/compare-texture-by-content.html

-Sam

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image canonner · Sep 28, 2016 at 10:33 AM 0
Share

yes, the solution you direct to me looks workable too, i get another workable solution by @Adam-$$anonymous$$echtley. anyway, thanks for you help. Wish you good.!!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

91 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What causes UV-mapping inconsistencies between projects? 2 Answers

Can I still edit the pivot of multiple selected sprites? 1 Answer

Force import of one specific format? 0 Answers

Editor: tile texture floor like HPL engine 0 Answers

Why are my textures misaligned in the standalone build? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges