/// <summary>
        ///     Process a imported asset.
        /// </summary>
        /// <param name="importedAssetPath"></param>
        /// <returns>True if processed.</returns>
        public bool ProcessImportedAsset(string importedAssetPath)
        {
            SetDefaultGroupTemplateIfNeeded();

            var addressablePath = _addressablePathGenerateService.GenerateFromAssetPath(importedAssetPath);

            if (string.IsNullOrEmpty(addressablePath))
            {
                return(false);
            }

            var addressingMode    = _setting.BaseAddressingMode.Value;
            var packingMode       = _setting.BasePackingMode.Value;
            var groupTemplateGuid = _setting.GroupTemplateGuid.Value;
            var createOrMoveInfo  = _entryOperationInfoBuildService.BuildEntryCreateOrMoveInfo(importedAssetPath,
                                                                                               addressingMode, packingMode, groupTemplateGuid, _rules);

            if (createOrMoveInfo == null)
            {
                return(false);
            }

            var operationInfo = new EntryOperationInfo(createOrMoveInfo, null);

            return(_entryOperationInfoApplyService.Apply(operationInfo));
        }
        public void Apply_Remove_CanRemove()
        {
            // Set up services.
            var addressablesEditorService = new FakeAddressablesEditorAdapter();
            var assetDatabaseService      = new FakeAssetDatabaseAdapter();
            var service = new EntryOperationInfoApplyDomainService(addressablesEditorService, assetDatabaseService);

            // Set up test assets.
            const string groupName       = "BeforeGroup";
            var          beforeGroupInfo = addressablesEditorService.CreateGroup(groupName, false, false, false,
                                                                                 null, null);
            const string createdAssetPath = "Assets/Prefabs/prefab_test.prefab";
            var          groupTemplate    = ScriptableObject.CreateInstance <AddressableAssetGroupTemplate>();

            assetDatabaseService.CreateTestAsset("Assets/TestGroupTemplate.asset", groupTemplate);
            var assetGuid = assetDatabaseService.CreateTestAsset(createdAssetPath, new GameObject());

            addressablesEditorService.CreateOrMoveEntry(assetGuid, beforeGroupInfo.Guid);
            var beforeGroup = addressablesEditorService.Groups.Values.First(x => x.Name.Equals(groupName));

            Assert.That(beforeGroup.Entries.Count, Is.EqualTo(1));

            // Test.
            var removeOperationInfo = new EntryRemoveOperationInfo(createdAssetPath);
            var operationInfo       = new EntryOperationInfo(null, removeOperationInfo);

            service.Apply(operationInfo);
            Assert.That(beforeGroup.Entries.Count, Is.Zero);
            Assert.That(addressablesEditorService.Groups.Count, Is.Zero);
        }
        public void Apply_Create_CanCreate()
        {
            // Set up services.
            var addressablesEditorService = new FakeAddressablesEditorAdapter();
            var assetDatabaseService      = new FakeAssetDatabaseAdapter();
            var service = new EntryOperationInfoApplyDomainService(addressablesEditorService, assetDatabaseService);

            // Set up test assets.
            const string address           = "dummyAddress";
            const string createdAssetPath  = "Assets/Prefabs/prefab_test.prefab";
            const string groupName         = "TestPrefabs";
            var          labels            = new[] { "DummyLabel1", "DummyLabel2" };
            var          groupTemplate     = ScriptableObject.CreateInstance <AddressableAssetGroupTemplate>();
            var          groupTemplateGuid =
                assetDatabaseService.CreateTestAsset("Assets/TestGroupTemplate.asset", groupTemplate);
            var assetGuid = assetDatabaseService.CreateTestAsset(createdAssetPath, new GameObject());

            // Test.
            var createOrMoveOperationInfo = new EntryCreateOrMoveOperationInfo(createdAssetPath, address,
                                                                               groupName, groupTemplateGuid, labels);
            var operationInfo = new EntryOperationInfo(createOrMoveOperationInfo, null);

            service.Apply(operationInfo);
            var group = addressablesEditorService.Groups.Values.First();
            var entry = group.Entries.First();

            Assert.That(group.Name, Is.EqualTo(groupName));
            Assert.That(entry.Guid, Is.EqualTo(assetGuid));
            Assert.That(entry.Address, Is.EqualTo(address));
            Assert.That(entry.Labels.Length, Is.EqualTo(2));
            Assert.That(entry.Labels, Contains.Item(labels[0]));
            Assert.That(entry.Labels, Contains.Item(labels[1]));
        }
        /// <summary>
        ///     Process a moved asset.
        /// </summary>
        /// <param name="toAssetPath"></param>
        /// <param name="fromAssetPath"></param>
        /// <returns>True if processed.</returns>
        public bool ProcessMovedAsset(string toAssetPath, string fromAssetPath)
        {
            SetDefaultGroupTemplateIfNeeded();

            var toAddressablePath   = _addressablePathGenerateService.GenerateFromAssetPath(toAssetPath);
            var fromAddressablePath = _addressablePathGenerateService.GenerateFromAssetPath(fromAssetPath);

            var addressingMode    = _setting.BaseAddressingMode.Value;
            var packingMode       = _setting.BasePackingMode.Value;
            var groupTemplateGuid = _setting.GroupTemplateGuid.Value;

            if (!string.IsNullOrEmpty(toAddressablePath) && !string.IsNullOrEmpty(fromAddressablePath))
            {
                // Moving from the Addressables folder to the Addressables folder.
                // So, move the entry.
                var createOrMoveInfo = _entryOperationInfoBuildService.BuildEntryCreateOrMoveInfo(toAssetPath,
                                                                                                  addressingMode, packingMode, groupTemplateGuid, _rules);
                if (createOrMoveInfo == null)
                {
                    return(false);
                }

                var operationInfo = new EntryOperationInfo(createOrMoveInfo, null);
                return(_entryOperationInfoApplyService.Apply(operationInfo));
            }

            if (!string.IsNullOrEmpty(toAddressablePath) && string.IsNullOrEmpty(fromAddressablePath))
            {
                // Moving from the non-Addressables folder to the Addressables folder.
                // So, create the entry.
                var createOrMoveInfo = _entryOperationInfoBuildService.BuildEntryCreateOrMoveInfo(toAssetPath,
                                                                                                  addressingMode, packingMode, groupTemplateGuid, _rules);
                if (createOrMoveInfo == null)
                {
                    return(false);
                }

                var operationInfo = new EntryOperationInfo(createOrMoveInfo, null);
                return(_entryOperationInfoApplyService.Apply(operationInfo));
            }

            if (string.IsNullOrEmpty(toAddressablePath) && !string.IsNullOrEmpty(fromAddressablePath))
            {
                // Moving from the Addressables folder to the non-Addressables folder.
                // So, remove the entry.
                var removeInfo = _entryOperationInfoBuildService.BuildEntryRemoveInfo(toAssetPath);
                if (removeInfo == null)
                {
                    return(false);
                }

                var operationInfo = new EntryOperationInfo(null, removeInfo);
                return(_entryOperationInfoApplyService.Apply(operationInfo));
            }

            // Moving from the non-Addressables folder to the non-Addressables folder.
            // So, do nothing.
            return(false);
        }
        /// <summary>
        ///     Process a deleted asset.
        /// </summary>
        /// <param name="deletedAssetPath"></param>
        /// <returns>True if processed.</returns>
        public bool ProcessDeletedAsset(string deletedAssetPath)
        {
            SetDefaultGroupTemplateIfNeeded();

            var addressablePath = _addressablePathGenerateService.GenerateFromAssetPath(deletedAssetPath);

            if (string.IsNullOrEmpty(addressablePath))
            {
                return(false);
            }

            var removeInfo = _entryOperationInfoBuildService.BuildEntryRemoveInfo(deletedAssetPath);

            if (removeInfo == null)
            {
                return(false);
            }

            var operationInfo = new EntryOperationInfo(null, removeInfo);

            return(_entryOperationInfoApplyService.Apply(operationInfo));
        }
Example #6
0
        /// <summary>
        ///     Apply a <see cref="EntryOperationInfo" /> to the <see cref="AddressableAssetSettings" />.
        /// </summary>
        /// <param name="info"></param>
        /// <returns>True if processed.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public bool Apply(EntryOperationInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            Assert.IsFalse(info.CreateOrMoveInfo == null && info.RemoveInfo == null);

            var processed = false;

            if (info.CreateOrMoveInfo != null)
            {
                processed |= ApplyCreateOrMoveInfo(info.CreateOrMoveInfo);
            }

            if (info.RemoveInfo != null)
            {
                processed |= ApplyRemoveInfo(info.RemoveInfo);
            }

            return(processed);
        }