Tosetupourscene, weusedMeta's buildingblocks, which I explainedindetailin a previousvideo, thatyoucanwatchhere.
Forthisscene, I onlyneed a camerarigand a pass-throughlayer.
I thencreated a newgameobjectcalledSpatialAnchorManager, wherewewillattachourcustomcomponentsin a minute.
I wouldliketostartwith a simpleanchorplacementscript.
Insidethisclass, wedeclare a publicvariablecalledAnchorPrefabtohold a referencetotheprefabyouwanttoinstantiateinthegame.
Insidetheupdatemethod, there's a conditionalcheckusingtheOVRinputtodetermineiftheprimaryindextriggerbuttonontherightOculusTouchcontrollerhasbeenpressed.
UnityPlayerPrefsare a simplekeyvaluestoragesystemusedtosaveandloadsmallamountsofdatasuchasplayerpreferencesorgamesettingsbetweengamesessionswithoutrequiringcomplexfilehandling.
Tosavethosekeyvalues, wecreate a constantstringthatwillsavetheanchor's IDs.
Wewilllookatcloudsavingandloadingin a differentvideoaboutsharedspatialanchors.
Theloadmethodisresponsiblefortheasynchronousloadingofunboundanchorsbasedontheprovidedloadoptions, whichincludetheIDstoload, thestoragelocation, and a timeoutsetting.
ItcallsthestaticmethodloadUnboundedAnchorsontheOVRspatialanchortoloadtheseanchors, providing a callbackfunctionthatiscalledoncetheloadingprocesscompletes.
Itthenbindstheunboundanchortothisnewlyinstantiatedgameobject, creating a permanentlinkbetweentheanchordataandthegameobject.
Lastly, itupdatesthetextcomponentsoftheinstantiatedanchorgameobjectwiththeIDoftheanchorand a messageindicatingthattheanchorhasbeenloadedfromdevicestorage, providingvisualfeedbackwithinthesceneregardingthestatusofeachloadedanchor.