Load资源绕过异步,必须load结束才进行下面操作

public void Init()
    {
         FDJson();
    }
    
    
    void FDJson()
    {
        using(WWW _load = new WWW("file://"+ FileFunc.GetStreamPath("FontPreferenceC.json")))
        {
            while(!_load.isDone)
            {
                
            }
            ftData = JsonReader.Deserialize<FTData>(_load.text);
            
            if (FontData.shareData.FD == null)
            {
                print("hahaha:  null");
            }
            else
            {
                print("not null :  "+ FontData.shareData.FD.reinforceGroup.mainPage.BarTitle );
            }
            print("111111");
        }
    }

如果异步则用StartCortine

public void Init()
    {
         StartCortine(FDJson());
    }
    
    
    IEnumerator FDJson()
    {
        using(WWW _load = new WWW("file://"+ FileFunc.GetStreamPath("FontPreferenceC.json")))
        {
            yied return _load;
            ftData = JsonReader.Deserialize<FTData>(_load.text);
            
            if (FontData.shareData.FD == null)
            {
                print("hahaha:  null");
            }
            else
            {
                print("not null :  "+ FontData.shareData.FD.reinforceGroup.mainPage.BarTitle );
            }
            print("111111");
        }
    }

异步只是协程,不是多线程

原文地址:https://www.cnblogs.com/pengyingh/p/3014520.html