【发布时间】:2021-02-10 04:17:27
【问题描述】:
这是我的二维码跟踪代码。使用 gitHub 示例并添加了一个名为 'Launch' 的新函数
public void Launch(string uri)
当我稍后调用它时,它会给出:
The name 'Launch' does not exist in this current context
我的声明是错误的还是应该包含在“QRTracking”函数中?使用,Unity 2019.4.14f1,Visual Studio 2019,UWP 平台。删除了一些带有“...”的代码部分,以减少我认为不相关的大小。任何提示都会非常有帮助。我是 C# 的新手。
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
#if WINDOWS_UWP
using Windows.Perception.Spatial;
public void Launch (string uri)
{
Debug.Log($"LaunchUri: Launching {uri}"); #if WINDOWS_UWP
UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
{
bool result = await global::Windows.System.Launcher.LaunchUriAsync(new
System.Uri(uri));
if (!result)
{
Debug.LogError("Launching URI failed to launch.");
}
}, false); #else
Application.OpenURL(uri);
#endif
}
#endif
namespace QRTracking
{
[RequireComponent(typeof(QRTracking.SpatialGraphCoordinateSystem))]
public class QRCode : MonoBehaviour
{
public Microsoft.MixedReality.QR.QRCode qrCode;
private GameObject qrCodeCube;
....
....
private bool launch = false;
private System.Uri uriResult;
private long lastTimeStamp = 0;
// Use this for initialization
void Start()
{
PhysicalSize = 0.1f;
CodeText = "Dummy";
if (qrCode == null)
{
throw new System.Exception("QR Code Empty");
}
PhysicalSize = qrCode.PhysicalSideLength;
CodeText = qrCode.Data;
....
....
QRID.text = "Id:" + qrCode.Id.ToString();
QRNodeID.text = "NodeId:" + qrCode.SpatialGraphNodeId.ToString();
QRText.text = CodeText;
if (System.Uri.TryCreate(CodeText, System.UriKind.Absolute,out uriResult))
{
validURI = true;
QRText.color = Color.blue;
}
...
...
Debug.Log("Id= " + qrCode.Id + "NodeId= " + qrCode.SpatialGraphNodeId + " PhysicalSize
= " + PhysicalSize + " TimeStamp = " + qrCode.SystemRelativeLastDetectedTime.Ticks + "
QRVersion = " + qrCode.Version + " QRData = " + CodeText);
// added here
Debug.Log("Call Launch");
Launch("http://" + CodeText"); // -> error: Name 'Launch' does not exist in the
current context
}
.....
.....
【问题讨论】:
-
它不在类范围内。把它移到课堂上。