Example #1
0
    private static ABO load_abo(int abi)
    {
        //TODO: remove recursive call
        ABO abo = null;

        abi_to_abo.TryGetValue(abi, out abo);
        if (abo != null)
        {
            abo.refn++;
            DBGPRINT("load_abo abi:" + abi + " ref:" + abo.refn);
            return(abo);
        }
        abo             = new ABO();
        abi_to_abo[abi] = abo;        //insert first, for circle depend
        var name   = abi_to_name[abi];
        var depend = MANIFEST.GetDirectDependencies(name);

        for (int i = 0; i < depend.Length; i++)
        {
            var dn = depend[i];
            var di = 0;
            name_to_abi.TryGetValue(dn, out di);
            if (di == 0)
            {
                DBGPRINT("load_abo depend nonexist assetbundle:" + dn);
                return(null);
            }
            load_abo(di);
            abo.dependencies.Add(di);
        }
        var path = Path.Combine(ROOT, name);

        DBGPRINT("load_abo depend assetbundle:" + path);
        var ab = AssetBundle.LoadFromFile(path);

        System.Diagnostics.Debug.Assert(ab != null);
        abo.ab  = ab;
        abo.abi = abi;
        return(abo);
    }
Example #2
0
    private static void unload_abo(int abi)
    {
        ABO abo = null;

        abi_to_abo.TryGetValue(abi, out abo);
        if (abo == null)
        {
            DBGPRINT("unload_abo nonexist abo:" + abi);
            return;
        }
        --abo.refn;
        DBGPRINT("unload_abo abi:" + abi + " ref:" + abo.refn);
        if (abo.refn <= 0)
        {
            var iter = abo.dependencies.GetEnumerator();
            while (iter.MoveNext())
            {
                unload_abo(iter.Current);
            }
            abo.ab.Unload(true);
            abi_to_abo.Remove(abi);
            DBGPRINT("unload_abo clear abi:" + abi);
        }
    }