Exemplo n.º 1
0
        /// <summary>
        /// Validates parameters, initializes renderers, and listens to events.
        /// </summary>
        void Start()
        {
            if (_destroyedContentEffect == null)
            {
                Debug.LogError("Error: PersistentBall._destroyedContentEffect is not set, disabling script.");
                enabled = false;
                return;
            }

            if (_nameText == null)
            {
                Debug.LogError("Error: PersistentBall._nameText is not set, disabling script.");
                enabled = false;
                return;
            }

            if (_highlightEffect == null)
            {
                Debug.LogError("Error: PersistentBall._highlightEffect is not set, disabling script.");
                enabled = false;
                return;
            }
            _highlightEffect.SetActive(false);

            if (_lineToPCF == null)
            {
                Debug.LogError("Error: PersistentBall._lineToPCF is not set, disabling script.");
                enabled = false;
                return;
            }

            _lineToPCF.positionCount = 2;
            _lineToPCF.enabled       = false;

            _renderers = GetComponentsInChildren <Renderer>();
            _collider  = GetComponent <Collider>();

            ContentTap contentTap = GetComponent <ContentTap>();

            contentTap.OnContentTap += DestroyContent;

            _nameText.transform.position = transform.position + new Vector3(0, 0.25f, 0);
            _nameText.text = "Object ID:" + gameObject.GetInstanceID();

           #if PLATFORM_LUMIN
            MLResult result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PersistentBall failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }
            #endif
        }
Exemplo n.º 2
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
        }
Exemplo n.º 3
0
        /// <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
        }