private void AddAnnotationObjects(HashSet <Renderer> renderers) { //Renderers are unique! foreach (Renderer renderer in renderers) { GameObject target = renderer.gameObject; if (!target.TryGetComponent(out AnnotationObject annotationObject)) //Check if added before by other objectManagers or manually { //If not added annotationObject = target.AddComponent <AnnotationObject>(); //Attach the script to objects of interest //Set render callback //Set ID #if UNITY_EDITOR totalIds += (uint)incrementID; annotationObject.ID = totalIds; #else annotationObject.ID = ++totalIds; #endif } //Add callback to this manager annotationObject.renderCallBacks.Add(OnWillRenderAnnotationObject); //Add to annotated objects of this manager AnnotatedObjects.Add(annotationObject); } }
private void OnWillRenderAnnotationObject(AnnotationCamera camera, AnnotationObject annotationObject) { if (!AnnotatedObjects.Contains(annotationObject)) { return; //Object rendered is not part of this object manager } if (RenderedObjects.ContainsKey(camera)) { RenderedObjects[camera].Add(annotationObject); } else { RenderedObjects.Add(camera, new HashSet <AnnotationObject>() { annotationObject }); } }