public void AssetBundleLoading(AssetBundleLoadingContext context)
        {
            if (!File.Exists(context.Parameters.Path))
            {
                // the game is trying to load a path that does not exist, lets redirect to our own resources

                // obtain different resource path
                var normalizedPath = context.GetNormalizedPath();
                var modFolderPath  = Path.Combine("mods", normalizedPath);

                // if the path exists, let's load that instead
                if (File.Exists(modFolderPath))
                {
                    var bundle = AssetBundle.LoadFromFile(modFolderPath);

                    context.Bundle = bundle;
                    context.Complete(
                        skipRemainingPrefixes: true,
                        skipOriginalCall: true);
                }
            }
        }
Beispiel #2
0
        private void AssetBundleLoadingHook(AssetBundleLoadingContext context)
        {
            if (!File.Exists(context.Parameters.Path))
            {
                string bundle = context.Parameters.Path.Substring(context.Parameters.Path.IndexOf("/abdata/")).Replace("/abdata/", "");

                if (BundleManager.Bundles.TryGetValue(bundle, out List <LazyCustom <AssetBundle> > lazyList))
                {
                    context.Bundle      = lazyList[0].Instance;
                    context.Bundle.name = bundle;
                    context.Complete();
                }
                else
                {
                    //Create a placeholder asset bundle for png files without a matching asset bundle
                    if (IsPngFolderOnly(bundle))
                    {
                        context.Bundle      = AssetBundleHelper.CreateEmptyAssetBundle();
                        context.Bundle.name = bundle;
                        context.Complete();
                    }
                }
            }
        }