Example #1
0
        public static AssetBundleBuild GetAllAssets(ModInfo info, string platform)
        {
            AssetIndexer     ai  = ModsEditor.GetAssetIndexer(info.InternalName);
            AssetBundleBuild abb = new AssetBundleBuild();

            abb.assetBundleName  = info.PackageName + "." + platform;
            abb.addressableNames = new string[ai.InfoList.Count + 3];
            abb.assetNames       = new string[ai.InfoList.Count + 3];
            int i = 0;

            for (i = 0; i < ai.InfoList.Count; i++)
            {
                abb.addressableNames[i] = ai.InfoList[i].FullName;
                abb.assetNames[i]       = AssetDatabase.GUIDToAssetPath(ai[i].AssetId.ToString());
            }
            //添加包信息内容
            abb.addressableNames[i] = "ModInfo";
            abb.assetNames[i++]     = ModsEditor.GetModInfoPath(info.InternalName);

            abb.addressableNames[i] = "AssetIndexer";
            abb.assetNames[i++]     = ModsEditor.GetAssetIndexerPath(info.InternalName);

            abb.addressableNames[i] = "LanguageDic";
            abb.assetNames[i++]     = ModsEditor.GetLanguageDicPath(info.InternalName);
            return(abb);
        }
        /// <summary>
        /// 导入资源到Mod时触发的事件
        /// </summary>
        static void ImportAsset(string ModName, UnityEngine.Object asset)
        {
            //如果该资源名称未处理过,先处理名称,然后让它在下一轮Import事件处理(重命名会重新Import)
            if (asset.GetAssetModNameEditor() != ModName)
            {
                AddModName(ModName, asset);
                return;
            }
            AssetIndexer ai = ModsEditor.GetAssetIndexer(ModName);
            //检测该资源是否已经存在
            int assetindex = ai.TryGet(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset)));

            if (assetindex == -1)
            {
                ai.Add(asset.name, CreatAssetInfo(asset));
            }
            else
            {
                if (ai.NameList[assetindex] == asset.name)
                {
                    return;//没被重命名就无视
                }
                ai.Rename(ai.NameList[assetindex], asset.name);
            }
        }
        /// <summary>
        /// 用于重命名在Mod中的Asset
        /// </summary>
        /// <returns>经过处理后的名称</returns>
        static string RenameAsset(string NewAssetFullName, UnityEngine.Object asset)
        {
            AssetIndexer ai = ModsEditor.GetAssetIndexer(AssetUtility.GetModName(NewAssetFullName));

            if (ai.Contains(NewAssetFullName) != -1)
            {
                int i = 1;
                while (ai.Contains(NewAssetFullName + i) != -1)
                {
                    i++;
                }
                NewAssetFullName = NewAssetFullName + i;
                Debug.LogError("资源名字重复!资源名:" + asset.name + "。已改名为" + NewAssetFullName);
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetOrScenePath(asset), NewAssetFullName);
            }
            else
            {
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetOrScenePath(asset), NewAssetFullName);
            }
            return(NewAssetFullName);
        }
        /// <summary>
        /// 从Mod中移除资源时触发的事件
        /// </summary>
        static void DeleteAsset(string ModName, string AssetName)
        {
            AssetIndexer ai = ModsEditor.GetAssetIndexer(ModName);

            ai?.Remove(ModName + "." + AssetName);
        }
