예제 #1
0
    public void StartLoad()
    {
        //1.如果已经加载过
        AssetBundle lmAssetBundle = null;

        GameObjectLightmapAssetBundleLoader.lmAbDic.TryGetValue(assetBundlePath, out lmAssetBundle);

        if (lmAssetBundle != null)
        {
            InitByAssetBundle(lmAssetBundle);
            return;
        }
        //2.如果正在加载中
        GameObjectLightmapAssetBundleLoaderCmp gameObjectLightmapAssetBundleLoaderCmp = null;

        lmCmpDic.TryGetValue(assetBundlePath, out gameObjectLightmapAssetBundleLoaderCmp);

        if (gameObjectLightmapAssetBundleLoaderCmp == null)
        {
            gameObjectLightmapAssetBundleLoaderCmp = InitByAssetBundle;
            lmCmpDic.Add(assetBundlePath, gameObjectLightmapAssetBundleLoaderCmp);
            StartCoroutine(loadLightMapAssetBundle());
        }
        else
        {
            lmCmpDic[assetBundlePath] += InitByAssetBundle;
        }
        isReLoad = false;
    }
예제 #2
0
    IEnumerator loadLightMapAssetBundle()
    {
        WWW www = new WWW("file://" + Application.streamingAssetsPath + "/" + assetBundlePath);

        yield return(www);

        if (www.isDone)
        {
            assetBundle = www.assetBundle;

            GameObjectLightmapAssetBundleLoader.lmAbDic.Add(assetBundlePath, assetBundle);

            //InitByAssetBundle();

            String[]     allAssetNames = assetBundle.GetAllAssetNames();
            LightmapData data          = tempMapDatas[index];
            if (allAssetNames.Length == 1)
            {
                texture2DlightmapLight = assetBundle.LoadAsset(allAssetNames[0]) as Texture2D;

                data.lightmapColor = texture2DlightmapLight;
            }
            else
            if (allAssetNames.Length == 2)
            {
                texture2DlightmapColor = assetBundle.LoadAsset(allAssetNames[0]) as Texture2D;
                texture2DlightmapDir   = assetBundle.LoadAsset(allAssetNames[1]) as Texture2D;

                //LightmapData data = new LightmapData();
                data.lightmapColor = texture2DlightmapColor;
                data.lightmapDir   = texture2DlightmapDir;
            }

            GameObjectLightmapAssetBundleLoaderCmp gameObjectLightmapAssetBundleLoaderCmp = null;
            lmCmpDic.TryGetValue(assetBundlePath, out gameObjectLightmapAssetBundleLoaderCmp);

            if (gameObjectLightmapAssetBundleLoaderCmp != null)
            {
                //gameObjectLightmapAssetBundleLoaderCmp(assetBundle);
                Delegate[] invocationList = gameObjectLightmapAssetBundleLoaderCmp.GetInvocationList();
                foreach (Delegate i in invocationList)
                {
                    i.DynamicInvoke(assetBundle);
                }

                lmCmpDic.Remove(assetBundlePath);
            }
        }
    }