private IEnumerator Start()
        {
            //hooks:
            Transmission.Instance.OnOldestPeerUpdated.AddListener(HandleOldestPeerUpdated);
            Transmission.Instance.OnGlobalStringChanged.AddListener(HandleGlobalStringChanged);
            Transmission.Instance.OnGlobalStringsReceived.AddListener(HandleGlobalStringsReceived);

            //refs:
            _camera = Camera.main.transform;

            //system start-ups:
            if (!MLPersistentCoordinateFrames.IsStarted)
            {
                MLPersistentCoordinateFrames.Start();

                //wait for MLPersistentCoordinateFrames to localize:
                while (!MLPersistentCoordinateFrames.IsLocalized)
                {
                    yield return(null);
                }

                //establish shared pcf:
                MLPersistentCoordinateFrames.FindClosestPCF(_camera.position, out _anchorPCF, MLPersistentCoordinateFrames.PCF.Types.MultiUserMultiSession);
                if (_anchorPCF == null)
                {
                    //keep looking:
                    yield return(new WaitForSeconds(_pcfSearchTimeout));
                }

                //hooks:
                MLPersistentCoordinateFrames.OnLocalized        += HandleLocalized;
                MLPersistentCoordinateFrames.PCF.OnStatusChange += HandlePCFStatusChange;
            }
        }
Пример #2
0
 public void FindClosestPCF()
 {
     if (PhotonNetwork.IsMasterClient && pv.IsMine)
     {
         MLPersistentCoordinateFrames.FindClosestPCF(Camera.main.transform.position, AssignClosestPCF);
     }
 }
Пример #3
0
    private void HandleTriggerDown()
    {
        // place a cube 5 units in front
        Vector3 objPos = controlInput.transform.position + controlInput.transform.forward * 5;

        // Find the closest PCF and spawn the resource as an offset in local space
        MLPersistentCoordinateFrames.PCF pcfToBindTo;
        var returnResult = MLPersistentCoordinateFrames.FindClosestPCF(objPos, out pcfToBindTo, MLPersistentCoordinateFrames.PCF.Types.MultiUserMultiSession, true);

        SpawnAndAttachToPCF(resourceToSpawn.name, objPos, pcfToBindTo.CFUID.ToString(), pcfToBindTo.Position, pcfToBindTo.Rotation);
    }
Пример #4
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>
        /// Helper function to add new objects and binding them to closest PCFs.
        /// This function shows how youc an use the underlying systems to accomplish
        /// game object to a PCF binding
        /// </summary>
        public void StoreReferencePointAtPosition(Vector3 position)
        {
            if (!MLPersistentCoordinateFrames.IsStarted)
            {
                return;
            }

            var returnResult = MLPersistentCoordinateFrames.FindClosestPCF(position, (MLResult result, MLPCF pcf) =>
            {
                if (result.IsOk)
                {
                    Debug.LogFormat("Closest PCF found. Binding {0} to PCF {1}:", referencePointName, pcf.CFUID);

                    if (alignedBinding == null)
                    {
                        alignedBinding = MLContentBinder.BindToPCF(referencePointName, AlignedReferencePoint.instance.gameObject, pcf);
                    }
                    else
                    {
                        alignedBinding.PCF = pcf;
                        alignedBinding.Update();
                    }

                    _state = State.SaveRequired;
                    //Debug.LogFormat("object: {0} - {1} {2} {3}, {4} {5} {6} {7}",
                    //newExampleObject.GO.name,
                    //newExampleObject.GO.transform.position.x,
                    //newExampleObject.GO.transform.position.y,
                    //newExampleObject.GO.transform.position.z,
                    //newExampleObject.GO.transform.rotation.x,
                    //newExampleObject.GO.transform.rotation.y,
                    //newExampleObject.GO.transform.rotation.z,
                    //newExampleObject.GO.transform.rotation.w);
                }
                else
                {
                    SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Reason:" + result);
                }
            });

            if (!returnResult.IsOk)
            {
                SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Result Code:" + returnResult);
            }
        }