Example #5
0
        public static void BindCommonServices(this ContainerBuilder builder, IReloadingManager <AppSettings> generalSettingsManager, ILog log)
        {
            var generalSettings = generalSettingsManager.CurrentValue;

            builder.RegisterType <HealthService>()
            .As <IHealthService>()
            .SingleInstance();

            var indexerConfiguration = new IndexerConfiguration
            {
                StorageCredentials = new StorageCredentials(generalSettings.BcnExploler.NinjaIndexerCredentials.AzureName,
                                                            generalSettings.BcnExploler.NinjaIndexerCredentials.AzureKey),
                Network = generalSettings.BcnExploler.UsedNetwork()
            };

            builder.Register(p => new IndexerClient(indexerConfiguration)).AsSelf().InstancePerDependency();

            builder.RegisterType <AssetBalanceChangesRepository>()
            .As <IAssetBalanceChangesRepository>()
            .InstancePerDependency();

            builder.RegisterType <BlockService>()
            .As <IBlockService>()
            .InstancePerDependency();

            builder.RegisterType <AddressService>()
            .As <IAddressService>()
            .InstancePerDependency();

            builder.RegisterType <TransactionService>()
            .As <ITransactionService>()
            .InstancePerDependency();

            builder.RegisterType <MainChainService>()
            .As <IMainChainService>()
            .InstancePerDependency();

            builder.RegisterType <SearchService>()
            .As <ISearchService>()
            .InstancePerDependency();

            builder.Register(p =>
            {
                var context = p.Resolve <IComponentContext>();
                return
                (new CachedDataDictionary <string, IAssetDefinition>(
                     async() => AssetIndexer.IndexAssetsDefinitions(
                         await context.Resolve <IAssetDefinitionRepository>().GetAllAsync(),
                         await context.Resolve <IAssetImageRepository>().GetAllAsync())
                     , validDataInSeconds: 1 * 10 * 60));
            }
                             ).AsSelf().SingleInstance();


            builder.RegisterInstance(new AssetImageCacher(
                                         AzureBlobStorage.Create(
                                             generalSettingsManager.ConnectionString(p => p.BcnExploler.Db.AssetsConnString)), log))
            .As <IAssetImageCacher>();

            builder.RegisterInstance(generalSettingsManager.CurrentValue.BcnExploler.UsedNetwork())
            .AsSelf()
            .SingleInstance();

            builder.RegisterType <MainChainService>()
            .As <IMainChainService>()
            .InstancePerDependency();

            builder.Register(p =>
            {
                var context = p.Resolve <IComponentContext>();

                return
                (new CachedMainChainService(new MemoryCacheManager(), AzureBlobStorage.Create(generalSettingsManager.Nested(x => x.BcnExploler.Db.AssetsConnString)), context.Resolve <IMainChainService>(), context.Resolve <AppSettings>()));
            }
                             ).As <ICachedMainChainService>()
            .SingleInstance();

            builder.Register(p =>
            {
                var context = p.Resolve <IComponentContext>();
                return
                (new CachedDataDictionary <string, IAssetCoinholdersIndex>(
                     async() => AssetIndexer.IndexAssetCoinholders(await context.Resolve <IAssetCoinholdersIndexRepository>().GetAllAsync())
                     , validDataInSeconds: 1 * 10 * 60));
            }
                             ).AsSelf().SingleInstance();

            builder.Register(p =>
            {
                var context = p.Resolve <IComponentContext>();
                return
                (new CachedDataDictionary <string, IAssetScore>(
                     async() => AssetIndexer.IndexAssetScores(await context.Resolve <IAssetScoreRepository>().GetAllAsync())
                     , validDataInSeconds: 1 * 10 * 60));
            }
                             ).AsSelf().SingleInstance();

            builder.RegisterType <AssetDefinitionReader>().As <IAssetDefinitionReader>();

            builder.Register(p =>
            {
                var context = p.Resolve <IComponentContext>();
                return(new CachedBlockService(new MemoryCacheManager(), context.Resolve <IBlockService>()));
            }
                             ).As <ICachedBlockService>().SingleInstance();


            builder.Register(p =>
            {
                var context = p.Resolve <IComponentContext>();
                return(new CachedTransactionService(new MemoryCacheManager(), context.Resolve <ITransactionService>()));
            }
                             ).As <ICachedTransactionService>().SingleInstance();

            builder.Register(p =>
            {
                var context = p.Resolve <IComponentContext>();
                return(new CachedAddressService(new MemoryCacheManager(), context.Resolve <IAddressService>()));
            }
                             ).As <ICachedAddressService>().SingleInstance();

            builder.RegisterType <AssetService>()
            .As <IAssetService>()
            .SingleInstance();

            builder.RegisterType <OffchainNotificationsApiProvider>()
            .As <IOffchainNotificationsApiProvider>()
            .SingleInstance();

            builder.RegisterType <OffchainNotificationsService>()
            .As <IOffchainNotificationsService>()
            .SingleInstance();
        }