Exemplo n.º 1
0
    /// <summary>
    /// 加载WindowNode
    ///
    /// </summary>
    /// <param name="windowNode"></param>
    /// <returns></returns>
    IEnumerator LoadWindowGameObjectByWindowNode(WindowNode windowNode)
    {
        AssetBundleManager assetBundleManager = AssetBundleManager.Instance;

        if (assetBundleManager == null)
        {
            Debug.LogErrorFormat("Load window asset[{0}] error[AssetBundleManager is null when window been loading]. windowNode[ID:{1}] be clear!", windowNode.WindowAssetName, windowNode.WindowName);
            CloseWindow(windowNode.WindowName, false, false);
            yield break;
        }
        LoadAssetAsyncOperation operation = assetBundleManager.LoadAssetAsync <GameObject>(windowNode.WindowAssetName, false);

        if (operation != null && !operation.IsDone)
        {
            yield return(operation);
        }
        if (m_WindowNodeList.Contains(windowNode))
        {
            if (operation != null && operation.IsDone)
            {
                UnityEngine.Object resource = operation.GetAsset <UnityEngine.Object>();
                if (resource != null)
                {
                    GameObject windowGameObject = Instantiate(resource) as GameObject;
                    if (windowGameObject != null)
                    {
                        SetWindowNodeGameObject(windowNode, windowGameObject);
                    }
                    else
                    {
                        Debug.LogErrorFormat("Load window asset[{0}] error[Asset was not a gameObject]. windowNode[ID:{1}] be clear!", windowNode.WindowAssetName, windowNode.WindowName);
                        CloseWindow(windowNode.WindowName, false, false);
                    }
                }
                else
                {
                    Debug.LogErrorFormat("Load window asset[{0}] error[Asset was null]. windowNode[ID:{1}] be clear!", windowNode.WindowAssetName, windowNode.WindowName);
                    CloseWindow(windowNode.WindowName, false, false);
                }
            }
            else
            {
                Debug.LogErrorFormat("Load window asset[{0}] error. windowNode[ID:{1}] be clear!", windowNode.WindowAssetName, windowNode.WindowName);
                CloseWindow(windowNode.WindowName, false, false);
            }
        }
        else
        {
            // 在加载的过程中,本窗体已经被删除掉了
        }
    }
Exemplo n.º 2
0
    IEnumerator ELoadAudioClip(string key, System.Action <AudioClip, string> callback)
    {
        AssetBundleManager assetBundleManager = AssetBundleManager.Instance;

        if (assetBundleManager == null)
        {
            Debug.LogErrorFormat("Load window asset[{0}] error[AssetBundleManager is null when window been loading]. windowNode[ID:{1}] be clear!", key, key);
            yield break;
        }

        LoadAssetAsyncOperation operation = assetBundleManager.LoadAssetAsync <AudioClip>(key, false);

        if (operation != null && !operation.IsDone)
        {
            yield return(operation);
        }

        if (operation != null && operation.IsDone)
        {
            AudioClip resource = operation.GetAsset <AudioClip>();
            if (resource != null)
            {
                if (callback != null)
                {
                    callback(resource, key);
                }
            }
            else
            {
                Debug.LogErrorFormat("Load Audio asset[{0}] error[Asset was null]. ", key);
            }
        }
        else
        {
            Debug.LogErrorFormat("Load Audio asset[{0}] error.", key);
        }
    }