Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 根据需要从另一个类和方法获取变量_C#_Unity3d - Fatal编程技术网

C# 根据需要从另一个类和方法获取变量

C# 根据需要从另一个类和方法获取变量,c#,unity3d,C#,Unity3d,我不知道这是否可行,但我试图实现的是仅在需要时从字段获取敏感密码,然后清除它(每次都不使用自定义清除方法) 所以我有这个类/方法可以得到: public class letterhead { public static letterhead phpClass; public string letterheadres; void Start() { phpClass = this; } public void Letterhead

我不知道这是否可行,但我试图实现的是仅在需要时从字段获取敏感密码,然后清除它(每次都不使用自定义清除方法)

所以我有这个类/方法可以得到:

public class letterhead
{
    public static letterhead phpClass;
    public string letterheadres;

    void Start()
    {
        phpClass = this;
    }

    public void Letterhead()
    {
        StartCoroutine(LetterheadAsync());
    }

    IEnumerator LetterheadAsync()
    {
        UnityWebRequest www = UnityWebRequest.Get($"https://mysite/letterhead1.php?dg=letterhead");
        yield return www.SendWebRequest();


        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
        }
        else
        {

            var result = www.downloadHandler.text;
            result = www.downloadHandler.text;
            Debug.Log(result);
            letterheadres = result;                
        }
    }
}
这节课我需要字母头枕:

  public class Password{
    private string letterhead3 = letterhead.phpClass.letterheadres;
}

现在你可以看到,我必须首先调用信笺()来获取信笺头并自己清除它,我试图实现的是,当我需要密码类中的信笺头3时,从信笺头()从信笺头类中获取它,然后自动清除它。

你在找类似的东西吗

public class Password {
    public static string letterhead
    {
        get
        {
            string value = letterhead.phpClass.letterheadres; // Make a copy which you will return
            // Write your clearing procedure here
            // letterhead.phpClass.letterheadres = null;
            return value;
        }
    }
}

// You can get the value from other class as
string value = Password.letterhead; // If there is a value, You will get it and it will be cleared automatically due to the getter.
确保在访问数据之前已获取数据。此外,这只会奏效一次。如果您再次需要数据,则必须再次发出web请求,并在获取数据后获取值。如果得到正确的值,则可以保证内容(信头类)将被清除