コード例 #1
0
        public AssetGetter LoadAllAssets(string assetPath)
        {
            string loadPath = GetAssetPathWithExtend(assetPath.ToLower());

            string pullPath = System.IO.Path.Combine(Application.dataPath, loadPath.ToLower());

            pullPath = pullPath.Replace('\\', '/');
            string []     files = System.IO.Directory.GetFiles(pullPath);
            List <Object> objs  = new List <Object>();

            for (int i = 0; i < files.Length; ++i)
            {
                if (files[i].Contains(".meta"))
                {
                    continue;
                }
                Logger.LogWarp.Log(files[i].Substring(files[i].Replace('\\', '/').LastIndexOf("/")));

                var o = AssetDatabase.LoadAssetAtPath <Object>("Assets/" + loadPath + files[i].Substring(files[i].Replace('\\', '/').LastIndexOf("/")));
                objs.Add(o);
            }

            AssetHolder assetHolder = new AssetHolder(objs.ToArray());
            AssetGetter getter      = new AssetGetter();

            getter.SetAssetHolder(assetHolder);
            return(getter);
        }
コード例 #2
0
        bool LoadAssetFromNameAssetHolder <T>(string assetName, string bundleName, out T getter)
            where T : IAssetGetter, new()
        {
            // 1 从nameAssetHolders获取资源
            AssetHolder assetHolder = null;

            bundleName = GetBundleName(assetName);
            string[] dependencies = null;
            getter = new T();
            if (nameAssetHolders.TryGetValue(assetName, out assetHolder))
            {
                getter.SetAssetHolder(assetHolder);

                //记录Bundle引用
                //nameAssetHolders有,那么bundleHolders必有
                bundleHolders[bundleName].AddRefence(assetName);
                dependencies = manifest.GetAllDependencies(bundleName);
                for (int i = 0, iMax = dependencies.Length; i < iMax; ++i)
                {
                    bundleHolders[dependencies[i]].AddRefence(assetName);
                }
                return(true);
            }

            return(false);
        }
コード例 #3
0
        //异步

        public void LoadAssetAsync(string assetPath, System.Action <AssetGetter> callback)
        {
            string      loadPath    = GetAssetPathWithExtend(assetPath.ToLower());
            Object      obj         = AssetDatabase.LoadAssetAtPath <Object>(loadPath);
            AssetHolder assetHolder = new AssetHolder(obj);
            AssetGetter getter      = new AssetGetter();

            getter.SetAssetHolder(assetHolder);
            callback(getter);
        }
コード例 #4
0
        //同步
        public AssetGetter LoadAsset(string assetPath)
        {
            string      loadPath    = GetAssetPathWithExtend(assetPath.ToLower());
            Object      obj         = AssetDatabase.LoadAssetAtPath <Object>(loadPath);
            AssetHolder assetHolder = new AssetHolder(obj);
            AssetGetter getter      = new AssetGetter();

            getter.SetAssetHolder(assetHolder);
            return(getter);
        }
コード例 #5
0
        public void LoadGameObjectAsync(string assetPath, System.Action <GameObjectGetter> callback)
        {
            string     loadPath = GetAssetPathWithExtend(assetPath.ToLower());
            GameObject prefab   = AssetDatabase.LoadAssetAtPath <GameObject>(loadPath);

            AssetHolder      assetHolder = new AssetHolder(prefab);
            GameObjectGetter getter      = new GameObjectGetter();

            getter.SetAssetHolder(assetHolder);
            callback(getter);
        }
コード例 #6
0
        public GameObjectGetter LoadGameObject(string assetPath)
        {
            string     loadPath = GetAssetPathWithExtend(assetPath.ToLower());
            GameObject prefab   = AssetDatabase.LoadAssetAtPath <GameObject>(loadPath);

            AssetHolder      assetHolder = new AssetHolder(prefab);
            GameObjectGetter getter      = new GameObjectGetter();

            getter.SetAssetHolder(assetHolder);
            return(getter);
        }
コード例 #7
0
        IEnumerator CoLoadAssetAsync <T>(AssetBundle assetBundle, string assetName, E_LoadAsset eloadAsset, System.Action <T> callback)
            where T : IAssetGetter, new()
        {
            AssetBundleRequest assetRequest = null;

            switch (eloadAsset)
            {
            case E_LoadAsset.LoadSingle:
                int    index             = assetName.LastIndexOf("/");
                string assetNameInBundle = assetName.Substring(index + 1);
                assetRequest = assetBundle.LoadAssetAsync(assetNameInBundle);
                break;

            case E_LoadAsset.LoadAll:
                assetRequest = assetBundle.LoadAllAssetsAsync <Object>();
                break;
            }

            while (!assetRequest.isDone)
            {
                yield return(assetRequest);
            }

            AssetHolder assetHolder = null;

            switch (eloadAsset)
            {
            case E_LoadAsset.LoadSingle:
                assetHolder = new AssetHolder(assetRequest.asset);
                break;

            case E_LoadAsset.LoadAll:
                assetHolder = new AssetHolder(assetRequest.allAssets);
                break;
            }

            T getter = new T();

            getter.SetAssetHolder(assetHolder);
            nameAssetHolders.Add(assetName, assetHolder);
#if UNITY_EDITOR
            var request = bundleAsyncs.Dequeue();
            Logger.LogWarp.Log(request.assetName + " " + request.currRequestID + " Dequeue");
#else
            bundleAsyncs.Dequeue();
#endif
            if (callback != null)
            {
                callback(getter);
            }
        }
