From our thread on the Unity Forums
Wow! Didn’t realise it had been so long since my last post! Still, there’s been a lot of work going on, mainly in relation to custom editors and tools that will help with content creation.
I’ve beefed up the NPC Editor so adding NPCs to maps is all done via a custom editor window and their appearance and roles (vendor, trainer, etc. etc) are completely configurable via the editor window and custom inspectors. I’ve also made it better synchronised with the Quest system, so now any changes to NPCs in scenes will automatically update the quests data to keep everything properly linked and it even prevents accidental deletion of NPCs that are linked to quests.
I’ve also given NPCs the ability to patrol and made a waypoint designer for the editor. This presented a bit of a challenge early on because I used the Handles.PositionHandle method to make it so that I can drag the path nodes in the editor and I wanted to be able to know which handle was currently selected so that I could use that information to do inserts and deletions.
The problem was that there wasn’t an obvious way to know which handle had been clicked on. I trawled through numerous posts and the seemingly best option was to make a note of the waypoint node index when the handle was actually moved, but this wouldn’t allow me to click select them (without having to move them), which is what I really wanted.
However, just as I was about to settle for that I stumbled across this polyline editor on the community wiki http://wiki.unity3d.com/index.php/PolyLineEditor which seemed to be using handles exactly how I wanted, with insert and delete. So a quick root around in the code and I found the answer.
I do a for next loop of all the nodes in the waypoint array and include this code in the loop.
Which works exactly how I wanted it to. However, it would have been nice to have a more obvious way to accomplish this, or at least an example in the Unity docs for the Handles class, as I’m guessing it’s probably quite a common requirement when using handles.
I’ve also made it so that nodes automatically snap to the terrain surface when created and moved, and it also gives visual feedback at design time if any node is placed in a position that can’t be navigated to.
Here’s a couple of images showing the path editor in action.
To finish, here’s a short video of the village of Fernville which will be the starting area for new characters. Still work in progress, but it should give an idea of how it’s going to look eventually.