Esempio n. 1
0
    public void UnLoad(string bundleName, ELoadType loadType, bool unloadAllLoadedObjects = false) // ELoadType
    {
        string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType);
        int    nBundleId         = strFullBundleName.GetHashCode();

        //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + "</color>");
        BundleLoaderManager.Instance.UnloadAssetBundle(nBundleId, unloadAllLoadedObjects);
    }
Esempio n. 2
0
    public Object RGetNoInstance(string bundleName, string assetName = "", string suffix = ".prefab", ELoadType loadType = ELoadType.Max)
    {
        string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType);
        string strFullAssetName  = BundleLoaderManager.GetAssertName(bundleName, assetName, suffix, loadType);
        Object source            = BundleLoaderManager.Instance.Load(strFullBundleName, strFullAssetName, loadType);

        return(source);
    }
Esempio n. 3
0
    public void UnLoadIcon(string bundleName)
    {
        string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, ELoadType.Icon);
        //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + "</color>");
        int nBundleId = strFullBundleName.GetHashCode();

        BundleLoaderManager.Instance.UnloadAssetBundle(nBundleId, false);
    }
Esempio n. 4
0
    //获取实例化资源的地方(同步方式加载预设)
    public GameObject RGet(string bundleName, string assetName, ELoadType loadType, GameObject parent = null)
    {
        if (string.IsNullOrEmpty(bundleName))
        {
            return(null);
        }

        string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType);
        string strFullAssetName  = BundleLoaderManager.GetAssertName(bundleName, assetName, ABPathHelper.PrefabSuffix, loadType);
        //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + " assetName: " + strFullAssetName + "</color>");

        Object source = null;

#if UNITY_EDITOR
        if (GameUtils.ScriptLoad && loadType == ELoadType.UI)
        {
            source = UnityEditor.AssetDatabase.LoadAssetAtPath(strFullAssetName, typeof(UnityEngine.Object));
        }
        else
#endif
        {
            source = BundleLoaderManager.Instance.Load(strFullBundleName, strFullAssetName, loadType);
        }

        if (source is GameObject)
        {
            GameObject go = GameObject.Instantiate(source) as GameObject;
            MaterialUtils.ResetGameObjectMaterials(go);

            if (loadType == ELoadType.UI)
            {
                AutoDestroy autoDestroyCom = go.GetComponent <AutoDestroy>();
                if (autoDestroyCom == null)
                {
                    autoDestroyCom = go.AddComponent <AutoDestroy>();
                }
            }
            go.name = go.name.Replace("(Clone)", "");

            int nBundleId = strFullBundleName.GetHashCode();
            m_AllGameObjects.Add(go, nBundleId);
            if (parent != null)
            {
                go.transform.parent        = parent.transform;
                go.transform.localPosition = Vector3.zero;
                go.transform.localScale    = Vector3.one;
                go.transform.localRotation = Quaternion.identity;
            }
            return(go);
        }
        else
        {
            Debug.Log("<color=red> object is null: " + strFullAssetName + "\n" + "</color>");
        }
        return(null);
    }
Esempio n. 5
0
    public GameObject Spawn(string bundleName, string assetName, ELoadType loadType, Transform parent = null)
    {
        if (string.IsNullOrEmpty(bundleName))
        {
            return(null);
        }

        //Debug.Log("<color=red> Spawn: " + bundleName + "/" + fileName + "\n" + "</color>");

        SpawnPool pool = null;

        if (!m_Pools.TryGetValue(loadType, out pool))
        {
            AssetManageInfo info = AssetManageConfigManager.Instance.GetInfo(loadType);
            pool            = CreateSpawnPool(loadType, info.delayDelTime);
            pool.limitCount = info.limitCount;
            if (loadType == ELoadType.Effect)
            {
                pool.transform.parent = CGameRoot.UIRoot.transform;
            }
        }

        string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType);
        string strFullAssetName  = BundleLoaderManager.GetAssertName(bundleName, assetName, ABPathHelper.PrefabSuffix, loadType);

        //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + " assetName: " + strFullAssetName + "</color>");

        int nBundleId = strFullBundleName.GetHashCode();
        int nAssetId  = strFullAssetName.GetHashCode();

        PrefabPool prefabPool = pool.GetPrefabPool(nBundleId, nAssetId);
        GameObject inst       = null;

        if (prefabPool != null && prefabPool.prefab != null)
        {
            inst = pool.Spawn(prefabPool.prefab, nBundleId, nAssetId, parent);
        }
        else
        {
            Object source = BundleLoaderManager.Instance.Load(strFullBundleName, strFullAssetName, loadType);
            if (source != null)
            {
                inst = pool.Spawn(source, nBundleId, nAssetId, parent);
            }
            else
            {
                Debug.Log("<color=red> object is null: " + strFullAssetName + "\n" + "</color>");
            }
        }
        return(inst);
    }