Exemplo n.º 1
0
        /* ========================== Load From File ========================== */

        public static AssetBundle CreateBundleFromFile(string path)
        {
#if PROFILE_FILE
            Profiler.BeginSample("BundleEncoder.CreateBundleFromFile");
#endif
            AssetBundle bundle = null;

#if LOAD_FROM_FILE
            try
            {
                Encoding enc = GetEncodingOfFile(path);
                LogUtil.Trace("CreateBundleFromFile: " + path + " enc=" + enc);
                if (enc == Encoding.Unity)
                {
                    string fullpath = FileUtils.PrepareBundleFile(path);
                    bundle = AssetBundle.LoadFromFile(fullpath);
#if PROFILE_FILE
                    Profiler.EndSample();
#endif
                    return(bundle);
                }
                LogUtil.Trace("CreateBundleFromFile: fallback to LoadFromMemory for this encoding");
            }
            catch (Exception e)
            {
                // just fallback to LoadFromMemory
                LogUtil.Error("CreateBundleFromFile: fallback to LoadFromMemory because of Error " + e);
            }
#endif // LOAD_FROM_FILE

            byte[] data = DecodeBundleFile(path);
            bundle = AssetBundle.LoadFromMemory(data);
#if PROFILE_FILE
            Profiler.EndSample();
#endif
            return(bundle);
        }
Exemplo n.º 2
0
        public static string GetStringFromFile(string fpath)
        {
            string data = null;

            var length = searchPaths.Count;

            for (var i = 0; i < length; i++)
            {
                var    p    = searchPaths[i];
                string path = p + fpath;
                data = GetStringFromFileNoSearching(path);
                if (data != null)
                {
                    break;
                }
            }

            if (data == null)
            {
                LogUtil.Error("GetStringFromFile: cannot find " + fpath);
            }

            return(data);
        }
Exemplo n.º 3
0
        private void doBind(object state)
        {
            IntPtr L = (IntPtr)state;

            Assembly[] ams = AppDomain.CurrentDomain.GetAssemblies();

            bindProgress = 0;

            List <Type> bindlist = new List <Type>();

            for (int n = 0; n < ams.Length; n++)
            {
                Assembly a  = ams[n];
                Type[]   ts = null;
                try
                {
                    ts = a.GetExportedTypes();
                }
                catch
                {
                    continue;
                }
                for (int k = 0; k < ts.Length; k++)
                {
                    Type t = ts[k];
                    if (t.GetCustomAttributes(typeof(LuaBinderAttribute), false).Length > 0)
                    {
                        bindlist.Add(t);
                    }
                }
            }

            bindProgress = 1;

            bindlist.Sort(new System.Comparison <Type>((Type a, Type b) => {
                LuaBinderAttribute la = (LuaBinderAttribute)a.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0];
                LuaBinderAttribute lb = (LuaBinderAttribute)b.GetCustomAttributes(typeof(LuaBinderAttribute), false)[0];

                return(la.order.CompareTo(lb.order));
            }));

            List <Action <IntPtr> > list = new List <Action <IntPtr> >();

            for (int n = 0; n < bindlist.Count; n++)
            {
                Type t       = bindlist[n];
                var  sublist = (Action <IntPtr>[])t.GetMethod("GetBindList").Invoke(null, null);
                list.AddRange(sublist);
            }

            bindProgress = 2;

            int count = list.Count;

            try {
                for (int n = 0; n < count; n++)
                {
                    Action <IntPtr> action = list[n];
                    action(L);
                    bindProgress = (int)(((float)n / count) * 98.0) + 2;
                }
            } catch (Exception e) {
                LogUtil.Error(e.ToString());
            }

            bindProgress = 100;
        }
Exemplo n.º 4
0
        internal static IEnumerator LoadAsync(string parentBundlePath, string uri, int ttl)
        {
            string keyName = GetBundleKey(uri);

            GetTTLSettings(uri, ref ttl);

            AssetBundleRef abRef;

            while (loadingBundles.Contains(keyName))
            {
                LogUtil.Trace("BundleManager: is already Loading " + keyName);
                yield return(null);
            }

            if (TryGetRefreshedBundleRef(keyName, ttl, out abRef))
            {
                loadingBundles.Remove(keyName);
                abRef.AddParentBundle(parentBundlePath);
                yield break;
            }
            else
            {
                loadingBundles.Add(keyName);

                LogUtil.Trace("BundleManager: LoadAsyncWithNoCallback " + uri);
                AssetBundle bundle = null;

                if (loadWithWWW)
                {
                    var www = BundleEncoder.CreateBundleFromWWWAsync(uri, wwwVersion, wwwCrc);
                    while (!www.isDone)
                    {
                        yield return(null);
                    }
                    if (www.error == null || www.error == "")
                    {
                        bundle = www.assetBundle;
                    }
                    else
                    {
                        LogUtil.Error("BundleManager: creating bundle from WWW failed: " + www.error);
                    }
                }
                else
                {
                    var req = BundleEncoder.CreateBundleFromFileAsync(uri);
                    while (!req.isDone && !TryGetRefreshedBundleRef(keyName, ttl, out abRef))
                    {
                        yield return(null);
                    }

                    if (req.isDone)
                    {
                        bundle = req.assetBundle;
                    }
                }

                if (bundle != null)
                {
                    abRef             = new AssetBundleRef(uri, ttl);
                    abRef.AssetBundle = bundle;
                    dictAssetBundleRefs.Add(keyName, abRef);
                    listAssetBundleUris.Add(uri);
                    AddLoadHistory(uri, true);
                    loadingBundles.Remove(keyName);
                    abRef.AddParentBundle(parentBundlePath);
                }
                else
                {
                    if (TryGetRefreshedBundleRef(keyName, ttl, out abRef))
                    {
                        loadingBundles.Remove(keyName);
                        abRef.AddParentBundle(parentBundlePath);
                    }
                    else
                    {
                        LogUtil.Error("BundleManager: creating bundle from uri failed! " + uri);
                    }
                }

                loadingBundles.Remove(keyName);
            }
        }