I have an Enum that controls the UID (Uniuque Identifier) of each of my objects or items within my game. Originally I had them sorted, so tools were followed by consumable items and then seeds etc. However this was causing me issues within Unity, or it was when I wanted to add a new Tool.
The reason is that all the Items in my Scene have a UID on them and I set this from within the inspector, using this technique it is very easy to swap what an object it, or set it when I add new artwork into the game etc.
The image above shows me having set the Item_Type UID to be a World item, wooden log.
The problem I am facing is when I add a NEW UID into the Enum table it bumps all the values below it down by one (obviously I guess). However Unity does not see me do this as it is in code, so the Unity inspector shows me the wrong values. My wooden log would become a Tree as it happens as that is the previous UID in the Enum list.
This makes adding in new Items a real pain. So I wrote a remap table to handle this, without explaining this too much, I have to say my implementation was a failure. Which annoyed me as it took time to get al the code correct to use a remap type table, gah! Cannot always get it right of course.
So what do I do now ?
I changed my code and got rid of the Remap table all together. Then I made the code more intelligent as to what UID goes where. This means I trawl through all the Items sorting them when the game runs. This is now in and working and oh boy it seems cleaner. It was more coding, and a bit more runtime work (initially anyway), but then I think this should work now and be future proof.
Hopefully I can add anything I want to the end of the Enum and it won't effect any other item within the list. This certainly solves my Inspector issue.
Have a good one,
Da Voodoochief
Monday, May 18, 2015
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment