Example #1
0
        public AssetBundleLoadAssetOperation LoadAssetAsync <T>(GameAssetStruct gas, System.Action <T> pCallBack) where T : UnityEngine.Object
        {
            Log(LogType.Info, "Loading " + gas.AssetName + " from " + gas.BundleFullName + " bundle");

            AssetBundleLoadAssetOperation operation = null;

#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(gas.BundleFullName, gas.AssetName);
                if (assetPaths.Length == 0)
                {
                    Log(LogType.Error, "There is no asset with name \"" + gas.AssetName + "\" in " + gas.BundleFullName);
                    return(null);
                }

                // @TODO: Now we only get the main object from the first asset. Should consider type also.
                //Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                T target = AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]);
                operation = new AssetBundleLoadAssetOperationSimulation(target, null);
                pCallBack(operation.GetAsset <T>());
            }
            else
#endif
            {
                LoadAssetBundleAsy(gas.BundleFullName);
                operation = new AssetBundleLoadAssetOperationFull(gas.BundleFullName, gas.AssetName, typeof(T), a => {
                    pCallBack(a.GetAsset <T>());
                });

                m_InProgressOperations.Add(operation);
            }

            return(operation);
        }
Example #2
0
        public T[] LoadAllAssets <T>(GameAssetStruct gas) where T : UnityEngine.Object
        {
#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(gas.BundleFullName);
                T[]      result     = new T[assetPaths.Length];
                if (assetPaths.Length == 0)
                {
                    Log(LogType.Error, "There is no asset with name \"" + gas.AssetName + "\" in " + gas.BundleFullName);
                    return(null);
                }
                for (int i = 0, length = assetPaths.Length; i < length; i++)
                {
                    // @TODO: Now we only get the main object from the first asset. Should consider type also.
                    Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[i]);
                    AssetBundleLoadAssetOperationSimulation operation = new AssetBundleLoadAssetOperationSimulation(target, null);
                    result[i] = operation.GetAsset <T>();
                }
                return(result);
            }
            else
#endif
            {
                AssetBundle bundle = LoadOrGetAssetsBundle(gas);
                if (bundle != null)
                {
                    return(bundle.LoadAllAssets <T>());
                }
                return(null);
            }
        }