Esempio n. 1
0
        /// <summary>
        /// Add listeners to content events
        /// </summary>
        /// <param name="persistentBehavior">Dynamic Content</param>
        void AddContentListeners(MLPersistentBehavior persistentBehavior)
        {
            persistentBehavior.OnStatusUpdate += HandleContentStatusUpdate;

            PersistentBall contentBehavior = persistentBehavior.GetComponent <PersistentBall>();

            contentBehavior.OnContentDestroy += RemoveContent;
        }
Esempio n. 2
0
        /// <summary>
        /// Remove listeners from content events
        /// </summary>
        /// <param name="persistentBehavior">Dynamic Content</param>
        void RemoveContentListeners(MLPersistentBehavior persistentBehavior)
        {
            // it is safe to unsubscribe to events even if we're not originally subscribing to them
            persistentBehavior.OnStatusUpdate -= HandleContentStatusUpdate;

            PersistentBall contentBehavior = persistentBehavior.GetComponent <PersistentBall>();

            contentBehavior.OnContentDestroy -= RemoveContent;
        }
Esempio n. 3
0
        /// <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>
        /// Handler when touchpad gesture continues.
        /// </summary>
        /// <param name="controllerId">Id of the incoming controller.</param>
        /// <param name="touchpadGesture">Class of which gesture was continued.</param>
        private void HandleTouchpadGestureContinue(byte controllerId, MLInput.Controller.TouchpadGesture touchpadGesture)
        {
            if (!_controller.IsControllerValid(controllerId))
            {
                return;
            }

            if (_deleteAllInitiated)
            {
#if PLATFORM_LUMIN
                if (touchpadGesture.Type == MLInput.Controller.TouchpadGesture.GestureType.RadialScroll)
                {
                    ++_deleteAllSequenceFrameCount;
                    if (_deleteAllSequenceFrameCount >= _deleteAllSequenceMinFrames)
                    {
                        _deleteAllInitiated = false;

                        foreach (KeyValuePair <PersistentBall, string> persistentContentPair in _persistentContentMap)
                        {
                            PersistentBall persistentContent = persistentContentPair.Key;

                            string val = _persistentContentMap[persistentContent];

                            if (val == "Created")
                            {
                                --numPersistentContentCreated;
                            }
                            else if (val == "Regained")
                            {
                                --numPersistentContentRegained;
                            }

                            persistentContent.DestroyContent(persistentContent.gameObject);
                        }

                        _persistentContentMap.Clear();
                    }
                }
#endif
            }
        }
        /// <summary>
        /// Destroys the given content and spawns another gameObject as a particle system effect.
        /// </summary>
        /// <param name="content">Content to destroy, assumed to be this content.</param>
        private void OnContentDestroy(GameObject content)
        {
            #if PLATFORM_LUMIN
            PersistentBall persistentContent = content.GetComponent <PersistentBall>();
            if (_persistentContentMap.ContainsKey(persistentContent))
            {
                string val = _persistentContentMap[persistentContent];

                if (val == "Created")
                {
                    --numPersistentContentCreated;
                }
                else if (val == "Regained")
                {
                    --numPersistentContentRegained;
                }

                _persistentContentMap.Remove(persistentContent);
            }
            #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
        }