Search Unity

Advanced Guid properties

Discussion in 'Assets and Asset Store' started by Hightlander, Aug 17, 2015.

  1. Hightlander

    Hightlander

    Joined:
    May 30, 2013
    Posts:
    30
    The usual task in the development process is making sure an entity has a proper identifier. Someone is using int numerals, others use string names, risking running into a conflict with duplicates.

    The best solution - GUID, a globally unique identifier. The total number of unique such GUIDs is 2¹²²(approximately 5.3×10³⁶). This number is so large that the probability of the same number being generated randomly twice is negligible. Using Guids in unity3d editor is somewhat uncomfortable: unity3d can not serialize them. We have to use a string representation instead of an actual GUID. Then we need to convert it back to the GUID.



    There are several approaches to this. Firstly, you can use properties with initialization in Awake()


    Secondly, some form of lazy initialization may be adopted.


    However, it is prone to string format errors.

    Another problem arises. When you look at the string representation like {353fe684-d854-4332-a778-336714d8eedf} you may be unable to immediately identify an entity being referenced, is it a ship, a lifeless planet, or an armor-piercing bullets. (Well, I developed an ability to identify some annoying objects after a while)


    Finally I implemented an extension to address these issues.


    The main point is a wrapper class AGuid. It wraps the native Guid struct and has the following features:

    • it is comparable to the native Guid
    • typecast to the Guid and vice versa.

    • it is serialized by Unity engine

    • can be displayed and edited in the Inspector
    • “Edit” window does not allow to input data of an incorrect format.

    You can also give human-friendly names to identifiers that will be displayed instead of the string representation. These names are saved in the project as a file. It goes to a source control system, if you are using one, so the whole team can use the same set of the human-friendly aliases.



    Is anyone interested in such an extension?
    Shall I polish it and publish it to the store?