コード例 #1
0
 public static object LoadAssetWrapped(AssetBundle ab, string name, Type t)
 {
     if (ab == null)
     {
         return(null);
     }
     return(TextAsset.Wrap <object>(ab.LoadAsset(name, TextAsset.Unwrap(t))));
 }
コード例 #2
0
    public object[] LoadAllAssets(Type typ)
    {
        Debug.Stack("Loading all assets of type ", typ, " in ", name);
        if (!Ensure())
        {
            return(null);
        }
        List <object> allAss = new List <object>();

        if (m_AssetBundle != null)
        {
            foreach (var tobj in m_AssetBundle.LoadAllAssets(TextAsset.Unwrap(typ)).Select(TextAsset.Wrap <UnityEngine.Object>))
            {
                var obj = TextAsset.Wrap <UnityEngine.Object>(tobj);
                // virtuals assets of same name always remove the object from listing.
                if (obj != null && !virtualAssets.ContainsKey(obj.name))
                {
                    allAss.Add(obj);
                }
                else
                {
                    Debug.Log("vanilla", obj.name, " nuked by virtual asset");
                }
            }
        }

        Debug.Log("Found ", allAss.Count, " base assets");
        foreach (var n in virtualAssets.Keys)
        {
            var virt = LoadVirtualAsset(n, typ);
            if (virt != null)
            {
                Debug.Log("Adding virtual asset", n, typ);
                // original asset overriden
                allAss.Add(virt);
            }
        }

        return(allAss.ToArray());
    }
コード例 #3
0
    public IEnumerator LoadAssetAsync(string name, Type t, Action <object> cb)
    {
        Debug.Stack("Async Loading ", name, t);
        var obj = LoadVirtualAsset(name, t);

        if (obj != null)
        {
            cb(obj);
            yield break;
        }
        if (!Ensure(name))
        {
            goto @out;
        }
        obj = LoadFromVirtualBundles(name, t);
        if (obj != null)
        {
            goto @out;
        }
        var req = m_AssetBundle.LoadAssetAsync(name, TextAsset.Unwrap(t));

        if (req == null)
        {
            goto @out;
        }
        pending++;
        yield return(req);

        pending--;
        obj = req.asset;
        if (obj == null && m_AssetBundle == null)
        {
            Debug.Log("Falling back to sync load for ", name, " due to pulled rug.");
            Ensure(name);
            // fall back to sync
            obj = m_AssetBundle.LoadAsset(name, TextAsset.Unwrap(t));
        }
@out:
        cb(TextAsset.Wrap <object>(obj));
    }