public void Decorate(GameObject go, Dictionary<string, object> options, AssetBundle assetBundle) { go.AddComponent<Fence>(); Dictionary<string, object> fenceOptions = options["fence_options"] as Dictionary<string, object>; GameObject flat = Object.Instantiate(assetBundle.LoadAsset((string)fenceOptions["flat"])) as GameObject; flat.transform.rotation = Quaternion.identity; GameObject post = Object.Instantiate(assetBundle.LoadAsset((string)fenceOptions["post"])) as GameObject; post.transform.rotation = Quaternion.identity; go.GetComponent<Fence>().flatGO = flat; go.GetComponent<Fence>().postGO = post; go.GetComponent<Fence>().hasMidPosts = false; }
static int LoadAsset(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2) { UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.CheckObject(L, 1, typeof(UnityEngine.AssetBundle)); string arg0 = ToLua.CheckString(L, 2); UnityEngine.Object o = obj.LoadAsset(arg0); ToLua.Push(L, o); return(1); } else if (count == 3) { UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.CheckObject(L, 1, typeof(UnityEngine.AssetBundle)); string arg0 = ToLua.CheckString(L, 2); System.Type arg1 = ToLua.CheckMonoType(L, 3); UnityEngine.Object o = obj.LoadAsset(arg0, arg1); ToLua.Push(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AssetBundle.LoadAsset")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public Object Resolve(GameItemInfo gameItem) { Initialize(); ResourceGameItem item = gameItem as ResourceGameItem; if (item != null) { return(Resources.Load(item.Address)); } AssetBundleGameItem assetBundleGameItem = gameItem as AssetBundleGameItem; if (assetBundleGameItem != null) { if (_assetBundles.ContainsKey(assetBundleGameItem.AssetBundle)) { return(_assetBundles[assetBundleGameItem.AssetBundle].LoadAsset(assetBundleGameItem.ItemName)); } if (!IsAssetBundleDownloaded(assetBundleGameItem.AssetBundle)) { throw new Exception(string.Format("Asset bundle {0} is not downloaded", assetBundleGameItem.AssetBundle)); } Uri bundleServerAddress = GetBundleServerAddress(assetBundleGameItem.AssetBundle); UnityEngine.AssetBundle assetBundle = UnityEngine.AssetBundle.LoadFromFile( InfoResolver.Resolve <FortInfo>() .ServerConnectionProvider.UserConnection.LoadFromCache(bundleServerAddress)); _assetBundles[assetBundleGameItem.AssetBundle] = assetBundle; return(assetBundle.LoadAsset(assetBundleGameItem.ItemName)); } return((Object)gameItem.GetType().GetProperty("GameItem").GetValue(gameItem, new object[0])); }
static int QPYX_LoadAsset_YXQP(IntPtr L_YXQP) { try { int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP); if (QPYX_count_YXQP == 2) { UnityEngine.AssetBundle QPYX_obj_YXQP = (UnityEngine.AssetBundle)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.AssetBundle)); string QPYX_arg0_YXQP = ToLua.CheckString(L_YXQP, 2); UnityEngine.Object QPYX_o_YXQP = QPYX_obj_YXQP.LoadAsset(QPYX_arg0_YXQP); ToLua.Push(L_YXQP, QPYX_o_YXQP); return(1); } else if (QPYX_count_YXQP == 3) { UnityEngine.AssetBundle QPYX_obj_YXQP = (UnityEngine.AssetBundle)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.AssetBundle)); string QPYX_arg0_YXQP = ToLua.CheckString(L_YXQP, 2); System.Type QPYX_arg1_YXQP = ToLua.CheckMonoType(L_YXQP, 3); UnityEngine.Object QPYX_o_YXQP = QPYX_obj_YXQP.LoadAsset(QPYX_arg0_YXQP, QPYX_arg1_YXQP); ToLua.Push(L_YXQP, QPYX_o_YXQP); return(1); } else { return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to method: UnityEngine.AssetBundle.LoadAsset")); } } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
static public int LoadAsset(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 2) { UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l); System.String a1; checkType(l, 2, out a1); var ret = self.LoadAsset(a1); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 3) { UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Type a2; checkType(l, 3, out a2); var ret = self.LoadAsset(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
private UnityEngine.Object LoadFromBundle(AssetBundle bundle, string name) { #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 return bundle.Load(name); #else return bundle.LoadAsset(name); #endif }
private bool initManifest(string assetPath) { string path = assetPath + "/AssetBundles"; UnityEngine.AssetBundle mainfest_bundle = UnityEngine.AssetBundle.LoadFromFile(path); if (mainfest_bundle != null) { manifest = (AssetBundleManifest)mainfest_bundle.LoadAsset("AssetBundleManifest"); mainfest_bundle.Unload(false); } return(manifest != null); }
public GameObject Decorate(Dictionary<string, object> options, AssetBundle bundle) { GameObject asset = null; switch (_type) { case "billboard": asset = Object.Instantiate(bundle.LoadAsset((string) options["model"])) as GameObject; break; } Decorate(asset, options, bundle); return asset; }
static int LoadAsset(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2 && ToLua.CheckTypes(L, 1, typeof(UnityEngine.AssetBundle), typeof(string))) { UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.ToObject(L, 1); string arg0 = ToLua.ToString(L, 2); UnityEngine.Object o = null; try { o = obj.LoadAsset(arg0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } ToLua.Push(L, o); return(1); } else if (count == 3 && ToLua.CheckTypes(L, 1, typeof(UnityEngine.AssetBundle), typeof(string), typeof(System.Type))) { UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.ToObject(L, 1); string arg0 = ToLua.ToString(L, 2); System.Type arg1 = (System.Type)ToLua.ToObject(L, 3); UnityEngine.Object o = null; try { o = obj.LoadAsset(arg0, arg1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } ToLua.Push(L, o); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: UnityEngine.AssetBundle.LoadAsset"); } return(0); }
/// <summary> /// 初始化 /// </summary> public void initialize(Action func) { byte[] stream; string uri = string.Empty; //------------------------------------Shared-------------------------------------- uri = Util.DataPath + "shared.assetbundle"; Debug.LogWarning("LoadFile::>> " + uri); stream = File.ReadAllBytes(uri); shared = AssetBundle.CreateFromMemoryImmediate(stream); #if UNITY_5 shared.LoadAsset("Dialog", typeof(GameObject)); #else shared.Load("Dialog", typeof(GameObject)); #endif if (func != null) func(); //资源初始化完成,回调游戏管理器,执行后续操作 }
/// <summary> /// 初始化 /// </summary> public void initialize(Action func) { if (AppConst.ExampleMode) { byte[] stream; string uri = string.Empty; //------------------------------------Shared-------------------------------------- uri = Util.DataPath + "shared" + AppConst.ExtName; Debug.LogWarning("LoadFile::>> " + uri); stream = File.ReadAllBytes(uri); shared = AssetBundle.LoadFromMemory(stream); #if UNITY_5 shared.LoadAsset("Dialog", typeof(GameObject)); #else shared.Load("Dialog", typeof(GameObject)); #endif } if (func != null) func(); //资源初始化完成,回调游戏管理器,执行后续操作 }
/// <summary> /// 载入Manifest /// </summary> public static AssetBundleManifest LoadMainManifestByPath(string full_name) { if (!System.IO.File.Exists(full_name)) { return(null); } AssetBundleManifest manifest = null; UnityEngine.AssetBundle mainfest_bundle = UnityEngine.AssetBundle.LoadFromFile(full_name); if (mainfest_bundle != null) { manifest = (AssetBundleManifest)mainfest_bundle.LoadAsset("AssetBundleManifest"); mainfest_bundle.Unload(false); } return(manifest); }
public GameObject Decorate(Dictionary<string, object> options, AssetBundle bundle) { GameObject asset = null; switch (_type) { case "deco": case "trashbin": case "seating": case "seatingAuto": case "lamp": asset = Object.Instantiate(bundle.LoadAsset((string) options["model"])) as GameObject; break; case "fence": asset = new GameObject(); break; } Decorate(asset, options, bundle); return asset; }
static int LoadAsset(IntPtr L) { #if UNITY_EDITOR ToluaProfiler.AddCallRecord("UnityEngine.AssetBundle.Register"); #endif try { int count = LuaDLL.lua_gettop(L); if (count == 2) { UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.CheckObject <UnityEngine.AssetBundle>(L, 1); string arg0 = ToLua.CheckString(L, 2); UnityEngine.Object o = obj.LoadAsset(arg0); ToLua.Push(L, o); return(1); } else if (count == 3) { UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.CheckObject <UnityEngine.AssetBundle>(L, 1); string arg0 = ToLua.CheckString(L, 2); System.Type arg1 = ToLua.CheckMonoType(L, 3); UnityEngine.Object o = obj.LoadAsset(arg0, arg1); ToLua.Push(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AssetBundle.LoadAsset")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// Add a UI package from two assetbundles with a optional main asset name. /// </summary> /// <param name="desc">A assetbunble contains description file.</param> /// <param name="res">A assetbundle contains resources.</param> /// <param name="mainAssetName">Main asset name.</param> /// <returns>UIPackage</returns> public static UIPackage AddPackage(AssetBundle desc, AssetBundle res, string mainAssetName) { string source = null; #if UNITY_5 if (mainAssetName != null) { TextAsset ta = desc.LoadAsset<TextAsset>(mainAssetName); if (ta != null) source = ta.text; } else { string[] names = desc.GetAllAssetNames(); foreach (string n in names) { if (n.IndexOf("@") == -1) { TextAsset ta = desc.LoadAsset<TextAsset>(n); if (ta != null) { source = ta.text; if (mainAssetName == null) mainAssetName = Path.GetFileNameWithoutExtension(n); break; } } } } #else if (mainAssetName != null) { TextAsset ta = (TextAsset)desc.Load(mainAssetName, typeof(TextAsset)); if (ta != null) source = ta.text; } else { source = ((TextAsset)desc.mainAsset).text; mainAssetName = desc.mainAsset.name; } #endif if (source == null) throw new Exception("FairyGUI: invalid package."); if (desc != res) desc.Unload(true); return AddPackage(source, res, mainAssetName); }
public Component[] LoadScripts(string assetName, Type t = null) { TextAsset asset = null; try { asset = _assetBundle.LoadAsset <TextAsset>(assetName); } catch (Exception) { // ignored } if (asset == null) { LogUtils.Debug("No scripts found in asset bundle: " + _assetBundle); return(new Component[0]); } if (_bundleScripts == null) { _bundleScripts = new GameObject(Name + "-BundleScripts"); } List <Component> components = new List <Component>(); var assembly = Assembly.Load(asset.bytes); string failedAt; string failedInstruction; if (!SafeCodeHandler.IsSafeAssembly(assembly, out failedInstruction, out failedAt)) { _assetBundle.Unload(true); throw new Exception("Illegal asset script detected: [" + failedInstruction + "] at " + failedAt + " is not allowed (file: " + _assetFile + ")"); } var types = assembly.GetTypes(); foreach (var type in types) { if (!type.IsSubclassOf(typeof(Component)) && type != typeof(Component)) { continue; } if (t != null && (!type.IsSubclassOf(t) && type != t)) { continue; } AttachToGameObjectAttribute[] attrs = (AttachToGameObjectAttribute[])type.GetCustomAttributes(typeof(AttachToGameObjectAttribute), true); bool wasAttached = false; foreach (AttachToGameObjectAttribute attr in attrs) { GameObject obj = LoadAsset <Object>(attr.GameObject) as GameObject; if (obj == null) { LogUtils.LogError("AttachToGameObjectAttribute: Couldn't find GameObject \"" + attr.GameObject + "\" in component " + type.FullName + " in bundle " + _assetBundle + "!"); continue; } components.Add(_bundleScripts.AddComponent(type)); wasAttached = true; } if (!wasAttached) { components.Add(_bundleScripts.AddComponent(type)); } } return(components.ToArray()); }
public void Decorate(GameObject go, Dictionary<string, object> options, AssetBundle assetBundle) { var consumable = go.AddComponent<ConsumableProductInstance> (); BindingFlags flags = BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic; typeof(Product).GetField ("displayName", flags).SetValue (consumable, _name); consumable.defaultPrice = (float)(double)options ["price"]; if (options.ContainsKey ("hand")) { switch ((string)options ["hand"]) { case "left": consumable.handSide = Hand.Side.LEFT; break; case "right": consumable.handSide = Hand.Side.RIGHT; break; } } else { consumable.handSide = Hand.Side.LEFT; } if (options.ContainsKey ("consumeanimation")) { switch ((string)options ["consumeanimation"]) { case "generic": consumable.consumeAnimation = ConsumableProduct.ConsumeAnimation.GENERIC; break; case "drink_straw": consumable.consumeAnimation = ConsumableProduct.ConsumeAnimation.DRINK_STRAW; break; case "lick": consumable.consumeAnimation = ConsumableProduct.ConsumeAnimation.LICK; break; case "with_hands": consumable.consumeAnimation = ConsumableProduct.ConsumeAnimation.WITH_HANDS; break; } } else { consumable.consumeAnimation = ConsumableProduct.ConsumeAnimation.GENERIC; } if (options.ContainsKey ("temperature")) { switch ((string)options ["temperature"]) { case "none": consumable.temperaturePreference = ConsumableProduct.TemperaturePreference.NONE; break; case "cold": consumable.temperaturePreference = ConsumableProduct.TemperaturePreference.COLD; break; case "hot": consumable.temperaturePreference = ConsumableProduct.TemperaturePreference.HOT; break; } } else { consumable.temperaturePreference = ConsumableProduct.TemperaturePreference.NONE; } consumable.portions = (int)(Int64)options ["portions"]; if (options.ContainsKey ("trash")) { Dictionary<string,object> trashItem = options ["trash"] as Dictionary<string,object>; switch ((string)trashItem["model"]) { case "PopCanTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.PopCanTrash).gameObject; break; case "TeaTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.TeaTrash).gameObject; break; case "CandyTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.CandyTrash).gameObject; break; case "SoftDrinkTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.SoftDrinkTrash).gameObject; break; case "SnowconeTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.SnowconeTrash).gameObject; break; case "BubbleTeaTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.BubbleTeaTrash).gameObject; break; case "ChipBagTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.ChipBagTrash).gameObject; break; case "MiniDonutsTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.MiniDonutsTrash).gameObject; break; case "ChineseFoodTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.ChineseFoodTrash).gameObject; break; case "PopcornTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.PopcornTrash).gameObject; break; case "FriesTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.FriesTrash).gameObject; break; case "HotDrinkTrash": consumable.trash = AssetManager.Instance.getPrefab (Prefabs.HotDrinkTrash).gameObject; break; default: var asset = UnityEngine.Object.Instantiate (assetBundle.LoadAsset ((string)trashItem ["model"])) as GameObject; UnityEngine.Debug.Log (asset); asset.gameObject.SetActive (false); Trash trash = asset.AddComponent<TrashInstance> (); trash.setId (consumable.name + "_trash"); if (trashItem.ContainsKey("disgustfactor")) { trash.disgustFactor = (float)(double)trashItem ["disgustfactor"]; } if (trashItem.ContainsKey("canwiggle")) { trash.canWiggle = (bool)trashItem ["canwiggle"]; } if (trashItem.ContainsKey("volume")) { trash.volume = (float)(double)trashItem ["volume"]; } AssetManager.Instance.registerObject (asset); consumable.trash = asset; break; } } }
public static UIPackage AddPackage(AssetBundle desc, AssetBundle res, string resourceNamePrefix) { #if UNITY_5 byte[] bytes = desc.LoadAsset<TextAsset>(desc.GetAllAssetNames()[0]).bytes; #else byte[] bytes = ((TextAsset)desc.mainAsset).bytes; #endif if (desc != res) desc.Unload(true); return AddPackage(bytes, res, resourceNamePrefix); }
static public int LoadAsset(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif int argc = LuaDLL.lua_gettop(l); if (matchType(l, argc, 2, typeof(string))) { UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l); System.String a1; checkType(l, 2, out a1); var ret = self.LoadAsset <UnityEngine.Object>(a1); pushValue(l, true); pushValue(l, ret); return(2); } else if (matchType(l, argc, 2, typeof(string))) { UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l); System.String a1; checkType(l, 2, out a1); var ret = self.LoadAsset(a1); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 3) { UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Type a2; checkType(l, 3, out a2); var ret = self.LoadAsset(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function LoadAsset to call"); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
public GameObject Decorate(Dictionary<string, object> options, AssetBundle assetBundle) { var asset = UnityEngine.Object.Instantiate(assetBundle.LoadAsset((string)options["model"])) as GameObject; asset.gameObject.SetActive (false); this.Decorate (asset,options, assetBundle); AssetManager.Instance.registerObject (asset.gameObject.GetComponent<Product> ()); return asset; }