Example #1
0
    public static void LoadAsset <T>(Dictionary <string, T> collections, string path) where T : UnityEngine.Object
    {
        //Debug.Log(string.Format("{0}:name={1} path={2}", System.Reflection.MethodBase.GetCurrentMethod().Name, name, AssetBundlePath + path));
        T obj = null;

#if UNITY_EDITOR
        obj = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(AssetBundlePath + "/" + path);
#else
        string asset_name = PackRule.PathToAssetBundleName(path);
        //Debug.Log($"asset_name:{asset_name}");
        if (!allAssetBundle.ContainsKey(asset_name))
        {
            allAssetBundle[asset_name] = LoadAB(asset_name);
        }
        Debug.Log($"path:{path}");
        Debug.Log(allAssetBundle[asset_name]);
        obj = allAssetBundle[asset_name].LoadAsset <T>(Path.GetFileName(path));
#endif
        if (obj != null)
        {
            collections.Add(path, obj);
        }
        else
        {
            throw new Exception($"Load {path} Faild");
        }
    }
Example #2
0
        public void LoadAsset <T>(string file_path, Action <UObject[]> action = null, LuaFunction func = null) where T : UObject
        {
#if UNITY_EDITOR
            if (AppConfig.DebugMode)
            {
                StartCoroutine(LoadAssetInLocal <T>(file_path, action, func));
                return;
            }
#endif
            // string assetName = System.IO.Path.GetFileNameWithoutExtension(file_path);
            string abName  = PackRule.PathToAssetBundleName(file_path);
            string resName = file_path.ToLower();
            this.LoadAsset <T>(abName, new string[] { resName }, action, func);
        }
Example #3
0
        public static void PackName()

        {
            string path = SysDefine.PATH_ASSETBUNDLE_LOCAL + "/" + "ui/itemGain/UIGainItem.prefab";
            string Name = PackRule.PathToAssetBundleName(path);
            var    ab   = ResMgr.LoadAB(Name);

            foreach (var name in ab.GetAllAssetNames())
            {
                Debug.Log(name);
                var obj = ab.LoadAsset(name);
            }
            //ab.GetAllAssetNames
            //Debug.Log(Name);
        }
Example #4
0
        public void LoadAsset <T>(string file_path, Action <UObject[]> action = null, LuaFunction func = null) where T : UObject
        {
#if UNITY_EDITOR
            if (AppConfig.DebugMode)
            {
                T sprite = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(file_path);
                if (sprite != null)
                {
                    if (func != null)
                    {
                        List <T> list = new List <T>();
                        list.Add(sprite);
                        object[] args = new object[] { list.ToArray() };
                        func.Call(args);
                        func.Dispose();
                        func = null;
                    }
                    else if (action != null)
                    {
                        List <UObject> list = new List <UObject>();
                        list.Add(sprite);
                        UObject[] args = list.ToArray();
                        action(args);
                    }
                    return;
                }
                else
                {
                    Debug.Log("ResourceManager:LoadAsset Error:cannot find file:" + file_path);
                }
            }
#endif
            // string assetName = System.IO.Path.GetFileNameWithoutExtension(file_path);
            string abName  = PackRule.PathToAssetBundleName(file_path);
            string resName = file_path.ToLower();
            this.LoadAsset <T>(abName, new string[] { resName }, action, func);
        }
Example #5
0
        public void LoadPrefabGameObject(string name, LuaFunction func = null)
        {
            string assetName = System.IO.Path.GetFileNameWithoutExtension(name);
            string abName    = PackRule.PathToAssetBundleName(name);

#if UNITY_EDITOR
            if (AppConfig.DebugMode)
            {
                //这个接口只在编辑器模式下生效
                UnityEngine.Object obj    = UnityEditor.AssetDatabase.LoadAssetAtPath(name, typeof(UnityEngine.Object));
                GameObject         prefab = obj as GameObject;
                if (prefab == null)
                {
                    return;
                }

                GameObject go = Instantiate(prefab) as GameObject;
                go.name = assetName;
                if (func != null)
                {
                    func.Call(go);
                }
                return;
            }
#endif

            // if (!is_sync_load)
            // {
            this.LoadPrefab(abName, assetName, delegate(UnityEngine.Object[] objs) {
                if (objs.Length == 0)
                {
                    return;
                }
                GameObject prefab = objs[0] as GameObject;
                if (prefab == null)
                {
                    return;
                }

                GameObject go = Instantiate(prefab) as GameObject;
                go.name       = assetName;

                if (func != null)
                {
                    func.Call(go);
                }
                Debug.LogWarning("CreatePanel::>> " + name + " " + prefab);
            });
            // }
            // else
            // {
            //Cat_Todo : luaframework资源想同步加载的话好像只能通过宏?有空处理下
            //GameObject prefab = ResManager.LoadAsset<GameObject>(name, assetName);
            //if (prefab == null) return;

            //GameObject go = Instantiate(prefab) as GameObject;
            //go.name = assetName;

            //if (func != null) func.Call(go);
            //Debug.LogWarning("CreatePanel::>> " + name + " " + prefab);
            // }
        }