Пример #6
0
        #pragma warning restore 414


        /// <summary>
        /// Starts the MLPersistentCoordinateFrames api and initializes bindings.
        /// </summary>
        void Start()
        {
            #if PLATFORM_LUMIN
            MLResult result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PCFVisual failed starting MLPersistentCoordinateFrames, disabling script. Reason: {0}", result);
                enabled = false;
                return;
            }

            MLPersistentCoordinateFrames.FindClosestPCF(transform.position, out MLPersistentCoordinateFrames.PCF pcf);

            _visualTransformBinding = new TransformBinding(isPersistent: false);
            _visualTransformBinding.Bind(pcf, transform);

            _visualTextBinding = new TextMeshBinding();
            _visualTextBinding.Bind(pcf, _statusText);
            #endif
        }
        /// <summary>
        /// Helper function to add new objects and binding them to closest PCFs.
        /// This function shows how youc an use the underlying systems to accomplish
        /// game object to a PCF binding
        /// </summary>
        void CreateObject()
        {
            Vector3 position = new Vector3(UnityEngine.Random.Range(-1.5f, 1.5f), UnityEngine.Random.Range(-1.5f, 1.5f), UnityEngine.Random.Range(1.5f, 5.0f));

            ExampleObject newExampleObject = new ExampleObject();

            newExampleObject.GO      = Instantiate(_goPrefab, position, UnityEngine.Random.rotation);
            newExampleObject.GO.name = Guid.NewGuid().ToString();
            _exampleObjects.Add(newExampleObject);

            var returnResult = MLPersistentCoordinateFrames.FindClosestPCF(position, (MLResult result, MLPCF pcf) =>
            {
                if (result.IsOk)
                {
                    Debug.LogFormat("Closest PCF found. Binding {0} to PCF {1}:", newExampleObject.GO.name, pcf.CFUID);
                    newExampleObject.Binding = MLContentBinder.BindToPCF(newExampleObject.GO.name, newExampleObject.GO, pcf);
                    _state = State.SaveRequired;
                    Debug.LogFormat("object: {0} - {1} {2} {3}, {4} {5} {6} {7}",
                                    newExampleObject.GO.name,
                                    newExampleObject.GO.transform.position.x,
                                    newExampleObject.GO.transform.position.y,
                                    newExampleObject.GO.transform.position.z,
                                    newExampleObject.GO.transform.rotation.x,
                                    newExampleObject.GO.transform.rotation.y,
                                    newExampleObject.GO.transform.rotation.z,
                                    newExampleObject.GO.transform.rotation.w);
                }
                else
                {
                    RemoveObject(newExampleObject);
                    SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Reason:" + result);
                }
            });

            if (!returnResult.IsOk)
            {
                RemoveObject(newExampleObject);
                SetProgress(FAILED_TO_FIND_CLOSEST_PCF + " Result Code:" + returnResult);
            }
        }
Пример #8
0
 public void FindNearestPCF()
 {
     Debug.Log("Finding nearest pcf");
     MLPersistentCoordinateFrames.FindClosestPCF(Camera.main.transform.position, OnFoundNearestPCF);
 }
Пример #9
0
        private ActsAsGlobalOrigin.AnchorResult anchorToClosestPCF(ActsAsGlobalOrigin.AnchorAttempt anchorAttempt, MLPersistentCoordinateFrames.PCF.Types type)
        {
            if (MLPersistentCoordinateFrames.IsLocalized == false)
            {
                print("Localized map must first be created before finding a PCF");
                return(ActsAsGlobalOrigin.AnchorResult.GeneralFail);
            }

            MLResult resultFindClosestSecondaryPCFType = MLPersistentCoordinateFrames.FindClosestPCF(transform.position, out MLPersistentCoordinateFrames.PCF closestPCF, type);

            switch (resultFindClosestSecondaryPCFType.Result)
            {
            case MLResult.Code.Ok:
            {
                if (closestPCF == null)
                {
                    return(resultFailFrom(anchorAttempt));
                }
                else
                {
                    ///
                    /// Bind this GameObject's transform to the PCF
                    ///
                    this.transformBinding = new TransformBinding(this.GetInstanceID().ToString(), "ActsAsGlobalOrigin");
                    if (this.transformBinding == null)
                    {
                        return(resultFailFrom(anchorAttempt));
                    }

                    if (this.transformBinding.Bind(closestPCF, transform))
                    {
                        closestPCF.AddBinding(this);
                        this.pcf = closestPCF;

                        print("Added Binding");

                        return(resultSuccessFrom(anchorAttempt));
                    }
                    else
                    {
                        return(resultFailFrom(anchorAttempt));
                    }
                }
            }

            case MLResult.Code.InvalidParam:
                throw new System.NotImplementedException();

            case MLResult.Code.PrivilegeDenied:
                throw new System.NotImplementedException();

            case MLResult.Code.UnspecifiedFailure:
                print("UnspecifiedFailure");
                return(ActsAsGlobalOrigin.AnchorResult.GeneralFail);

            case MLResult.Code.PassableWorldLowMapQuality:
                print("PassableWorldLowMapQuality - quality of the room map is too low, re-map room");
                return(ActsAsGlobalOrigin.AnchorResult.PassableWorldLowMapQuality);

            case MLResult.Code.PassableWorldUnableToLocalize:
                print("PassableWorldUnableToLocalize - room layout has changed, re-map room or adjust lighting");
                return(ActsAsGlobalOrigin.AnchorResult.PassableWorldUnableToLocalize);
            }
            return(ActsAsGlobalOrigin.AnchorResult.GeneralFail);
        }
Пример #10
0
 private void FindPCF_Enter()
 {
     MLPersistentCoordinateFrames.FindClosestPCF(_camera.position, out pcfAnchor);
     ChangeState(State.FindFloor);
 }