As I was thinking about what's a view, and how to give it to an AI agent, I was considering what are the view properties, it has a field of view, a facing direction, an origin and how far we see. I realised that this description is a good description of a camera. So why should I make a camera-like component if I can try using the existing Unity camera component.
I tried to figure out if there was a way to know every gameobject present in the line of sight of the camera in Unity. There is, but it is too time and memory expensive (I'll be happy to show you how). There are other information you may think of using like using renderer.isVisible, OnBecameVisible(), OnWillRenderObject() but you'll have to attach a script to every object you want your AI to be able to see. Besides, renderer.isVisible doesn't tell you from which camera it is visible, and none of these method takes care of occlusion. All these datas are hard to work with knowing we are working with mutliple camera.
Know if GameObject is in AI Line of Sight
Now we can know if a gameobjet is inside our view but not if we can see it because it may be hidden by another object closer the camera position. So I use linecasts to know if we can see the object. But to which position should I cast? Object center position is a good choice but not necessarily accurate enough. I use the object mesh bounds, and go through all the bounds positions and stop when a linecast don't go through anything and then I know a see the object.
The perfect way would be to do a linecast between each vertice of the mesh but it would be too much time expensive.