/// <summary> /// Instantiates a new object with MLPCFPersistentContent. The MLPCFPersistentContent is /// responsible for restoring and saving itself. /// </summary> /// <param name="position">Position to spawn the content at.</param> /// <param name="rotation">Rotation to spawn the content at.</param> private void CreateContent(Vector3 position, Quaternion rotation) { GameObject gameObj = Instantiate(_content, position, rotation); #if PLATFORM_LUMIN MLPersistentCoordinateFrames.FindClosestPCF(position, out MLPersistentCoordinateFrames.PCF pcf); PersistentBall persistentContent = gameObj.GetComponent <PersistentBall>(); persistentContent.BallTransformBinding = new TransformBinding(gameObj.GetInstanceID().ToString(), "Ball"); persistentContent.BallTransformBinding.Bind(pcf, gameObj.transform); ContentTap contentTap = persistentContent.GetComponent <ContentTap>(); contentTap.OnContentTap += OnContentDestroy; ++numPersistentContentCreated; _persistentContentMap.Add(persistentContent, "Created"); #endif }
/// <summary> /// Reads all stored persistent bindings. /// Each stored binding will contain a PCF object with a CFUID. /// Use that stored CFUID to see if the PCF exists in this session, if it does then the stored binding can be regained. /// If the binding is regained correctly then the persistent content will retain it's pose from the last known launch. /// </summary> private void RegainAllStoredBindings() { #if PLATFORM_LUMIN TransformBinding.storage.LoadFromFile(); List <TransformBinding> allBindings = TransformBinding.storage.Bindings; List <TransformBinding> deleteBindings = new List <TransformBinding>(); foreach (TransformBinding storedBinding in allBindings) { // Try to find the PCF with the stored CFUID. MLResult result = MLPersistentCoordinateFrames.FindPCFByCFUID(storedBinding.PCF.CFUID, (MLResult.Code resultCode, MLPersistentCoordinateFrames.PCF pcf) => { if (pcf != null && MLResult.IsOK(pcf.CurrentResultCode)) { GameObject gameObj = Instantiate(_content, Vector3.zero, Quaternion.identity); PersistentBall persistentContent = gameObj.GetComponent <PersistentBall>(); persistentContent.BallTransformBinding = storedBinding; persistentContent.BallTransformBinding.Bind(pcf, gameObj.transform, true); ContentTap contentTap = persistentContent.GetComponent <ContentTap>(); contentTap.OnContentTap += OnContentDestroy; ++numPersistentContentRegained; _persistentContentMap.Add(persistentContent, "Regained"); } else { deleteBindings.Add(storedBinding); } }); } foreach (TransformBinding storedBinding in deleteBindings) { storedBinding.UnBind(); } bindingsLoaded = true; #endif }