コード例 #1
0
    private void OnStatusChange(MLPersistentCoordinateFrames.PCF.Status pcfStatus, MLPersistentCoordinateFrames.PCF pcf)
    {
        if (displayDebugVisuals)
        {
            if (pcfStatus == MLPersistentCoordinateFrames.PCF.Status.Created)
            {
                PCFAnchorVisual newVisual = Instantiate(AnchorVisualPrefab, pcf.Position, pcf.Rotation);
                newVisual.transform.parent = visualParent.transform;
                newVisual.GetComponent <PCFAnchorVisual>().PCF = pcf;
            }

            if (pcfStatus == MLPersistentCoordinateFrames.PCF.Status.Lost)
            {
                foreach (var visual in visualParent.GetComponentsInChildren <PCFAnchorVisual>())
                {
                    if (visual.PCF.Equals(pcf))
                    {
                        DestroyImmediate(visual.gameObject);
                    }
                }
            }

            if (pcfStatus == MLPersistentCoordinateFrames.PCF.Status.Updated)
            {
                foreach (var visual in visualParent.GetComponentsInChildren <PCFAnchorVisual>())
                {
                    if (visual.PCF.Equals(pcf))
                    {
                        visual.gameObject.transform.position = pcf.Position;
                        visual.gameObject.transform.rotation = pcf.Rotation;
                        Debug.LogFormat("PCF Updated anchor: was {0}, is now {1}", visual.PCF.ToString(), pcf.ToString());
                        visual.PCF = pcf;
                    }
                }
            }
        }
    }
コード例 #2
0
    public void HandleAnchorsChanged(MLXRSession.AnchorsUpdatedEventArgs e)
    {
        foreach (MLXRAnchor anchor in e.added)
        {
            Debug.Log("PCF: ADD " + anchor.id);
            string anchorString = anchor.id.ToString();
            if (!PcfPoseLookup.ContainsKey(anchorString))
            {
                PcfPoseLookup[anchorString] = (new PcfPoseData()
                {
                    pcfId = anchorString,
                    position = anchor.pose.position,
                    rotation = anchor.pose.rotation
                });
            }

            if (displayDebugVisuals)
            {
                Pose            pose      = anchor.pose;
                PCFAnchorVisual newVisual = Instantiate(AnchorVisualPrefab, pose.position, pose.rotation);
                newVisual.transform.parent = visualParent.transform;
                newVisual.GetComponent <PCFAnchorVisual>().Anchor = anchor;
            }
        }

        foreach (MLXRAnchor anchor in e.removed)
        {
            Debug.Log("PCF: REMOVE " + anchor.id);
            string anchorString = anchor.id.ToString();
            if (PcfPoseLookup.ContainsKey(anchorString))
            {
                PcfPoseLookup.Remove(anchorString);
            }

            if (displayDebugVisuals)
            {
                foreach (var visual in visualParent.GetComponentsInChildren <PCFAnchorVisual>())
                {
                    if (visual.Anchor.id.Equals(anchor.id))
                    {
                        DestroyImmediate(visual.gameObject);
                    }
                }
            }
        }

        foreach (MLXRAnchor anchor in e.updated)
        {
            string anchorString = anchor.id.ToString();
            if (PcfPoseLookup.ContainsKey(anchorString))
            {
                PcfPoseLookup[anchorString].position = anchor.pose.position;
                PcfPoseLookup[anchorString].rotation = anchor.pose.rotation;
            }

            if (displayDebugVisuals)
            {
                foreach (var visual in visualParent.GetComponentsInChildren <PCFAnchorVisual>())
                {
                    if (visual.Anchor.id.Equals(anchor.id))
                    {
                        Pose pose = anchor.pose;
                        visual.gameObject.transform.position = pose.position;
                        visual.gameObject.transform.rotation = pose.rotation;
                        Debug.LogFormat("PCF Updated anchor: was {0}, is now {1}", visual.Anchor.ToString(), anchor.ToString());
                        visual.Anchor = anchor;
                    }
                }
            }
        }
    }