Example #1
0
    static ResNode GetFontOnRunTime(string assetBundleName, string assetName)
    {
        ResNode res      = null;
        int     hashCode = (assetBundleName + assetName).GetHashCode();

        if (m_FontResNodeTable.TryGetValue(hashCode, out res))
        {
            return(res);
        }

        Dictionary <string, UnityEngine.Object> assetTable = null;

        if (m_FontAssetsTable.TryGetValue(assetBundleName, out assetTable))
        {
            UnityEngine.Object asset = null;
            if (assetTable.TryGetValue(assetName, out asset))
            {
                res = AllocResNode(hashCode.ToString());

                if (res.config == null)
                {
                    res.config = new ResConfigData();
                }
                res.config.AssetBundleName = assetBundleName;
                res.config.AssetName       = assetName;
                res.isAsync = false;
                res.FillAssets(asset);
                res.status = ResNodeStatus.LoadFinish;
                m_FontResNodeTable.Add(hashCode, res);
            }
            else
            {
                AssetBudleLog("找不到字体:" + assetName);
            }
        }
        else
        {
            AssetBudleLog("找不到字体包:" + assetBundleName);
        }

        if (null != res)
        {
            res.assetType = AssetType.Asset_Font;
        }
        return(res);
    }
    private static void GetCommonRes_OnRunTime(ref ResNode reslut, string AssetBundleName, string AssetName, System.Type t)
    {
        if (!isOnRunTimeMode)
        {
            return;
        }
        string str      = AssetBundleName + AssetName;
        string hashCode = str.GetHashCode().ToString();

        if (m_CommonResNodeTable.TryGetValue(hashCode, out reslut))
        {
            reslut.AddRef();
            return;
        }
        Dictionary <string, UnityEngine.Object> assetTable = null;

        if (m_CommonAssetsTable.TryGetValue(AssetBundleName, out assetTable))
        {
            UnityEngine.Object asset = null;
            if (assetTable.TryGetValue(AssetName, out asset))
            {
                reslut = AllocResNode(hashCode.ToString());
                reslut.Clear();
                if (null == reslut.config)
                {
                    reslut.config = new ResConfigData();
                }
                reslut.config.AssetName       = AssetName;
                reslut.config.AssetBundleName = AssetBundleName;
                reslut.config.AssetGUID       = hashCode;
                reslut.isAsync = false;
                reslut.FillAssets(asset);
                reslut.status = ResNodeStatus.LoadFinish;
                reslut.AddRef();

                reslut.assetType = AssetBundleName.EndsWith(AssetBundleManager.PrefabVariant) ? AssetType.Asset_Prefab : AssetType.Asset_CommonAssets;
                m_CommonResNodeTable.Add(hashCode, reslut);
            }
            else
            {
                AssetBudleLog("在通用资源包:" + AssetBundleName + "找不到资源:" + AssetName);
            }
        }
        return;
    }
    private static void GetCommonRes(ref ResNode reslut, ResConfigData config)
    {
        if (!isOnRunTimeMode)
        {
            return;
        }

        if (m_CommonResNodeTable.TryGetValue(config.AssetGUID, out reslut))
        {
            reslut.AddRef();
            return;
        }
        Dictionary <string, UnityEngine.Object> assetTable = null;

        if (m_CommonAssetsTable.TryGetValue(config.AssetBundleName, out assetTable))
        {
            UnityEngine.Object asset = null;
            if (assetTable.TryGetValue(config.AssetName, out asset))
            {
                reslut = AllocResNode(config.AssetGUID);
                reslut.Clear();

                reslut.config    = config;
                reslut.assetType = config.AssetBundleName.EndsWith(AssetBundleManager.PrefabVariant) ? AssetType.Asset_Prefab : AssetType.Asset_CommonAssets;
                reslut.isAsync   = false;
                reslut.FillAssets(asset);
                reslut.status = ResNodeStatus.LoadFinish;
                reslut.AddRef();
                m_CommonResNodeTable.Add(config.AssetGUID, reslut);
            }
            else
            {
                AssetBudleLog("在通用资源包:" + config.AssetBundleName + "找不到资源:" + config.AssetName);
            }
        }
        return;
    }
