We left off on a bit of a low note. Sure our locking system locks our entities when we add the TransformLock component but all it does is force it into the scene's origin. We can do better than that. Clearly we need a way to lock/free the transform's position values. Since we want to have different combinations of locked/freed values we'll need to set up enumerated flags.
Couple of things to note; bit twiddling means I don't have to remember the base 10 representation of the binary bits and I've already created the flag combinations because it's a small enough range and it means less typing later. And the following extension allows us to query whether a given flag value has another particular value in it.
Next we add the flags as a field in the component.
And finally we need to update the inspector to make the data useful. In order to do that we should define what it is that the system needs to do for us. First we want to be able to change the enum flags (this is easily done via Unity's own EditorGUILayout). Secondly we want to make sure that whenever a flag has been set for a particular component we update that component's saved value. Lastly, we want to keep replacing the transform's position values which are locked with those of the saved data. Let's get to it.
Our custom inspection method;
And the last method for querying whether a saved component should be re-set;
That's it. The position lock system works. Try it. It's fun. This approach is also applicable to both the rotation and scale data of the Transform component. Personally I also implemented the system for locking parents and names of entities and I have, obviously, more tools written up to make the process easier to read and perform through code (specialized extensions for setting/getting positions, refactored classes for handling enum management, etc). But those particular implementations I'll leave aside for now. Anyway, hope it was interesting and, as usual, if you've got a better way or just some pointers (heh, oh god, that's a terrible joke) feel free to comment!