コード例 #8
0
        /// <summary>
        /// 维护资源和GameObject的引用关系
        /// </summary>
        /// <param name="go"></param>
        /// <param name="assetHolder"></param>
        public void AddGameObjectAssetHolder(GameObject go, AssetHolder assetHolder)
        {
            //记录资源引用
            assetHolder.AddRefence(go);

            HashSet <AssetHolder> assetHolders = null;

            if (!goAssetHolders.TryGetValue(go, out assetHolders))
            {
                assetHolders = new HashSet <AssetHolder>();
                goAssetHolders.Add(go, assetHolders);
            }
            assetHolders.Add(assetHolder);
        }
 static int SetAssetHolder(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UFrame.ResourceManagement.AssetGetter obj  = (UFrame.ResourceManagement.AssetGetter)ToLua.CheckObject <UFrame.ResourceManagement.AssetGetter>(L, 1);
         UFrame.ResourceManagement.AssetHolder arg0 = (UFrame.ResourceManagement.AssetHolder)ToLua.CheckObject <UFrame.ResourceManagement.AssetHolder>(L, 2);
         obj.SetAssetHolder(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #10
0
        IEnumerator CoLoadAssetAsync <T>(AssetBundle assetBundle, string assetName, E_LoadAsset eloadAsset, System.Action <T> callback)
            where T : IAssetGetter, new()
        {
            AssetBundleRequest assetRequest = null;

            switch (eloadAsset)
            {
            case E_LoadAsset.LoadSingle:
                int    index             = assetName.LastIndexOf("/");
                string assetNameInBundle = assetName.Substring(index + 1);
                Debug.LogError(assetName + " " + assetNameInBundle);
                //assetRequest = assetBundle.LoadAssetAsync(assetName);
                assetRequest = assetBundle.LoadAssetAsync(assetNameInBundle);
                break;

            case E_LoadAsset.LoadAll:
                assetRequest = assetBundle.LoadAllAssetsAsync <Object>();
                break;
            }

            while (!assetRequest.isDone)
            {
                yield return(assetRequest);
            }

            AssetHolder assetHolder = null;

            switch (eloadAsset)
            {
            case E_LoadAsset.LoadSingle:
                assetHolder = new AssetHolder(assetRequest.asset);
                break;

            case E_LoadAsset.LoadAll:
                assetHolder = new AssetHolder(assetRequest.allAssets);
                break;
            }

            T getter = new T();

            getter.SetAssetHolder(assetHolder);
            nameAssetHolders.Add(assetName, assetHolder);

            callback(getter);
            bundleAsyncs.Dequeue();
        }
コード例 #11
0
        T LoadAsset <T>(string assetName, E_LoadAsset eLoadAsset)
            where T : IAssetGetter, new()
        {
            T      getter;
            string bundleName = GetBundleName(assetName);

            if (LoadAssetFromNameAssetHolder(assetName, bundleName, out getter))
            {
                return(getter);
            }

            AssetBundle bundle = LoadBundle(assetName, bundleName);

            if (bundle == null)
            {
                return(getter);
            }

            //所有bundle加载完毕
            AssetHolder assetHolder = null;

            switch (eLoadAsset)
            {
            case E_LoadAsset.LoadSingle:
                int    index             = assetName.LastIndexOf("/");
                string assetNameInBundle = assetName.Substring(index + 1);
                //Debug.LogError(assetName + " " + assetNameInBundle);

                assetHolder = new AssetHolder(bundle.LoadAsset(assetNameInBundle));
                break;

            case E_LoadAsset.LoadAll:
                assetHolder = new AssetHolder(bundle.LoadAllAssets());
                break;
            }
            getter.SetAssetHolder(assetHolder);

            nameAssetHolders.Add(assetName, assetHolder);

            return(getter);
        }
コード例 #12
0
 public void SetAssetHolder(AssetHolder assetHolder)
 {
     this.assetHolder = assetHolder;
 }
コード例 #13
0
 public void AddGameObjectAssetHolder(GameObject go, AssetHolder assetHolder)
 {
     resLoader.AddGameObjectAssetHolder(go, assetHolder);
 }
コード例 #14
0
 public void AddGameObjectAssetHolder(GameObject go, AssetHolder assetHolder)
 {
 }