示例#1
0
    public void LoadAssetAndInitialize(string assetName, Transform parent, Vector3 pos, System.Action <GameObject> call = null)
    {
        UnityEngine.Object ret = LoadAssetFromResource(assetName);
        if (ret == null)
        {
            AssetBundleReader reader = AssetBundleReaderManager.Instance.LoadAssetBundle(assetName);
            AssetPack         ap     = null;
            CoroutineAgent.WaitOperation(
                () => reader.IsLoaded,
                () =>
            {
                if (reader.IsLoaded && reader.AssetBundleData != null)
                {
                    ret = reader.AssetBundleData.LoadAsset(assetName.AssetFileName().NoExtension());
                    reader.UnLoadAssetBundle();
                }

                if (ret != null)
                {
                    if (!m_dicAsset.ContainsKey(assetName))
                    {
                        ap = new AssetPack(ret, false);
                        m_dicAsset.Add(assetName, ap);
                    }
                    else
                    {
                        ap = m_dicAsset[assetName];
                        Debug.logger.LogWarning("ResMgr", "ResMgr.LoadAssetAndInitialize: asset name->" + assetName + ", already in asset pool");
                    }
                }
                else
                {
                    Debug.logger.LogError("ResMgr", "ResMgr.LoadAssetAndInitialize: assetName->" + assetName + ", finds no asset!");
                }
                //targetObj.GetComponent<UITexture>().mainTexture = (Texture)ret;
                GameObject go              = GameObject.Instantiate(ret) as GameObject;
                go.transform.parent        = parent;
                go.transform.localPosition = pos;
                go.transform.localScale    = Vector3.one;
                if (call != null)
                {
                    call(go);
                }
            }, this);
        }
        else
        {
            GameObject go = GameObject.Instantiate(ret) as GameObject;
            go.transform.parent        = parent;
            go.transform.localPosition = pos;
            go.transform.localScale    = Vector3.one;
            if (call != null)
            {
                call(go);
            }
        }
    }
示例#2
0
    public void LoadAssetTexture(string assetName, GameObject targetObj, bool isKeepInMemory = false)
    {
        UnityEngine.Object ret = LoadAssetFromResource(assetName);
        if (ret == null)
        {
            AssetBundleReader reader = AssetBundleReaderManager.Instance.LoadAssetBundle(assetName);
            AssetPack         ap     = null;
            CoroutineAgent.WaitOperation(
                () => reader.IsLoaded,
                () =>
            {
                if (reader.IsLoaded && reader.AssetBundleData != null)
                {
                    ret = reader.AssetBundleData.LoadAsset(assetName.AssetFileName().NoExtension());
                    reader.UnLoadAssetBundle();
                }

                if (ret != null)
                {
                    if (!m_dicAsset.ContainsKey(assetName))
                    {
                        ap = new AssetPack(ret, isKeepInMemory);
                        m_dicAsset.Add(assetName, ap);
                    }
                    else
                    {
                        ap = m_dicAsset[assetName];
                        Debug.logger.LogWarning("ResMgr", "ResMgr.LoadAssetTexture: asset name->" + assetName + ", already in asset pool");
                    }
                }
                else
                {
                    Debug.logger.LogError("ResMgr", "ResMgr.LoadAssetTexture: assetName->" + assetName + ", finds no asset!");
                }
                targetObj.GetComponent <UITexture>().mainTexture = (Texture)ret;
            }, this);
        }
        else
        {
            targetObj.GetComponent <UITexture>().mainTexture = (Texture)ret;
        }
    }