Example #4
0
    static ResNode GetFontEditor(string assetBundleName, string assetName)
    {
        ResNode res      = null;
        int     hashCode = (assetBundleName + assetName).GetHashCode();

        if (m_FontResNodeTable.TryGetValue(hashCode, out res))
        {
            return(res);
        }
        UnityEngine.Object [] asset = LoadAssetOnEditorFromAbInstance(assetBundleName, assetName, typeof(Font));
        if (asset != null && asset.Length > 0)
        {
            res = AllocResNode(hashCode.ToString());

            if (res.config == null)
            {
                res.config = new ResConfigData();
            }

            res.config.AssetName       = assetName;
            res.config.AssetBundleName = assetBundleName;
            res.isAsync = false;
            res.FillAssets(asset);
            res.status = ResNodeStatus.LoadFinish;
            m_FontResNodeTable.Add(hashCode, res);
        }
        else
        {
            AssetBudleLog("找不到字体包:" + assetBundleName + ",字体名:" + assetName);
        }

        if (null != res)
        {
            res.assetType = AssetType.Asset_Font;
        }
        return(res);
    }
    private static void GetCommonRes_OnEditor(ref ResNode reslut, string AssetBundleName, string AssetName, System.Type t)
    {
        if (isOnRunTimeMode)
        {
            return;
        }

        string str      = AssetBundleName + AssetName;
        string hashCode = str.GetHashCode().ToString();

        if (m_CommonResNodeTable.TryGetValue(hashCode, out reslut))
        {
            reslut.AddRef();
            return;
        }

        Dictionary <string, UnityEngine.Object> assetTable = null;

        UnityEngine.Object asset = null;
        /*编辑器下找不到资源,就去加载*/
        if (m_CommonAssetsTable.TryGetValue(AssetBundleName, out assetTable))
        {
            if (assetTable.TryGetValue(AssetName, out asset))
            {
                reslut = AllocResNode(hashCode.ToString());
                reslut.Clear();

                if (null == reslut.config)
                {
                    reslut.config = new ResConfigData();
                }
                reslut.config.AssetName       = AssetName;
                reslut.config.AssetBundleName = AssetBundleName;
                reslut.config.AssetGUID       = hashCode;
                reslut.isAsync = false;
                reslut.FillAssets(asset);
                reslut.assetType = AssetBundleName.EndsWith(AssetBundleManager.PrefabVariant) ? AssetType.Asset_Prefab : AssetType.Asset_CommonAssets;
                reslut.AddRef();
                m_CommonResNodeTable.Add(hashCode, reslut);
            }
            else
            {
                UnityEngine.Object[] assets = LoadAssetOnEditorFromAbInstance(AssetBundleName, AssetName, t);
                if (null != assets && assets.Length > 0)
                {
                    assetTable = new Dictionary <string, UnityEngine.Object>();
                    foreach (UnityEngine.Object ob in assets)
                    {
                        assetTable.Add(ob.name, ob);
                    }
                    //再将东西取出来
                    asset  = assetTable[AssetName];
                    reslut = AllocResNode(hashCode.ToString());
                    reslut.Clear();
                    reslut.FillAssets(asset);
                    reslut.status = ResNodeStatus.LoadFinish;
                    if (reslut.config == null)
                    {
                        reslut.config = new ResConfigData();
                    }
                    reslut.config.AssetName       = AssetName;
                    reslut.config.AssetBundleName = AssetBundleName;
                    reslut.config.AssetGUID       = hashCode;
                    reslut.isAsync   = false;
                    reslut.assetType = AssetBundleName.EndsWith(AssetBundleManager.PrefabVariant) ? AssetType.Asset_Prefab : AssetType.Asset_CommonAssets;
                    reslut.AddRef();
                    m_CommonResNodeTable.Add(hashCode, reslut);
                }
                else
                {
                    AssetBudleLog("在通用资源包:" + AssetBundleName + "找不到资源:" + AssetName);
                }
            }
        }
        else
        {
            UnityEngine.Object[] assets = LoadAssetOnEditorFromAbInstance(AssetBundleName, AssetName, t);
            if (null != assets && assets.Length > 0)
            {
                assetTable = new Dictionary <string, UnityEngine.Object>();
                foreach (UnityEngine.Object ob in assets)
                {
                    assetTable.Add(ob.name, ob);
                }
                m_CommonAssetsTable.Add(AssetBundleName, assetTable);

                //再将东西取出来
                asset  = assetTable[AssetName];
                reslut = AllocResNode(hashCode.ToString());
                reslut.Clear();

                if (reslut.config == null)
                {
                    reslut.config = new ResConfigData();
                }
                reslut.config.AssetName       = AssetName;
                reslut.config.AssetBundleName = AssetBundleName;
                reslut.config.AssetGUID       = hashCode;
                reslut.isAsync = false;
                reslut.FillAssets(asset);
                reslut.status    = ResNodeStatus.LoadFinish;
                reslut.assetType = AssetBundleName.EndsWith(AssetBundleManager.PrefabVariant) ? AssetType.Asset_Prefab : AssetType.Asset_CommonAssets;
                reslut.AddRef();
                m_CommonResNodeTable.Add(hashCode, reslut);
            }
            else
            {
                AssetBudleLog("在通用资源包:" + AssetBundleName + "找不到资源:" + AssetName);
            }
        }
        return;
    }