Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /// <summary>
  2. /// Start is called before the first frame update
  3. /// </summary>
  4. /// <remarks>
  5. /// This is a pretty dirty solution to the problem of attaching the object to the desk. Do not use in production.
  6. /// </remarks>
  7. /// <returns></returns>
  8. IEnumerator Start()
  9. {
  10.     OVRSemanticClassification deskElement = null;
  11.  
  12.     //loop until we find the desk element
  13.     while (deskElement == null)
  14.     {
  15.         yield return null;
  16.  
  17.         // find all the objects with semantic classifications in the scene
  18.         var classifications = FindObjectsByType<OVRSemanticClassification>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
  19.  
  20.         foreach (var classification in classifications)
  21.         {
  22.             // if the object is a table, set it as the desk element
  23.             // and break the loop
  24.             if (classification.Labels.Contains("TABLE"))
  25.             {
  26.                 deskElement = classification;
  27.                 break;
  28.             }
  29.         }
  30.     }
  31.     // wait for a bit before attaching the object to the desk, so it initializes properly
  32.     yield return new WaitForSeconds(0.33f);
  33.  
  34.     //now parent the object to the desk
  35.     transform.SetParent(deskElement.transform, false);
  36. }